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

Piers Lauder pierslauder@users.sourceforge.net
Fri, 20 Jul 2001 03:52:08 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv3523/dist/src/Lib

Modified Files:
	imaplib.py 
Log Message:
apply patch item #416253

Index: imaplib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/imaplib.py,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -r1.30 -r1.31
*** imaplib.py	2001/07/20 10:28:51	1.30
--- imaplib.py	2001/07/20 10:52:06	1.31
***************
*** 15,20 ****
  # Authentication code contributed by Donn Cave <donn@u.washington.edu> June 1998.
  # String method conversion by ESR, February 2001.
  
! __version__ = "2.40"
  
  import binascii, re, socket, time, random, sys
--- 15,21 ----
  # Authentication code contributed by Donn Cave <donn@u.washington.edu> June 1998.
  # String method conversion by ESR, February 2001.
+ # GET/SETACL contributed by Anthony Baxter <anthony@interlink.com.au> April 2001.
  
! __version__ = "2.47"
  
  import binascii, re, socket, time, random, sys
***************
*** 45,52 ****
--- 46,55 ----
          'EXPUNGE':      ('SELECTED',),
          'FETCH':        ('SELECTED',),
+         'GETACL':       ('AUTH', 'SELECTED'),
          'LIST':         ('AUTH', 'SELECTED'),
          'LOGIN':        ('NONAUTH',),
          'LOGOUT':       ('NONAUTH', 'AUTH', 'SELECTED', 'LOGOUT'),
          'LSUB':         ('AUTH', 'SELECTED'),
+         'NAMESPACE':    ('AUTH', 'SELECTED'),
          'NOOP':         ('NONAUTH', 'AUTH', 'SELECTED', 'LOGOUT'),
          'PARTIAL':      ('SELECTED',),
***************
*** 54,57 ****
--- 57,62 ----
          'SEARCH':       ('SELECTED',),
          'SELECT':       ('AUTH', 'SELECTED'),
+         'SETACL':       ('AUTH', 'SELECTED'),
+         'SORT':         ('SELECTED',),
          'STATUS':       ('AUTH', 'SELECTED'),
          'STORE':        ('SELECTED',),
***************
*** 59,63 ****
          'UID':          ('SELECTED',),
          'UNSUBSCRIBE':  ('AUTH', 'SELECTED'),
-         'NAMESPACE':    ('AUTH', 'SELECTED'),
          }
  
--- 64,67 ----
***************
*** 156,159 ****
--- 160,164 ----
          if __debug__:
              if self.debug >= 1:
+                 _mesg('imaplib version %s' % __version__)
                  _mesg('new IMAP4 connection, tag=%s' % self.tagpre)
  
***************
*** 188,201 ****
          #       Allow UPPERCASE variants of IMAP4 command methods.
          if Commands.has_key(attr):
!             return eval("self.%s" % attr.lower())
          raise AttributeError("Unknown IMAP4 command: '%s'" % attr)
  
  
  
!     #       Public methods
  
  
      def open(self, host, port):
!         """Setup 'self.sock' and 'self.file'."""
          self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
          self.sock.connect((self.host, self.port))
--- 193,209 ----
          #       Allow UPPERCASE variants of IMAP4 command methods.
          if Commands.has_key(attr):
!             return getattr(self, attr.lower())
          raise AttributeError("Unknown IMAP4 command: '%s'" % attr)
  
  
  
!     #       Overridable methods
  
  
      def open(self, host, port):
!         """Setup connection to remote server on "host:port".
!         This connection will be used by the routines:
!             read, readline, send, shutdown.
!         """
          self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
          self.sock.connect((self.host, self.port))
***************
*** 203,206 ****
--- 211,247 ----
  
  
+     def read(self, size):
+         """Read 'size' bytes from remote."""
+         return self.file.read(size)
+ 
+ 
+     def readline(self):
+         """Read line from remote."""
+         return self.file.readline()
+ 
+ 
+     def send(self, data):
+         """Send data to remote."""
+         self.sock.send(data)
+ 
+ 
+     def shutdown(self):
+         """Close I/O established in "open"."""
+         self.file.close()
+         self.sock.close()
+ 
+ 
+     def socket(self):
+         """Return socket instance used to connect to IMAP4 server.
+ 
+         socket = <instance>.socket()
+         """
+         return self.sock
+ 
+ 
+ 
+     #       Utility methods
+ 
+ 
      def recent(self):
          """Return most recent 'RECENT' responses if any exist,
***************
*** 230,242 ****
  
  
-     def socket(self):
-         """Return socket instance used to connect to IMAP4 server.
- 
-         socket = <instance>.socket()
-         """
-         return self.sock
- 
  
- 
      #       IMAP4 commands
  
--- 271,275 ----
***************
*** 369,372 ****
--- 402,414 ----
  
  
+     def getacl(self, mailbox):
+         """Get the ACLs for a mailbox.
+ 
+         (typ, [data]) = <instance>.getacl(mailbox)
+         """
+         typ, dat = self._simple_command('GETACL', mailbox)
+         return self._untagged_response(typ, dat, 'ACL')
+ 
+ 
      def list(self, directory='""', pattern='*'):
          """List mailbox names in directory matching pattern.
