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/Config.pm | 5 ++--- lib/Iurt/DKMS.pm | 2 +- lib/Iurt/Mail.pm | 24 ++++++++++++++++++++++-- lib/Iurt/Process.pm | 8 ++++---- 4 files changed, 29 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/Iurt/Config.pm b/lib/Iurt/Config.pm index 7093d1d..2005542 100644 --- a/lib/Iurt/Config.pm +++ b/lib/Iurt/Config.pm @@ -239,9 +239,8 @@ sub get_maint { } my $maint = `GET 'http://maintdb.mageia.org/$srpm_name'`; chomp $maint; - my $email_maint = $maint . '@mageia.org'; - $run->{maint}{$srpm} = $email_maint; - $email_maint, $srpm_name; + $run->{maint}{$srpm} = $maint; + $maint, $srpm_name; } sub get_author_email { diff --git a/lib/Iurt/DKMS.pm b/lib/Iurt/DKMS.pm index 7410008..868770c 100644 --- a/lib/Iurt/DKMS.pm +++ b/lib/Iurt/DKMS.pm @@ -262,7 +262,7 @@ sub dkms_compile { "Modules for $name have been built for the current kernel ($kerver) while they should have been build for $modulesdir.", "Please report to the maintainer of $name", )), - "Iurt the rebuild bot <$config->{admin}>", 0); + "Iurt the rebuild bot <$config->{admin}>", 0, $config); next; } 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"; diff --git a/lib/Iurt/Process.pm b/lib/Iurt/Process.pm index ff95428..88aa544 100644 --- a/lib/Iurt/Process.pm +++ b/lib/Iurt/Process.pm @@ -234,7 +234,7 @@ sub perform_command { sendmail($config->{admin}, '' , "$opt{hash} on $run->{my_arch} for $run->{media}: broken pipe", "$comment\n$output", "Iurt the build bot <$config->{admin}>", - $opt{debug_mail}); + $opt{debug_mail}, $config); } else { if ($opt{type} eq 'shell') { $comment = "Command failed: $command\n"; @@ -255,7 +255,7 @@ sub perform_command { } plog('ERR', "ERROR: $wr !"); - sendmail($config->{admin}, '' , "$opt{hash} on $run->{my_arch} for $run->{media}: could not proceed", "$wr\n\n$comment\n$output", "Iurt the rebuild bot <$config->{admin}>", $opt{debug_mail}) if $opt{wait_mail}; + sendmail($config->{admin}, '' , "$opt{hash} on $run->{my_arch} for $run->{media}: could not proceed", "$wr\n\n$comment\n$output", "Iurt the rebuild bot <$config->{admin}>", $opt{debug_mail}, $config) if $opt{wait_mail}; } } } @@ -287,9 +287,9 @@ sub perform_command { if ($opt{mail} && $config->{sendmail} && !$config->{no_mail}{$opt{mail}}) { if (! ($cache->{warning}{$opt{hash}}{$opt{mail}} % $opt{freq})) { my $cc = join ',', grep { !$config->{no_mail}{$_} } split ',', $opt{cc}; - sendmail($opt{mail}, $cc, $opt{error} , "$comment\n$out", "Iurt the rebuild bot <$config->{admin}>", $opt{debug_mail}); + sendmail($opt{mail}, $cc, $opt{error} , "$comment\n$out", "Iurt the rebuild bot <$config->{admin}>", $opt{debug_mail}, $config); } elsif ($config->{admin}) { - sendmail($config->{admin}, '' , $opt{error}, "$comment\n$out", "Iurt the rebuild bot <$config->{admin}>", $opt{debug_mail}); + sendmail($config->{admin}, '' , $opt{error}, "$comment\n$out", "Iurt the rebuild bot <$config->{admin}>", $opt{debug_mail}, $config); } } $cache->{warning}{$opt{hash}}{$opt{mail}}++; -- cgit v1.2.1