]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 589128: Adds a preference allowing users to choose between text or html
authorByron Jones <bjones@mozilla.com>
Mon, 25 Jul 2011 14:16:26 +0000 (22:16 +0800)
committerByron Jones <bjones@mozilla.com>
Mon, 25 Jul 2011 14:16:26 +0000 (22:16 +0800)
for bugmail.
r=LpSolit, a=LpSolit

14 files changed:
Bugzilla/Bug.pm
Bugzilla/BugMail.pm
Bugzilla/Flag.pm
Bugzilla/Install.pm
Bugzilla/Search/Quicksearch.pm
Bugzilla/Token.pm
Bugzilla/User.pm
extensions/Voting/Extension.pm
process_bug.cgi
relogin.cgi
sanitycheck.cgi
template/en/default/global/setting-descs.none.tmpl
whine.pl
whineatnews.pl

index 2ab4a6bffa5e8bb34beec23f63ba4c6c895be0a4..bf4529f6fc2ef121a06d71c7291cb9fc50ab6f87 100644 (file)
@@ -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') {
index 03eb1925d41a9421e24e6f98a725cfa2d113263d..55eeeab25e97a081525aea09311a9961cd63f7f5 100644 (file)
@@ -374,35 +374,41 @@ 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(
             attributes => {
                 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");
+    if (scalar(@parts) == 1) {
+        $email->content_type_set($parts[0]->content_type);
+    } else {
+        $email->content_type_set('multipart/alternative');
+    }
     $email->parts_set(\@parts);
-    $email->content_type_set('multipart/alternative');
     return $email;
 }
 
index e8d30bd206d6e71bb94e048d71a62518d5401ed5..a4b5a026aeba0c878085d02d492bedcb46f75445 100644 (file)
@@ -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;
index 808a5069843e6e185c866fa267471345b2603d01..ce8fe6bad8c385a72c9fc0a67b25fdcbdfdf3a17 100644 (file)
@@ -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' },
     }
 };
 
index 25850a378b08fe7abce27b45287b6f3dab3fc5a5..8425a2be2aed9262591214de1a7f2fd08b432fbd 100644 (file)
@@ -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);
index e15991f370d489ac06a88a9b4e4798c2c897ad11..69751e9057e94d4176b1c9ac671a1e9aee3de7ab 100644 (file)
@@ -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)
index d21314604a3e2f8b803bf61280f4a08fcd5dc734..1884322414a676265028460a8ac6c0711e416470 100644 (file)
@@ -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,
index 8417e0ec3579acb393df4dcad73d6094f2b68e92..8a786e6597ee9ff89775caf93b64c689545ab597 100644 (file)
@@ -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);
index 0d57bfcfea6870490f4314ec8ed49978348bf6a5..0348424faef1498ecbf0d410b3c131e6a8691706 100755 (executable)
@@ -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);
index f6a410c050574f42e7a3ef42f71ab882c628aff9..07796f9f69aee6c007075c92497416b3e15fa897 100755 (executable)
@@ -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);
 
index 6bf113b24888ea58f9b5018b6d1bcff2ee65e46b..7d530ea4bef2a05d05acc3e564ce4a5622bca4f6 100755 (executable)
@@ -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;
index 54683b3603348f3e5bf57abe582578b92983e5bf..a0b11f0487d2ed76adfa56f24ca312056b0803c7 100644 (file)
@@ -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",
                    } 
 %]
 
index 872061fb65a21620cf2e863cfb048538d6c4de0e..7b8809c25b81b8aafbd9af6f0f11e029f0c20463 100755 (executable)
--- a/whine.pl
+++ b/whine.pl
@@ -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'} ||= [];
 
index 19b0e44fc642571eabb50c8a11a9bc9b26547331..3bfe298714ab7b657b952bae7d7cff5d3582102c 100755 (executable)
@@ -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());