/head: changeset 36

More updates
This commit is contained in:
jgoerzen 2002-06-21 07:51:21 +01:00
parent 0a0572fee5
commit 75dcb0dd16
9 changed files with 114 additions and 18 deletions

View File

@ -16,6 +16,10 @@
# 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
##################################################
# General definitions
##################################################
[general] [general]
# This specifies where imapsync is to store its metadata. # This specifies where imapsync is to store its metadata.
@ -31,11 +35,38 @@ metadata = ~/.imapsync
accounts = Test accounts = Test
# This is an account definition clause. ##################################################
# Mailbox name recorder
##################################################
[mbnames]
# imapsync can record your mailbox names in a format you specify.
# You can define the header, each mailbox item, the separator,
# and the footer. Here is an example for Mutt.
# If enabled is yes, all six setting must be specified, even if they
# are just the empty string "".
#
# The header, peritem, sep, and footer are all Python expressions passed
# through eval, so you can (and must) use Python quoting.
enabled = no
filename = ~/Mutt/muttrc.mailboxes
header = "mailboxes "
peritem = "+%(accountname)s/%(foldername)s"
sep = " "
footer = "\n"
##################################################
# Accounts
##################################################
# This is an account definition clause. You'll have one of these
# for each account listed in general/accounts above.
[Test] [Test]
# Specify the remote hostname. # Specify the remote hostname.
remotehost = pi.complete.org remotehost = examplehost
# Whether or not to use SSL. # Whether or not to use SSL.
ssl = yes ssl = yes
@ -50,7 +81,13 @@ remoteuser = pilot
# prompted. # prompted.
# remotepass = fake # remotepass = fake
# Specify local repository. # Specify local repository.
localfolders = ~/Test localfolders = ~/Test
# You can specify a folder translator. This must be a eval-able
# Python expression that takes a foldername arg and returns the new
# value. I suggest a lambda. This example will remove "INBOX." from
# the leading edge of folders (great for Courier IMAP users)
# nametrans = lambda foldername: re.sub('^INBOX.', '', foldername)

View File

@ -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 imapsync import imaplib, imaputil, imapserver, repository, folder from imapsync import imaplib, imaputil, imapserver, repository, folder, mbnames
import re, os, os.path, imapsync, sys import re, os, os.path, imapsync, sys
from ConfigParser import ConfigParser from ConfigParser import ConfigParser
@ -43,6 +43,7 @@ accounts = accounts.split(",")
server = None server = None
remoterepos = None remoterepos = None
localrepos = None localrepos = None
mailboxes = []
for accountname in accounts: for accountname in accounts:
ui.acct(accountname) ui.acct(accountname)
@ -63,7 +64,7 @@ for accountname in accounts:
# Connect to the remote server. # Connect to the remote server.
server = imapserver.IMAPServer(user, password, host, port, ssl) server = imapserver.IMAPServer(user, password, host, port, ssl)
remoterepos = repository.IMAP.IMAPRepository(server) remoterepos = repository.IMAP.IMAPRepository(config, accountname, server)
# Connect to the Maildirs. # Connect to the Maildirs.
localrepos = repository.Maildir.MaildirRepository(os.path.expanduser(config.get(accountname, "localfolders"))) localrepos = repository.Maildir.MaildirRepository(os.path.expanduser(config.get(accountname, "localfolders")))
@ -75,8 +76,10 @@ for accountname in accounts:
remoterepos.syncfoldersto(localrepos) remoterepos.syncfoldersto(localrepos)
for remotefolder in remoterepos.getfolders(): for remotefolder in remoterepos.getfolders():
mailboxes.append({'accountname': accountname,
'foldername': remotefolder.getvisiblename()})
# Load local folder. # Load local folder.
localfolder = localrepos.getfolder(remotefolder.getname()) localfolder = localrepos.getfolder(remotefolder.getvisiblename())
if not localfolder.isuidvalidityok(remotefolder): if not localfolder.isuidvalidityok(remotefolder):
ui.validityproblem(remotefolder) ui.validityproblem(remotefolder)
continue continue
@ -92,7 +95,7 @@ for accountname in accounts:
len(remotefolder.getmessagelist().keys())) len(remotefolder.getmessagelist().keys()))
# Load status folder. # Load status folder.
statusfolder = statusrepos.getfolder(remotefolder.getname()) statusfolder = statusrepos.getfolder(remotefolder.getvisiblename())
statusfolder.cachemessagelist() statusfolder.cachemessagelist()
if not statusfolder.isnewfolder(): if not statusfolder.isnewfolder():
@ -109,3 +112,4 @@ for accountname in accounts:
statusfolder.save() statusfolder.save()
mbnames.genmbnames(config, mailboxes)

