Guest User

Untitled

a guest
Jan 30th, 2018
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. bounce_notice_recipient = someone@nowhere.com
  2. error_notice_recipient = someone@nowhere.com
  3.  
  4. someone: /dev/null
  5.  
  6. <?php
  7. #parse_logs.php
  8. # load local file into array
  9. $val = file("mail.log");
  10.  
  11. $pattern = '/status=bounced/';
  12.  
  13. foreach ($val as &$value) {
  14. if (preg_match($pattern,$value)) {
  15. $a = split('[<>]', $value);
  16.  
  17. //if you prefer you can also use: preg_match_all('/<(.*)>/', '$value', $matches);
  18. #can be helpful to print the following to the screen during tests
  19. # echo $a[1];
  20.  
  21. // Make a MySQL Connection
  22. mysql_connect("localhost", "username", "password") or die(mysql_error());
  23. mysql_select_db("postfix_db") or die(mysql_error());
  24.  
  25. // Insert a row of information into the table "example"
  26. mysql_query("INSERT INTO emails (emailaddress) VALUES('$a[1]') ")
  27. or die(mysql_error());
  28.  
  29. #again, if you want to see while running manually from cli
  30. #echo "Data Inserted!";
  31.  
  32. }
  33. #again, if you want to see while running manually from cli
  34. #echo "n";
  35. }
  36.  
  37. ?>
  38.  
  39. php parse.php > results.txt
  40.  
  41. php parse_logs.php | /usr/sbin/sendmail someemailaddress@nowhere.com
  42.  
  43. notify_classes = bounce, 2bounce, resource, software
  44. 2bounce_notice_recipient=bouncepipe@example.com
  45. bounce_notice_recipient=bouncepipe@example.com
  46.  
  47. bouncepipe@example.com bouncepipe:
  48.  
  49. bouncepipe unix - n n - - pipe
  50. flags=DRhu user=list argv=/etc/postfix/bouncepipe.pl
  51.  
  52. #!/usr/bin/perl
  53.  
  54. my $message = '';
  55. my $sender = '';
  56. my $recipient = '';
  57.  
  58. foreach $line ( <STDIN> )
  59. {
  60. $message .= $line;
  61. chomp( $line );
  62. if ( $line =~ /Final-Recipient: /)
  63. {
  64. my $index = index($line, ';');
  65. $recipient = substr($line, $index+2);
  66. }
  67. if ( $line =~ /X-Postfix-Sender: /)
  68. {
  69. my $index = index($line, ';');
  70. $sender = substr($line, $index+2);
  71. }
  72. }
  73. # Do whatever you need to do with $sender and $recipient
Add Comment
Please, Sign In to add comment