*/
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 ''";