View File

@ -1 +1,2 @@
import ui, folder, repository import ui, folder, repository, mbnames

View File

@ -16,11 +16,16 @@
# 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
import __main__
class BaseFolder: class BaseFolder:
def getname(self): def getname(self):
"""Returns name""" """Returns name"""
return self.name return self.name
def getvisiblename(self):
return self.name
def getroot(self): def getroot(self):
"""Returns the root of the folder, in a folder-specific fashion.""" """Returns the root of the folder, in a folder-specific fashion."""
return self.root return self.root

View File

@ -22,13 +22,17 @@ import rfc822
from StringIO import StringIO from StringIO import StringIO
class IMAPFolder(BaseFolder): class IMAPFolder(BaseFolder):
def __init__(self, imapserver, name): def __init__(self, imapserver, name, visiblename):
self.name = imaputil.dequote(name) self.name = imaputil.dequote(name)
self.root = imapserver.root self.root = imapserver.root
self.sep = imapserver.delim self.sep = imapserver.delim
self.imapserver = imapserver self.imapserver = imapserver
self.imapobj = self.imapserver.makeconnection() self.imapobj = self.imapserver.makeconnection()
self.messagelist = None self.messagelist = None
self.visiblename = visiblename
def getvisiblename(self):
return self.visiblename
def getuidvalidity(self): def getuidvalidity(self):
x = self.imapobj.status(self.getfullname(), ('UIDVALIDITY'))[1][0] x = self.imapobj.status(self.getfullname(), ('UIDVALIDITY'))[1][0]

View File

@ -0,0 +1,34 @@
# Mailbox name generator
# Copyright (C) 2002 John Goerzen
# <jgoerzen@complete.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import os.path
def genmbnames(config, boxlist):
"""Takes a configparser object and a boxlist, which is a list of hashes
containing 'accountname' and 'foldername' keys."""
if not config.getboolean("mbnames", "enabled"):
return
file = open(os.path.expanduser(config.get("mbnames", "filename")), "wt")
file.write(eval(config.get("mbnames", "header")))
itemlist = [eval(config.get("mbnames", "peritem", raw=1)) % item for item in boxlist]
file.write(eval(config.get("mbnames", "sep")).join(itemlist))
file.write(eval(config.get("mbnames", "footer")))
file.close()

View File

@ -45,11 +45,11 @@ class BaseRepository:
srchash = {} srchash = {}
for folder in srcfolders: for folder in srcfolders:
srchash[folder.getname().replace(src.getsep(), dest.getsep())] = \ srchash[folder.getvisiblename().replace(src.getsep(), dest.getsep())] = \
folder folder
desthash = {} desthash = {}
for folder in destfolders: for folder in destfolders:
desthash[folder.getname()] = folder desthash[folder.getvisiblename()] = folder
# #
# Find new folders. # Find new folders.

View File

