python - Exim filter pipe script only working on last email - not current -
this little combination processing second recent email coming in - not recent.
here's filter:
# exim filter save /srv/domain.com/bin/mail 660 pipe "/srv/domain.com/bin/sendtomailchimp.py"
it works - i.e. can see saving mail file , call script.. great! far good..
here's script:
#!/usr/bin/python mailbox_dir = '/srv/domain.com/mailboxes/enqace/mail' import mailbox import logging import time time.sleep(10) logging.basicconfig(filename='/srv/domain.com/mailboxes/enqace/logging.log',level=logging.debug) inbox = mailbox.mbox(mailbox_dir) logging.info('script called') key in inbox.iterkeys(): logging.info(key) message = inbox[key] subject = message['subject'] logging.info(subject) logging.info('===finish====')
(prints 0-6 along subject lines of each)
i can tail log. runs on getting email - seems parse mail mbox , completes before getting recent email (i.e. last one). hits last 1 (the recent) next time email comes in. if there 6 mails in mail file new 1 - 7th - subject line doesn't come in log entry. when 8th comes in..
is script in effect running - before exim has had chance send mail file? if whats work around? adding sleep(10) doesn't seem seen above..
update: pulling python prompt can see python correct amount of keys (i.e. message num) when called outside of pipe
mailbox_dir = 'mail' import mailbox inbox = mailbox.mbox(mailbox_dir) key in inbox.iterkeys(): print key
(prints 0-7)
Comments
Post a Comment