What is the best approach to filtering out spam emails? If a user account has existed for a while, there will be quite a lot of spam flowing into OpenERP. It is a waste to have all the junk mail stored forever in the database. At least I have not found an easy approach to deleting junk mail.
This is my concern as well. With a Trac instance where incoming emails generate support tickets, we have to cleanup spam often, otherwise database would suffer. While cleaning up the INBOX, before email reaches the system, is surely a good idea, some kind of filtering later cannot hurt. Note similar question here: http://help.openerp.com/question/18921/how-to-apply-filter-for-emails-in-generating-leads-from-incoming-mail/
You can patch the file
addons/fetchmail/fetchmail.py a little bit. In my case, our e-mail firewall already changes the subject of e-mails, if it is probably spam. I just did this:
@@ -198,6 +198,13 @@ result, data = imap_server.search(None, '(UNSEEN)') for num in data.split(): result, data = imap_server.fetch(num, '(RFC822)') + try: + subject = filter(lambda l: l.startswith("Subject: "), data.split("\n\n").split("\n")).split(" ", 1) + _logger.info("subject: %s", subject) + if subject.startswith("[SPAM-Firewall]_"): + continue + except Exception, e: + _logger.info("exception with subject %s", str(e)) res_id = mail_thread.message_process(cr, uid, server.object_id.model, data, save_original=server.original,
If you don't use a firewall, you could easily use the same mechanism to blacklist subjects, senders etc.
I have used a service from mailstrom.com to clean the email box from spam and other non-desired emails.
Martin - there is a question if you don't mind answering (I would be very glad to get an answer). I'm interested in importing all mail messages from my account, which has been sent directly to me (for example, if my company is @company.com, then I want to have all mails, which have been addressed to me (like firstname.lastname@example.org, where mariusz is my alias), fetched to OpenERP. Here is the code I've modified:
result, data = imap_server.search(None, '(ALL)') for num in data.split(): result, data = imap_server.fetch(num, '(RFC822)') try: to = filter(lambda l: l.startswith("To: "), data.split("\n\n").split("\n")).split(" ", 1) _logger.info("to: %s", to) if not to.endswith("@company.com"): continue except Exception, e: _logger.info("exception with address %s", str(e)) res_id = mail_thread.message_process(cr, uid, server.object_id.model, data, save_original=server.original,
The problem here is that headers are being processed well, but in the end OpenERP fetch 0 mails - what is the problem here? I wasn't able to trace bug here, whole fetchmail processes as follows, but gives 0 exceptions (and it should).
It returns a lot of results like
INFO test openrp.addons.fetchmail.fetchmail: to: <email@example.com>, but also mails which are not in the domain
@company.com. Any help would be appreciated.