Commit 037942d0 authored by Byron Jones's avatar Byron Jones

Bug 589128: Adds a preference allowing users to choose between text or html

for bugmail. r=LpSolit, a=LpSolit
parent 7ddff2f3
......@@ -3300,7 +3300,7 @@ sub comments {
my @comments = @{ $self->{'comments'} };
my $order = $params->{order}
|| Bugzilla->user->settings->{'comment_sort_order'}->{'value'};
|| Bugzilla->user->setting('comment_sort_order');
if ($order ne 'oldest_to_newest') {
@comments = reverse @comments;
if ($order eq 'newest_to_oldest_desc_first') {
......
......@@ -374,15 +374,13 @@ sub sendMail {
sub _generate_bugmail {
my ($user, $vars) = @_;
my $template = Bugzilla->template_inner($user->settings->{'lang'}->{'value'});
my $template = Bugzilla->template_inner($user->setting('lang'));
my ($msg_text, $msg_html, $msg_header);
$template->process("email/bugmail-header.txt.tmpl", $vars, \$msg_header)
|| ThrowTemplateError($template->error());
$template->process("email/bugmail.txt.tmpl", $vars, \$msg_text)
|| ThrowTemplateError($template->error());
$template->process("email/bugmail.html.tmpl", $vars, \$msg_html)
|| ThrowTemplateError($template->error());
my @parts = (
Email::MIME->create(
......@@ -390,19 +388,27 @@ sub _generate_bugmail {
content_type => "text/plain",
},
body => $msg_text,
),
Email::MIME->create(
)
);
if ($user->setting('email_format') eq 'html') {
$template->process("email/bugmail.html.tmpl", $vars, \$msg_html)
|| ThrowTemplateError($template->error());
push @parts, Email::MIME->create(
attributes => {
content_type => "text/html",
},
body => $msg_html,
),
);
}
# TT trims the trailing newline, and threadingmarker may be ignored.
my $email = new Email::MIME("$msg_header\n");
$email->parts_set(\@parts);
if (scalar(@parts) == 1) {
$email->content_type_set($parts[0]->content_type);
} else {
$email->content_type_set('multipart/alternative');
}
$email->parts_set(\@parts);
return $email;
}
......
......@@ -970,7 +970,7 @@ sub notify {
# use the default language for email notifications.
my $default_lang;
if (grep { !$_ } values %recipients) {
$default_lang = Bugzilla::User->new()->settings->{'lang'}->{'value'};
$default_lang = Bugzilla::User->new()->setting('lang');
}
foreach my $to (keys %recipients) {
......@@ -987,7 +987,7 @@ sub notify {
'threadingmarker' => build_thread_marker($bug->id, $thread_user_id) };
my $lang = $recipients{$to} ?
$recipients{$to}->settings->{'lang'}->{'value'} : $default_lang;
$recipients{$to}->setting('lang') : $default_lang;
my $template = Bugzilla->template_inner($lang);
my $message;
......
......@@ -90,6 +90,9 @@ sub SETTINGS {
timezone => { subclass => 'Timezone', default => 'local' },
# 2011-02-07 dkl@mozilla.com -- Bug 580490
quicksearch_fulltext => { options => ['on', 'off'], default => 'on' },
# 2011-06-21 glob@mozilla.com -- Bug 589128
email_format => { options => ['html', 'text_only'],
default => 'html' },
}
};
......
......@@ -142,7 +142,7 @@ sub quicksearch {
$searchstring =~ s/(^[\s,]+|[\s,]+$)//g;
ThrowUserError('buglist_parameters_required') unless ($searchstring);
$fulltext = Bugzilla->user->settings->{'quicksearch_fulltext'}->{'value'} eq 'on' ? 1 : 0;
$fulltext = Bugzilla->user->setting('quicksearch_fulltext') eq 'on' ? 1 : 0;
if ($searchstring =~ m/^[0-9,\s]*$/) {
_bug_numbers_only($searchstring);
......
......@@ -101,7 +101,7 @@ sub IssueEmailChangeToken {
# Mail the user the token along with instructions for using it.
my $template = Bugzilla->template_inner($user->settings->{'lang'}->{'value'});
my $template = Bugzilla->template_inner($user->setting('lang'));
my $vars = {};
$vars->{'oldemailaddress'} = $old_email . $email_suffix;
......@@ -144,7 +144,7 @@ sub IssuePasswordToken {
my ($token, $token_ts) = _create_token($user->id, 'password', remote_ip());
# Mail the user the token along with instructions for using it.
my $template = Bugzilla->template_inner($user->settings->{'lang'}->{'value'});
my $template = Bugzilla->template_inner($user->setting('lang'));
my $vars = {};
$vars->{'token'} = $token;
......@@ -292,7 +292,7 @@ sub Cancel {
$vars->{'cancelaction'} = $cancelaction;
# Notify the user via email about the cancellation.
my $template = Bugzilla->template_inner($user->settings->{'lang'}->{'value'});
my $template = Bugzilla->template_inner($user->setting('lang'));
my $message;
$template->process("account/cancel-token.txt.tmpl", $vars, \$message)
......
......@@ -593,11 +593,16 @@ sub settings {
return $self->{'settings'};
}
sub setting {
my ($self, $name) = @_;
return $self->settings->{$name}->{'value'};
}
sub timezone {
my $self = shift;
if (!defined $self->{timezone}) {
my $tz = $self->settings->{timezone}->{value};
my $tz = $self->setting('timezone');
if ($tz eq 'local') {
# The user wants the local timezone of the server.
$self->{timezone} = Bugzilla->local_timezone;
......@@ -2241,6 +2246,10 @@ value - the value of this setting for this user. Will be the same
is_default - a boolean to indicate whether the user has chosen to make
a preference for themself or use the site default.
=item C<setting(name)>
Returns the value for the specified setting.
=item C<timezone>
Returns the timezone used to display dates and times to the user,
......
......@@ -806,7 +806,7 @@ sub _remove_votes {
};
my $voter = new Bugzilla::User($userid);
my $template = Bugzilla->template_inner($voter->settings->{'lang'}->{'value'});
my $template = Bugzilla->template_inner($voter->setting('lang'));
my $msg;
$template->process("voting/votes-removed.txt.tmpl", $vars, \$msg);
......
......@@ -189,7 +189,7 @@ $vars->{'title_tag'} = "bug_processed";
my $action;
if (defined $cgi->param('id')) {
$action = $user->settings->{'post_bug_submit_action'}->{'value'};
$action = $user->setting('post_bug_submit_action');
if ($action eq 'next_bug') {
my $bug_list_obj = $user->recent_search_for($first_bug);
......
......@@ -164,7 +164,7 @@ elsif ($action eq 'begin-sudo') {
# Go ahead and send out the message now
my $message;
my $mail_template = Bugzilla->template_inner($target_user->settings->{'lang'}->{'value'});
my $mail_template = Bugzilla->template_inner($target_user->setting('lang'));
$mail_template->process('email/sudo.txt.tmpl', { reason => $reason }, \$message);
MessageToMTA($message);
......
......@@ -76,7 +76,7 @@ my $dbh = Bugzilla->dbh;
# take the user prefs into account rather than querying the web browser.
my $template;
if (Bugzilla->usage_mode == USAGE_MODE_CMDLINE) {
$template = Bugzilla->template_inner($user->settings->{'lang'}->{'value'});
$template = Bugzilla->template_inner($user->setting('lang'));
}
else {
$template = Bugzilla->template;
......
......@@ -49,6 +49,9 @@
"timezone" => "Timezone used to display dates and times",
"local" => "Same as the server",
"quicksearch_fulltext" => "Include comments when performing quick searches (slower)",
"email_format" => "Preferred email format",
"html" => "HTML",
"text_only" => "Text Only",
}
%]
......
......@@ -367,7 +367,7 @@ sub mail {
# Don't send mail to someone whose bugmail notification is disabled.
return if $addressee->email_disabled;
my $template = Bugzilla->template_inner($addressee->settings->{'lang'}->{'value'});
my $template = Bugzilla->template_inner($addressee->setting('lang'));
my $msg = ''; # it's a temporary variable to hold the template output
$args->{'alternatives'} ||= [];
......
......@@ -88,7 +88,7 @@ foreach my $email (sort (keys %bugs)) {
$vars->{'bugs'} = \@bugs;
my $msg;
my $template = Bugzilla->template_inner($user->settings->{'lang'}->{'value'});
my $template = Bugzilla->template_inner($user->setting('lang'));
$template->process("email/whine.txt.tmpl", $vars, \$msg)
or die($template->error());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment