diff options
author | Pascal Terjan <pterjan@mageia.org> | 2012-01-02 17:29:40 +0000 |
---|---|---|
committer | Pascal Terjan <pterjan@mageia.org> | 2012-01-02 17:29:40 +0000 |
commit | 7de111b45234089eeca433c9ceba9566017beba5 (patch) | |
tree | c9c789f21e5820ed8ab67199be1f8eaff61cb52d /lib/Iurt/Mail.pm | |
parent | 8e112e04c1dbdbe2721f24621532bddb4eeafa26 (diff) | |
download | iurt-7de111b45234089eeca433c9ceba9566017beba5.tar iurt-7de111b45234089eeca433c9ceba9566017beba5.tar.gz iurt-7de111b45234089eeca433c9ceba9566017beba5.tar.bz2 iurt-7de111b45234089eeca433c9ceba9566017beba5.tar.xz iurt-7de111b45234089eeca433c9ceba9566017beba5.zip |
Append domain when sending emails to user
Diffstat (limited to 'lib/Iurt/Mail.pm')
-rw-r--r-- | lib/Iurt/Mail.pm | 24 |
1 files changed, 22 insertions, 2 deletions
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"; |