0

So first of all this is my code:

with MailBox('imap.gmail.com').login('username', 'password', 'INBOX') as mailbox:
                for msg in mailbox.fetch(AND(mark_seen=False, from_="some_domain")):
                    prt_msg_text = msg.text
                    if 'some_text' in prt_msg_text:
                        *here I want to mark the email as seen, if a specific text is in the msg*

So I want to read the email first without marking it as seen and if a specific condition is true, I want to mark this specific email as seen. Is that possible to do?

2 Answers2

0

I am new to it aswell, but I'm good at googling.

from imap_tools import MailBox, A

with MailBox('imap.gmail.com').login('username', 'pwd', 'INBOX') as mailbox:
    uids = []
    for msg in mailbox.fetch(A(from_="@some.domain"), mark_seen=False):
        body = msg.text or msg.html
        if 'some_text' in body:
            uids.append(msg.uid)
    mailbox.flag(uids, imap_tools.MailMessageFlags.SEEN, True)

*mark_seen is fetch's argument.

Vladimir
  • 6,162
  • 2
  • 32
  • 36
Petr L.
  • 414
  • 5
  • 13
0

mark_seen is fetch's argument.

When you fix this error, use mark_seen arg and mailbox.flag method

Vladimir
  • 6,162
  • 2
  • 32
  • 36