From 3ea72a56c5bab10fa9d484e0a4c9e343163b7228 Mon Sep 17 00:00:00 2001 From: Dave Lawrence Date: Thu, 22 Mar 2012 01:53:10 -0400 Subject: Bug 656537 - automatically send a test email when a certificate is uploaded or changed via the securemail preferences tab r=glob --- extensions/SecureMail/Extension.pm | 32 +++++++++++++++++++--- .../en/default/account/prefs/securemail.html.tmpl | 8 ++++++ 2 files changed, 36 insertions(+), 4 deletions(-) (limited to 'extensions') diff --git a/extensions/SecureMail/Extension.pm b/extensions/SecureMail/Extension.pm index 4e1bbf237..5abc1eeb1 100644 --- a/extensions/SecureMail/Extension.pm +++ b/extensions/SecureMail/Extension.pm @@ -28,6 +28,8 @@ use Bugzilla::Object; use Bugzilla::User; use Bugzilla::Util qw(correct_urlbase trim trick_taint); use Bugzilla::Error; +use Bugzilla::Mailer; + use Crypt::OpenPGP::Armour; use Crypt::OpenPGP::KeyRing; use Crypt::OpenPGP; @@ -153,6 +155,7 @@ sub user_preferences { my $save = $args->{'save_changes'}; my $handled = $args->{'handled'}; my $vars = $args->{'vars'}; + my $params = Bugzilla->input_params; return unless $tab eq 'securemail'; @@ -161,9 +164,14 @@ sub user_preferences { my $user = new Bugzilla::User(Bugzilla->user->id); if ($save) { - my $public_key = Bugzilla->input_params->{'public_key'}; - $user->set('public_key', $public_key); + $user->set('public_key', $params->{'public_key'}); $user->update(); + + # Send user a test email + if ($user->{'public_key'}) { + _send_test_email($user); + $vars->{'test_email_sent'} = 1; + } } $vars->{'public_key'} = $user->{'public_key'}; @@ -173,6 +181,21 @@ sub user_preferences { $$handled = 1; } +sub _send_test_email { + my ($user) = @_; + my $template = Bugzilla->template_inner($user->settings->{'lang'}->{'value'}); + + my $vars = { + to_user => $user->email, + }; + + my $msg = ""; + $template->process("account/email/securemail-test.txt.tmpl", $vars, \$msg) + || ThrowTemplateError($template->error()); + + MessageToMTA($msg); +} + ############################################################################## # Encrypting the email ############################################################################## @@ -186,8 +209,9 @@ sub mailer_before_send { # what sort a particular email is. my $is_bugmail = $email->header('X-Bugzilla-Status'); my $is_passwordmail = !$is_bugmail && ($email->body =~ /cfmpw.*cxlpw/s); - - if ($is_bugmail || $is_passwordmail) { + my $is_test_email = $email->header('X-Bugzilla-Type') =~ /securemail-test/ ? 1 : 0; + + if ($is_bugmail || $is_passwordmail || $is_test_email) { # Convert the email's To address into a User object my $login = $email->header('To'); my $emailsuffix = Bugzilla->params->{'emailsuffix'}; diff --git a/extensions/SecureMail/template/en/default/account/prefs/securemail.html.tmpl b/extensions/SecureMail/template/en/default/account/prefs/securemail.html.tmpl index c71ea902e..db595a23f 100644 --- a/extensions/SecureMail/template/en/default/account/prefs/securemail.html.tmpl +++ b/extensions/SecureMail/template/en/default/account/prefs/securemail.html.tmpl @@ -17,6 +17,12 @@ # Contributor(s): Max Kanat-Alexander #%] +[% IF test_email_sent %] +
+ An encrypted test email has been sent to your address. +
+[% END %] +

Some [% terms.bugs %] in this [% terms.Bugzilla %] are in groups the administrator has deemed 'secure'. This means emails containing information about those [% terms.bugs %] will only be sent encrypted. Enter your PGP/GPG public key or @@ -30,3 +36,5 @@ SMIME certificate here to receive full update emails for such [% terms.bugs %].< + +

Submitting valid changes will automatically send an encrypted test email to your address.

-- cgit v1.2.3-24-g4f1b