Penguin
Blame: EximBounceProcessing
EditPageHistoryDiffInfoLikePages
Annotated edit history of EximBounceProcessing version 1, including all changes. View license author blame.
Rev Author # Line
1 MikeBordignon 1 This consists of 3 parts;
2
3 * Exim config change
4 * PHP script to process bounces
5 * A change to the From: header from which you send email
6
7 The config change is as follows;
8
9 <verbatim>
10 /etc/exim4/virtualDomains/<domain> (or however you've setup your virtual domains)
11
12 ^bounce.*:|/var/bounce_processing.php
13 </verbatim>
14
15 I also needed to change my Exim config to allow regexp in an alias, as per http://www.acmelabs.co.uk/?p=4
16
17 <verbatim>
18 /etc/exim4/conf.d/router/400_exim4-config_system_aliases:
19
20 data = ${lookup{$local_part}lsearch{/etc/aliases}}
21 </verbatim>
22 becomes
23 <verbatim>
24 data = ${lookup{$local_part}wildlsearch{/etc/aliases}}
25 </verbatim>
26
27 The PHP script is as follows;
28
29 <verbatim>
30 #!/usr/bin/php
31
32 <?php
33
34 /*
35 *** Script to process bounces
36
37 Mike Bordignon
38 16 Jan 2009
39 */
40
41 require('bounce_dbconn.php');
42
43
44 # Get stdin
45
46 $fp = fopen('php://stdin', 'r');
47 while ( !feof($fp) ) { $buff .= fread($fp, 4096); }
48 fclose($fp);
49 unset($fp);
50 $email_data = $buff;
51 unset($buff);
52 $email_data2 = explode(chr(10), $email_data);
53
54 foreach ($email_data2 as $v) {
55
56 // Find to address
57 if ( substr($v, 0, 10) == 'To: bounce' ) {
58
59 list(, $email) = explode(':', $v);
60 list($mailbox, $domain) = explode('@', $email);
61 list(, $bounce_id_sha) = explode('+', $mailbox);
62
63 $q = "SELECT id FROM addresses WHERE sha1Hash = '$bounce_id_sha'";
64 $r = mysql_query($q) or die(mysql_error());
65 if ( !mysql_num_rows($r) ) { break; }
66 else { $data = mysql_fetch_array($r); $bounce_id = $data['id']; }
67
68 mysql_select_db('database');
69 $q = "UPDATE addresses SET active = 0 WHERE id = $bounce_id";
70 mysql_query($q);
71
72 break;
73
74 }
75
76 }
77 </verbatim>
78
79 You'll obviously need to send your emails from a different From: address to identify them in the event they bounce. I use bounce+<sha1 or similar hash>@domain.co.nz. To create the hash I've used the database id concatenated with a secret.