This question has been flagged
3 Replies
9033 Views

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.

Avatar
Discard
Author

Even more targeted email filtering relates to not allowing in all the Facebook, LinkedIn, Google+ or Twitter messages. Similarly, I would want to filter all subscription/list emails.

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/

Most of the spam I get is already marked as such by the email firewall. I.e. The subject starts with the string [SPAM-Firewall]_. Is there an easy way to at least prevent issue creation if email.subject.startswith("Whatever"):?

Best Answer

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[0].split():
                         result, data = imap_server.fetch(num, '(RFC822)')
+                        try:
+                            subject = filter(lambda l: l.startswith("Subject: "), data[0][1].split("\n\n")[0].split("\n"))[0].split(" ", 1)[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[0][1],
                                                              save_original=server.original,

If you don't use a firewall, you could easily use the same mechanism to blacklist subjects, senders etc.

Avatar
Discard
Best Answer

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 mariusz@company.com, 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[0].split():
                result, data = imap_server.fetch(num, '(RFC822)')
                try:
                    to = filter(lambda l: l.startswith("To: "), data[0][1].split("\n\n")[0].split("\n"))[0].split(" ", 1)[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[0][1],
                                                     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: <mariusz@company.com>, but also mails which are not in the domain @company.com. Any help would be appreciated.

Avatar
Discard
Best Answer

I have used a service from mailstrom.com to clean the email box from spam and other non-desired emails.

Avatar
Discard
Author

This kind of approach seems to imply that I need to make sure that a filter service runs prior to each time OpenERP checks the email account. - Gary

Services like the one mentionned helps a user to clean his/her mailbox on a continuing basis - as long as the service is active; this is a way to unsubscribe from spam lists. but evidently it does not work as a filter on the fly!