nametrans does not like directories

Allan Wind allan_wind at lifeintegrity.com
Sun Feb 5 02:32:16 GMT 2012


Here is my .offlineimaprc:

[general]
accounts = lifeintegrity
#pythonfile = ~/src/offlineimap/local.py
socktimeout = 60
ui = Quiet

[Account lifeintegrity]
#autorefresh = 30
localrepository = maildir
#postsynchook = notmuch new
remoterepository = imap
status_backend = sqlite

[Repository maildir]
localfolders = ~/mail
#nametrans = test
type = Maildir

[Repository imap]
idlefolders = ['INBOX']
folderfilter = lambda f: f not in ['Sent', 'Trash']
maxconnections = 1
nametrans = lambda f: (f in ['Sent'] and f.lower()) or ('received/' + f.lower())
remotehost = imaps.lifeintegrity.com
remoteport = 993
remotepasseval = ...
remoteusereval = 'allan'
sep = '/'
ssl = yes
type = IMAP

and I have the following folders on my IMAP server:
INBOX, Trash, Sent, and Spam.

I delete ~/.offlineimap to ensure there is no state, then run 
~/src/offlineimap/offlineimap.py -u ttyui`.

The 3 maildir folders are created 
~/mail/{sent,received/inbox,received/spam}/{cur,tmp,new}.  The 
'Sent' folder is downloaded to 'sent' just fine, but 'INBOX' and 
'Spam' fail with:

ERROR: Exceptions occurred during the run!
ERROR: Aborting sync, folder 'received/inbox' [acc: 'lifeintegrity']
  getfolder() asked for a nonexisting folder 'received/inbox'.
ERROR: Aborting sync, folder 'received/spam' [acc: 'lifeintegrity']
  getfolder() asked for a nonexisting folder 'received/spam'.

If I change the nametrans filter to remove the 'received/' 
directory:

nametrans = lambda f: (f in ['Sent'] and f.lower()) or (f.lower())

then inbox and spam are downloaded just fine.  Apologies for not 
spelling it out initially.  I figured it was a design decision 
and easy to reproduce.  Let me know if there is anything else I 
can help with.   The nametrans = test for the maildir repository 
was just to convince myself that it was not being called.

The suggestion I was trying to make was that one should not have 
to write code for mapping in both directions.  Here was the 
implementation that I was playing with.  maildir_to_imap is 
completely generic, and only the inner if statement (marked # 
user specified) has mapping code in one direction.


imap_to_maildir_folders = {}
maildir_to_imap_folders = {}


def maildir_to_imap(f):
	return maildir_to_imap_folders[f]


def imap_to_maildir(f):
	if not imap_to_maildir_folders.has_key(f):
		# user specified
		if f in ['Sent', 'Trash']:
			imap_to_maildir_folders[f] = f.lower()
		else:
			imap_to_maildir_folders[f] = 'received/' + f.lower()
		maildir_to_imap_folders[imap_to_maildir_folders[f]] = f
	return imap_to_maildir_folders[f]


/Allan
-- 
Allan Wind
Life Integrity, LLC
<http://lifeintegrity.com>




More information about the OfflineIMAP-project mailing list