maildir on windows share ?

Vladimir Marek Vladimir.Marek at Oracle.COM
Fri Jul 8 22:11:46 BST 2011


Hi,

> > > I am not sure what Nicolas would say about such an optional configuration, but in
> > > case he finds it acceptable... Care to whip up a patch?
> > 
> > I'll probably do it anyway for myself. If there will be slightest chance
> > of being accepted, I'll gladly work on it.
> 
> Looks like you're not the only one to have hit this issue
> 
>   http://serverfault.com/questions/100711/maildir-in-windows-for-imap
> 
> ... Unless you are "User1"?

No, that's coincidence



> Agreed for a configuration option. I'm more thinking about something
> like
> 
>   maildir-windows-compatible = yes
> 
> with a good comment about what it does and why. A new entry in the
> manual in the "known bugs" section would be nice.

Ok, I'm attaching my first try. But I know neither Python on git, so
there might be some issues I missed ...

-- 
	Vlad
-------------- next part --------------
diff --git a/docs/MANUAL.rst b/docs/MANUAL.rst
index 26f31a6..e6a32e2 100644
--- a/docs/MANUAL.rst
+++ b/docs/MANUAL.rst
@@ -300,5 +300,26 @@ KNOWN BUGS
   * IDLE may only work "once" per refresh.  If you encounter this bug,
     please send a report to the list!
 
+* Maildir support in Windows drive
+    Maildir uses colon caracter (:) in message file names. Colon is however
+    forbidden character in windows drives. There are several workarounds for
+    that situation:
+
+   * Use "maildir-windows-compatible = yes" account OfflineIMAP configuration.
+      - That makes OfflineIMAP to use exclamation mark (!) instead of colon for
+        storing messages. Such files can be written to windows partitions. But
+        you will probably loose compatibility with other programs trying to
+        read the same Maildir.
+      - Exclamation mark was choosed because of the note in
+        http://docs.python.org/library/mailbox.html
+      - If you have some messages already stored without this option, you will
+        have to re-sync them again
+
+   * Enable file name character translation in windows registry (not tested)
+      - http://support.microsoft.com/kb/289627
+
+   * Use cygwin managed mount (not tested)
+      - not available anymore since cygwin 1.7
+
 SEE ALSO
 ========
diff --git a/offlineimap.conf b/offlineimap.conf
index 9329c66..724efdc 100644
--- a/offlineimap.conf
+++ b/offlineimap.conf
@@ -239,6 +239,16 @@ remoterepository = RemoteExample
 
 # maxage = 3
 
+
+# Maildir format uses colon (:) separator between uniq name and info.
+# Unfortunatelly colon is not allowed character in windows file name. If you
+# enable maildir-windows-compatible option, offlineimap will be able to store
+# messages on windows drive, but you will probably loose compatibility with
+# other programs working with the maildir
+
+# maildir-windows-compatible = yes
+
+
 [Repository LocalExample]
 
 # This is one of the two repositories that you'll work with given the
diff --git a/offlineimap/folder/Maildir.py b/offlineimap/folder/Maildir.py
index b576507..d50f7ff 100644
--- a/offlineimap/folder/Maildir.py
+++ b/offlineimap/folder/Maildir.py
@@ -31,7 +31,6 @@ except ImportError:
 from offlineimap import OfflineImapError
 
 uidmatchre = re.compile(',U=(\d+)')
-flagmatchre = re.compile(':.*2,([A-Z]+)')
 timestampmatchre = re.compile('(\d+)');
 
 timeseq = 0
@@ -63,6 +62,19 @@ class MaildirFolder(BaseFolder):
         self.messagelist = None
         self.repository = repository
         self.accountname = accountname
+
+        self.wincompatible = self.config.getdefault("Account " + self.accountname,
+            "maildir-windows-compatible", "no")
+        if self.wincompatible == "no":
+            self.infosep = ':'
+        elif self.wincompatible == "yes":
+            self.infosep = '!'
+        else:
+            raise OfflineImapError("maildir-wincompatible-compatible option can be "
+                "'no' or 'yes'. Your config has '%s'." %self.wincompatible, 30)
+
+        self.flagmatchre = re.compile(self.infosep + '.*2,([A-Z]+)')
+
         BaseFolder.__init__(self)
         #self.ui is set in BaseFolder.init()
         # Cache the full folder path, as we use getfullname() very often
@@ -156,7 +168,7 @@ class MaildirFolder(BaseFolder):
                     nouidcounter -= 1
                 else:
                     uid = long(uidmatch.group(1))
-            flagmatch = flagmatchre.search(messagename)
+            flagmatch = self.flagmatchre.search(messagename)
             flags = []
             if flagmatch:
                 flags = [x for x in flagmatch.group(1)]
@@ -271,11 +283,12 @@ class MaildirFolder(BaseFolder):
             dir_prefix = 'cur'
         else:
             dir_prefix = 'new'
-        infostr = ':'
-        infomatch = re.search('(:.*)$', newname)
+
+        infostr = self.infosep
+        infomatch = re.search('(' + self.infosep + '.*)$', newname)
         if infomatch:                   # If the info string is present..
             infostr = infomatch.group(1)
-            newname = newname.split(':')[0] # Strip off the info string.
+            newname = newname.split(self.infosep)[0] # Strip off the info string.
         infostr = re.sub('2,[A-Z]*', '', infostr)
         flags.sort()
         infostr += '2,' + ''.join(flags)


More information about the OfflineIMAP-project mailing list