Esempio n. 1
0
 def getAttachment(self, msg, toDir='./', byUid=False):
     """"""
     # self.download(msg, toDir, byUid, False)
     # p = Process(target=self.download, args=(msg, toDir, byUid))
     # p.start()
     # p.join()
     if not isinstance(msg, Message) :
         msg = self.getEmail(msg, byUid)
     for part in msg.walk():
         filename = part.get_filename()
         if part.get_content_maintype() == 'multipart' or not filename : continue
         with Io.wfile(Sys.join(toDir, filename)) as fo :
             fo.write(part.get_payload(decode=True))
Esempio n. 2
0
 def download(self, msg, toDir, byUid=False, reconError=True):
     """"""
     try:            
         if not isinstance(msg, Message) :
             msg = self.getEmail(msg, byUid)
         for part in msg.walk():
             filename = part.get_filename()
             if part.get_content_maintype() == 'multipart' or not filename : continue
             with Io.wfile(Sys.join(toDir, filename)) as fo :
                 fo.write(part.get_payload(decode=True))
     except Exception as e :
         print(e)
         self.reconnect()
         self.download(msg, toDir, byUid, False)