Merge pull request #8 from thekix/master

Remove email.Parse and other minor changes
This commit is contained in:
Rodolfo García Peñas (kix) 2020-10-12 12:43:54 +02:00 committed by GitHub
commit 9a994ced7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -15,6 +15,7 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import errno
import socket import socket
import time import time
import re import re
@ -311,7 +312,7 @@ class MaildirFolder(BaseFolder):
except OSError as e: except OSError as e:
if not hasattr(e, 'EEXIST'): if not hasattr(e, 'EEXIST'):
raise raise
if e.errno == e.EEXIST: if e.errno == errno.EEXIST:
if tries: if tries:
time.sleep(0.23) time.sleep(0.23)
continue continue
@ -365,9 +366,8 @@ class MaildirFolder(BaseFolder):
content, 'Delivery-date') content, 'Delivery-date')
except Exception as e: except Exception as e:
# This should never happen. # This should never happen.
from email.Parser import Parser
from offlineimap.ui import getglobalui from offlineimap.ui import getglobalui
datestr = Parser().parsestr(content, True).get("Date") datestr = emailutil.get_message_date(content)
ui = getglobalui() ui = getglobalui()
ui.warn("UID %d has invalid date %s: %s\n" ui.warn("UID %d has invalid date %s: %s\n"
"Not using message timestamp as file prefix" % "Not using message timestamp as file prefix" %
@ -386,9 +386,8 @@ class MaildirFolder(BaseFolder):
# In case date is wrongly so far into the future as to be > max # In case date is wrongly so far into the future as to be > max
# int32. # int32.
except Exception as e: except Exception as e:
from email.Parser import Parser
from offlineimap.ui import getglobalui from offlineimap.ui import getglobalui
datestr = Parser().parsestr(content, True).get("Date") datestr = emailutil.get_message_date(content)
ui = getglobalui() ui = getglobalui()
ui.warn("UID %d has invalid date %s: %s\n" ui.warn("UID %d has invalid date %s: %s\n"
"Not changing file modification time" % (uid, datestr, e)) "Not changing file modification time" % (uid, datestr, e))

View File

@ -316,9 +316,14 @@ class MappedIMAPFolder(IMAPFolder):
def change_message_uid(self, ruid, new_ruid): def change_message_uid(self, ruid, new_ruid):
"""Change the message from existing ruid to new_ruid """Change the message from existing ruid to new_ruid
:param new_uid: The old remote UID will be changed to a new The old remote UID will be changed to a new
UID. The UIDMaps case handles this efficiently by simply UID. The UIDMaps case handles this efficiently by simply
changing the mappings file.""" changing the mappings file.
Args:
ruid: Remote UID
new_ruid: New Remote UID
"""
if ruid not in self.r2l: if ruid not in self.r2l:
raise OfflineImapError("Cannot change unknown Maildir UID %s" % raise OfflineImapError("Cannot change unknown Maildir UID %s" %