--- 0002.patchv2	2011-01-27 18:13:11.000000000 +0100
+++ 0002-Factor-out-the-date-guessing-retrieving.patch	2011-01-28 09:04:53.000000000 +0100
@@ -1,29 +1,49 @@
-From dc0e8e0bb367496b03f47a1faeb44433ff76f8ed Mon Sep 17 00:00:00 2001
+From 5e1e94f0f06dd9769855b98163bbc8b2c1cecd6c Mon Sep 17 00:00:00 2001
 From: Sebastian Spaeth <Sebastian@SSpaeth.de>
 Date: Fri, 21 Jan 2011 13:53:16 +0100
 Subject: [PATCH 2/4] Factor out the date guessing/retrieving
 
 savemessage was too long and complex. Factor out the date guessing part
 of the function and put it into a function of its own. The logic of the
-date guessing is the same, however we don't need to run all our
-datetuples through imaplib.Time2InternalDate() as the imaplib.append()
-will do this for us.
+date guessing is the same, however, we do not use the
+imaplib.Time2InternalDate() function as it is buggy
+(http://bugs.python.org/issue11024) and returns localized patches. So we
+create INTERNALDATE ourselves and pass it to append() as a string.
+
+This commit fixes a bug that international users used to pass an invalid
+date to the IMAP server, which the server will either ignore or complain
+about.
 
 Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
 ---
- offlineimap/folder/IMAP.py |  121 +++++++++++++++++++++++++++++++------------
- 1 files changed, 87 insertions(+), 34 deletions(-)
+ Changelog.draft.rst        |    3 +-
+ offlineimap/folder/IMAP.py |  123 ++++++++++++++++++++++++++++++++------------
+ 2 files changed, 91 insertions(+), 35 deletions(-)
 
+diff --git a/Changelog.draft.rst b/Changelog.draft.rst
+index 8b599f9..bd6555d 100644
+--- a/Changelog.draft.rst
++++ b/Changelog.draft.rst
+@@ -18,7 +18,8 @@ Changes
+ 
+ Bug Fixes
+ ---------
+-
++* Do not send localized date strings to the IMAP server as it will
++  either ignore or refuse them.
+ 
+ Pending for the next major release
+ ==================================
 diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py
-index 37fc652..525c3b3 100644
+index 37fc652..a11ee38 100644
 --- a/offlineimap/folder/IMAP.py
 +++ b/offlineimap/folder/IMAP.py
-@@ -300,52 +300,105 @@ class IMAPFolder(BaseFolder):
+@@ -300,52 +300,107 @@ class IMAPFolder(BaseFolder):
          matchinguids.sort()
          return long(matchinguids[0])
  
 +
-+    def getmessagedate(self, content, rtime=None):
++    def getmessageinternaldate(self, content, rtime=None):
 +        """Parses mail and returns an INTERNALDATE string
 +
 +        It will use information in the following order, falling back as an attempt fails:
@@ -53,23 +73,23 @@
 +            # time.mktime(); Will be None if missing or not in a valid
 +            # format.  Note that indexes 6, 7, and 8 of the result tuple are
 +            # not usable.
-+            dtuple = rfc822.parsedate(message.getheader('Date'))
++            datetuple = rfc822.parsedate(message.getheader('Date'))
 +
-+            if dtuple is None:
++            if datetuple is None:
 +                #could not determine the date, use the local time.
 +                return None
 +        else:
 +            #rtime is set, use that instead
-+            dtuple = time.localtime(rtime)
++            datetuple = time.localtime(rtime)
 +
 +        try:
 +            # Check for invalid dates
-+            if dtuple[0] < 1981:
++            if datetuple[0] < 1981:
 +                raise ValueError
 +
 +            # Check for invalid dates
-+            datetuple_check = time.localtime(time.mktime(dtuple))
-+            if dtuple[:2] != datetuple_check[:2]:
++            datetuple_check = time.localtime(time.mktime(datetuple))
++            if datetuple[:2] != datetuple_check[:2]:
 +                raise ValueError
 +
 +        except (ValueError, OverflowError):
@@ -77,7 +97,7 @@
 +            # or something.  Argh.  It seems that Time2Internaldate
 +            # will rause a ValueError if the year is 0102 but not 1902,
 +            # but some IMAP servers nonetheless choke on 1902.
-+            self.ui.debug("Message with invalid date %s. Server will use local time." % dtuple)
++            self.ui.debug("Message with invalid date %s. Server will use local time." % datetuple)
 +            return None
 +
 +        #produce a string representation of datetuple that works as
@@ -85,13 +105,15 @@
 +        num2mon = {1:'Jan', 2:'Feb', 3:'Mar', 4:'Apr', 5:'May', 6:'Jun',
 +                   7:'Jul', 8:'Aug', 9:'Sep', 10:'Oct', 11:'Nov', 12:'Dec'}
 +
-+        if dtuple.tm_isdst == '1':
++        if datetuple.tm_isdst == '1':
 +            zone = -time.altzone
 +        else:
 +            zone = -time.timezone
++        offset_h, offset_m = divmod(zone//60, 60)
 +
-+        internaldate = '"%02d-%s-%04d %02d:%02d:%02d %+03d%02d"' % (dtuple.tm_mday, num2mon[dtuple.tm_mon], dtuple.tm_year, \
-+                                              dtuple.tm_hour, dtuple.tm_min, dtuple.tm_sec, divmod(zone//60, 60))
++        internaldate = '"%02d-%s-%04d %02d:%02d:%02d %+03d%02d"' \
++            % (datetuple.tm_mday, num2mon[datetuple.tm_mon], datetuple.tm_year, \
++               datetuple.tm_hour, datetuple.tm_min, datetuple.tm_sec, offset_h, offset_m)
 +
 +        return internaldate
 +
@@ -121,7 +143,7 @@
 -            # This backend always assigns a new uid, so the uid arg is ignored.
 -            # In order to get the new uid, we need to save off the message ID.
 +            # get the date of the message file, so we can pass it to the server.
-+            date = self.getmessagedate(content, rtime)
++            date = self.getmessageinternaldate(content, rtime)
  
 -            message = rfc822.Message(StringIO(content))
 -            datetuple_msg = rfc822.parsedate(message.getheader('Date'))
