Esempio n. 1
0
def get_email_body(message: Message, imap_session: imaplib.IMAP4_SSL) -> str:
    for part in message.walk():
        content_type = part.get_content_type()
        body = part.get_payload(decode=True)
        if body:
            body = body.decode()
        if content_type == "text/html":
            imap_session.close()
            imap_session.logout()
            return body
Esempio n. 2
0
 def logout(self):
     # sign off
     if self.do_expunge:
         # we may never have logged in, in which case we do nothing
         if self.logged_in:
             # expunge messages from the spam and unsure folders
             for fol in ["spam_folder",
                         "unsure_folder",]:
                 self.select(options["imap", fol])
                 self.expunge()
             # expunge messages from the ham and spam training folders
             for fol_list in ["ham_train_folders",
                              "spam_train_folders",]:
                 for fol in options["imap", fol_list]:
                     self.select(fol)
                     self.expunge()
     BaseIMAP.logout(self)  # superclass logout
Esempio n. 3
0
 def logout(self):
     """Log off from the IMAP server, possibly expunging.
     Note that most, if not all, of the expunging is probably done in
     SelectFolder, rather than here, for purposes of speed."""
     if self.connected and self.logged_in and self.do_expunge:
         for fol in ["spam_folder",
                     "unsure_folder",
                     "ham_folder"]:
             folder_name = options["imap", fol]
             if folder_name:
                 self.select(folder_name)
                 self.expunge()
         for fol_list in ["ham_train_folders",
                          "spam_train_folders",]:
             for fol in options["imap", fol_list]:
                 self.select(fol)
                 self.expunge()
     BaseIMAP.logout(self)  # superclass logout