Merge pull request #2832 from mbauskar/imap

[fixes] removed the fingerprint and used the message-id to check emai…
This commit is contained in:
Nabin Hait 2017-03-09 10:46:01 +05:30 committed by GitHub
commit deee6ca0e0
3 changed files with 5 additions and 64 deletions

View file

@ -1252,35 +1252,6 @@
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "fingerprint",
"fieldtype": "Data",
"hidden": 1,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Fingerprint",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
@ -1409,7 +1380,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2017-03-07 06:59:01.742335",
"modified": "2017-03-08 16:41:15.546938",
"modified_by": "Administrator",
"module": "Core",
"name": "Communication",

View file

@ -233,7 +233,6 @@ class EmailAccount(Document):
uid_list = []
exceptions = []
seen_status = []
fingerprint_list = []
uid_reindexed = False
if frappe.local.flags.in_test:
@ -247,7 +246,6 @@ class EmailAccount(Document):
incoming_mails = emails.get("latest_messages")
uid_list = emails.get("uid_list", [])
seen_status = emails.get("seen_status", [])
fingerprint_list = emails.get("fingerprint_list", [])
uid_reindexed = emails.get("uid_reindexed", False)
for idx, msg in enumerate(incoming_mails):
@ -256,7 +254,6 @@ class EmailAccount(Document):
args = {
"uid": uid,
"seen": None if not seen_status else get_seen(seen_status.get(uid, None)),
"fingerprint": None if not fingerprint_list else fingerprint_list.get(uid, None),
"uid_reindexed": uid_reindexed
}
communication = self.insert_communication(msg, args=args)
@ -324,11 +321,10 @@ class EmailAccount(Document):
# dont count emails sent by the system get those
raise SentEmailInInbox
if args.get("fingerprint", None) or email.message_id:
if email.message_id:
names = frappe.db.sql("""select distinct name from tabCommunication
where fingerprint='{fingerprint}' or message_id='{message_id}'
where message_id='{message_id}'
order by creation desc limit 1""".format(
fingerprint=args.get("fingerprint", ''),
message_id=email.message_id
), as_dict=True)
@ -358,8 +354,7 @@ class EmailAccount(Document):
"message_id": email.message_id,
"communication_date": email.date,
"has_attachment": 1 if email.attachments else 0,
"seen": seen or 0,
"fingerprint": args.get("fingerprint", None)
"seen": seen or 0
})
self.set_thread(communication, email)

View file

@ -109,7 +109,6 @@ class EmailServer:
self.errors = False
self.latest_messages = []
self.seen_status = {}
self.fingerprint_list = {}
self.uid_reindexed = False
uid_list = email_list = self.get_new_mails()
@ -159,7 +158,6 @@ class EmailServer:
out.update({
"uid_list": uid_list,
"seen_status": self.seen_status,
"fingerprint_list": self.fingerprint_list,
"uid_reindexed": self.uid_reindexed
})
@ -232,9 +230,7 @@ class EmailServer:
status, message = self.imap.uid('fetch', message_meta, '(BODY.PEEK[] BODY.PEEK[HEADER] FLAGS)')
raw, header, ignore = message
self.get_email_seen_status(message_meta, header[0])
self.get_email_headers_hash(message_meta, header[1])
self.get_email_seen_status(message_meta, raw[0])
self.latest_messages.append(raw[1])
else:
msg = self.pop.retr(msg_num)
@ -283,27 +279,6 @@ class EmailServer:
else:
self.seen_status.update({ uid: "UNSEEN" })
def get_email_headers_hash(self, uid, headers):
""" generate the email unique id from header hash
unique id can be used to update uid if UID is reindexed"""
hash = hashlib.sha1()
for header in headers:
if header[0] == 'Content-Type':
# skip variable boundaries
continue
try:
decoded_header = decode_header(header[1])
decoded = ''.join([val[0].decode(val[1]).encode('ascii', 'ignore') \
if val[1] is not None else val[0] for val in decoded_header])
cleaned = re.sub(r"\s+", u"", decoded, flags=re.UNICODE)
hash.update(cleaned)
except:
pass
self.fingerprint_list.update({ uid: hash.hexdigest() })
def has_login_limit_exceeded(self, e):
return "-ERR Exceeded the login limit" in strip(cstr(e.message))