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.
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.
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 email@example.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.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: <firstname.lastname@example.org>, but also mails which are not in the domain
@company.com. Any help would be appreciated.
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
About This Community
|Asked: 5/27/13, 11:18 PM|
|Seen: 2693 times|
|Last updated: 9/15/15, 7:45 AM|