MCPcopy
hub / github.com/charlierguo/gmail / fetch_thread

Method fetch_thread

gmail/message.py:186–213  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

184
185 # returns a list of fetched messages (both sent and received) in chronological order
186 def fetch_thread(self):
187 self.fetch()
188 original_mailbox = self.mailbox
189 self.gmail.use_mailbox(original_mailbox.name)
190
191 # fetch and cache messages from inbox or other received mailbox
192 response, results = self.gmail.imap.uid('SEARCH', None, '(X-GM-THRID ' + self.thread_id + ')')
193 received_messages = {}
194 uids = results[0].split(' ')
195 if response == 'OK':
196 for uid in uids: received_messages[uid] = Message(original_mailbox, uid)
197 self.gmail.fetch_multiple_messages(received_messages)
198 self.mailbox.messages.update(received_messages)
199
200 # fetch and cache messages from 'sent'
201 self.gmail.use_mailbox('[Gmail]/Sent Mail')
202 response, results = self.gmail.imap.uid('SEARCH', None, '(X-GM-THRID ' + self.thread_id + ')')
203 sent_messages = {}
204 uids = results[0].split(' ')
205 if response == 'OK':
206 for uid in uids: sent_messages[uid] = Message(self.gmail.mailboxes['[Gmail]/Sent Mail'], uid)
207 self.gmail.fetch_multiple_messages(sent_messages)
208 self.gmail.mailboxes['[Gmail]/Sent Mail'].messages.update(sent_messages)
209
210 self.gmail.use_mailbox(original_mailbox.name)
211
212 # combine and sort sent and received messages
213 return sorted(dict(received_messages.items() + sent_messages.items()).values(), key=lambda m: m.sent_at)
214
215
216class Attachment:

Callers

nothing calls this directly

Calls 4

fetchMethod · 0.95
MessageClass · 0.85
use_mailboxMethod · 0.80

Tested by

no test coverage detected