forked from horde/imp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimp-bounce-spam
executable file
·77 lines (67 loc) · 2.2 KB
/
imp-bounce-spam
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env php
<?php
/**
* This script bounces a message back to the sender and can be used with IMP's
* spam reporting feature to bounce spam.
*
* It takes the orginal message from standard input and requires the bounce
* message in the file imp/config/bounce.txt. Important: the bounce message
* must be a complete message including headers!
*
* Copyright 2005-2017 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @author Jan Schneider <[email protected]>
* @category Horde
* @license http://www.horde.org/licenses/gpl GPL
* @package IMP
*/
$baseFile = __DIR__ . '/../lib/Application.php';
if (file_exists($baseFile)) {
require_once $baseFile;
} else {
require_once 'PEAR/Config.php';
require_once PEAR_Config::singleton()
->get('horde_dir', null, 'pear.horde.org') . '/imp/lib/Application.php';
}
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 (!is_readable($bounce_template)) {
$cli->fatal('Bounce template does not exist.');
}
/* Read the message content. */
$data = $cli->readStdin();
/* Who's the spammer? */
$headers = Horde_Mime_Headers::parseHeaders($data);
$return_path = ($h = $headers['return-path'])
? $h->getAddressList(true)->first()->bare_address
: '';
/* Who's the target? */
$delivered_to = ($h = $headers['delivered-to'])
? $h->getAddressList(true)->first()->bare_address
: '';
/* Read the bounce template and construct the mail */
$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 ''";
$fd = popen($sendmail, 'w');
fputs($fd, preg_replace("/\n$/", "\r\n", $bounce . $data));
pclose($fd);