From: Michael M Slusarz Date: Thu, 9 Sep 2010 21:48:34 +0000 (-0600) Subject: Update bounce spam script X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=462869755f981eb030aa7d8f67924ec904ebec8e;p=horde.git Update bounce spam script --- diff --git a/imp/scripts/bounce_spam.php b/imp/scripts/bounce_spam.php index 1c25e9077..dbd3c8756 100755 --- a/imp/scripts/bounce_spam.php +++ b/imp/scripts/bounce_spam.php @@ -20,31 +20,44 @@ */ require_once dirname(__FILE__) . '/../lib/Application.php'; -Horde_Registry::appInit('imp', array('authentication' => true, 'cli' => true)); +Horde_Registry::appInit('imp', array( + 'authentication' => false, + 'cli' => true +)); +/** Configuration **/ + +/** + * Location of the bounce template. + * The following strings will be replaced in the template: + * %TO% - The spammer's e-mail address. + * %TARGET% - The target's e-mail address. + */ $bounce_template = IMP_BASE . '/config/bounce.txt'; +/** End Configuration **/ + /* If there's no bounce template file then abort */ if (!file_exists($bounce_template)) { - exit(0); + $cli->fatal('Bounce template does not exist.'); } /* Read the message content. */ -$data = Horde_Cli::readStdin(); +$data = $cli->readStdin(); /* Who's the spammer? */ -preg_match('/return-path: <(.*?)>\r?\n/i', $data, $matches); -$return_path = $matches[1]; +$headers = Horde_Mime_Headers::parseHeaders($data); +$return_path = Horde_Mime_Address::bareAddress($headers->getValue('return-path')); /* Who's the target? */ -preg_match_all('/delivered-to: (.*?)\r?\n/is', $data, $matches); -$delivered_to = $matches[1][count($matches[1])-1]; +$delivered_to = Horde_Mime_Address::bareAddress($headers->getValue('delivered-to')); /* Read the bounce template and construct the mail */ -$bounce = file_get_contents($bounce_template); -$bounce = str_replace(array('%TO%', '%TARGET%'), - array($return_path, $delivered_to), - $bounce); +$bounce = str_replace( + array('%TO%', '%TARGET%'), + array($return_path, $delivered_to), + file_get_contents($bounce_template) +); /* Send the mail */ $sendmail = "/usr/sbin/sendmail -t -f ''";