continue
# retrieve uidvalidity
try:
+ # Work around unsolicited server responses in imaplib by clearing them
+ self.mail_con.response('STATUS')
_result, data = self.mail_con.status(mailbox[2], '(UIDVALIDITY)')
except (self.mail_con.error):
raise UserWarning("Could not retrieve mailbox uidvalidity.")
def fetch_messages(self):
"""Fetches the messages from the current mailbox, return list of uids."""
try:
+ # Work around unsolicited server responses in imaplib by clearing them
+ self.mail_con.response('SEARCH')
_result, data = self.mail_con.uid('search', None, "ALL")
except (self.mail_con.error):
raise UserWarning("Could not fetch messages.")
def fetch_internal_date(self, mid):
"""Fetches the internal date of a message, returns a time tuple."""
try:
+ # Work around unsolicited server responses in imaplib by clearing them
+ self.mail_con.response('FETCH')
_result, data = self.mail_con.uid('fetch', mid, '(INTERNALDATE)')
except (self.mail_con.error):
raise UserWarning("Could not fetch the internal date of message " + mid.decode('iso-8859-1') + ".")
def fetch_received_date(self, mid):
"""Fetches the received date of a message, returns bytes reponse."""
try:
+ # Work around unsolicited server responses in imaplib by clearing them
+ self.mail_con.response('FETCH')
_result, data = self.mail_con.uid('fetch', mid, '(BODY.PEEK[HEADER.FIELDS (RECEIVED)])')
except (self.mail_con.error):
raise UserWarning("Could not fetch the received header of message " + mid.decode('iso-8859-1') + ".")
def fetch_basic_date(self, mid):
"""Fetches the basic date of a message, returns bytes reponse."""
try:
+ # Work around unsolicited server responses in imaplib by clearing them
+ self.mail_con.response('FETCH')
_result, data = self.mail_con.uid('fetch', mid, '(BODY.PEEK[HEADER.FIELDS (DATE)])')
except (self.mail_con.error):
raise UserWarning("Could not fetch the date header of message " + mid.decode('iso-8859-1') + ".")
"""Replaces a message with one with correct internal date."""
internal_date_sec = time.mktime(internal_date.timetuple())
try:
+ # Work around unsolicited server responses in imaplib by clearing them
+ self.mail_con.response('FETCH')
result, data = self.mail_con.uid('fetch', mid, '(RFC822)')
#logging.debug("Entire e-mail is: %s", data[0][1])
+ # Work around unsolicited server responses in imaplib by clearing them
+ self.mail_con.response('FETCH')
# retrieve and select flags to upload
fetched_flags = self.mail_con.uid('fetch', mid, '(FLAGS)')[1][0]
parsed_flags = imaplib.ParseFlags(fetched_flags)
logging.debug("Selected flags %s from parsed flags %s.", selected_flags, parsed_flags)
flags_str = " ".join(flag.decode('iso-8859-1') for flag in selected_flags)
+ # Work around unsolicited server responses in imaplib by clearing them
+ self.mail_con.response('APPEND')
# upload message copy and delete old one
result, data = self.mail_con.append(mailbox, flags_str,
internal_date_sec, data[0][1])
except (self.mail_con.error):
raise UserWarning("Could not replace the e-mail " + mid.decode('iso-8859-1') + ".")
try:
+ # Work around unsolicited server responses in imaplib by clearing them
+ self.mail_con.response('STORE')
result, data = self.mail_con.uid('STORE', mid, '+FLAGS', r'(\Deleted)')
logging.debug("Removing old copy of the message reponse: %s %s", result, data)
except (self.mail_con.error):