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