From 95aea5e489bb8656e813baa461e2d51ee8e4d2ae Mon Sep 17 00:00:00 2001 From: Eygene Ryabinkin Date: Tue, 27 Aug 2013 18:11:57 +0400 Subject: [PATCH 1/4] Add new expansion key for mbnames.peritem config variable It is called localfolders and holds expanded name for the same variable for the local repository of the account that is being processed. GitHub issue: https://github.com/OfflineIMAP/offlineimap/issues/21 Signed-off-by: Eygene Ryabinkin --- Changelog.rst | 3 +++ offlineimap.conf | 6 ++++++ offlineimap/accounts.py | 3 ++- offlineimap/mbnames.py | 8 ++++++-- offlineimap/repository/Base.py | 5 +++++ 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Changelog.rst b/Changelog.rst index 2e621f5..2d1b221 100644 --- a/Changelog.rst +++ b/Changelog.rst @@ -23,6 +23,9 @@ WIP (add new stuff for the next release) (Andreas Mack) * Allow to set message access and modification timestamps based on the "Date" header of the message itself. (Cyril Russo) +* "peritem" format string for [mbnames] got new expansion key + "localfolders" that corresponds to the same parameter of the + local repository for the account being processed. * [regression] pass folder names to the foldersort function, revert the documented behaviour diff --git a/offlineimap.conf b/offlineimap.conf index ec69bbb..836d075 100644 --- a/offlineimap.conf +++ b/offlineimap.conf @@ -129,6 +129,12 @@ accounts = Test # # The header, peritem, sep, and footer are all Python expressions passed # through eval, so you can (and must) use Python quoting. +# +# The following hash key are available to the expansion for 'peritem': +# - accountname: the name of the corresponding account; +# - foldername: the name of the folder; +# - localfolders: path to the local directory hosting all Maildir +# folders for the account. enabled = no filename = ~/Mutt/muttrc.mailboxes diff --git a/offlineimap/accounts.py b/offlineimap/accounts.py index c78d7d8..113d716 100644 --- a/offlineimap/accounts.py +++ b/offlineimap/accounts.py @@ -390,7 +390,8 @@ def syncfolder(account, remotefolder, quick): localfolder = account.get_local_folder(remotefolder) # Write the mailboxes - mbnames.add(account.name, localfolder.getname()) + mbnames.add(account.name, localfolder.getname(), + localrepos.getlocalroot()) # Load status folder. statusfolder = statusrepos.getfolder(remotefolder.getvisiblename().\ diff --git a/offlineimap/mbnames.py b/offlineimap/mbnames.py index 34eccf9..39dcf03 100644 --- a/offlineimap/mbnames.py +++ b/offlineimap/mbnames.py @@ -21,6 +21,7 @@ import re # for folderfilter from threading import Lock boxes = {} +localroots = {} config = None accounts = None mblock = Lock() @@ -30,9 +31,10 @@ def init(conf, accts): config = conf accounts = accts -def add(accountname, foldername): +def add(accountname, foldername, localfolders): if not accountname in boxes: boxes[accountname] = [] + localroots[accountname] = localfolders if not foldername in boxes[accountname]: boxes[accountname].append(foldername) @@ -64,10 +66,12 @@ def genmbnames(): {'re': re}) itemlist = [] for accountname in boxes.keys(): + localroot = localroots[accountname] for foldername in boxes[accountname]: if folderfilter(accountname, foldername): itemlist.append({'accountname': accountname, - 'foldername': foldername}) + 'foldername': foldername, + 'localfolders': localroot}) itemlist.sort(key = mb_sort_keyfunc) format_string = config.get("mbnames", "peritem", raw=1) itemlist = [format_string % d for d in itemlist] diff --git a/offlineimap/repository/Base.py b/offlineimap/repository/Base.py index db80ecd..1050721 100644 --- a/offlineimap/repository/Base.py +++ b/offlineimap/repository/Base.py @@ -259,3 +259,8 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object): for the threads to terminate.""" pass + def getlocalroot(self): + """ Local root folder for storing messages. + Will not be set for remote repositories.""" + return None + -- 1.8.1.3