From fdc84d3ce642939da018fead0ec56cd5eeb90a43 Mon Sep 17 00:00:00 2001 From: Brian Peterson Date: Tue, 15 Aug 2017 12:45:00 -0600 Subject: [PATCH 1/5] Correctly decode subject header in gmail client --- gmail_client/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gmail_client/message.py b/gmail_client/message.py index 85063cc..463535e 100644 --- a/gmail_client/message.py +++ b/gmail_client/message.py @@ -48,7 +48,7 @@ def parse_labels(headers): def parse_subject(encoded_header): if encoded_header is not None: - dh = encoded_header.encode('UTF-8') + dh = decode_email_header(encoded_header) else: dh = '' From 2c8a2596b61de4994dd414591fd184d863d96448 Mon Sep 17 00:00:00 2001 From: Brian Peterson Date: Tue, 15 Aug 2017 13:20:07 -0600 Subject: [PATCH 2/5] Bump to version 0.8 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 9c6fadd..1eb2360 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name = "gmail-client", - version = "0.0.7.7", + version = "0.0.8.0", author = "Wilberto Morales", author_email = "wilbertomorales777@gmail.com", description = ("A Pythonic interface for Google Mail. Based of https://github.com/charlierguo/gmai"), From 1f211668c5bfe6d4a5e8512348062f33ae83de3d Mon Sep 17 00:00:00 2001 From: Brian Peterson Date: Wed, 25 Oct 2017 16:43:10 -0600 Subject: [PATCH 3/5] Allow fetch without parse for finer-grained processing --- gmail_client/message.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/gmail_client/message.py b/gmail_client/message.py index 463535e..eb80496 100644 --- a/gmail_client/message.py +++ b/gmail_client/message.py @@ -174,6 +174,7 @@ def __init__(self, mailbox, uid): self.gmail = mailbox.gmail if mailbox else None self.message = None + self.raw = None self.headers = {} self.subject = None @@ -301,15 +302,25 @@ def _parse(self, raw_message): if re.search(r'X-GM-MSGID (\d+)', raw_headers): self.message_id = re.search(r'X-GM-MSGID (\d+)', raw_headers).groups(1)[0] - def fetch(self): return self.message if self.message else self.forced_fetch() + def fetch(self): + if self.message: + return self.message + else: + if self.raw: + self._parse(self.raw) + return self.message + else: + return self.forced_fetch() @property def has_attachments(self): return len(self.attachments) > 0 - def forced_fetch(self): + def forced_fetch(self, parse=False): _, results = self.gmail.imap.uid('FETCH', self.uid, '(BODY.PEEK[] FLAGS X-GM-THRID X-GM-MSGID X-GM-LABELS)') - self._parse(results[0]) + self.raw = results[0] + if parse: + self._parse(self.raw) return self.message From 576a62fc449a46bcc56fdec96b8ee4d3b4f1a038 Mon Sep 17 00:00:00 2001 From: Brian Peterson Date: Wed, 25 Oct 2017 16:46:19 -0600 Subject: [PATCH 4/5] Bump version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 1eb2360..4f3aee0 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name = "gmail-client", - version = "0.0.8.0", + version = "0.0.8.1", author = "Wilberto Morales", author_email = "wilbertomorales777@gmail.com", description = ("A Pythonic interface for Google Mail. Based of https://github.com/charlierguo/gmai"), From 51cd29925ec607fd776f28774bda6f3f5eb2822e Mon Sep 17 00:00:00 2001 From: Brian Peterson Date: Tue, 31 Oct 2017 13:09:08 -0600 Subject: [PATCH 5/5] Parse messages by default when doing a forced fetch --- gmail_client/message.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gmail_client/message.py b/gmail_client/message.py index eb80496..32e6e4c 100644 --- a/gmail_client/message.py +++ b/gmail_client/message.py @@ -310,13 +310,13 @@ def fetch(self): self._parse(self.raw) return self.message else: - return self.forced_fetch() + return self.forced_fetch(parse=True) @property def has_attachments(self): return len(self.attachments) > 0 - def forced_fetch(self, parse=False): + def forced_fetch(self, parse=True): _, results = self.gmail.imap.uid('FETCH', self.uid, '(BODY.PEEK[] FLAGS X-GM-THRID X-GM-MSGID X-GM-LABELS)') self.raw = results[0] if parse: