aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Kangas <skangas@skangas.se>2011-03-21 22:24:24 +0100
committerStefan Kangas <skangas@skangas.se>2011-03-21 22:24:24 +0100
commit7a522692d79d68d276fad9edf233530f68dadb7e (patch)
tree1b40f56a2cd8691817c07d2350320880b5a68a29
parent701456b6047b1d698ee3a8173249afaf2679e20f (diff)
Send confirmation when adding new alias
-rwxr-xr-xfripost-adduser2
-rwxr-xr-xfripost-newalias57
-rw-r--r--templ/new_alias.tt12
3 files changed, 60 insertions, 11 deletions
diff --git a/fripost-adduser b/fripost-adduser
index e96c5f3..b72ae30 100755
--- a/fripost-adduser
+++ b/fripost-adduser
@@ -113,7 +113,7 @@ $msg->attr('content-type.charset' => 'utf-8');
$msg->replace(To => $user->{username});
unless ($conf->{pretend}) {
- $msg->send() unless $conf->{pretend};;
+ $msg->send() unless $conf->{pretend};
say "Sent welcome message.";
}
dsay "-----------------------------------";
diff --git a/fripost-newalias b/fripost-newalias
index fb9acec..ecfa4bf 100755
--- a/fripost-newalias
+++ b/fripost-newalias
@@ -1,8 +1,9 @@
#!/usr/bin/perl
use 5.010_000;
-use warnings;
use strict;
+use warnings;
+use utf8;
=head1 NAME
@@ -18,13 +19,17 @@ fripost-newalias GOTO FROM...
use FindBin qw($Bin);
use lib "$Bin/lib";
-use Data::Dumper;
+use Encode qw(encode);
use Email::Valid;
use Fripost::Password;
use Fripost::Prompt;
use Fripost::Schema;
use IO::Prompt;
use Getopt::Long;
+use MIME::Base64;
+use MIME::Lite;
+use MIME::QuotedPrint;
+use Template;
use YAML::Syck;
## Get command line options
@@ -48,11 +53,6 @@ my @addr = @ARGV;
$goto //= prompt_username("Alias goto address: ");
@addr || push @addr, prompt "Alias address: ";
-if ($conf->{pretend}) {
- say "Nothing to do since we are pretending...";
- exit 0;
-}
-
# Show goto adress
say "goto adress: $goto";
@@ -84,15 +84,52 @@ for my $addr (@addr) {
goto => $goto,
domain => (split /\@/, $addr)[1],
});
- $db_alias->insert;
-
- say "New alias added from $addr to $goto.";
+ if (!$conf->{pretend}) {
+ $db_alias->insert;
+ say "New alias added from $addr to $goto.";
+ } else {
+ say "Pretending, will not add alias."
+ }
}
else {
say "There already exists an alias for $addr.";
}
}
+### Prepare sending emails
+my $tt = Template->new({
+ INCLUDE_PATH => "$Bin/templ",
+ INTERPOLATE => 1,
+}) || die "$Template::ERROR\n";
+
+my $msg = MIME::Lite->new(
+ From => encode('MIME-Q', 'Friposts administratörer') . ' <admin@fripost.org>',
+ Subject => encode('MIME-Q', 'Nya alias till din inkorg'),
+ Encoding => 'quoted-printable',
+);
+
+{
+ my ($vars, $data);
+ $vars = {
+ addrs => \@addr,
+ };
+
+ $tt->process('new_alias.tt', $vars, \$data)
+ || die $tt->error(), '\n';
+ $msg->data($data);
+
+ $msg->replace(To => $goto);
+
+ if (!$conf->{pretend}) {
+ confirm_or_abort("Send confirmation? ");
+ $msg->send;
+ say "Sent verification.";
+ }
+ else {
+ say "Pretending, will not send verification.";
+ }
+}
+
=head1 AUTHOR
Stefan Kangas C<< <skangas at skangas.se> >>
diff --git a/templ/new_alias.tt b/templ/new_alias.tt
new file mode 100644
index 0000000..969e6ad
--- /dev/null
+++ b/templ/new_alias.tt
@@ -0,0 +1,12 @@
+Hej,
+
+Följande adresser går nu till den här inkorgen:
+
+[% FOREACH addr IN addrs -%]
+ [% addr %]
+[% END -%]
+
+Hör av dig om något är fel eller annars är oklart.
+
+Med vänliga hälsningar,
+Administratörerna