[Python-checkins] CVS: python/dist/src/Lib imaplib.py,1.18,1.19

Guido van Rossum python-dev@python.org
Tue, 28 Mar 2000 15:20:56 -0500 (EST)


Update of /projects/cvsroot/python/dist/src/Lib
In directory eric:/projects/python/develop/guido/src/Lib

Modified Files:
	imaplib.py 
Log Message:
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.


Index: imaplib.py
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Lib/imaplib.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -r1.18 -r1.19
*** imaplib.py	2000/02/28 22:37:30	1.18
--- imaplib.py	2000/03/28 20:20:53	1.19
***************
*** 16,20 ****
  # Authentication code contributed by Donn Cave <donn@u.washington.edu> June 1998.
  
! __version__ = "2.33"
  
  import binascii, re, socket, string, time, random, sys
--- 16,20 ----
  # Authentication code contributed by Donn Cave <donn@u.washington.edu> June 1998.
  
! __version__ = "2.36"
  
  import binascii, re, socket, string, time, random, sys
***************
*** 447,454 ****
  
  
! 	def search(self, charset, criteria):
  		"""Search mailbox for matching messages.
  
! 		(typ, [data]) = <instance>.search(charset, criteria)
  
  		'data' is space separated list of matching message numbers.
--- 447,454 ----
  
  
! 	def search(self, charset, *criteria):
  		"""Search mailbox for matching messages.
  
! 		(typ, [data]) = <instance>.search(charset, criterium, ...)
  
  		'data' is space separated list of matching message numbers.
***************
*** 457,461 ****
  		if charset:
  			charset = 'CHARSET ' + charset
! 		typ, dat = self._simple_command(name, charset, criteria)
  		return self._untagged_response(typ, dat, name)
  
--- 457,461 ----
  		if charset:
  			charset = 'CHARSET ' + charset
! 		typ, dat = apply(self._simple_command, (name, charset) + criteria)
  		return self._untagged_response(typ, dat, name)
  
***************
*** 1023,1031 ****
  if __name__ == '__main__':
  
! 	import getpass, sys
  
! 	host = ''
! 	if sys.argv[1:]: host = sys.argv[1]
  
  	USER = getpass.getuser()
  	PASSWD = getpass.getpass("IMAP password for %s on %s" % (USER, host or "localhost"))
--- 1023,1041 ----
  if __name__ == '__main__':
  
! 	import getopt, getpass, sys
  
! 	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"))
***************
*** 1040,1044 ****
  	('list', ('/tmp', 'yy*')),
  	('select', ('/tmp/yyz 2',)),
! 	('search', (None, '(TO zork)')),
  	('partial', ('1', 'RFC822', 1, 1024)),
  	('store', ('1', 'FLAGS', '(\Deleted)')),
--- 1050,1054 ----
  	('list', ('/tmp', 'yy*')),
  	('select', ('/tmp/yyz 2',)),
! 	('search', (None, 'SUBJECT', 'test')),
  	('partial', ('1', 'RFC822', 1, 1024)),
  	('store', ('1', 'FLAGS', '(\Deleted)')),
***************
*** 1063,1088 ****
  		_mesg('%s => %s %s' % (cmd, typ, dat))
  		return dat
  
! 	Debug = 5
! 	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
! 
! 		uid = string.split(dat[-1])
! 		if not uid: continue
! 		run('uid', ('FETCH', '%s' % uid[-1],
! 			'(FLAGS INTERNALDATE RFC822.SIZE RFC822.HEADER RFC822.TEXT)'))
--- 1073,1111 ----
  		_mesg('%s => %s %s' % (cmd, typ, dat))
  		return dat
+ 
+ 	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
+ 
+ 			uid = string.split(dat[-1])
+ 			if not uid: continue
+ 			run('uid', ('FETCH', '%s' % uid[-1],
+ 				'(FLAGS INTERNALDATE RFC822.SIZE RFC822.HEADER RFC822.TEXT)'))
+ 
+ 		print '\nAll tests OK.'
+ 
+ 	except:
+ 		print '\nTests failed.'
+ 
+ 		if not Debug:
+ 			print '''
+ If you would like to see debugging output,
+ try: %s -d5
+ ''' % sys.argv[0]
  
! 		raise