From 85ff68da130d7a64d0ae4edfb90be034beb9e79b Mon Sep 17 00:00:00 2001 From: Ronald Portier Date: Thu, 4 Apr 2013 21:32:01 +0200 Subject: [PATCH] [IMP] - convert mailadresses to lowercase to increase change for match - handle situation that optional mail address componenents not present in mail - slight reorganisation of code to aid debugging and made pep8 compliant as well. --- .../match_algorithm/email_exact.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/fetchmail_attach_from_folder/match_algorithm/email_exact.py b/fetchmail_attach_from_folder/match_algorithm/email_exact.py index db4871f65..b3fabaf5e 100644 --- a/fetchmail_attach_from_folder/match_algorithm/email_exact.py +++ b/fetchmail_attach_from_folder/match_algorithm/email_exact.py @@ -34,21 +34,23 @@ class email_exact(base): mailaddresses = [] fields = conf.mail_field.split(',') for field in fields: - mailaddresses+=to_email(mail_message[field]) - return mailaddresses + if field in mail_message: + mailaddresses += to_email(mail_message[field]) + return [ addr.lower() for addr in mailaddresses ] def _get_mailaddress_search_domain( self, conf, mail_message, operator='=', values=None): mailaddresses = values or self._get_mailaddresses( conf, mail_message) if not mailaddresses: - return [(0,'=',1)] - return ((['|'] * (len(mailaddresses) - 1)) + [ + return [(0, '=', 1)] + search_domain = ((['|'] * (len(mailaddresses) - 1)) + [ (conf.model_field, operator, addr) for addr in mailaddresses] + safe_eval(conf.domain or '[]')) + return search_domain def search_matches(self, cr, uid, conf, mail_message, mail_message_org): - return conf.pool.get(conf.model_id.model).search( - cr, uid, - self._get_mailaddress_search_domain(conf, mail_message), - order=conf.model_order) + conf_model = conf.pool.get(conf.model_id.model) + search_domain = self._get_mailaddress_search_domain(conf, mail_message) + return conf_model.search( + cr, uid, search_domain, order=conf.model_order)