diff options
author | Guido van Rossum <guido@python.org> | 2000-03-28 20:20:53 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2000-03-28 20:20:53 (GMT) |
commit | 66d451397577a7710902b75104839afc7ca05b81 (patch) | |
tree | b88e6e6a57361bacf4d1b58b04260aa3b19f8945 /Lib/imaplib.py | |
parent | 84306246f1d9a70b887881e029a082aab8db9211 (diff) | |
download | cpython-66d451397577a7710902b75104839afc7ca05b81.zip cpython-66d451397577a7710902b75104839afc7ca05b81.tar.gz cpython-66d451397577a7710902b75104839afc7ca05b81.tar.bz2 |
Piers Lauder:
This patch fixes the "search" command in imaplib. The problem
was that a search can take multiple arguments, but as defined,
would only accept one.
I have also made changes to the test code at the end to be less
verbose by default, but to accept a verbosity argument.
Diffstat (limited to 'Lib/imaplib.py')
-rw-r--r-- | Lib/imaplib.py | 75 |
1 files changed, 49 insertions, 26 deletions
diff --git a/Lib/imaplib.py b/Lib/imaplib.py index 7b5526e..31893a5 100644 --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -15,7 +15,7 @@ Public functions: Internaldate2tuple # # Authentication code contributed by Donn Cave <donn@u.washington.edu> June 1998. -__version__ = "2.33" +__version__ = "2.36" import binascii, re, socket, string, time, random, sys @@ -446,17 +446,17 @@ class IMAP4: return self._simple_command('RENAME', oldmailbox, newmailbox) - def search(self, charset, criteria): + def search(self, charset, *criteria): """Search mailbox for matching messages. - (typ, [data]) = <instance>.search(charset, criteria) + (typ, [data]) = <instance>.search(charset, criterium, ...) 'data' is space separated list of matching message numbers. """ name = 'SEARCH' if charset: charset = 'CHARSET ' + charset - typ, dat = self._simple_command(name, charset, criteria) + typ, dat = apply(self._simple_command, (name, charset) + criteria) return self._untagged_response(typ, dat, name) @@ -1022,10 +1022,20 @@ if __debug__: if __name__ == '__main__': - import getpass, sys + import getopt, getpass, sys - host = '' - if sys.argv[1:]: host = sys.argv[1] + try: + optlist, args = getopt.getopt(sys.argv[1:], 'd:') + except getopt.error, val: + pass + + for opt,val in optlist: + if opt == '-d': + Debug = int(val) + + if not args: args = ('',) + + host = args[0] USER = getpass.getuser() PASSWD = getpass.getpass("IMAP password for %s on %s" % (USER, host or "localhost")) @@ -1039,7 +1049,7 @@ if __name__ == '__main__': ('append', ('/tmp/yyz 2', None, None, test_mesg)), ('list', ('/tmp', 'yy*')), ('select', ('/tmp/yyz 2',)), - ('search', (None, '(TO zork)')), + ('search', (None, 'SUBJECT', 'test')), ('partial', ('1', 'RFC822', 1, 1024)), ('store', ('1', 'FLAGS', '(\Deleted)')), ('expunge', ()), @@ -1063,26 +1073,39 @@ if __name__ == '__main__': _mesg('%s => %s %s' % (cmd, typ, dat)) return dat - Debug = 5 - M = IMAP4(host) - _mesg('PROTOCOL_VERSION = %s' % M.PROTOCOL_VERSION) + try: + M = IMAP4(host) + _mesg('PROTOCOL_VERSION = %s' % M.PROTOCOL_VERSION) + + for cmd,args in test_seq1: + run(cmd, args) + + for ml in run('list', ('/tmp/', 'yy%')): + mo = re.match(r'.*"([^"]+)"$', ml) + if mo: path = mo.group(1) + else: path = string.split(ml)[-1] + run('delete', (path,)) + + for cmd,args in test_seq2: + dat = run(cmd, args) + + if (cmd,args) != ('uid', ('SEARCH', 'ALL')): + continue - for cmd,args in test_seq1: - run(cmd, args) + uid = string.split(dat[-1]) + if not uid: continue + run('uid', ('FETCH', '%s' % uid[-1], + '(FLAGS INTERNALDATE RFC822.SIZE RFC822.HEADER RFC822.TEXT)')) - for ml in run('list', ('/tmp/', 'yy%')): - mo = re.match(r'.*"([^"]+)"$', ml) - if mo: path = mo.group(1) - else: path = string.split(ml)[-1] - run('delete', (path,)) + print '\nAll tests OK.' - for cmd,args in test_seq2: - dat = run(cmd, args) + except: + print '\nTests failed.' - if (cmd,args) != ('uid', ('SEARCH', 'ALL')): - continue + if not Debug: + print ''' +If you would like to see debugging output, +try: %s -d5 +''' % sys.argv[0] - uid = string.split(dat[-1]) - if not uid: continue - run('uid', ('FETCH', '%s' % uid[-1], - '(FLAGS INTERNALDATE RFC822.SIZE RFC822.HEADER RFC822.TEXT)')) + raise |