Implement some more environment variables and simplify test mode

This commit is contained in:
Jon Goldberg 2018-01-18 01:26:13 -05:00
parent 90d4ba62d0
commit 36576d043a
1 changed files with 7 additions and 4 deletions

View File

@ -13,6 +13,11 @@ $debugMode = getenv('DEBUG_MODE');
// Dry Run Mode will suppress sending an e-mail to Redmine. Only really useful with debug mode on.
$dryRun = getenv('DRY_RUN');
// Test addresses work normally, but tag the email subject with "[TEST]".
$test = getenv('TEST');
$deliveryAddress = getenv('DELIVERY_ADDRESS');
if($debugMode) {
error_reporting(E_ALL);
}
@ -41,7 +46,7 @@ while (!feof($fd)) {
//if this line is the "delivered-to", extract the subaddress, if there is one.
if(preg_match("/^delivered-to: (.*)/i", $line, $matches)) {
$deliveredTo = $matches[1];
if(preg_match("/support_mt.*\+(\S*)@/i", $deliveredTo, $matches)) {
if(preg_match("/$deliveryAddress.*\+(\S*)@/i", $deliveredTo, $matches)) {
$project = $matches[1];
}
}
@ -52,9 +57,7 @@ while (!feof($fd)) {
}
//Alter the Subject if this is a test.
$subjectAlterTo = substr($deliveredTo, 1, 12);
if(substr($deliveredTo, 1, 15) == 'support_mt_test' &&
preg_match("/^Subject:(.*)/i", $line)) {
if ($test && preg_match("/^Subject:(.*)/i", $line)) {
$line = $subject = str_replace('Subject: ', 'Subject: [TEST] ', $line);
}