0

I'm using python imaplib to fetch email from server. All things goes well.

when I "fetch", the thread will be blocked and whole attachment will be fetched as base64 string in payload.

I wonder how or what to do if the attachment is large or big? And I also wonder is there a way to fecth or load the attachment like stream?

    server = IMAP4(imapserver)
    server.login(account, password)
    print(server.select("INBOX", readonly=True))
    unseen = server.search(None, "TEXT xxxx")
    mailidx = unseen[1][0]
    types, data = server.fetch(mailidx, "RFC822")  #  blocked and wait for load
    msg_struct = BytesParser(policy=default).parsebytes(data[0][1])
    for part in msg_struct.walk():
         ........
         part.get_payload(decode=True)  # return whole file in memory
W.X
  • 175
  • 2
  • 13
  • I don't think `imaplib` supports using it as a stream, it's a basic synchronous request/response library with no bells and/or whistles. You could stick it in a thread so it won't block, or try another library. – Max Jul 30 '19 at 14:30
  • Thanks Max, means it's no possible to deal it with stream or section? any other suggestion of imap4 library? – W.X Jul 31 '19 at 01:33

0 Answers0