***************
*** 407,412 ****
          try: typ, dat = self._simple_command('LOGOUT')
          except: typ, dat = 'NO', ['%s: %s' % sys.exc_info()[:2]]
!         self.file.close()
!         self.sock.close()
          if self.untagged_responses.has_key('BYE'):
              return 'BYE', self.untagged_responses['BYE']
--- 449,453 ----
          try: typ, dat = self._simple_command('LOGOUT')
          except: typ, dat = 'NO', ['%s: %s' % sys.exc_info()[:2]]
!         self.shutdown()
          if self.untagged_responses.has_key('BYE'):
              return 'BYE', self.untagged_responses['BYE']
***************
*** 426,429 ****
--- 467,480 ----
  
  
+     def namespace(self):
+         """ Returns IMAP namespaces ala rfc2342
+ 
+         (typ, [data, ...]) = <instance>.namespace()
+         """
+         name = 'NAMESPACE'
+         typ, dat = self._simple_command(name)
+         return self._untagged_response(typ, dat, name)
+ 
+ 
      def noop(self):
          """Send NOOP command.
***************
*** 466,471 ****
          name = 'SEARCH'
          if charset:
!             charset = 'CHARSET ' + charset
!         typ, dat = apply(self._simple_command, (name, charset) + criteria)
          return self._untagged_response(typ, dat, name)
  
--- 517,523 ----
          name = 'SEARCH'
          if charset:
!             typ, dat = apply(self._simple_command, (name, 'CHARSET', charset) + criteria)
!         else:
!             typ, dat = apply(self._simple_command, (name,) + criteria)
          return self._untagged_response(typ, dat, name)
  
***************
*** 501,504 ****
--- 553,578 ----
  
  
+     def setacl(self, mailbox, who, what):
+         """Set a mailbox acl.
+ 
+         (typ, [data]) = <instance>.create(mailbox, who, what)
+         """
+         return self._simple_command('SETACL', mailbox, who, what)
+ 
+ 
+     def sort(self, sort_criteria, charset, *search_criteria):
+         """IMAP4rev1 extension SORT command.
+ 
+         (typ, [data]) = <instance>.sort(sort_criteria, charset, search_criteria, ...)
+         """
+         name = 'SORT'
+         #if not name in self.capabilities:	# Let the server decide!
+         #	raise self.error('unimplemented extension command: %s' % name)
+         if (sort_criteria[0],sort_criteria[-1]) != ('(',')'):
+         	sort_criteria = '(%s)' % sort_criteria
+         typ, dat = apply(self._simple_command, (name, sort_criteria, charset) + search_criteria)
+         return self._untagged_response(typ, dat, name)
+ 
+ 
      def status(self, mailbox, names):
          """Request named status conditions for mailbox.
***************
*** 507,512 ****
          """
          name = 'STATUS'
!         if self.PROTOCOL_VERSION == 'IMAP4':
!             raise self.error('%s unimplemented in IMAP4 (obtain IMAP4rev1 server, or re-code)' % name)
          typ, dat = self._simple_command(name, mailbox, names)
          return self._untagged_response(typ, dat, name)
--- 581,586 ----
          """
          name = 'STATUS'
!         #if self.PROTOCOL_VERSION == 'IMAP4':	# Let the server decide!
!         #    raise self.error('%s unimplemented in IMAP4 (obtain IMAP4rev1 server, or re-code)' % name)
          typ, dat = self._simple_command(name, mailbox, names)
          return self._untagged_response(typ, dat, name)
***************
*** 548,553 ****
          name = 'UID'
          typ, dat = apply(self._simple_command, (name, command) + args)
!         if command == 'SEARCH':
!             name = 'SEARCH'
          else:
              name = 'FETCH'
