Bläddra i källkod

[email] [fix] decode subject

version-14
Rushabh Mehta 12 år sedan
förälder
incheckning
7c7191c305
1 ändrade filer med 11 tillägg och 5 borttagningar
  1. +11
    -5
      webnotes/utils/email_lib/receive.py

+ 11
- 5
webnotes/utils/email_lib/receive.py Visa fil

@@ -29,17 +29,18 @@ class IncomingMail:
Single incoming email object. Extracts, text / html and attachments from the email Single incoming email object. Extracts, text / html and attachments from the email
""" """
def __init__(self, content): def __init__(self, content):
import email
import email.utils
import email, email.utils, email.header
import datetime import datetime
self.mail = email.message_from_string(content) self.mail = email.message_from_string(content)
self.text_content = '' self.text_content = ''
self.html_content = '' self.html_content = ''
self.attachments = []
self.attachments = []
self.parse() self.parse()
self.set_content_and_type() self.set_content_and_type()
self.set_subject()

self.from_email = extract_email_id(self.mail["From"]) self.from_email = extract_email_id(self.mail["From"])
self.from_real_name = email.utils.parseaddr(self.mail["From"])[0] self.from_real_name = email.utils.parseaddr(self.mail["From"])[0]
@@ -51,6 +52,12 @@ class IncomingMail:
for part in self.mail.walk(): for part in self.mail.walk():
self.process_part(part) self.process_part(part)


def set_subject(self):
_subject = email.header.decode_header(self.mail.get("Subject", "No Subject"))
self.subject = _subject[0][0]
if _subject[0][1]:
self.subject = _subject[0][0].decode(_subject[0][1])

def set_content_and_type(self): def set_content_and_type(self):
self.content, self.content_type = '[Blank Email]', 'text/plain' self.content, self.content_type = '[Blank Email]', 'text/plain'
if self.text_content: if self.text_content:
@@ -111,8 +118,7 @@ class IncomingMail:


def get_thread_id(self): def get_thread_id(self):
import re import re
subject = self.mail.get('Subject', '')
l = re.findall('(?<=\[)[\w/-]+', subject)
l = re.findall('(?<=\[)[\w/-]+', self.subject)
return l and l[0] or None return l and l[0] or None


class POP3Mailbox: class POP3Mailbox:


Laddar…
Avbryt
Spara