From 3c199703c2d2f5c495e5aed1d86308a39a02e52b Mon Sep 17 00:00:00 2001 From: jgoerzen Date: Thu, 20 Jun 2002 08:40:29 +0100 Subject: [PATCH] /head: changeset 18 Updated. --- head/offlineimap.conf | 56 +++++++++++++++++++++++++++++ head/offlineimap/folder/IMAP.py | 13 +++++-- head/offlineimap/folder/Maildir.py | 6 ++-- head/offlineimap/imapserver.py | 2 ++ head/offlineimap/imaputil.py | 29 ++++++++++++++- head/offlineimap/repository/IMAP.py | 4 +-- 6 files changed, 101 insertions(+), 9 deletions(-) create mode 100644 head/offlineimap.conf diff --git a/head/offlineimap.conf b/head/offlineimap.conf new file mode 100644 index 0000000..85907ab --- /dev/null +++ b/head/offlineimap.conf @@ -0,0 +1,56 @@ +# Sample configuration file +# Copyright (C) 2002 John Goerzen +# +# +# 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 + +[general] + +# This specifies where imapsync is to store its metadata. +# This directory will be created if it does not already exist. + +metadata = ~/.imapsync + +# This variable specifies which accounts are defined. Separate them +# with commas. Account names should be alphanumeric only. +# You will need to specify one section per account below. You may +# not use "general" for an account name. +# + +accounts = Test + +# This is an account definition clause. + +[Test] +# Specify the remote hostname. +remotehost = imap.postoffice.net + +# Whether or not to use SSL. +ssl = yes + +# Specify the port. If not specified, use a default port. +# remoteport = 993 + +# Specify the remote user name. +remoteuser = jgoerzen//quovix.com + +# Specify the remote password. If not specified, you will be +# prompted. +# remotepass = fake + + +# Specify local repository. + +localfolders = ~/Test diff --git a/head/offlineimap/folder/IMAP.py b/head/offlineimap/folder/IMAP.py index 808c1fd..04ba879 100644 --- a/head/offlineimap/folder/IMAP.py +++ b/head/offlineimap/folder/IMAP.py @@ -31,14 +31,14 @@ class IMAPFolder(BaseFolder): def getuidvalidity(self): x = self.imapobj.status(self.getfullname(), ('UIDVALIDITY'))[1][0] uidstring = imaputil.imapsplit(x)[1] - return int(imaputil.flagsplit(x)[1]) + return long(imaputil.flagsplit(uidstring)[1]) def cachemessagelist(self): assert(self.imapobj.select(self.getfullname())[0] == 'OK') self.messagelist = {} response = self.imapobj.status(self.getfullname(), ('MESSAGES'))[1][0] result = imaputil.imapsplit(response)[1] - maxmsgid = int(imaputil.flags2hash(result)['MESSAGES']) + maxmsgid = long(imaputil.flags2hash(result)['MESSAGES']) # Now, get the flags and UIDs for these. response = self.imapobj.fetch('1:%d' % maxmsgid, '(FLAGS UID)')[1] @@ -46,5 +46,12 @@ class IMAPFolder(BaseFolder): # Discard the message number. messagestr = imaputil.imapsplit(messagestr)[1] options = imaputil.flags2hash(messagestr) - + uid = long(options['UID']) + flags = imaputil.flagsimap2maildir(options['FLAGS']) + self.messagelist[uid] = {'uid': uid, 'flags': flags} + + def getmessagelist(self): + return self.messagelist + + diff --git a/head/offlineimap/folder/Maildir.py b/head/offlineimap/folder/Maildir.py index d27040a..2ff9203 100644 --- a/head/offlineimap/folder/Maildir.py +++ b/head/offlineimap/folder/Maildir.py @@ -35,7 +35,7 @@ class MaildirFolder(BaseFolder): if not os.path.exists(self.uidfilename): return None file = open(self.uidfilename, "rt") - retval = int(file.readline().strip()) + retval = long(file.readline().strip()) file.close() return retval @@ -75,7 +75,7 @@ class MaildirFolder(BaseFolder): uid = nouidcounter nouidcounter -= 1 else: - uid = int(uidmatch.group(1)) + uid = long(uidmatch.group(1)) flagmatch = re.search(':.*2,([A-Z]+)') flags = [] if flagmatch: @@ -107,7 +107,7 @@ class MaildirFolder(BaseFolder): if attempts > 15: raise IOError, "Couldn't write to file %s" % messagename messagename = '%d.%d.%s,U=%d' % \ - (int(time.time()), + (long(time.time()), os.getpid(), socket.gethostname(), uid) diff --git a/head/offlineimap/imapserver.py b/head/offlineimap/imapserver.py index 7305bed..83621f5 100644 --- a/head/offlineimap/imapserver.py +++ b/head/offlineimap/imapserver.py @@ -58,6 +58,8 @@ class IMAPServer: if self.delim == None: self.delim, self.root = \ imaputil.imapsplit(imapobj.list('""', '""')[1][0])[1:] + self.delim = imaputil.dequote(self.delim) + self.root = imaputil.dequote(self.root) return imapobj diff --git a/head/offlineimap/imaputil.py b/head/offlineimap/imaputil.py index 2122adf..9359c79 100644 --- a/head/offlineimap/imaputil.py +++ b/head/offlineimap/imaputil.py @@ -66,7 +66,7 @@ def imapsplit(string): workstr = workstr[len(parenlist):] retval.append(parenlist) elif workstr[0] == '"': - quotelist = re.search('^("([^"]|\\")*")', workstr).group(1) + quotelist = re.search('^("(?:[^"]|\\\\")*")', workstr).group(1) workstr = workstr[len(quotelist):] retval.append(quotelist) else: @@ -75,3 +75,30 @@ def imapsplit(string): retval.append(unq) return retval +def flagsimap2maildir(string): + flagmap = {'\\Seen': 'S', + '\\Answered': 'R', + '\\Flagged': 'F', + '\\Deleted': 'T', + '\\Draft': 'D'} + retval = [] + imapflaglist = flagsplit(string) + for imapflag in imapflaglist: + if flagmap.has_key(imapflag): + retval.append(flagmap[imapflag]) + retval.sort() + return retval + +def flagsmaildir2imap(list): + flagmap = {'S': '\\Seen', + 'R': '\\Answered', + 'F': '\\Flagged', + 'T': '\\Deleted', + 'D': '\\Draft'} + retval = [] + for mdflag in list: + if flagmap.has_key(mdflag): + retval.append(flagmap[mdflag]) + retval.sort() + return retval + diff --git a/head/offlineimap/repository/IMAP.py b/head/offlineimap/repository/IMAP.py index ef8de9a..e7ed88b 100644 --- a/head/offlineimap/repository/IMAP.py +++ b/head/offlineimap/repository/IMAP.py @@ -31,13 +31,13 @@ class IMAPRepository(BaseRepository): return self.imapserver.delim def getfolder(self, foldername): - return folder.IMAP.IMAPFolder(self.imapserver, name) + return folder.IMAP.IMAPFolder(self.imapserver, foldername) def getfolders(self): if self.folders != None: return self.folders retval = [] - for string in self.imapobj.list(self.imapserver.root)[1]: + for string in self.imapobj.list()[1]: flags, delim, name = imaputil.imapsplit(string) if '\\Noselect' in imaputil.flagsplit(flags): continue