/head: changeset 6

Updated -- more writing
This commit is contained in:
jgoerzen 2002-06-19 06:22:21 +01:00
parent ab27fdaad7
commit abcbfd9b2f
10 changed files with 130 additions and 3 deletions

29
head/Makefile Normal file
View File

@ -0,0 +1,29 @@
# 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
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

View File

@ -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)

View File

View File

@ -0,0 +1,34 @@
# Base folder support
# 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
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()

View File

@ -0,0 +1,28 @@
# IMAP folder support
# 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
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

View File

@ -0,0 +1 @@
import Base, IMAP

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -0,0 +1 @@
import IMAP, Base