Update of /cvsroot/spambayes/spambayes/scripts In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv27616/scripts
Modified Files: sb_imapfilter.py Log Message: patch 1707808 from Dave Abrahams - tte patch for imap Index: sb_imapfilter.py =================================================================== RCS file: /cvsroot/spambayes/spambayes/scripts/sb_imapfilter.py,v retrieving revision 1.66 retrieving revision 1.67 diff -C2 -d -r1.66 -r1.67 *** sb_imapfilter.py 7 Apr 2006 02:36:40 -0000 1.66 --- sb_imapfilter.py 11 May 2007 00:23:08 -0000 1.67 *************** *** 177,181 **** timeout = 60 # seconds ! def __init__(self, server, port, debug=0, do_expunge=False): # There's a tricky situation where if use_ssl is False, but we # try to connect to a IMAP over SSL server, we will just hang --- 177,191 ---- timeout = 60 # seconds ! def __init__(self, server, debug=0, do_expunge = options["imap", "expunge"] ): ! ! if server.find(':') > -1: ! server, port = server.split(':', 1) ! port = int(port) ! else: ! if options["imap", "use_ssl"]: ! port = 993 ! else: ! port = 143 ! # There's a tricky situation where if use_ssl is False, but we # try to connect to a IMAP over SSL server, we will just hang *************** *** 386,389 **** --- 396,400 ---- RFC822_HEADER_RE = re.compile(r"(RFC822.HEADER) (\{[\d]+\})") UID_RE = re.compile(r"(UID) ([\d]+)") + UID_RE2 = re.compile(r" *(UID) ([\d]+)\)") FETCH_RESPONSE_RE = re.compile(r"([0-9]+) \(([" + \ re.escape(FLAG_CHARS) + r"\"\{\}\(\)\\ ]*)\)?") *************** *** 407,410 **** --- 418,424 ---- data = {} expected_literal = None + if self.UID_RE2.match(response[-1]): + response = response[:-1] + for part in response: # We ignore parentheses by themselves, for convenience. *************** *** 721,724 **** --- 735,739 ---- break else: + self.imap_server.print_log() raise BadIMAPResponseError("recent", "Cannot find saved message") *************** *** 1076,1079 **** --- 1091,1112 ---- + def servers(promptForPass = False): + """Returns a list containing a tuple (server,user,passwd) for each IMAP server in options. + + If promptForPass is True or at least on password is missing from options, + prompts the user for each server's password. + """ + + servers = options["imap", "server"] + usernames = options["imap", "username"] + pwds = options["imap", "password"] + + if promptForPass or len(pwds) < len(usernames): + pwds = [] + for u in usernames: + pwds.append(getpass("Enter password for %s:" % (u,))) + + return zip(servers,usernames,pwds) + def run(force_UI=False): try: *************** *** 1090,1095 **** promptForPass = False launchUI = False - servers = "" - usernames = "" for opt, arg in opts: --- 1123,1126 ---- *************** *** 1133,1164 **** print "Done." ! if options["imap", "server"]: ! servers = options["imap", "server"] ! usernames = options["imap", "username"] ! if not promptForPass: ! pwds = options["imap", "password"] ! else: ! pwds = None ! if not launchUI and not force_UI: ! print "You need to specify both a server and a username." ! sys.exit() ! ! if promptForPass: ! pwds = [] ! for i in xrange(len(usernames)): ! pwds.append(getpass("Enter password for %s:" % (usernames[i],))) ! ! servers_data = [] ! for server, username, password in zip(servers, usernames, pwds or []): ! if server.find(':') > -1: ! server, port = server.split(':', 1) ! port = int(port) ! else: ! if options["imap", "use_ssl"]: ! port = 993 ! else: ! port = 143 ! servers_data.append((server, port, username, password)) # Load stats manager. stats = Stats.Stats(options, message_db) --- 1164,1173 ---- print "Done." ! if not ( launchUI or force_UI or options["imap", "server"] ): ! print "You need to specify both a server and a username." ! sys.exit() + servers_data = servers(promptForPass) + # Load stats manager. stats = Stats.Stats(options, message_db) *************** *** 1180,1188 **** if sleepTime or not (doClassify or doTrain): imaps = [] ! for server, port, username, password in servers_data: if server == "": imaps.append(None) else: ! imaps.append(IMAPSession(server, port, imapDebug, doExpunge)) def close_db(): --- 1189,1197 ---- if sleepTime or not (doClassify or doTrain): imaps = [] ! for server, username, password in servers_data: if server == "": imaps.append(None) else: ! imaps.append(IMAPSession(server, imapDebug, doExpunge)) def close_db(): *************** *** 1201,1204 **** --- 1210,1214 ---- httpServer = UserInterfaceServer(options["html_ui", "port"]) + pwds = [ x[2] for x in servers_data ] httpServer.register(IMAPUserInterface(classifier, imaps, pwds, IMAPSession, stats=stats, *************** *** 1214,1219 **** if doClassify or doTrain: imaps = [] ! for server, port, username, password in servers_data: ! imaps.append(((server, port, imapDebug, doExpunge), username, password)) --- 1224,1229 ---- if doClassify or doTrain: imaps = [] ! for server, username, password in servers_data: ! imaps.append(((server, imapDebug, doExpunge), username, password)) *************** *** 1230,1235 **** options.set_restore_point() while True: ! for (server, port, imapDebug, doExpunge), username, password in imaps: ! imap = IMAPSession(server, port, imapDebug, doExpunge) if options["globals", "verbose"]: print "Account: %s:%s" % (imap.server, imap.port) --- 1240,1245 ---- options.set_restore_point() while True: ! for (server, imapDebug, doExpunge), username, password in imaps: ! imap = IMAPSession(server, imapDebug, doExpunge) if options["globals", "verbose"]: print "Account: %s:%s" % (imap.server, imap.port) _______________________________________________ Spambayes-checkins mailing list Spambayes-checkins@python.org http://mail.python.org/mailman/listinfo/spambayes-checkins