--- 622,627 ----
          name = 'UID'
          typ, dat = apply(self._simple_command, (name, command) + args)
!         if command in ('SEARCH', 'SORT'):
!             name = command
          else:
              name = 'FETCH'
***************
*** 567,582 ****
                  notified by server in CAPABILITY response.
  
          (typ, [data]) = <instance>.xatom(name, arg, ...)
          """
!         if name[0] != 'X' or not name in self.capabilities:
!             raise self.error('unknown extension command: %s' % name)
          return apply(self._simple_command, (name,) + args)
  
-     def namespace(self):
-         """ Returns IMAP namespaces ala rfc2342
-         """
-         name = 'NAMESPACE'
-         typ, dat = self._simple_command(name)
-         return self._untagged_response(typ, dat, name)
  
  
--- 641,657 ----
                  notified by server in CAPABILITY response.
  
+         Assumes command is legal in current state.
+ 
          (typ, [data]) = <instance>.xatom(name, arg, ...)
+ 
+         Returns response appropriate to extension command `name'.
          """
!         name = name.upper()
!         #if not name in self.capabilities:	# Let the server decide!
!         #    raise self.error('unknown extension command: %s' % name)
!         if not Commands.has_key(name):
!             Commands[name] = (self.state,)
          return apply(self._simple_command, (name,) + args)
  
  
  
***************
*** 641,646 ****
  
          try:
!             self.sock.send('%s%s' % (data, CRLF))
!         except socket.error, val:
              raise self.abort('socket error: %s' % val)
  
--- 716,721 ----
  
          try:
!             self.send('%s%s' % (data, CRLF))
!         except (socket.error, OSError), val:
              raise self.abort('socket error: %s' % val)
  
***************
*** 665,671 ****
  
              try:
!                 self.sock.send(literal)
!                 self.sock.send(CRLF)
!             except socket.error, val:
                  raise self.abort('socket error: %s' % val)
  
--- 740,746 ----
  
              try:
!                 self.send(literal)
!                 self.send(CRLF)
!             except (socket.error, OSError), val:
                  raise self.abort('socket error: %s' % val)
  
***************
*** 742,746 ****
                      if self.debug >= 4:
                          _mesg('read literal size %s' % size)
!                 data = self.file.read(size)
  
                  # Store response with literal as tuple
--- 817,821 ----
                      if self.debug >= 4:
                          _mesg('read literal size %s' % size)
!                 data = self.read(size)
  
                  # Store response with literal as tuple
***************
*** 790,794 ****
      def _get_line(self):
  
!         line = self.file.readline()
          if not line:
              raise self.abort('socket error: EOF')
--- 865,869 ----
      def _get_line(self):
  
!         line = self.readline()
          if not line:
              raise self.abort('socket error: EOF')
***************
*** 1060,1064 ****
  
      USER = getpass.getuser()
!     PASSWD = getpass.getpass("IMAP password for %s on %s:" % (USER, host or "localhost"))
  
      test_mesg = 'From: %s@localhost\nSubject: IMAP4 test\n\ndata...\n' % USER
--- 1135,1139 ----
  
      USER = getpass.getuser()
!     PASSWD = getpass.getpass("IMAP password for %s on %s: " % (USER, host or "localhost"))
  
      test_mesg = 'From: %s@localhost\nSubject: IMAP4 test\n\ndata...\n' % USER
***************
*** 1074,1077 ****
--- 1149,1153 ----
      ('partial', ('1', 'RFC822', 1, 1024)),
      ('store', ('1', 'FLAGS', '(\Deleted)')),
+     ('namespace', ()),
      ('expunge', ()),
      ('recent', ()),
***************
*** 1091,1095 ****
      def run(cmd, args):
          _mesg('%s %s' % (cmd, args))
!         typ, dat = apply(eval('M.%s' % cmd), args)
          _mesg('%s => %s %s' % (cmd, typ, dat))
          return dat
--- 1167,1171 ----
      def run(cmd, args):
          _mesg('%s %s' % (cmd, args))
!         typ, dat = apply(getattr(M, cmd), args)
          _mesg('%s => %s %s' % (cmd, typ, dat))
          return dat
***************
*** 1098,1101 ****
--- 1174,1178 ----
          M = IMAP4(host)
          _mesg('PROTOCOL_VERSION = %s' % M.PROTOCOL_VERSION)
+         _mesg('CAPABILITIES = %s' % `M.capabilities`)
  
          for cmd,args in test_seq1: