From 275a0cf6d7b1ef35e8a4cfc69988f15bdf5049c4 Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Mon, 4 Sep 2006 23:54:28 +0000 Subject: Add script to send emails to user (hardcoded for use with kaospilot.no for now) --- localinformuser | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 localinformuser (limited to 'localinformuser') diff --git a/localinformuser b/localinformuser new file mode 100755 index 0000000..41098a8 --- /dev/null +++ b/localinformuser @@ -0,0 +1,76 @@ +#!/usr/bin/perl -wT + +use strict; + +use LWP::Simple; +use User::pwent; +use User::grent; +use Mail::Sendmail; + +sub getmailbody($;$) { + my $info = shift; + my $lang = shift || 'en'; + + my $baseurl = "http://support.kaospilot.no/"; + my $url = $baseurl . $info . "/email." . $lang . ".txt"; + + my $mailbody = get($url) || die "Couldn't get email content from <$url>."; + + return ($mailbody); +} + +sub getuserinfo($) { + my $username = shift; + + my $pw = getpwnam($username) || die "Username \"$username\" does not exist."; + + my ($fullname, $office, $workphone, $homephone, $other) = split /\s*,\s*/, $pw->gecos; + my @addresshints; + if (defined($other)) { + @addresshints = grep {/^([\.[:alnum:]_-]+|\+)?@([\.[:alnum:]_-]+)?$/} split /\s+/, $other; + } + + return ($fullname, @addresshints); +} + +my $mailbody = getmailbody("intro", "da"); + +while (my $username = shift @ARGV) { + + my ($fullname, @addresses) = getuserinfo($username); + my $localaddress = "$username\@users.kaospilot.no"; + + my %mail = ( + To => join(", ", grep {/^[\.[:alnum:]_-]+@[\.[:alnum:]_-]+\.[[:alnum:]_-]+$/} @addresses), + Cc => $username . '@users.kaospilot.no', + From => 'jonas@kaospilot.no', + Bcc => 'hostmaster@kaospilot.no', + 'Reply-to' => 'teknik@lists.kaospilot.no', + Subject => "Din konto ved kaospilot.no", + 'Content-Type' => 'text/plain; charset="UTF-8"' + ); + + $mail{'body'} = $mailbody; + $mail{'body'} =~ s//$fullname/g; + $mail{'body'} =~ s//$username/g; + $mail{'body'} =~ s//$localaddress/g; + $mail{'body'} =~ s//Jonas Smedegaard/g; + + sendmail(%mail) or do { + warn 'Error sending request: ' . $Mail::Sendmail::error; + } +#DEBUG warn "Request forwarded to Mailman. Log says:\n", $Mail::Sendmail::log; + +} + +__END__ + +my $valid_email = '/^[+_A-Za-z0-9-]+(\.[+_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(\.[_A-Za-z0-9-]+)$/'; + +# Mail functions require this for tainted mode +$ENV{PATH} = '/tmp'; + +my ($from, $mailname, $action, $subject, $infostring, $errors); + +warn $ARGV[0]; + -- cgit v1.2.3