/offlineimap/head: changeset 229
Applied part 1 of Tommi's patch.
This commit is contained in:
parent
6e94ead957
commit
9be2bec748
@ -75,6 +75,16 @@ ui = Tk.Blinkenlights, Tk.VerboseUI, TTY.TTYUI, Noninteractive.Basic,
|
|||||||
|
|
||||||
ignore-readonly = no
|
ignore-readonly = no
|
||||||
|
|
||||||
|
########## Advanced settings
|
||||||
|
|
||||||
|
# You can give a Python source filename here and all config file
|
||||||
|
# python snippets will be evaluated in the context of that file.
|
||||||
|
# This allows you to e.g. define helper functions in the Python
|
||||||
|
# source file and call them from this config file.
|
||||||
|
#
|
||||||
|
# pythonfile = ~/.offlineimap.py
|
||||||
|
#
|
||||||
|
|
||||||
##################################################
|
##################################################
|
||||||
# Mailbox name recorder
|
# Mailbox name recorder
|
||||||
##################################################
|
##################################################
|
||||||
@ -251,6 +261,14 @@ remoteuser = username
|
|||||||
# folderincludes = ['box1', 'box2', 'box3', 'box4',
|
# folderincludes = ['box1', 'box2', 'box3', 'box4',
|
||||||
# 'box5', 'box6']
|
# 'box5', 'box6']
|
||||||
|
|
||||||
|
# You can specify foldersort to determine how folders are sorted.
|
||||||
|
# This affects order of synchronization and mbnames. The expression
|
||||||
|
# should return -1, 0, or 1, as the default Python cmp() does.
|
||||||
|
#
|
||||||
|
# To reverse the sort:
|
||||||
|
#
|
||||||
|
# foldersort = lambda x, y: -cmp(x, y)
|
||||||
|
|
||||||
|
|
||||||
# OfflineIMAP can use multiple connections to the server in order
|
# OfflineIMAP can use multiple connections to the server in order
|
||||||
# to perform multiple synchronization actions simultaneously.
|
# to perform multiple synchronization actions simultaneously.
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
from offlineimap import imaplib, imaputil, imapserver, repository, folder, mbnames, threadutil, version
|
from offlineimap import imaplib, imaputil, imapserver, repository, folder, mbnames, threadutil, version, localeval
|
||||||
from offlineimap.threadutil import InstanceLimitedThread, ExitNotifyThread
|
from offlineimap.threadutil import InstanceLimitedThread, ExitNotifyThread
|
||||||
from offlineimap.ui import UIBase
|
from offlineimap.ui import UIBase
|
||||||
import re, os, os.path, offlineimap, sys
|
import re, os, os.path, offlineimap, sys
|
||||||
@ -58,10 +58,16 @@ if not os.path.exists(configfilename):
|
|||||||
|
|
||||||
config.read(configfilename)
|
config.read(configfilename)
|
||||||
|
|
||||||
if '-u' in options:
|
if config.has_option("general", "pythonfile"):
|
||||||
ui = offlineimap.ui.detector.getUImod(options['-u'])(config)
|
path=os.path.expanduser(config.get("general", "pythonfile"))
|
||||||
else:
|
else:
|
||||||
ui = offlineimap.ui.detector.findUI(config)
|
path=None
|
||||||
|
localeval = localeval.LocalEval(path)
|
||||||
|
|
||||||
|
if '-u' in options:
|
||||||
|
ui = offlineimap.ui.detector.getUImod(options['-u'])(config, localeval)
|
||||||
|
else:
|
||||||
|
ui = offlineimap.ui.detector.findUI(config, localeval)
|
||||||
ui.init_banner()
|
ui.init_banner()
|
||||||
|
|
||||||
if '-d' in options:
|
if '-d' in options:
|
||||||
@ -138,7 +144,7 @@ def syncaccount(accountname, *args):
|
|||||||
server = imapserver.ConfigedIMAPServer(config, accountname, passwords)
|
server = imapserver.ConfigedIMAPServer(config, accountname, passwords)
|
||||||
servers[accountname] = server
|
servers[accountname] = server
|
||||||
|
|
||||||
remoterepos = repository.IMAP.IMAPRepository(config, accountname, server)
|
remoterepos = repository.IMAP.IMAPRepository(config, localeval, accountname, server)
|
||||||
|
|
||||||
# Connect to the Maildirs.
|
# Connect to the Maildirs.
|
||||||
localrepos = repository.Maildir.MaildirRepository(os.path.expanduser(config.get(accountname, "localfolders")), accountname, config)
|
localrepos = repository.Maildir.MaildirRepository(os.path.expanduser(config.get(accountname, "localfolders")), accountname, config)
|
||||||
@ -256,7 +262,7 @@ def syncitall():
|
|||||||
threads.append(thread)
|
threads.append(thread)
|
||||||
# Wait for the threads to finish.
|
# Wait for the threads to finish.
|
||||||
threadutil.threadsreset(threads)
|
threadutil.threadsreset(threads)
|
||||||
mbnames.genmbnames(config, mailboxes)
|
mbnames.genmbnames(config, localeval, mailboxes)
|
||||||
|
|
||||||
def sync_with_timer():
|
def sync_with_timer():
|
||||||
currentThread().setExitMessage('SYNC_WITH_TIMER_TERMINATE')
|
currentThread().setExitMessage('SYNC_WITH_TIMER_TERMINATE')
|
||||||
|
@ -18,16 +18,16 @@
|
|||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
def genmbnames(config, boxlist):
|
def genmbnames(config, localeval, boxlist):
|
||||||
"""Takes a configparser object and a boxlist, which is a list of hashes
|
"""Takes a configparser object and a boxlist, which is a list of hashes
|
||||||
containing 'accountname' and 'foldername' keys."""
|
containing 'accountname' and 'foldername' keys."""
|
||||||
if not config.getboolean("mbnames", "enabled"):
|
if not config.getboolean("mbnames", "enabled"):
|
||||||
return
|
return
|
||||||
file = open(os.path.expanduser(config.get("mbnames", "filename")), "wt")
|
file = open(os.path.expanduser(config.get("mbnames", "filename")), "wt")
|
||||||
file.write(eval(config.get("mbnames", "header")))
|
file.write(localeval.eval(config.get("mbnames", "header")))
|
||||||
itemlist = [eval(config.get("mbnames", "peritem", raw=1)) % item for item in boxlist]
|
itemlist = [localeval.eval(config.get("mbnames", "peritem", raw=1)) % item for item in boxlist]
|
||||||
file.write(eval(config.get("mbnames", "sep")).join(itemlist))
|
file.write(localeval.eval(config.get("mbnames", "sep")).join(itemlist))
|
||||||
file.write(eval(config.get("mbnames", "footer")))
|
file.write(localeval.eval(config.get("mbnames", "footer")))
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ import re
|
|||||||
from threading import *
|
from threading import *
|
||||||
|
|
||||||
class IMAPRepository(BaseRepository):
|
class IMAPRepository(BaseRepository):
|
||||||
def __init__(self, config, accountname, imapserver):
|
def __init__(self, config, localeval, accountname, imapserver):
|
||||||
"""Initialize an IMAPRepository object. Takes an IMAPServer
|
"""Initialize an IMAPRepository object. Takes an IMAPServer
|
||||||
object."""
|
object."""
|
||||||
self.imapserver = imapserver
|
self.imapserver = imapserver
|
||||||
@ -32,12 +32,15 @@ class IMAPRepository(BaseRepository):
|
|||||||
self.nametrans = lambda foldername: foldername
|
self.nametrans = lambda foldername: foldername
|
||||||
self.folderfilter = lambda foldername: 1
|
self.folderfilter = lambda foldername: 1
|
||||||
self.folderincludes = []
|
self.folderincludes = []
|
||||||
|
self.foldersort = cmp
|
||||||
if config.has_option(accountname, 'nametrans'):
|
if config.has_option(accountname, 'nametrans'):
|
||||||
self.nametrans = eval(config.get(accountname, 'nametrans'))
|
self.nametrans = localeval.eval(config.get(accountname, 'nametrans'), {'re': re})
|
||||||
if config.has_option(accountname, 'folderfilter'):
|
if config.has_option(accountname, 'folderfilter'):
|
||||||
self.folderfilter = eval(config.get(accountname, 'folderfilter'))
|
self.folderfilter = localeval.eval(config.get(accountname, 'folderfilter'), {'re': re})
|
||||||
if config.has_option(accountname, 'folderincludes'):
|
if config.has_option(accountname, 'folderincludes'):
|
||||||
self.folderincludes = eval(config.get(accountname, 'folderincludes'))
|
self.folderincludes = localeval.eval(config.get(accountname, 'folderincludes'), {'re': re})
|
||||||
|
if config.has_option(accountname, 'foldersort'):
|
||||||
|
self.foldersort = localeval.eval(config.get(accountname, 'foldersort'), {'re': re})
|
||||||
|
|
||||||
def getsep(self):
|
def getsep(self):
|
||||||
return self.imapserver.delim
|
return self.imapserver.delim
|
||||||
@ -71,6 +74,6 @@ class IMAPRepository(BaseRepository):
|
|||||||
retval.append(folder.IMAP.IMAPFolder(self.imapserver, foldername,
|
retval.append(folder.IMAP.IMAPFolder(self.imapserver, foldername,
|
||||||
self.nametrans(foldername),
|
self.nametrans(foldername),
|
||||||
self.accountname))
|
self.accountname))
|
||||||
retval.sort(lambda x, y: cmp(x.getvisiblename(), y.getvisiblename()))
|
retval.sort(lambda x, y: self.foldersort(x.getvisiblename(), y.getvisiblename()))
|
||||||
self.folders = retval
|
self.folders = retval
|
||||||
return retval
|
return retval
|
||||||
|
@ -16,16 +16,21 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
from offlineimap.ui import *
|
import offlineimap.ui
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
def findUI(config):
|
def findUI(config, localeval):
|
||||||
uistrlist = ['Tk.Blinkenlights', 'Tk.VerboseUI', 'TTY.TTYUI',
|
uistrlist = ['Tk.Blinkenlights', 'Tk.VerboseUI', 'TTY.TTYUI',
|
||||||
'Noninteractive.Basic', 'Noninteractive.Quiet']
|
'Noninteractive.Basic', 'Noninteractive.Quiet']
|
||||||
|
namespace={}
|
||||||
|
for ui in dir(offlineimap.ui):
|
||||||
|
if ui.startswith('_') or ui=='detector':
|
||||||
|
continue
|
||||||
|
namespace[ui]=getattr(offlineimap.ui, ui)
|
||||||
if config.has_option("general", "ui"):
|
if config.has_option("general", "ui"):
|
||||||
uistrlist = config.get("general", "ui").replace(" ", "").split(",")
|
uistrlist = config.get("general", "ui").replace(" ", "").split(",")
|
||||||
for uistr in uistrlist:
|
for uistr in uistrlist:
|
||||||
uimod = getUImod(uistr)
|
uimod = getUImod(uistr, localeval, namespace)
|
||||||
if uimod:
|
if uimod:
|
||||||
uiinstance = uimod(config)
|
uiinstance = uimod(config)
|
||||||
if uiinstance.isusable():
|
if uiinstance.isusable():
|
||||||
@ -33,9 +38,9 @@ def findUI(config):
|
|||||||
sys.stderr.write("ERROR: No UIs were found usable!\n")
|
sys.stderr.write("ERROR: No UIs were found usable!\n")
|
||||||
sys.exit(200)
|
sys.exit(200)
|
||||||
|
|
||||||
def getUImod(uistr):
|
def getUImod(uistr, localeval, namespace):
|
||||||
try:
|
try:
|
||||||
uimod = eval(uistr)
|
uimod = localeval.eval(uistr, namespace)
|
||||||
except (AttributeError, NameError):
|
except (AttributeError, NameError), e:
|
||||||
return None
|
return None
|
||||||
return uimod
|
return uimod
|
||||||
|
Loading…
Reference in New Issue
Block a user