From 36576d043aec04f43d7a22bf67c6a81c488773fc Mon Sep 17 00:00:00 2001 From: Jon Goldberg Date: Thu, 18 Jan 2018 01:26:13 -0500 Subject: [PATCH] Implement some more environment variables and simplify test mode --- redirect.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/redirect.php b/redirect.php index ab116af..0cd5667 100755 --- a/redirect.php +++ b/redirect.php @@ -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); }