]> code.delx.au - offlineimap/commitdiff
/offlineimap/head: changeset 167
authorjgoerzen <jgoerzen>
Tue, 23 Jul 2002 19:55:18 +0000 (20:55 +0100)
committerjgoerzen <jgoerzen>
Tue, 23 Jul 2002 19:55:18 +0000 (20:55 +0100)
- Modified imaputil.py and folder/Maildir.py to run faster. Eliminated
  many regular expressions; pre-compiled many others.

- Fixed threadutil's exitnotifyloop to always handle threads in the
  order they exited, rather than sometimes in the inverse order. This
  way, make sure to handle thread's exception messages before a thread
  exited.

offlineimap/head/debian/changelog
offlineimap/head/offlineimap/folder/Maildir.py
offlineimap/head/offlineimap/imaputil.py
offlineimap/head/offlineimap/threadutil.py

index 7dc006f3cf983d6f533866de06fa01d2c163f058..43a1266c7d67f35209ba4cbb7b5fcffe0f90a7e9 100644 (file)
@@ -1,3 +1,13 @@
+offlineimap (3.1.1) unstable; urgency=low
+
+  * Modified imaputil.py and folder/Maildir.py to run faster.  Eliminated
+    many regular expressions; pre-compiled many others.
+  * Fixed threadutil's exitnotifyloop to always handle threads in the order
+    they exited, rather than sometimes in the inverse order.  This way,
+    make sure to handle thread's exception messages before a thread exited.
+
+ -- John Goerzen <jgoerzen@complete.org>  Tue, 23 Jul 2002 06:53:16 -0500
+
 offlineimap (3.1.0) unstable; urgency=low
 
   * When uploading messages from a Maildir, now convert \r\n to \n in case
index 22e463f92d2c91ca5e830fdce52bf92082df0ec1..b0288598c93ae69bf384f45f82b8729c002a588a 100644 (file)
@@ -20,6 +20,10 @@ from Base import BaseFolder
 from offlineimap import imaputil
 import os.path, os, re, time, socket, md5
 
+foldermatchre = re.compile(',FMD5=([0-9a-f]{32})')
+uidmatchre = re.compile(',U=(\d+)')
+flagmatchre = re.compile(':.*2,([A-Z]+)')
+
 timeseq = 0
 lasttime = long(0)
 
@@ -84,7 +88,7 @@ class MaildirFolder(BaseFolder):
                           filename in os.listdir(fulldirname)])
         for file in files:
             messagename = os.path.basename(file)
-            foldermatch = re.search(',FMD5=([0-9a-f]{32})', messagename)
+            foldermatch = foldermatchre.search(messagename)
             if (not foldermatch) or \
                md5.new(self.getvisiblename()).hexdigest() \
                != foldermatch.group(1):
@@ -94,14 +98,14 @@ class MaildirFolder(BaseFolder):
                 uid = nouidcounter
                 nouidcounter -= 1
             else:                       # It comes from our folder.
-                uidmatch = re.search(',U=(\d+)', messagename)
+                uidmatch = uidmatchre.search(messagename)
                 uid = None
                 if not uidmatch:
                     uid = nouidcounter
                     nouidcounter -= 1
                 else:
                     uid = long(uidmatch.group(1))
-            flagmatch = re.search(':.*2,([A-Z]+)', messagename)
+            flagmatch = flagmatchre.search(messagename)
             flags = []
             if flagmatch:
                 flags = [x for x in flagmatch.group(1)]
index caaeba3bd5e956b63c28d7344c1532a50a561893..3dbf1480df4a50b6f50e369cbdb63fc63cf8583b 100644 (file)
@@ -16,7 +16,8 @@
 #    along with this program; if not, write to the Free Software
 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-import re
+import re, string
+quotere = re.compile('^("(?:[^"]|\\\\")*")')
 
 def dequote(string):
     """Takes a string which may or may not be quoted and returns it, unquoted.
@@ -46,7 +47,7 @@ def options2hash(list):
 def flags2hash(string):
     return options2hash(flagsplit(string))
 
-def imapsplit(string):
+def imapsplit(imapstring):
     """Takes a string from an IMAP conversation and returns a list containing
     its components.  One example string is:
 
@@ -56,23 +57,36 @@ def imapsplit(string):
 
     ['(\\HasNoChildren)', '"."', '"INBOX.Sent"']"""
     
-    workstr = string
+    workstr = imapstring.strip()
     retval = []
     while len(workstr):
-        if re.search('^\s', workstr):
-            workstr = re.search('^\s(.*)$', workstr).group(1)
-        elif workstr[0] == '(':
-            parenlist = re.search('^(\(.*\))', workstr).group(1)
-            workstr = workstr[len(parenlist):]
+        if workstr[0] == '(':
+            # Needs rindex to properly process eg (FLAGS () UID 123)
+            rpareni = workstr.rindex(')') + 1
+            parenlist = workstr[0:rpareni]
+            workstr = workstr[rpareni:].lstrip()
             retval.append(parenlist)
         elif workstr[0] == '"':
-            quotelist = re.search('^("(?:[^"]|\\\\")*")', workstr).group(1)
-            workstr = workstr[len(quotelist):]
+            quotelist = quotere.search(workstr).group(1)
+            workstr = workstr[len(quotelist):].lstrip()
             retval.append(quotelist)
         else:
-            unq = re.search('^(\S+)', workstr).group(1)
-            workstr = workstr[len(unq):]
-            retval.append(unq)
+            splits = string.split(workstr, maxsplit = 1)
+            splitslen = len(splits)
+            # The unquoted word is splits[0]; the remainder is splits[1]
+            if splitslen == 2:
+                # There's an unquoted word, and more string follows.
+                retval.append(splits[0])
+                workstr = splits[1]    # split will have already lstripped it
+                continue
+            elif splitslen == 1:
+                # We got a last unquoted word, but nothing else
+                retval.append(splits[0])
+                # Nothing remains.  workstr would be ''
+                break
+            elif splitslen == 0:
+                # There was not even an unquoted word.
+                break
     return retval
             
 def flagsimap2maildir(string):
index 3f784175fc5cb683e6d646a5675fb770bc710e29..496ae4e6748406f2148a53cc01de1449fc23c4e5 100644 (file)
@@ -80,7 +80,7 @@ def exitnotifymonitorloop(callback):
             exitcondition.wait(1)
 
         while len(exitthreads):
-            callback(exitthreads.pop())
+            callback(exitthreads.pop(0)) # Pull off in order added!
         exitcondition.release()
 
 class ExitNotifyThread(Thread):