From 7de111b45234089eeca433c9ceba9566017beba5 Mon Sep 17 00:00:00 2001 From: Pascal Terjan Date: Mon, 2 Jan 2012 17:29:40 +0000 Subject: Append domain when sending emails to user --- lib/Iurt/Mail.pm | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'lib/Iurt/Mail.pm') diff --git a/lib/Iurt/Mail.pm b/lib/Iurt/Mail.pm index b805db2..6a9edb6 100644 --- a/lib/Iurt/Mail.pm +++ b/lib/Iurt/Mail.pm @@ -8,15 +8,35 @@ our @EXPORT = qw( sendmail ); +sub expand_email { + my($email, $config) = @_; + return $email unless $config->{email_domain}; + my $name = ""; + my $addr = $email; + if ($email =~ /^(.*)<(.*)>$/) { + $name = $1; + $addr = $2; + } + if ($addr =~ /@/) { + return $email; + } + return "$name<$addr\@$config->{email_domain}>"; +} + sub sendmail { - my ($to, $cc, $subject, $text, $from, $debug) = @_; + my ($to, $cc, $subject, $text, $from, $debug, $config) = @_; do { print "Cannot find sender-email-address [$to]\n"; return } unless defined($to); my $MAIL; if (!$debug) { open $MAIL, "| /usr/sbin/sendmail -t" or return } else { open $MAIL, ">&STDOUT" or return } + $to = expand_email($to, $config); my $sender = encode_mimewords($to); $subject = encode_mimewords($subject); print $MAIL "To: $sender\n"; - if ($cc) { $cc = encode_mimewords($cc); print $MAIL "Cc: $cc\n" } + if ($cc) { + $cc = expand_email($cc, $config); + $cc = encode_mimewords($cc); + print $MAIL "Cc: $cc\n" + } print $MAIL "From: $from\n"; print $MAIL "Subject: $subject\n"; print $MAIL "\n"; -- cgit v1.2.1