Complete.Org: Mailing Lists: Archives: offlineimap: December 2003:
OfflineIMAP and Courier IMAPd
Home

OfflineIMAP and Courier IMAPd

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: offlineimap@xxxxxxxxxxxx
Subject: OfflineIMAP and Courier IMAPd
From: Rene Wagner <reenoo@xxxxxx>
Date: Sat, 13 Dec 2003 21:08:55 +0100

Hi,
my mail setup requires me to sync folders of two Courier IMAPd
accounts.

I have tried IMAP<->IMAP synchronization with OfflineIMAP but
the only thing that it does is copying mail back and forth
leaving multiple copies...
Also, it crashes regularly although somewhat randomly.

As a workaround I am now directly syncing between the
remote IMAP folders and the maildir where the local
courier-imapd stores mail (~/Maildir for debian).

For this to make any sense it has to generate a maildir
structure that is compatible with courier-imapd.

My .offlineimaprc looks like this now:

--- SNIP ---

[Repository Local]
type = Maildir
localfolders = ~/Maildir
sep = .
                                                                
[Repository Remote]
type = IMAP
remotehost = remotehost
remoteuser = remoteuser
ssl=yes
nametrans = lambda foldername: re.sub('^$', '.',re.sub('^INBOX', '',
foldername))

--- SNIP ---

However this does not work with offlineimap (at least not
with the current version from debian sid).

With these modifications it works fine:

--- ./usr/lib/python2.2/site-packages/offlineimap/repository/Maildir.py
2003-10-31 22:14:24.000000000 +0100
+++ /usr/lib/python2.2/site-packages/offlineimap/repository/Maildir.py 
2003-12-13 16:58:14.000000000 +0100
@@ -74,7 +74,8 @@
                        (foldername, subdir)
         else:
             self.debug("makefolder: calling makedirs %s" % foldername)
-            os.makedirs(foldername, 0700)
+            if not os.path.isdir(foldername):
+                os.makedirs(foldername, 0700)
         self.debug("makefolder: creating cur, new, tmp")
         for subdir in ['cur', 'new', 'tmp']:
             os.mkdir(os.path.join(foldername, subdir), 0700)

For the plain syncronization functionality this is enough already.

But of course I also wanted to make use of the mbnames feature
offlineimap provides, so that I can get an automatically generated
courierimapsubscribed file.

--- SNIP ---
[mbnames]
enabled = yes
replacecurrent = "INBOX"
filename = ~/Maildir/courierimapsubscribed
header = ""
peritem = "%(foldername)s"
sep = "\n"
footer = "\n"
--- SNIP ---

You will wonder what the replacecurrent option is. I introduced it so
that I can revert the changes from the nametrans statement above.

The corresponding code looks like this:

--- ./usr/lib/python2.2/site-packages/offlineimap/mbnames.py   
2003-10-31 22:14:35.000000000 +0100
+++ /usr/lib/python2.2/site-packages/offlineimap/mbnames.py    
2003-12-13 20:30:32.000000000 +0100
@@ -53,7 +53,8 @@
         if not config.getdefaultboolean("mbnames", "enabled", 0):
             return
         file = open(os.path.expanduser(config.get("mbnames",
"filename")), "wt")
-        file.write(localeval.eval(config.get("mbnames", "header")))
+        if config.get("mbnames", "header"):
+            file.write(localeval.eval(config.get("mbnames", "header")))
         folderfilter = lambda accountname, foldername: 1
         if config.has_option("mbnames", "folderfilter"):
             folderfilter = localeval.eval(config.get("mbnames",
"folderfilter"),
@@ -65,7 +66,15 @@
                     itemlist.append(config.get("mbnames", "peritem",
raw=1) % \
                                     {'accountname': accountname,
                                      'foldername': foldername})
-        file.write(localeval.eval(config.get("mbnames",
"sep")).join(itemlist))
+        newlist=[]
+        for i in itemlist:
+                i = re.sub('\"$', '', re.sub("^\"", '', i))
+               replacecurrent = config.get("mbnames", "replacecurrent")
+                if replacecurrent:
+                    replacecurrent = re.sub('\"$', '', re.sub("^\"",
'', replacecurrent))
+                    i = re.sub('^\.', '%s.' % replacecurrent,
re.sub('^\.$', '%s' % replacecurrent, i))
+               newlist.append(i)
+        file.write(localeval.eval(config.get("mbnames",
"sep")).join(newlist))
         file.write(localeval.eval(config.get("mbnames", "footer")))
         file.close()
     finally:

The first part is neccessary to prevent offlineimap from crashing
when you set an empty header.

The second replaces all leading dots with the string from
replacecurrent.

The various other re.sub's were neccessary to remove all the leading and
trailing '"' I had in the output file.

I haven't had the time to check if that's already fixed in the
development version or something. 

I just want to allow others to benefit from what I've done.

Patches are against offlineimap-4.0.2 from debian sid.

Regards,

Rene


-- Binary/unsupported file stripped by Ecartis --
-- Type: text/x-patch
-- File: Maildir.patch


-- Binary/unsupported file stripped by Ecartis --
-- Type: text/x-patch
-- File: mbnames.patch




[Prev in Thread] Current Thread [Next in Thread]
  • OfflineIMAP and Courier IMAPd, Rene Wagner <=