aboutsummaryrefslogtreecommitdiffstats
path: root/fripost-newalias
diff options
context:
space:
mode:
authorGustav Eek <gustav.eek@fripost.org>2011-05-14 13:41:47 +0200
committerGustav Eek <gustav.eek@fripost.org>2011-05-14 13:41:47 +0200
commite14bd8eea4ad519e36a56dc868ed2e9effe1295e (patch)
tree1f4e6441be3602fa596b8564cc893b464580c503 /fripost-newalias
parent16ed1260dd2433d9c25cd550a06c175093416f58 (diff)
parentab34b78c7b247436a3d10d89b5f029fbe093ffe5 (diff)
Merge branch 'master' of https://github.com/skangas/fripost-tools
Diffstat (limited to 'fripost-newalias')
-rwxr-xr-xfripost-newalias61
1 files changed, 49 insertions, 12 deletions
diff --git a/fripost-newalias b/fripost-newalias
index fb9acec..4592522 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
@@ -45,13 +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: ";
-
-if ($conf->{pretend}) {
- say "Nothing to do since we are pretending...";
- exit 0;
-}
+$goto //= prompt_email("Alias goto address: ", 'is_user');
+@addr || push @addr, prompt "Alias from address: ";
# 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> >>