question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for getting back all messages in a thread?

See original GitHub issue

First, thank you for this great library, it definitely simplifies using imap over some other libraries in python land.

I’ve been trying to use this to be able to download all messages in a thread ( reply-to chain ), and the only way I’ve been able to do this was via searching the Header for a In-Reply-To message-id from the first email, or via the References Header field ( although that has been less reliable ).

I was wondering if imap_tools provided and easier way to do this, and if not whether that’s something that would be good to implement?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ikvkcommented, May 31, 2020

Hi, Key question: how do I do this without the imap_tools library? As far as I understand, it is not possible to do this universally by now.

https://stackoverflow.com/questions/16816425/

I think you’re taking the right approach.

0reactions
elithompsoncommented, Feb 8, 2022

Related: I needed to get the Gmail thread ids from messages and was able to subclass Mailbox to get it like this:

import re
from typing import Iterable, Sequence
from imap_tools import MailBox


class Mbox(MailBox):
    def _fetch_in_bulk(self, message_nums: Sequence[str], message_parts: str, reverse: bool) -> Iterable[list]:
        # attach the X-GM-THRID flag so Gmail returns the values
        message_parts = message_parts.replace(")", " X-GM-THRID)")
        return super(Mbox, self)._fetch_in_bulk(message_nums, message_parts, reverse)


def get():
    thrid_search = re.compile(r"X-GM-THRID (\d+)")
    with Mbox("imap.gmail.com").login("example@example.com", "password") as mb:
        messages = mb.fetch(bulk=True)
        for message in messages:
            d = message._raw_uid_data.decode("utf-8")
            result = re.search(thrid_search, d)
            thrid = result.groups()[0]
            print(message.uid)
            print("\t GmThrid:", thrid)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Delete and recover messages on your iPhone or iPad
Within a conversation, touch and hold the message bubble to open an options menu. Tap More . Tap the Trash button , then...
Read more >
How to recover deleted Messages conversations on your iPhone
Learn how to recover deleted conversations in Messages on your iPhone. ... Resources: Get Support for iPhone: http://apple.co/iPhone To ...
Read more >
Accidentally Delete iMessage Conversation? How to Recover
See and recover deleted chats & iMessage photos wholly or selectively. Undelete iMessage thread to your iPhone or Mac/PC without backup. Preview ...
Read more >
How to find and retrieve deleted text messages on Android
If you are among them and want a convenient alternative, use a third-party SMS app like Pulse to back up and restore your...
Read more >
How to Recover Deleted Text Messages: Your Complete Guide
Not all territories or carriers will allow iCloud to backup SMS messages, ... from your Android and need to get it back, stop...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found