@ -18,20 +18,27 @@
from Base import BaseRepository from Base import BaseRepository
from imapsync import folder, imaputil from imapsync import folder, imaputil
import re
class IMAPRepository(BaseRepository): class IMAPRepository(BaseRepository):
def __init__(self, imapserver): def __init__(self, config, accountname, imapserver):
"""Initialize an IMAPRepository object. Takes an IMAPServer """Initialize an IMAPRepository object. Takes an IMAPServer
object.""" object."""
self.imapserver = imapserver self.imapserver = imapserver
self.config = config
self.accountname = accountname
self.imapobj = imapserver.makeconnection() self.imapobj = imapserver.makeconnection()
self.folders = None self.folders = None
self.nametrans = lambda foldername: foldername
if config.has_option(accountname, 'nametrans'):
self.nametrans = eval(config.get(accountname, 'nametrans'))
def getsep(self): def getsep(self):
return self.imapserver.delim return self.imapserver.delim
def getfolder(self, foldername): def getfolder(self, foldername):
return folder.IMAP.IMAPFolder(self.imapserver, foldername) return folder.IMAP.IMAPFolder(self.imapserver, foldername,
self.nametrans(foldername))
def getfolders(self): def getfolders(self):
if self.folders != None: if self.folders != None:
@ -41,6 +48,7 @@ class IMAPRepository(BaseRepository):
flags, delim, name = imaputil.imapsplit(string) flags, delim, name = imaputil.imapsplit(string)
if '\\Noselect' in imaputil.flagsplit(flags): if '\\Noselect' in imaputil.flagsplit(flags):
continue continue
retval.append(folder.IMAP.IMAPFolder(self.imapserver, name)) retval.append(folder.IMAP.IMAPFolder(self.imapserver, name,
self.nametrans(imaputil.dequote(name))))
self.folders = retval self.folders = retval
return retval return retval

View File

@ -38,6 +38,9 @@ class UIBase:
def getpass(s, accountname, host, port, user): def getpass(s, accountname, host, port, user):
raise NotImplementedException raise NotImplementedException
def folderlist(s, list):
return ', '.join(["%s[%s]" % (s.getnicename(x), x.getname()) for x in list])
################################################## MESSAGES ################################################## MESSAGES
def init_banner(s): def init_banner(s):
@ -81,21 +84,21 @@ class UIBase:
df.getname())) df.getname()))
def copyingmessage(s, uid, src, destlist): def copyingmessage(s, uid, src, destlist):
ds = ["%s[%s]" % (s.getnicename(x), x.getname()) for x in destlist].join(', ') ds = s.folderlist(destlist)
s._msg("Copy message %d %s[%s] -> %s" % (uid, s.getnicename(src), s._msg("Copy message %d %s[%s] -> %s" % (uid, s.getnicename(src),
src.getname(), ds)) src.getname(), ds))
def deletingmessage(s, uid, destlist): def deletingmessage(s, uid, destlist):
ds = ["%s[%s]" % (s.getnicename(x), x.getname()) for x in destlist].join(', ') ds = s.folderlist(destlist)
s._msg("Deleting message %d in %s" % (uid, ds)) s._msg("Deleting message %d in %s" % (uid, ds))
def addingflags(s, uid, flags, destlist): def addingflags(s, uid, flags, destlist):
ds = ["%s[%s]" % (s.getnicename(x), x.getname()) for x in destlist].join(', ') ds = s.folderlist(destlist)
s._msg("Adding flags %s to message %d on %s" % \ s._msg("Adding flags %s to message %d on %s" % \
(flags.join(", "), uid, ds)) (flags.join(", "), uid, ds))
def deletingflags(s, uid, flags, destlist): def deletingflags(s, uid, flags, destlist):
ds = ["%s[%s]" % (s.getnicename(x), x.getname()) for x in destlist].join(', ') ds = s.folderlist(destlist)
s._msg("Deleting flags %s to message %d on %s" % \ s._msg("Deleting flags %s to message %d on %s" % \
(flags.join(", "), uid, ds)) (flags.join(", "), uid, ds))