diff --git a/head/Makefile b/head/Makefile new file mode 100644 index 0000000..788a4c9 --- /dev/null +++ b/head/Makefile @@ -0,0 +1,29 @@ +# 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 + +doc: + PYTHONPATH=`pwd` pydoc2.2 dictdlib > dictdlib.txt + PYTHONPATH=`pwd` pydoc2.2 -w dictdlib + +clean: + -rm -f `find . -name "*~"` + -rm -f `find . -name "*.pyc"` + +changelog: + cvs2cl + cvs commit ChangeLog + rm ChangeLog.bak diff --git a/head/offlineimap.py b/head/offlineimap.py index 0b66096..961a697 100644 --- a/head/offlineimap.py +++ b/head/offlineimap.py @@ -17,7 +17,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -from imapsync import imaplib, imaputil, imapserver +from imapsync import imaplib, imaputil, imapserver, repository, folder import re import getpass @@ -28,3 +28,5 @@ passwd = getpass.getpass('Password: ') server = imapserver.IMAPServer(user, passwd, host, ssl = 1) imapobj = server.makeconnection() delim, root = imaputil.imapsplit(imapobj.list('""', '""')[1][0])[1:] + +repos = repository.IMAP.IMAPRepository(server) diff --git a/head/offlineimap/__init__.py b/head/offlineimap/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/head/offlineimap/folder/Base.py b/head/offlineimap/folder/Base.py new file mode 100644 index 0000000..f80c78f --- /dev/null +++ b/head/offlineimap/folder/Base.py @@ -0,0 +1,34 @@ +# Base folder support +# 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 + +class BaseFolder: + def getname(self): + """Returns name""" + return self.name + + def getroot(self): + """Returns the root of the folder, in a folder-specific fashion.""" + return self.root + + def getsep(self): + """Returns the separator for this folder type.""" + return self.sep + + def getfullname(self): + return self.getroot() + self.getsep() + self.getname() + diff --git a/head/offlineimap/folder/IMAP.py b/head/offlineimap/folder/IMAP.py new file mode 100644 index 0000000..0274055 --- /dev/null +++ b/head/offlineimap/folder/IMAP.py @@ -0,0 +1,28 @@ +# IMAP folder support +# 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 + +from Base import BaseFolder +from imapsync import imaputil + +class IMAPFolder(BaseFolder): + def __init__(self, imapserver, name): + self.name = imaputil.dequote(name) + self.root = imapserver.root + self.sep = imapserver.delim + self.imapserver = imapserver + diff --git a/head/offlineimap/folder/__init__.py b/head/offlineimap/folder/__init__.py index e69de29..dda8dd1 100644 --- a/head/offlineimap/folder/__init__.py +++ b/head/offlineimap/folder/__init__.py @@ -0,0 +1 @@ +import Base, IMAP diff --git a/head/offlineimap/imapserver.py b/head/offlineimap/imapserver.py index 6e4a032..7305bed 100644 --- a/head/offlineimap/imapserver.py +++ b/head/offlineimap/imapserver.py @@ -16,7 +16,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -from imapsync import imaplib +from imapsync import imaplib, imaputil class IMAPServer: def __init__(self, username, password, hostname, port = None, ssl = 1): @@ -25,12 +25,24 @@ class IMAPServer: self.hostname = hostname self.port = port self.usessl = ssl + self.delim = None + self.root = None if port == None: if ssl: self.port = 993 else: self.port = 143 + def getdelim(self): + """Returns this server's folder delimiter. Can only be called + after one or more calls to makeconnection.""" + return self.delim + + def getroot(self): + """Returns this server's folder root. Can only be called after one + or more calls to makeconnection.""" + return self.root + def makeconnection(self): """Opens a connection to the server and returns an appropriate object.""" @@ -42,6 +54,11 @@ class IMAPServer: imapobj = imaplib.IMAP4(self.hostname, self.port) imapobj.login(self.username, self.password) + + if self.delim == None: + self.delim, self.root = \ + imaputil.imapsplit(imapobj.list('""', '""')[1][0])[1:] + return imapobj diff --git a/head/offlineimap/imaputil.py b/head/offlineimap/imaputil.py index 5c24e2a..a8f28f5 100644 --- a/head/offlineimap/imaputil.py +++ b/head/offlineimap/imaputil.py @@ -30,6 +30,11 @@ def dequote(string): string = string.replace('\\\\', '\\') return string +def flagsplit(string): + if string[0] != '(' or string[-1] != ')': + raise ValueError, "Passed string '%s' is not a flag list" % string + return string[1:-1].split(" ") + def imapsplit(string): """Takes a string from an IMAP conversation and returns a list containing its components. One example string is: diff --git a/head/offlineimap/repository/IMAP.py b/head/offlineimap/repository/IMAP.py index 59d19db..c354b59 100644 --- a/head/offlineimap/repository/IMAP.py +++ b/head/offlineimap/repository/IMAP.py @@ -17,10 +17,20 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA from Base import BaseRepository +from imapsync import folder, imaputil class IMAPRepository(BaseRepository): def __init__(self, imapserver): """Initialize an IMAPRepository object. Takes an IMAPServer object.""" self.imapserver = imapserver - + self.imapobj = imapserver.makeconnection() + + def getfolders(self): + retval = [] + for string in self.imapobj.list(self.imapserver.root)[1]: + flags, delim, name = imaputil.imapsplit(string) + if '\\Noselect' in imaputil.flagsplit(flags): + continue + retval.append(folder.IMAP.IMAPFolder(self.imapserver, name)) + return retval diff --git a/head/offlineimap/repository/__init__.py b/head/offlineimap/repository/__init__.py index e69de29..dab9055 100644 --- a/head/offlineimap/repository/__init__.py +++ b/head/offlineimap/repository/__init__.py @@ -0,0 +1 @@ +import IMAP, Base