From 7a522692d79d68d276fad9edf233530f68dadb7e Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 21 Mar 2011 22:24:24 +0100 Subject: Send confirmation when adding new alias --- fripost-newalias | 57 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 10 deletions(-) (limited to 'fripost-newalias') 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') . ' ', + 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<< >> -- cgit v1.2.3 From c7701570975feab6dd268802c6f552381d691529 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Mon, 21 Mar 2011 22:31:02 +0100 Subject: Updates --- fripost-newalias | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'fripost-newalias') diff --git a/fripost-newalias b/fripost-newalias index ecfa4bf..4592522 100755 --- a/fripost-newalias +++ b/fripost-newalias @@ -50,8 +50,8 @@ my $schema = Fripost::Schema->connect( # Get information my $goto = fix_username(shift @ARGV); my @addr = @ARGV; -$goto //= prompt_username("Alias goto address: "); -@addr || push @addr, prompt "Alias address: "; +$goto //= prompt_email("Alias goto address: ", 'is_user'); +@addr || push @addr, prompt "Alias from address: "; # Show goto adress say "goto adress: $goto"; -- cgit v1.2.3