Skip to content

Commit de0ccdf

Browse files
committed
[deploy-vhost] Allow multiple emails in crontab MAILTO
Cron permits a comma-separated list of emails in MAILTO, so we should support this too. The change will warn if none of the addresses are external.
1 parent 8b7b0ca commit de0ccdf

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

bin/deploy-vhost

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -950,17 +950,22 @@ sub install_or_remove_crontab {
950950
open CRON, $tmp_crontab or die "can't open $tmp_crontab: $!";
951951
while (<CRON>) {
952952
if (/^MAILTO=(.*)$/) {
953-
system("/data/mysociety/bin/lookup_google_apps_email.sh $1");
954-
my $result = $? >> 8;
955-
if ($result == 1) {
956-
unlink $tmp_crontab;
957-
die "MAILTO=$1: not a valid address in crontab";
958-
} elsif ($result == 2) {
959-
warn "Google Apps API not working; can't check MAILTO address";
960-
} elsif ($result != 0) {
961-
warn "unexpected result code $result from lookup_google_apps_email.sh";
953+
my $found_external;
954+
foreach my $mailto (split(',', $1)) {
955+
next if $mailto =~ /\@${hostname}/;
956+
$found_external = 1;
957+
system("/data/mysociety/bin/lookup_google_apps_email.sh $mailto");
958+
my $result = $? >> 8;
959+
if ($result == 1) {
960+
unlink $tmp_crontab;
961+
die "MAILTO=$mailto: not a valid address in crontab";
962+
} elsif ($result == 2) {
963+
warn "Google Apps API not working; can't check MAILTO address";
964+
} elsif ($result != 0) {
965+
warn "unexpected result code $result from lookup_google_apps_email.sh";
966+
}
962967
}
963-
968+
warn "No external email found in MAILTO" unless ($found_external);
964969
last;
965970
}
966971
}

0 commit comments

Comments
 (0)