# There is ruby script which uses simsai to parse bounce mails

IMPORTANT NOTES:

1. Script file bounce_wrapper.sh should be under /etc/mail/smrsh with below permission. Same goes for bounce.rb
   -rwxr-xr-x 1 root  smmsp  979 Jul 13 18:09 ruby_wrapper.sh
2. It is done in ruby because at the time sisimai is a good ruby library which parses the bounce emails
3. Alias should be under /etc/mail/aliases with the following line
   `www-data: "|/etc/mail/smrsh/bounce_wrapper.sh /etc/mail/smrsh/bounce.rb /home/sagar/.rvm test", sagar.kumar@CRUWorldWine.onmicrosoft.com`
4. Both files, ruby and sh files should be executable, otherwise you will get mailer error 126 in /etc/syslog.
5. Log file for the script should be under /var/mail becuase only mail can write and the script run as mail user `logfile = '/var/mail/log_file.txt'`
6. It works as follows: all the bounce mails goes through www-data user, so we make alias on the server level (sendmail) which redirects it to script /etc/mail/smrsh/bounce_wrapper.sh and since we also want to receive to a email for inspection. That's why, we have two aliases.
7. For debugging you can use following:
   `sudo -u mail /etc/mail/smrsh/bounce_wrapper.sh /etc/mail/smrsh/bounce.rb /home/sagar/.rvm production`
8. Another script for importing from a directory:
   `ruby bounce_from_directory.rb --prod --directory /home/sagar/bounce_18_jul`
9. Remember while running from your user, it might not receive bounce mail because your user must have an alias in /etc/aliases
10. Improved the script for release of resources after the script ends in both subscriber in php and publisher in ruby.
11. Improved the script by introducing heartbeat which will run every 30 seconds to avoid below error:`Error subscribing to Redis channel: Read operation timed out.`
