########################################################################## # # WorldPilot Public License (WPL) Version 0.99 # ------------------------------------- # # Copyright (c) Neuberger & Hughes GmbH. All rights reserved. # Copyright (c) Ryan Hughes. All rights reserved. # # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # 1. Redistributions in source code must retain the above copyright # notice, this list of conditions, and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions, and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # # 3. Neuberger & Hughes GmbH requests that attribution be given to # Worldpilot in any manner possible. Worldpilot includes a # "worldpilot" button that is installed by default. While it is not a # license violation to remove this button, it is requested that the # attribution remain. A significant investment has been put into # worldpilot, and this effort will continue if the worldpilot community # continues to grow. This is one way to assure that growth. # # 4. All advertising materials and documentation mentioning # features derived from or use of this software must display # the following acknowledgement: # # "This product includes software developed by Neuberger & Hughes # GmbH for use in the Worldpilot Organizer and Messaging Server # (http://www.worldpilot.org/)." # # In the event that the product being advertised includes an # intact WorldPilot distribution (with copyright and license included) # then this clause is waived. # # 5. Names associated with Worldpilot or Neuberger & Hughes GmbH # must not be used to endorse or promote products derived from this # software without prior written permission from Neuberger & Hughes GmbH. # # 6. Modified redistributions of any form whatsoever must retain # the following acknowledgment: # # "This product includes software developed by Neuberger & Hughes # GmbH for use in the Worldpilot Organizer and Messaging Server # (http://www.worldpilot.org/)." # # Intact (re-)distributions of any official WorldPilot release do not # require an external acknowledgement. # # 7. Modifications are encouraged but must be packaged separately as # patches to official WorldPilot releases. Distributions that do not # clearly separate the patches from the original work must be clearly # labeled as unofficial distributions. Modifications which do not # carry the name Worldpilot may be packaged in any form, as long as they # conform to all of the clauses above. # # # Disclaimer # # THIS SOFTWARE IS PROVIDED BY NEUBERGRE & HUGHES GMBH ``AS IS'' AND ANY # EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # # This software consists of contributions made by Neuberger & Hughes GmbH # and many individuals on behalf of Neuberger & Hughes GmbH. # Specific attributions are listed in the accompanying worldpilot credits # file. # ########################################################################### from imaplib import * import re import time import string try: import DateTime except: pass InternalDate = re.compile(r'.*INTERNALDATE "' r'[A-Za-z ,]*?(?P[ 123][0-9])[- ](?P[A-Z][a-z][a-z])[- ](?P[0-9][0-9][0-9][0-9])' r' (?P[0-9][0-9]):(?P[0-9][0-9]):(?P[0-9][0-9])' r' (?P[-+])(?P[0-9][0-9])(?P[0-9][0-9])' r'.*"') LiteralString = re.compile(r'\s*\{(?P\d+)\}(?P.*)') QuotedString = re.compile(r'\s*"(?P[^"]*)"(?P.*)') ListOpen = re.compile(r'\s*\((?P.*)') ListClose = re.compile(r'\s*\)(?P.*)') Atom = re.compile(r'\s*(?P\\?[\w\[\]\./]+)(?P.*)') #Atom2 = re.compile(r'\s*(?P\\?[\w\[\]/]+)(?P.*)') Number = re.compile(r'\s*(?P\\?[\d]+)(?P.*)') NIL = re.compile(r'\s*(?PNIL)(?P.*)') SLASH = re.compile(r'\s*(?P"/")(?P.*)') def Internaldate2tuple(resp): """Convert IMAP4 INTERNALDATE to UT. Returns Python time module tuple. """ mo = InternalDate.match(resp) if not mo: return None mon = Mon2num[mo.group('mon')] zonen = mo.group('zonen') for name in ('day', 'year', 'hour', 'min', 'sec', 'zoneh', 'zonem'): exec "%s = string.atoi(mo.group('%s'))" % (name, name) # INTERNALDATE timezone must be subtracted to get UT zone = (zoneh*60 + zonem)*60 if zonen == '-': zone = -zone tt = (year, mon, day, hour, min, sec, -1, -1, -1) utc = time.mktime(tt) # Following is necessary because the time module has no 'mkgmtime'. # 'mktime' assumes arg in local timezone, so adds timezone/altzone. lt = time.localtime(utc) if time.daylight and lt[-1]: zone = zone + time.altzone else: zone = zone + time.timezone return time.localtime(utc - zone) def CreateStruct(data): c=[] s=[c] newrec=1 while data: if newrec: c=s[0] n=[] c.append(n) c=n newrec=1 if type(data[0])==type(()): conts=data[0] else: conts=[data[0]] data=data[1:] while conts: line=conts[0] conts=conts[1:] while line!="": m=QuotedString.match(line) if m: c.append(m.group('String')) line=m.group('Rest') continue m=ListOpen.match(line) if m: n=[] c.append(n) s.append(c) c=n line=m.group('Rest') continue m=ListClose.match(line) if m: c=s[-1] s=s[:-1] line=m.group('Rest') continue m=NIL.match(line) if m: c.append(None) line=m.group('Rest') continue ## m=SLASH.match(line) ## if m: ## c.append(None) ## line=m.group('Rest') m=Number.match(line) if m: c.append(int(m.group('Number'))) line=m.group('Rest') continue m=Atom.match(line) if m: c.append(m.group('Atom')) line=m.group('Rest') continue ## m=Atom2.match(line) ## if m: ## c.append(m.group('Atom')) ## line=m.group('Rest') ## continue m=LiteralString.match(line) if m: try: line=conts[0] conts=conts[1:] c.append(line) except: pass line="" newrec=0 continue else: line="" newrec=0 c=s[0] return c def makemap(array): mi={} for i in range(0,len(array),2): item=array[i] value=array[i+1] mi[item]=value return mi