Sunday, 4 December 2022

How can i read large EmailMessage object using wb+ if the file is large using python3?

I wish to write a very large EmailMessage object using binary in small sizes just like it is done using buffer.read(1024). IS there a way? I have tried like this which is wrong as the Email Message object is not having read() method:

    with open(complete_path,'wb+') as fp:
        while True:
            x = msg.read(1024)
            if x:
                fp.write(x.as_bytes())
            else:
                break
        fp.write(x.as_bytes())

Here msg is the EmailMessage object and trying to save it at location complete_path When tried with below code it works for most of the mails but does not complete and gets stuck for few mails and generated zombies:

      with open(complete_path,'wb+') as fp:
          fp.write(msg.as_bytes())

I am reading the email in a fuglu plugin and not from a file. Please guide.



from How can i read large EmailMessage object using wb+ if the file is large using python3?

No comments:

Post a Comment