summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'extensions')
-rw-r--r--extensions/SecureMail/Extension.pm32
-rw-r--r--extensions/SecureMail/template/en/default/account/prefs/securemail.html.tmpl8
2 files changed, 36 insertions, 4 deletions
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 <mkanat@bugzilla.org>
#%]
+[% IF test_email_sent %]
+ <div id="message">
+ An encrypted test email has been sent to your address.
+ </div>
+[% END %]
+
<p>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 %].<
<textarea id="public_key" name="public_key" cols="72" rows="12">
[%- public_key FILTER html %]</textarea>
+
+<p>Submitting valid changes will automatically send an encrypted test email to your address.</p>