########################################################################## # # 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. # ########################################################################### """WorldPilot as a Zope Product """ import Acquisition import AccessControl import OFS from Globals import HTMLFile, HTML, MessageDialog, Persistent from ImageFile import ImageFile from WPUtil import CreateStruct, makemap, Internaldate2tuple import string import time import sys sys.path.append('/easybin') from AccessControl.Permission import Permission import Resource import WPimaplib try: import DateTime except: pass import StringIO import mimetools import mimetypes import re import rfc822 import os from OFS import content_types try: import easyReg WPDomain=easyReg.Data['DomainName']['Value'] except: try: import DOMAIN WPDomain=DOMAIN.domain #print "DOMAIN: ",WPDomain except: WPDomain="hey.setup.your.worldpilot.domain" import IMAPHACK class IMAPHeaderList: def __init__(self, Offset=0, Len=None): self.Offset=Offset self.List=[] #self.Len=Len self.Indexes={} self.CurrentIndex=self.List def append(self, Item): self.List.append(Item) def reverse(self): self.List.reverse() def __getitem__(self, ItemNr): return self.CurrentIndex[ItemNr-self.Offset] def __len__(self): return self.Offset+len(self.List) def createIndex(self, Index, Order="Down"): if Index==None or Index=="": self.CurrentIndex=self.List return self.List if self.Indexes.has_key(Index+"."+Order): self.CurrentIndex=self.Indexes[Index+"."+Order] return self.Indexes[Index+"."+Order] elif Order=="Up" and self.Indexes.has_key(Index+"."+"Down"): self.Indexes[Index+"."+Order]=self.Indexes[Index+"."+"Down"][:] self.Indexes[Index+"."+Order].reverse() self.CurrentIndex=self.Indexes[Index+"."+Order] return self.Indexes[Index+"."+Order] s=[] for Item in self.List: key=getattr(Item, Index) s.append((key,Item)) s.sort() i=[] for key, value in s: i.append(value) if Order=="Up": i.reverse() self.Indexes[Index+"."+Order]=i self.CurrentIndex=self.Indexes[Index+"."+Order] return i class IMAPHeader: def __init__(self, ID, Flags, FromName, FromAddress, ToName, ToAddress, Date, Subject, Size, Body): self.UID=ID self.Flags=Flags self.FromName=FromName self.FromAddress=FromAddress self.ToName=ToName self.ToAddress=ToAddress self.Date=Date self.Subject=Subject self.Size=Size self.Body=Body class IMAPFolder: def __init__(self, Name, FullName="", PaddedName=""): self.Children=[] self.Name=Name self.FullName=FullName self.PaddedName=PaddedName self.Map={} def tpId(self): return self.Name def tpURL(self): return self.Name def AddChild(self, Child): try: if self.Map[Child.Name]: pass except: self.Children.append(Child) self.Map[Child.Name]=Child def GetChild(self, ChildName): return (self.Map[ChildName]) def GetChildren(self): return self.Children class MsgPart: def __init__(self, BodyPart, BodyType, BodySubtype, BodyParameterList=None, BodyId=None, BodyDescription=None, BodyEncoding=None, BodySize=None, BodyEnvelope=None, BodyLines=None, BodyMD5=None, BodyDisposition=None, BodyLanguage=None, BodyHeader=None, BodyText=None, BodyMime=None, BodyAttachment=None, BodyContentType=None): self.BodyPart=BodyPart self.BodyType=BodyType self.BodySubtype=BodySubtype self.BodyParameterList=BodyParameterList self.BodyId=BodyId self.BodyDescription=BodyDescription self.BodyEncoding=BodyEncoding self.BodySize=BodySize self.BodyEnvelope=BodyEnvelope self.BodyLines=BodyLines self.BodyMD5=BodyMD5 self.BodyDisposition=BodyDisposition self.BodyLanguage=BodyLanguage self.BodyHeader=BodyHeader self.BodyText=BodyText self.BodyMime=BodyMime self.BodyAttachment=BodyAttachment self.BodyContentType=BodyContentType class MsgEnvelope: def __init__(self, EnvDate, EnvSubject, EnvFrom, EnvSender, EnvReplyTo, EnvTo, EnvCc, EnvBcc, EnvInReplyTo, EnvMessageId): self.EnvDate=EnvDate self.EnvSubject=EnvSubject self.EnvFrom=EnvFrom self.EnvSender=EnvSender self.EnvReplyTo=EnvReplyTo self.EnvTo=EnvTo self.EnvCc=EnvCc self.EnvBcc=EnvBcc self.EnvInReplyTo=EnvInReplyTo self.EnvMessageId=EnvMessageId class MsgAddress: def __init__(self, AddrPersonalName, AddrAtDomainList, AddrMailboxName, AddrHostName): self.AddrPersonalName=AddrPersonalName self.AddrAtDomainList=AddrAtDomainList self.AddrMailboxName=AddrMailboxName self.AddrHostName=AddrHostName class MsgParameter: def __init__(self, ParameterName, ParameterValue): self.ParameterName=ParameterName self.ParameterValue=ParameterValue class PartDisposition: def __init__(self, PartDispositionType, PartDispositionAttr, PartDispositionAttrMap=None): self.PartDispositionType=PartDispositionType self.PartDispositionAttr=PartDispositionAttr if PartDispositionAttrMap: self.PartDispositionAttrMap=PartDispositionAttrMap else: if PartDispositionAttr: self.PartDispositionAttrMap={} for i in PartDispositionAttr: self.PartDispositionAttrMap[i.ParameterName]=i class MsgMessage: def __init__(self, MsgUid, MsgFlags, MsgInternalDate, MsgRfc822Size, MsgEnvelope, MsgParts, MsgText, MsgTextPart=None): self.MsgUid=MsgUid self.MsgFlags=MsgFlags self.MsgInternalDate=MsgInternalDate self.MsgRfc822Size=MsgRfc822Size self.MsgEnvelope=MsgEnvelope self.MsgParts=MsgParts self.MsgText=MsgText self.MsgTextPart=MsgTextPart class Logon: usedUIDs={} def __init__(self,User,Passwd,IP,imapserver): self.User=User self.Passwd=Passwd self.IP=IP self.Caches={} self.UID=self.genUID() self.imapserver=imapserver self.Setup() def Setup(self): try: self.Signature=open("/var/spool/worldpilot/user/%s/signature" % (self.User), "r").read() except: self.Signature=Resource.Standard.getResourceMapping('us')["defaultSignature"].raw try: self.IdentityName=open("/var/spool/worldpilot/user/%s/IdentityName" % (self.User), "r").read() except: self.IdentityName=self.getUser() try: self.IdentityEMail=open("/var/spool/worldpilot/user/%s/IdentityEMail" % (self.User), "r").read() except: self.IdentityEMail=self.getUser()+"@"+WPDomain def getUser(self): return str(self.User) def getPasswd(self): return self.Passwd def check(self, Passwd=None): if Passwd!=None: self.Passwd=Passwd return self.checkPasswd() def getUID(self): return self.UID def genUID(self): import random u=int(1000000000*random.random()) while Logon.usedUIDs.has_key(u): u=int(1000000000*random.random()) return str(u) def saveSignature(self, Signature): # this has to move to a storage class now self.Signature=Signature try: open("/var/spool/worldpilot/user/%s/signature" % (self.User), "w").write(Signature) except: try: os.mkdir("/var/spool/worldpilot/user/%s" % (self.User)) open("/var/spool/worldpilot/user/%s/signature" % (self.User), "w").write(Signature) except: return 0 return 1 def saveIdentityName(self, IdentityName): # this has to move to a storage class now self.IdentityName=IdentityName try: open("/var/spool/worldpilot/user/%s/IdentityName" % (self.User), "w").write(IdentityName) except: try: os.mkdir("/var/spool/worldpilot/user/%s" % (self.User)) open("/var/spool/worldpilot/user/%s/IdentityName" % (self.User), "w").write(IdentityName) except: return 0 return 1 def saveIdentityEMail(self, IdentityEMail): # this has to move to a storage class now self.IdentityEMail=IdentityEMail try: open("/var/spool/worldpilot/user/%s/IdentityEMail" % (self.User), "w").write(IdentityEMail) except: try: os.mkdir("/var/spool/worldpilot/user/%s" % (self.User)) open("/var/spool/worldpilot/user/%s/IdentityEMail" % (self.User), "w").write(IdentityEMail) except: return 0 return 1 def callResource(self, ResourceName, client, mapping=None): return Resource.Standard.callResource(ResourceName,'us', client=client, mapping=mapping) def checkPasswd(self): try: #self.Connection=WPimaplib.IMAP4(self.imapserver) Connection=WPimaplib.IMAP4(self.imapserver) #return self.Connection.login(self.User, self.Passwd) return Connection.login(self.User, self.Passwd) except: return None def getConnection(self, REQUEST=None): if REQUEST and REQUEST.has_key('Folder'): Folder=REQUEST['Folder'] else: Folder="INBOX" M=self.getNewConnection() M.select(Folder) return M def clearCache(self, REQUEST): self.Caches={} def clearCacheFolder(self, Folder, REQUEST=None): try: del self.Caches[Folder] except: pass def getNewConnection(self): try: conn=WPimaplib.IMAP4(self.imapserver) if conn.login(self.User, self.Passwd): return conn else: return None except: return None def getIMAPFolders(self, REQUEST): "Doc String :-)" st=[] M=self.getConnection(REQUEST) if IMAPHACK.UseLSUB: F=M.lsub(IMAPHACK.MailListRoot) else: F=M.list(IMAPHACK.MailListRoot) FS=CreateStruct(F[1]) rf=IMAPFolder('root') for folder in FS: FolderFullName=folder[2] cf=rf if string.find(FolderFullName,'/'): Folders=re.split(r'\/', FolderFullName) else: Folders=re.split(r'\.', FolderFullName) # print Folders if not Folders: Folders=FolderFullName try: padding="" folderCount=0 for Folder in Folders[:-1]: # print Folder try: cf=cf.GetChild(Folder) except: cf.AddChild(IMAPFolder(Folder,Folder,padding+Folder)) cf=cf.GetChild(Folder) # print Folders[:-1] folderCount=folderCount+1 padding=padding+"  " cf.AddChild(IMAPFolder(Folders[-1],FolderFullName, padding+Folders[-1])) except: pass return rf def addChildrenToList(self, List, Tree): if Tree.FullName!="": List.append(Tree) for child in Tree.GetChildren(): self.addChildrenToList(List, child) def getIMAPFoldersList(self, REQUEST): List=[] FolderTree=self.getIMAPFolders(REQUEST) self.addChildrenToList(List, FolderTree) return List def moveMessages(self, REQUEST): if REQUEST.has_key('Folder'): Folder=REQUEST['Folder'] else: Folder="INBOX" if REQUEST.has_key('Messages'): Messages=REQUEST['Messages'] else: Messages=[] if REQUEST.has_key('MoveToFolder'): MoveToFolder=REQUEST['MoveToFolder'] else: MoveToFolder="" if len(Messages): M=self.getConnection(REQUEST) result=M.uid("COPY", string.join(Messages,","), MoveToFolder) result2=M.uid("STORE", string.join(Messages,","), '+FLAGS', '(\Deleted)') REQUEST['Result']=str(result)+str(MoveToFolder)+str(result2)+"!" def deleteMessages(self, REQUEST): if REQUEST.has_key('Folder'): Folder=REQUEST['Folder'] else: Folder="INBOX" if REQUEST.has_key('Messages'): Messages=REQUEST['Messages'] else: Messages=[] if Folder=="INBOX.Trash": M=self.getConnection(REQUEST) result=M.uid("STORE", string.join(Messages,","), '+FLAGS', '(\Deleted)') result2=M.expunge() REQUEST['Result']=str(result)+str(Folder)+str(result2)+"!" else: MoveToFolder="INBOX.Trash" M=self.getConnection(REQUEST) result=M.uid("COPY", string.join(Messages,","), MoveToFolder) result2=M.uid("STORE", string.join(Messages,","), '+FLAGS', '(\Deleted)') REQUEST['Result']=str(result)+str(MoveToFolder)+str(result2)+"!" #Purge \Deleted Messages Option still needed... def appendMessage(self, Folder, Flags, save, REQUEST=None): M=self.getConnection(REQUEST) M.append(Folder, Flags, None, save.read()) self.clearCacheFolder(Folder) def createFolder(self, Folder, REQUEST=None): M=self.getConnection(REQUEST) print 'Creating Folder: '+ Folder M.create(Folder) #self.clearCacheFolder(Folder) def deleteFolder(self, Folder, REQUEST=None): M=self.getConnection(REQUEST) Result=M.delete(Folder) REQUEST['Result']=str(Result) #self.clearCacheFolder(Folder) def draftMessage(self, PrevUID, Folder, Flags, save, REQUEST=None): self.appendMessage(Folder, Flags, save, REQUEST) M=self.getConnection(REQUEST) if PrevUID: M.uid("STORE", str(PrevUID), '+FLAGS', '(\Deleted)') def cacheIMAPFetch(self, REQUEST): "Doc String :-)" if REQUEST.has_key('Folder'): Folder=REQUEST['Folder'] else: Folder="INBOX" if REQUEST.has_key('Index'): Index=REQUEST['Index'] else: Index=None if REQUEST.has_key('Order'): Order=REQUEST['Order'] else: Order="Down" if self.Caches.has_key(Folder): self.Caches[Folder].createIndex(Index, Order) return self.Caches[Folder] else: st=IMAPHeaderList() self.Caches[Folder]=st pass M=self.getConnection(REQUEST) M.select(Folder) #E=M.fetch('1:*', '(UID FLAGS INTERNALDATE RFC822.SIZE ENVELOPE)') E=M.uid('FETCH', '1:*', 'ALL') if E[1][0]!=None: ES=CreateStruct(E[1]) else: return () for mail in ES: sequence_number=mail[0] mi=makemap(mail[1]) try: Date=DateTime.DateTime(0) Date=self.makeDateTimeFromRfc822(mi['ENVELOPE'][0]) except: pass #ID, Flags, FromName, FromAddress, ToName, ToAddress, Date, Subject, Size, Body try: Flags=mi['FLAGS'] except: Flags="" try: FromAddress=mi['ENVELOPE'][2][0][2]+"@"+mi['ENVELOPE'][2][0][3] except: FromAddress="" try: FromName=mi['ENVELOPE'][2][0][0] except: FromName=FromAddress try: ToAddress=mi['ENVELOPE'][5][0][2]+"@"+mi['ENVELOPE'][5][0][3] except: ToAddress="" try: ToName=mi['ENVELOPE'][5][0][0] except: ToName=ToAddress try: Subject=mi['ENVELOPE'][1] except: Subject="" try: Size=mi['RFC822.SIZE'] except: Size=1 Body="" try: if not '\\Deleted' in Flags: st.append(IMAPHeader(mi['UID'],Flags, FromName, FromAddress, ToName, ToAddress, Date, Subject, Size, Body)) except: pass st.reverse() st.createIndex(Index, Order) return st def makeAddressList(self,ST): if ST: al=[] for ADDR in ST: al.append(MsgAddress(ADDR[0],ADDR[1],ADDR[2],ADDR[3])) return al else: return None def makeEnvelope(self, ST): #print "ENVELOPESOURCE", ST if ST: return(MsgEnvelope( self.makeDateTimeFromRfc822(ST[0]), ST[1], self.makeAddressList(ST[2]), self.makeAddressList(ST[3]), self.makeAddressList(ST[4]), self.makeAddressList(ST[5]), self.makeAddressList(ST[6]), self.makeAddressList(ST[7]), ST[8], ST[9], )) else: return None def makePartDisposition(self, ST): if ST: l=[] m={} array=ST[1] for i in range(0,len(array),2): item=array[i] value=array[i+1] l.append(MsgParameter(item, value)) m[item]=value return PartDisposition(ST[0], l, m) else: return None def makePartList(self, M, UID, Part, PL, ST, Depth): MsgText=None MsgTextPart=None MultiParts=[] partnr=0 while type(ST[partnr])==type([]): MultiParts.append(ST[partnr]) partnr=partnr+1 if partnr>0: """Multipart Part""" BodyType="MULTIPART" BodySubtype=ST[partnr+0] BodyParameterList=ST[partnr+1] BodyDisposition=self.makePartDisposition(ST[partnr+2]) BodyLanguage=ST[partnr+3] if Part=="": HeaderPart="RFC822.HEADER" else: HeaderPart="BODY["+Part+".HEADER]" tf=M.uid('FETCH', '%d'%(UID,), '%s'%(HeaderPart)) ts=CreateStruct(tf[1]) tm=makemap(ts[0][1]) BodyHeader=tm[HeaderPart] BodyAttachment=None PL.append(MsgPart( BodyPart=Part, BodyType=BodyType, BodySubtype=BodySubtype, BodyContentType=BodyType+"/"+BodySubtype, BodyParameterList=BodyParameterList, #BodyId=BodyId, #BodyDescription=BodyDescription, #BodyEncoding=BodyEncoding, #BodySize=BodySize, #BodyEnvelope=BodyEnvelope, #BodyLines=BodyLines, #BodyMD5=BodyMD5, BodyDisposition=BodyDisposition, BodyLanguage=BodyLanguage, BodyHeader=BodyHeader, #BodyText=BodyText, BodyAttachment=BodyAttachment, )) else: offset=0 BodyType=ST[0] BodySubtype=ST[1] BodyParameterList=ST[2] BodyId=ST[3] BodyDescription=ST[4] BodyEncoding=ST[5] BodySize=ST[6] BodyEncoding=string.lower(BodyEncoding) BodyEnvelope=None BodyStructure=None BodyLines=None if BodyType=="MESSAGE" and BodySubtype=="RFC822": try: BodyEnvelope=self.makeEnvelope(ST[7]) BodyStructure=ST[7+1] BodyLines=ST[7+2] except: pass offset=3 if BodyType=="TEXT": BodyLines=ST[7] offset=1 BodyMD5=ST[7+offset] BodyDisposition=self.makePartDisposition(ST[8+offset]) BodyLanguage=ST[9+offset] BodyText=None BodyHeader=None BodyMime=None #print #print BodyType, BodySubtype #print if (BodyType=='TEXT' #and BodySubtype=='PLAIN' or BodyType=="MESSAGE" and BodySubtype!="RFC822" ): BodyPart="BODY["+Part+"]" if Part=="": HeaderPart="RFC822.HEADER" if (BodyType=='TEXT' and BodySubtype=='PLAIN'): TextPart="RFC822.TEXT" else: TextPart="RFC822.TEXT" else: if (BodyType=='TEXT' and BodySubtype=='PLAIN'): TextPart="BODY["+Part+".TEXT]" HeaderPart="BODY["+Part+".HEADER]" else: HeaderPart="BODY["+Part+".HEADER]" TextPart="BODY["+Part+".TEXT]" if HeaderPart!="": tf=M.uid('FETCH', '%d'%(UID,), '(%s %s)'%(HeaderPart, TextPart)) else: tf=M.uid('FETCH', '%d'%(UID,), '%s'%(TextPart)) ts=CreateStruct(tf[1]) tm=makemap(ts[0][1]) #print tm if HeaderPart!="": BodyHeader=tm[HeaderPart] #if BodyType=="MESSAGE" and BodySubtype=="RFC822": # BodyText=None #else: BodyText=tm[TextPart] if BodyText==None: tf=M.uid('FETCH', '%d'%(UID,), '%s'%(BodyPart)) ts=CreateStruct(tf[1]) tm=makemap(ts[0][1]) BodyText=tm[BodyPart] #print "BODYENCODING", BodyEncoding if BodyEncoding in ('quoted-printable', 'base64'): Input=StringIO.StringIO(BodyText) DecodedText=StringIO.StringIO() #print "DECODEING", BodyEncoding mimetools.decode(Input, DecodedText, BodyEncoding) BodyText=DecodedText.getvalue() if not MsgText and BodySubtype=='PLAIN':#and Part=="" MsgText=BodyText MsgTextPart=Part #print "HEADER:", BodyHeader #print "TEXT:", BodyText BodyAttachment=None elif BodyType=="MESSAGE" and BodySubtype=="RFC822": if BodyEncoding and BodyEncoding in ('7bit','8bit','quoted-printable'): BodyAttachment=None else: BodyAttachment=1 else: BodyAttachment=1 try: MimePart="BODY["+Part+".MIME]" tf=M.uid('FETCH', '%d'%(UID,), '%s'%(MimePart)) ts=CreateStruct(tf[1]) tm=makemap(ts[0][1]) #print tm BodyMime=tm[MimePart] except: pass PL.append(MsgPart( BodyPart=Part, BodyType=BodyType, BodySubtype=BodySubtype, BodyContentType=BodyType+"/"+BodySubtype, BodyParameterList=BodyParameterList, BodyId=BodyId, BodyDescription=BodyDescription, BodyEncoding=BodyEncoding, BodySize=BodySize, BodyEnvelope=BodyEnvelope, BodyLines=BodyLines, BodyMD5=BodyMD5, BodyDisposition=BodyDisposition, BodyLanguage=BodyLanguage, BodyHeader=BodyHeader, BodyText=BodyText, BodyMime=BodyMime, BodyAttachment=BodyAttachment, )) if Depth>0: Depth=Depth-1 if BodyType=="MESSAGE" and BodySubtype=="RFC822" and not BodyAttachment: self.makePartList(M, UID, Part, PL, BodyStructure, Depth) partnr=0 while partnr20: ti=Internaldate2tuple('INTERNALDATE "'+ tis + '"') else: ti=Internaldate2tuple('INTERNALDATE "'+ tis + ' +0000"') try: dt=None dt=DateTime.DateTime() dt=DateTime.DateTime(time.mktime(ti)) except: pass return dt def makeDateTimeFromRfc822(self, tis): if len(tis)>25: ti=rfc822.mktime_tz(rfc822.parsedate_tz(tis)) else: ti=time.mktime(rfc822.parsedate(tis)) try: dt=None dt=DateTime.DateTime() dt=DateTime.DateTime(ti) except: pass return dt def makeMessage(self, M, Depth, ST): #print ST MsgParts=[] MsgUid=ST['UID'] MsgFlags=ST['FLAGS'] MsgInternalDate=self.makeDateTimeFromInternaldate(ST['INTERNALDATE']) MsgRfc822Size=['RFC822.SIZE'] MsgEnvelope=self.makeEnvelope(ST['ENVELOPE']) MsgTextPart,MsgText=self.makePartList(M, MsgUid, "", MsgParts, ST['BODYSTRUCTURE'], Depth) return( MsgMessage( MsgUid=MsgUid, MsgFlags=MsgFlags, MsgInternalDate=MsgInternalDate, MsgRfc822Size=MsgRfc822Size, MsgEnvelope=MsgEnvelope, MsgParts=MsgParts, MsgText=MsgText, MsgTextPart=MsgTextPart, )) def getPart(self, REQUEST, RESPONSE): if REQUEST.has_key('Folder'): Folder=REQUEST['Folder'] else: Folder="INBOX" if REQUEST.has_key('Message'): Message=REQUEST['Message'] else: Message=1 if REQUEST.has_key('Part'): Part=REQUEST['Part'] else: Part="1" if REQUEST.has_key('MimeEncoding'): MimeEncoding=string.lower(REQUEST['MimeEncoding']) else: MimeEncoding="base64" if REQUEST.has_key('AttType'): AttType=string.lower(REQUEST['AttType']) else: AttType="" if REQUEST.has_key('AttSubType'): AttSubType=string.lower(REQUEST['AttSubType']) else: AttSubType="" if REQUEST.has_key('FileName'): FileName=string.lower(REQUEST['FileName']) else: FileName="ATT0001.DAT" M=self.getNewConnection() M.select(Folder) E=M.uid('FETCH', '%s'%(Message), 'BODY[%s]'%(Part)) ES=CreateStruct(E[1]) EM=makemap(ES[0][1]) input=StringIO.StringIO(EM['BODY[%s]'%(Part)]) output=StringIO.StringIO() mimetools.decode(input, output, MimeEncoding) decodeddata=output.getvalue() open("/tmp/att2","w").write(decodeddata) undecodeddata=input.getvalue() open("/tmp/att","w").write(undecodeddata) #RESPONSE.setHeader('Content-Type', AttType+'/'+AttSubType+'; name="MyName.tgz"') RESPONSE.setHeader('content-type', AttType+'/'+AttSubType) RESPONSE.setHeader('content-length', len(decodeddata)) RESPONSE.setHeader('content-disposition', 'attachment; filename="'+FileName+'"') return decodeddata def getPartRaw(self, Part, Output, REQUEST): if REQUEST.has_key('Folder'): Folder=REQUEST['Folder'] else: Folder="INBOX" if REQUEST.has_key('Message'): Message=REQUEST['Message'] else: Message=1 #if REQUEST.has_key('MimeEncoding'): MimeEncoding=string.lower(REQUEST['MimeEncoding']) #else: MimeEncoding="base64" #if REQUEST.has_key('AttType'): AttType=string.lower(REQUEST['AttType']) #else: AttType="" #if REQUEST.has_key('AttSubType'): AttSubType=string.lower(REQUEST['AttSubType']) #else: AttSubType="" M=self.getNewConnection() M.select(Folder) E=M.uid('FETCH', '%s'%(Message), 'BODY[%s]'%(Part)) ES=CreateStruct(E[1]) EM=makemap(ES[0][1]) Output.write(EM['BODY[%s]'%(Part)]) return 1 def getIMAPMsg(self, Depth=20, REQUEST=None): if REQUEST.has_key('Folder'): Folder=REQUEST['Folder'] else: Folder="INBOX" if REQUEST.has_key('Message'): Message=REQUEST['Message'] else: Message="1" st=[] M=self.getConnection(REQUEST) M.select(Folder) E=M.uid('FETCH', '%d'%(int(Message)), '(FLAGS INTERNALDATE RFC822.SIZE ENVELOPE BODYSTRUCTURE)') #print E[1] if E[1][0]!=None: ES=CreateStruct(E[1]) else: return () for mail in ES: sequence_number=mail[0] mi=makemap(mail[1]) if self.Caches.has_key(Folder): for m in self.Caches[Folder].List: if m.UID==int(Message): m.Flags.append('\Seen') #result=M.uid("STORE", Message, '+FLAGS', '(\Seen)') return self.makeMessage(M, Depth, mi) class Logons: def __init__(self): self.UserMap={} self.UIDMap={} def addLogon(self, Logon): self.UserMap[Logon.getUser()]=Logon self.UIDMap[Logon.getUID()]=Logon def delLogon(self, UID): del self.UserMap[self.UIDMap[UID].getUser()] del self.UIDMap[UID] def checkUID(self, UID, REQUEST): if self.UIDMap.has_key(UID): REQUEST['User']=self.UIDMap[UID].getUser() REQUEST['Logon']=self.UIDMap[UID] REQUEST['LogonUID']=UID dt=DateTime.DateTime() tz=dt._localzone REQUEST['TimeZone']=tz REQUEST['DT']=dt return self.UIDMap[UID] else: return None def checkLogon(self, thisLogon, REQUEST): UID=thisLogon.getUID() if self.UIDMap.has_key(UID): REQUEST['User']=self.UIDMap[UID].getUser() REQUEST['Logon']=self.UIDMap[UID] REQUEST['LogonUID']=UID dt=DateTime.DateTime() tz=dt._localzone REQUEST['TimeZoneb']=tz REQUEST['DT']=dt return self.UIDMap[UID] else: return None DefaultLogon=Logon(None,None,None,None) SESSIONROOT="/var/spool/worldpilot/sessions" import cPickle class Sessions( Acquisition.Implicit, Persistent, AccessControl.Role.RoleManager, OFS.Folder.Folder, ): "Doc String :-)" sess={} logons={} initialized=0 DefaultWorldPilot=None def __init__(self): #Sessions.sess['__roles__']=None self.id="sessions" pass def tpId(self): return "sessions" def tpURL(self): return "sessions" def tpValues(self): """Returns a list of the folder's sub-folders, used by tree tag.""" return self._getSessions() def manage_workspace(self, REQUEST=None): "Doc String :-)" return DefaultLogon.callResource('sessions_manage_workspace', client=self, mapping=REQUEST) def addSession(self, ID, link): Sessions.sess[ID]=link def delSession(self, ID): del Sessions.sess[ID] del Sessions.logons[ID] self.Commit() def _getSessions(self): r=[] for i in Sessions.sess.keys(): r.append(Sessions.sess[i]) return r def findPreviousSession(self, REQUEST): found=None if REQUEST.has_key('User') and REQUEST.has_key('Passwd'): for sessid in Sessions.sess.keys(): session=Sessions.sess[sessid] if session._Logon.getUser()==REQUEST['User']: if not found: if session._Logon.check(REQUEST['Passwd']): found=session._Logon else: self.delSession(sessid) if found: self.Commit() return found def registerLogon(self, thisLogon): Sessions.logons[thisLogon.getUID()]=thisLogon self.Commit() def Commit(self): path=SESSIONROOT if not os.path.isdir(path): os.makedirs(path) cPickle.Pickler(open(SESSIONROOT+'/Logons','wb')).dump(Sessions.logons) def initialize(self, parent): if Sessions.initialized: return 1 Sessions.initialized=1 if hasattr(parent, 'imapserver') and parent.imapserver!="": imapserver = parent.imapserver else: imapserver = 'localhost' if hasattr(parent, 'smtpserver') and parent.smtpserver!="": smtpserver = parent.smtpserver else: smtpserver = 'localhost' #print "INITIALIZING SESSIONS" try: Sessions.logons=cPickle.Unpickler(open(SESSIONROOT+'/Logons','rb')).load() for logon in Sessions.logons.keys(): self.createWorldPilotSession(parent, Sessions.logons[logon], imapserver, smtpserver) except: pass #print "DIDNT WORK TO LOAD SESSIONS" def createWorldPilotSession(self, parent, thisLogon, imapserver, smtpserver, REQUEST=None): if thisLogon==None: previous=self.findPreviousSession(REQUEST) if previous: thisLogon=previous if not REQUEST is None: REQUEST['LogonUID']=thisLogon.getUID() REQUEST['Logon']=thisLogon return previous if thisLogon==None: if REQUEST.has_key('User') and REQUEST.has_key('Passwd'): #print "!HAS USER" thisLogon=Logon(REQUEST['User'], REQUEST['Passwd'], "172", imapserver) #print thisLogon if thisLogon.check(): #print "CHECKED" self.registerLogon(thisLogon) else: #print "FAILED" return None else: return None if not REQUEST is None: REQUEST['LogonUID']=thisLogon.getUID() REQUEST['Logon']=thisLogon NewWorldPilot=WorldPilotSession( thisLogon.getUID(), thisLogon.getUser(), thisLogon.getUser(), smtpserver, ) NewWorldPilot.aq_parent=parent NewWorldPilot._WorldPilot=parent NewWorldPilot._Logon=thisLogon p=Permission('View',WorldPilot.publicmethods, NewWorldPilot) p.setRoles(('Anonymous','Manager')) self.addSession(thisLogon.getUID(),NewWorldPilot) thisLogon.Setup() return thisLogon def __bobo_traverse__(self, REQUEST=None, key=None): try: return getattr(self, key) except: try: return Sessions.sess[key] except: raise KeyError import Globals import OFS.Folder import sys import ZODB.FileStorage import ZODB import Zope import ZODB.ZApplication import OFS.Application class Composers: #(AccessControl.Role.RoleManager): "Doc String :-)" sess={} DefaultWorldPilot=None def __init__(self): Composers.sess['__roles__']=None self.nextid=1 def nextID(self): ID=str(self.nextid) self.nextid=self.nextid+1 return ID def addSession(self, ID=None, link=None): Composers.sess[ID]=link return ID def delSession(self, ID): del Composers.sess[ID] def __getattr__(self, key): try: return Composers.sess[key] except: try: int(key) if not Composers.DefaultWorldPilot: Composers.DefaultWorldPilot=WorldPilot( "007", None, None, (1,2,3)) p=Permission('View', WorldPilot.publicmethods, Sessions.DefaultWorldPilot) p.setRoles(('Anonymous','Manager')) return Composers.DefaultWorldPilot except: raise KeyError import WPsmtplib class WPSmtp(WPsmtplib.SMTP): dotline=re.compile('^\.$', re.M) def sendmail(self,from_addr,to_addrs,msgs,save): if not self.helo_resp: self.helo() (code,resp)=self.mail(from_addr) if code <>250: self.rset() raise WPsmtplib.SMTPSenderRefused senderrs={} for each in to_addrs: (code,resp)=self.rcpt(each) if (code <> 250) and (code <> 251): senderrs[each]=(code,resp) if len(senderrs)==len(to_addrs): #th' server refused all our recipients self.rset() raise WPsmtplib.SMTPRecipientsRefused code=self.data(msgs,save) if code <>250 : self.rset() raise WPsmtplib.SMTPDataError #if we got here then somebody got our mail return senderrs def data(self,msgs,save): self.putcmd("data") (code,repl)=self.getreply() if self.debuglevel >0 : print "data:", (code,repl) if code <> 354: return -1 else: for msg in msgs: while 1: line=msg.readline() if not line: break if len(line)>1 and line[-2]=="\015": pass #line=line+"\012" else: line=line[:-1]+"\015\012" save.write(line) if len(line)==3 and line[0]==".": line=".."+"\015\012" self.send(line) self.send("\015\012.\015\012") (code,msg)=self.getreply() if self.debuglevel >0 : print "data:", (code,msg) return code StringType=type('') import Storage.LocalStorage import Components.Notes import Components.ToDo import Components.Events import Components.AddressCards Storage.LocalStorage.DefaultLogon=DefaultLogon class MyWorldPilotUserStorage( Storage.LocalStorage.WorldPilotUserStorage, ): "Doc String :-)" def initialize(self): if not os.path.isdir(self.path): os.makedirs(self.path) self.loadSubFolders() if not self._subfolders.has_key('Notes'): Notes=Components.Notes.WorldPilotNotesFolder('Notes', 'Notes', self.path+'/Notes') Notes.Commit() del Notes if not self._subfolders.has_key('ToDo'): ToDo=Components.ToDo.WorldPilotToDoFolder('ToDo', 'ToDo', self.path+'/ToDo') ToDo.Commit() del ToDo if not self._subfolders.has_key('Events'): Events=Components.Events.WorldPilotEventsFolder('Events', 'Events', self.path+'/Events') Events.Commit() del Events if not self._subfolders.has_key('AddressCards'): AddressCards=Components.AddressCards.WorldPilotAddressCardsFolder('AddressCards', 'AddressCards', self.path+'/AddressCards') AddressCards.Commit() del AddressCards self.loadSubFolders() class WorldPilotMail( Acquisition.Implicit, Persistent, AccessControl.Role.RoleManager, OFS.Folder.Folder, ): """A WorldPilot product.""" icon='misc_/WorldPilot/worldpilot' meta_type='WorldPilot' manage_options=( {'label':'Properties','action':'manage_main'}, {'label':'View','action':''}, {'label':'Security','action':'manage_access'}, ) __ac_permissions__=( ('View management screens',('manage_tabs','manage_main')), ('Change permissions',('manage_access',)), ('View',('','menu','prog','logonhtml'),('Anonymous','Manager')), ) def __init__(self,id,title,Session, smtpserver): self.id=id self.title=title self._Session=Session self.composers=Composers() self.smtpserver = smtpserver MyLogons=Logons() prog__roles__=None menu__roles__=None manage_main=HTMLFile('worldpilotInfo',globals()) manage_workspace=HTMLFile('worldpilotInfo',globals()) #manage_workspace=HTML(worldpilot_manage_workspace,globals()) logo=ImageFile('logo.gif',globals()) shortcut=ImageFile('shortcut.gif',globals()) pixel=ImageFile('pixel.gif',globals()) folder=ImageFile('folder.gif',globals()) wpdown=ImageFile('wpdown.gif',globals()) wpup=ImageFile('wpup.gif',globals()) wpnavdown=ImageFile('wpnavdown.gif',globals()) wpnavup=ImageFile('wpnavup.gif',globals()) wpnavmore=ImageFile('wpnavmore.gif',globals()) wpnavless=ImageFile('wpnavless.gif',globals()) wpnavtop=ImageFile('wpnavtop.gif',globals()) wpnavbot=ImageFile('wpnavbot.gif',globals()) wpnavmax=ImageFile('wpnavmax.gif',globals()) wpnavmin=ImageFile('wpnavmin.gif',globals()) wpidxup=ImageFile('wpidxup.gif',globals()) wpidxdown=ImageFile('wpidxdown.gif',globals()) wparrow=ImageFile('wparrow.gif',globals()) LogID="" sessions=Sessions() wpicon=ImageFile('Mail.gif',globals()) publicmethods=('', 'signature','folders','compose','composerhead','composerbody','logoff','menu','prog',) def logon(self, REQUEST=None): "logs on" if REQUEST.has_key('User') and REQUEST.has_key('Passwd'): thisLogon=Logon(REQUEST['User'], REQUEST['Passwd'], "172") if thisLogon.check(): #return str(dir(self)) WorldPilot.MyLogons.addLogon(thisLogon) REQUEST['LogonUID']=thisLogon.getUID() REQUEST['Logon']=thisLogon NewWorldPilot=WorldPilot( thisLogon.getUID(), thisLogon.getUser(), "", []) NewWorldPilot.aq_parent=self #NewWorldPilot.storage=app=Zope.app()['Storage'] p=Permission('View',WorldPilot.publicmethods, NewWorldPilot) p.setRoles(('Anonymous','Manager')) WorldPilot.sessions.addSession(REQUEST['LogonUID'],NewWorldPilot) #WorldPilot.storages.aq_parent=self return thisLogon else: return None else: return None def tpValues(self): return () def manage_workspace(self, REQUEST=None): "Doc String :-)" return DefaultLogon.callResource('sessions_manage_workspace', client=self, mapping=REQUEST) def setListControl(self, REQUEST=None): if not REQUEST.has_key('ListSize'): REQUEST['ListSize']=20 if REQUEST.has_key('GOTO'): if REQUEST.has_key('query_start'): REQUEST['query_start']="1" def addComposer(self, REQUEST=None): "adds a Composer" ID=self.composers.nextID() NewWorldPilot=WorldPilotMail( ID, self.title, self._Session, self.smtpserver, ) NewWorldPilot.aq_parent=self p=Permission('View', WorldPilot.publicmethods, NewWorldPilot) p.setRoles(('Anonymous','Manager')) REQUEST['ComposerID']=ID NewWorldPilot.loadDraft(REQUEST) self.composers.addSession(ID,NewWorldPilot) def createPartTmp(self, Start=2, REQUEST=None): thisLogon = self.getLogon(REQUEST) try: NextPartID=self.NextPartID except: try: try: os.mkdir("/var/spool/worldpilot/" + str(thisLogon.getUID()) ) except: pass try: os.mkdir("/var/spool/worldpilot/" + str(thisLogon.getUID()) + "/" + REQUEST['ComposerID'] ) except: pass except: pass NextPartID=Start self.NextPartID=NextPartID+1 return NextPartID,open("/var/spool/worldpilot/" + str(thisLogon.getUID()) +"/" + REQUEST['ComposerID'] + "/" +str(NextPartID), "w") def openPartTmp(self, PartID, REQUEST): thisLogon = self.getLogon(REQUEST) try: return open("/var/spool/worldpilot/" + str(thisLogon.getUID()) +"/" + REQUEST['ComposerID'] + "/" +str(PartID), "r") except: return StringIO.StringIO('') def createMessageTmp(self, REQUEST): thisLogon = self.getLogon(REQUEST) try: return open("/var/spool/worldpilot/" + str(thisLogon.getUID()) + "/" + REQUEST['ComposerID'] + "/" + "message", "w") except: try: try: os.mkdir("/var/spool/worldpilot/" + str(thisLogon.getUID()) ) except: pass try: os.mkdir("/var/spool/worldpilot/" + str(thisLogon.getUID()) + "/" + REQUEST['ComposerID'] ) except: pass except: pass return open("/var/spool/worldpilot/" + str(thisLogon.getUID()) + "/" + REQUEST['ComposerID'] + "/" + "message", "w") def openMessageTmp(self, REQUEST): thisLogon = self.getLogon(REQUEST) try: return open("/var/spool/worldpilot/" + str(thisLogon.getUID()) + "/" + REQUEST['ComposerID'] + "/" + "message", "r") except: return StringIO.StringIO('') def loadDraft(self, REQUEST): ComposeUID=None ComposeSubject="" ComposeEnvTo=None ComposeEnvCc=None ComposeEnvBcc=None ComposeEnvInReplyTo=None ComposeText="" ComposeParts=[None] ComposeEnvMessageId=None ComposeMsg=None thisLogon = self.getLogon(REQUEST) if thisLogon: ComposeText=thisLogon.Signature try: if (REQUEST.has_key('DraftSource') and REQUEST['DraftSource']=='Forward' or REQUEST.has_key('DraftSourceForward')): thisLogon = self.getLogon(REQUEST) if thisLogon: SourceMsg=thisLogon.getIMAPMsg(1, REQUEST) if SourceMsg.MsgEnvelope.EnvSubject!=None: ComposeSubject=SourceMsg.MsgEnvelope.EnvSubject else: ComposeSubject="" ComposeSubject="Fw: " + ComposeSubject PartID,PartTmpIO=self.createPartTmp(2, REQUEST) thisLogon.getPartRaw( "", PartTmpIO, REQUEST) BodyType='message' BodySubtype='rfc822' BodyEncoding="7bit" params="" MH="" MH=MH+'Content-Type: %s/%s%s\n' % (BodyType, BodySubtype, params) MH=MH+"Content-Transfer-Encoding: %s\n" % (BodyEncoding) MH=MH+"\n" ComposeParts=[ None, MsgPart( str(PartID), #BodyPart BodyType=BodyType, BodySubtype=BodySubtype, BodyParameterList=None, BodyId=None, BodyDescription=None, BodyEncoding=BodyEncoding, BodySize=None, BodyEnvelope=None, BodyLines=None, BodyMD5=None, BodyDisposition=PartDisposition( "inline", None, None, ), BodyLanguage=None, BodyHeader=None, BodyText=None, BodyMime=MH, BodyAttachment=1, BodyContentType=None, ) ] elif (REQUEST.has_key('DraftSource') and REQUEST['DraftSource']=='Reply' or REQUEST.has_key('DraftSourceReply')): thisLogon = self.getLogon(REQUEST) if thisLogon: SourceMsg=thisLogon.getIMAPMsg(1, REQUEST) if SourceMsg.MsgEnvelope.EnvSubject!=None: ComposeSubject=SourceMsg.MsgEnvelope.EnvSubject else: ComposeSubject="" ComposeSubject="Re: " + ComposeSubject ComposeEnvTo=SourceMsg.MsgEnvelope.EnvFrom ComposeText="> " + string.join(string.split(SourceMsg.MsgText, "\n"), "\n> ")+ "\n" + thisLogon.Signature elif (REQUEST.has_key('DraftSource') and REQUEST['DraftSource']=='Draft'): thisLogon = self.getLogon(REQUEST) if thisLogon: SourceMsg=thisLogon.getIMAPMsg(1, REQUEST) #ComposeUID=SourceMsg.MsgUid #ComposeSubject=SourceMsg.MsgEnvelope.EnvSubject #ComposeText=SourceMsg.MsgText ComposeMsg=SourceMsg for Part in ComposeMsg.MsgParts: if Part.BodyPart!=ComposeMsg.MsgTextPart: PartID,PartTmpIO=self.createPartTmp(2, REQUEST) thisLogon.getPartRaw( Part.BodyPart, PartTmpIO, REQUEST) else: #New ComposeEnvTo=self.composeMsgAddress('ComposeEnvTo', REQUEST) pass except: pass if not ComposeMsg: try: FromUser,FromDomain=string.split(thisLogon.IdentityEMail,'@') except: FromUser=thisLogon.getUser() FromDomain=WPDomain #print "FROM", thisLogon.IdentityName, FromUser, FromDomain ComposeFrom=[MsgAddress(thisLogon.IdentityName, None, FromUser, FromDomain)] ComposeEnvelope=MsgEnvelope( None, #EnvDate ComposeSubject, #EnvSubject ComposeFrom, #EnvFrom None, #ComposeSender=EnvSender None, #ComposeReplyTo=EnvReplyTo ComposeEnvTo, #=EnvTo ComposeEnvCc, #=EnvCc ComposeEnvBcc, #=EnvBcc ComposeEnvInReplyTo, #=EnvInReplyTo ComposeEnvMessageId, #=EnvMessageId ) self.ComposeMsg=MsgMessage( ComposeUID, #MsgUid None, #MsgFlags None, #MsgInternalDate None, #MsgRfc822Size ComposeEnvelope,#MsgEnvelope ComposeParts, #MsgParts ComposeText, #MsgText ) else: self.ComposeMsg=ComposeMsg def frameset(self, REQUEST=None): "Doc String :-)" return self.displayIfLoggedOn('mail_frameset', REQUEST, self.logonScreen) def handle(self, REQUEST=None): "Doc String :-)" return self.displayIfLoggedOn('mail_handle', REQUEST, self.logonScreen) def composeMsgAddress(self, Name, REQUEST): al=[] if REQUEST.has_key(Name): astr=rfc822.AddrlistClass(REQUEST[Name]).getaddrlist() for a in astr: try: AddrPersonalName=a[0] AddrAtDomainList=None AddrMailboxName, AddrHostName=string.split(a[1], '@', 1) al.append(MsgAddress( AddrPersonalName, AddrAtDomainList, AddrMailboxName, AddrHostName, )) except: pass if len(al): return al else: return None def composeAddressListHeader(self, MsgAddressList): ToList=[] ToHeader="" if MsgAddressList!=None: for i in MsgAddressList: ToList.append(str(i.AddrMailboxName)+"@"+str(i.AddrHostName)) if i.AddrPersonalName and i.AddrPersonalName!="": ToHeader=ToHeader+'"'+ str(i.AddrPersonalName) + '" ' ToHeader=ToHeader+'<'+ str(i.AddrMailboxName)+"@"+str(i.AddrHostName) + '>,' if len(ToHeader): ToHeader=ToHeader[:-1] return ToList,ToHeader else: return None,None def composing(self, REQUEST): "Doc String :-)" self.getComposerID(REQUEST) ComposeMsg=self.ComposeMsg ComposeMsg.MsgEnvelope.EnvTo=self.composeMsgAddress('ComposeEnvTo', REQUEST) ComposeMsg.MsgEnvelope.EnvCc=self.composeMsgAddress('ComposeEnvCc', REQUEST) ComposeMsg.MsgEnvelope.EnvBcc=self.composeMsgAddress('ComposeEnvBcc', REQUEST) if REQUEST.has_key('ComposeEnvSubject'): ComposeMsg.MsgEnvelope.EnvSubject=REQUEST['ComposeEnvSubject'] else: ComposeMsg.MsgEnvelope.EnvSubject="" if REQUEST.has_key('ComposeMsgText'): ComposeMsg.MsgText=REQUEST['ComposeMsgText'] else: ComposeMsg.MsgText="" if REQUEST.has_key('Attach'): if REQUEST.has_key('file') and REQUEST['file'].filename: file=REQUEST['file'] headers=hasattr(file, 'headers') and file.headers or None data=(headers is None) and file or file.read() content_type=None if headers and headers.has_key('content-type'): content_type=headers['content-type'] if not content_type: #content_type, enc=mimetypes.guess_type(self.id()) content_type=None if not content_type: if content_types.find_binary(data) >= 0: content_type='application/octet-stream' else: content_type=content_types.text_type(data) content_type=string.lower(content_type) BodyType,BodySubtype=string.split(content_type, "/") #self.update_data(data, content_type) input=StringIO.StringIO(data) PartID,PartTmpIO=self.createPartTmp(2, REQUEST) BodyEncoding="base64" ComposeParameters=[MsgParameter( ParameterName="filename", ParameterValue=file.filename) ] params='; name="%s"' % (file.filename) MH="" #MH=str(headers) splits=re.split("[/\\\\]",file.filename) filename=splits[-1] MH=MH+'Content-Type: %s/%s%s\n' % (BodyType, BodySubtype, params) MH=MH+'Content-Transfer-Encoding: %s\n' % (BodyEncoding) MH=MH+'Content-Disposition: inline; filename="%s"\n'%(file.filename) MH=MH+"\n" mimetools.encode(input, PartTmpIO, BodyEncoding) if not self.ComposeMsg.MsgParts: self.ComposeMsg.MsgParts=[None] self.ComposeMsg.MsgParts.append( MsgPart( str(PartID), #BodyPart BodyType=BodyType, #BodyType BodySubtype=BodySubtype, #BodySubtype BodyParameterList=None, BodyId=None, BodyDescription=None, BodyEncoding=BodyEncoding, BodySize=None, BodyEnvelope=None, BodyLines=None, BodyMD5=None, BodyDisposition=PartDisposition( "inline", ComposeParameters, None, ), BodyLanguage=None, BodyHeader=None, BodyText=None, BodyMime=MH, BodyAttachment=1, BodyContentType=None, ) ) return self.displayIfLoggedOn('composerbody', REQUEST, self.logonScreen) if REQUEST.has_key('Send') or REQUEST.has_key('SaveDraft'): ToList,ToHeader=self.composeAddressListHeader(ComposeMsg.MsgEnvelope.EnvTo) CcList,CcHeader=self.composeAddressListHeader(ComposeMsg.MsgEnvelope.EnvCc) BccList,BccHeader=self.composeAddressListHeader(ComposeMsg.MsgEnvelope.EnvBcc) FromList,FromHeader=self.composeAddressListHeader(ComposeMsg.MsgEnvelope.EnvFrom) Smtp=WPSmtp(self.smtpserver,25) Msgs=[] H="" if 1: H=H+"From: " + FromHeader + "\n" if ToHeader: H=H+"To: " + ToHeader + "\n" else: pass # no way if CcHeader: H=H+"Cc: " + CcHeader + "\n" if 1: H=H+"Subject: " + ComposeMsg.MsgEnvelope.EnvSubject + "\n" H=H+"Date: " + DateTime.DateTime().rfc822() + "\n" #!!!Timezone H=H+"Mime-Version: 1.0\n" if ComposeMsg.MsgParts and len(ComposeMsg.MsgParts)>1: boundary="------------"+mimetools.choose_boundary()+"------------" H=H+'Content-Type: multipart/mixed; boundary="%s"\n' % (boundary,) H=H+'\n' H=H+'This is a multi-part message in MIME format.\n' MH="" MH=MH+'Content-Type: text/plain; charset="iso-8859-1"\n' MH=MH+"Content-Transfer-Encoding: quoted-printable\n" MH=MH+"\n" HeaderIO=StringIO.StringIO(H) Msgs.append(HeaderIO) MimeHeaderIO=StringIO.StringIO(MH) if ComposeMsg.MsgParts and len(ComposeMsg.MsgParts)>1: Msgs.append(StringIO.StringIO("--"+boundary+"\n")) Msgs.append(MimeHeaderIO) else: Msgs.append(MimeHeaderIO) if len(ComposeMsg.MsgText) and ComposeMsg.MsgText[-1]=='\n': MsgTextIO=StringIO.StringIO(ComposeMsg.MsgText+"\n") else: MsgTextIO=StringIO.StringIO(ComposeMsg.MsgText+"\n\n") MsgTextQuotedIO=StringIO.StringIO() mimetools.encode(MsgTextIO, MsgTextQuotedIO, 'quoted-printable') MsgTextQuotedIO.seek(0) Msgs.append(MsgTextQuotedIO) if ComposeMsg.MsgParts and len(ComposeMsg.MsgParts)>1: for Part in ComposeMsg.MsgParts: if Part and Part.BodyAttachment: MH="" params="" if Part.BodyParameterList: pass # make param list MH=MH+'Content-Type: %s/%s%s\n' % (Part.BodyType, Part.BodySubtype, params) MH=MH+"Content-Transfer-Encoding: %s\n" % (Part.BodyEncoding) MH=MH+"\n" MH=Part.BodyMime Msgs.append(StringIO.StringIO("--"+boundary+"\n")) MimeHeaderIO=StringIO.StringIO(MH) Msgs.append(MimeHeaderIO) Msgs.append(self.openPartTmp(Part.BodyPart, REQUEST)) Msgs.append(StringIO.StringIO("--"+boundary+"--\n\n")) SendToList=[] if ToList: SendToList=SendToList+ToList if CcList: SendToList=SendToList+CcList if BccList: SendToList=SendToList+BccList thisLogon = self.getLogon(REQUEST) if REQUEST.has_key('Send'): if thisLogon: save=self.createMessageTmp(REQUEST) Smtp.sendmail(FromList[0], SendToList, Msgs, save) Smtp.quit() save.close() save=self.openMessageTmp(REQUEST) thisLogon.appendMessage("INBOX.Sent", "\\Seen", save, REQUEST) return self.displayIfLoggedOn('composersent', REQUEST, self.logonScreen) if REQUEST.has_key('SaveDraft'): if thisLogon: save=self.createMessageTmp(REQUEST) for msg in Msgs: while 1: line=msg.readline() if not line: break if len(line)>1 and line[-2]=="\015": pass #line=line+"\012" else: line=line[:-1]+"\015\012" save.write(line) save.close() save=self.openMessageTmp(REQUEST) thisLogon.draftMessage(ComposeMsg.MsgUid, "INBOX.Drafts", "\\Seen \\Draft", save, REQUEST) return self.displayIfLoggedOn('composersaved', REQUEST, self.logonScreen) if REQUEST.has_key('Cancel'): return self.displayIfLoggedOn('composercanceled', REQUEST, self.logonScreen) else: return self.displayIfLoggedOn('composerbody', REQUEST, self.logonScreen) def checkLogonUID(self,LogonUID=None, REQUEST=None): "checks the LogonUID" if LogonUID==None: LogonUID="" return WorldPilot.MyLogons.checkUID(LogonUID, REQUEST) def getLogon(self, REQUEST=None): return self._Session.getLogon(REQUEST) def checkNotLoggedOn(self, REQUEST=None): if REQUEST.has_key('LogonUID') and self.checkLogonUID(REQUEST['LogonUID'], REQUEST): return 0 else: try: spl=string.split(REQUEST['URL0'], '/') if spl[-3]=="sessions" and self.checkLogonUID(spl[-2], REQUEST): return 0 elif len(spl)>4 and spl[-5]=="sessions" and self.checkLogonUID(spl[-4], REQUEST): return 0 else: raise KeyError except: if self.logon(REQUEST): return 0 else: return 1 def standard_error_message(self, REQUEST=None): return DefaultLogon.callResource('gotologon', client=self, mapping=REQUEST) def displayLogonScreen(self, REQUEST=None): return DefaultLogon.callResource('gotologon', client=self, mapping=REQUEST) def displayIfLoggedOn(self, ResourceName, REQUEST=None, LogonScreen=None): "Doc String :-)" thisLogon = self.getLogon(REQUEST) if not thisLogon: if not LogonScreen: LogonScreen=self.displayLogonScreen return LogonScreen(REQUEST) else: return thisLogon.callResource(ResourceName, client=self, mapping=REQUEST) def logonScreen(self, REQUEST): "Doc String :-)" return DefaultLogon.callResource('logon', client=self, mapping=REQUEST) def index_html(self, REQUEST): "Doc String :-)" return self.displayIfLoggedOn('index_html', REQUEST, self.logonScreen) def getComposerID(self, REQUEST): try: spl=string.split(REQUEST['URL0'], '/') if spl[-3]=="composers": REQUEST['ComposerID']=spl[-2] return spl[-2] else: raise KeyError except: return None def composerhead(self, REQUEST): "Doc String :-)" self.getComposerID(REQUEST) return self.displayIfLoggedOn('composerhead', REQUEST, self.logonScreen) def composerbody(self, REQUEST): "Doc String :-)" self.getComposerID(REQUEST) return self.displayIfLoggedOn('composerbody', REQUEST, self.logonScreen) def compose(self, REQUEST): "Doc String :-)" self.addComposer(REQUEST) return self.displayIfLoggedOn('composerfs', REQUEST, self.logonScreen) def logoff(self, REQUEST): "Doc String :-)" return self.displayIfLoggedOn('goodbye', REQUEST, self.logonScreen) def getpart(self, REQUEST, RESPONSE): "gets a part" thisLogon = self.getLogon(REQUEST) REQUEST['REQUEST']=REQUEST if not thisLogon: return self.displayLogonScreen(REQUEST) else: return thisLogon.getPart(REQUEST, RESPONSE) def prog(self, REQUEST): "Doc String :-)" thisLogon = self.getLogon(REQUEST) if thisLogon: if REQUEST.has_key('MoveTo') and REQUEST.has_key('Messages'): thisLogon.moveMessages(REQUEST) thisLogon.clearCache(REQUEST) if REQUEST.has_key('Delete') and REQUEST.has_key('Messages'): thisLogon.deleteMessages(REQUEST) thisLogon.clearCache(REQUEST) if REQUEST.has_key('Refresh'): thisLogon.clearCache(REQUEST) if REQUEST.has_key('DraftSource') or REQUEST.has_key('DraftSourceReply') or REQUEST.has_key('DraftSourceForward') or REQUEST.has_key('Compose'): self.addComposer(REQUEST) url=REQUEST['URL1'] + "/composers/" + REQUEST['ComposerID'] + "/composerbody?BLA=bla" if REQUEST.has_key('DraftSource'): url=url+"&DraftSource=" + REQUEST['DraftSource'] if REQUEST.has_key('Message'): url=url+"&Message=" + REQUEST['Message'] if REQUEST.has_key('Folder'): url=url+"&Folder=" + REQUEST['Folder'] raise 'Redirect', url if REQUEST.has_key('ViewMsg') and not REQUEST.has_key('Cancel'): return self.displayIfLoggedOn('viewmsg', REQUEST) if REQUEST.has_key('GoTo'): REQUEST['Folder']=REQUEST['MoveToFolder'] return self.displayIfLoggedOn('prog', REQUEST) def viewmsg(self, REQUEST): "Doc String :-)" return self.displayIfLoggedOn('viewmsg', REQUEST) def menu(self, REQUEST): "Doc String :-)" return self.displayIfLoggedOn('menu', REQUEST) def folders(self, REQUEST): "Doc String :-)" thisLogon = self.getLogon(REQUEST) Error=None if thisLogon: if REQUEST.has_key('CreateFolder'): if REQUEST.has_key('NewFolder') and REQUEST['NewFolder']!='': if REQUEST.has_key('PickedFolderFullName') and REQUEST['PickedFolderFullName']!="": thisLogon.createFolder(REQUEST['PickedFolderFullName']+"."+REQUEST['NewFolder'], REQUEST) else: Error="ErrPickInFolder" else: Error="ErrEnterNewFolder" if REQUEST.has_key('DeleteFolder'): if REQUEST.has_key('PickedFolderFullName') and REQUEST['PickedFolderFullName']!='': thisLogon.deleteFolder(REQUEST['PickedFolderFullName'], REQUEST) else: Error="ErrPickDeleteFolder" if Error: REQUEST['Error']=Error return self.displayIfLoggedOn('folders', REQUEST) def signature(self, REQUEST): "signature" thisLogon = self.getLogon(REQUEST) Error=None if thisLogon: if REQUEST.has_key('Save'): if REQUEST.has_key('SignatureText'): # and REQUEST['SignatureText']!='': thisLogon.saveSignature(REQUEST['SignatureText']) if REQUEST.has_key('IdentityName'): # and REQUEST['SignatureText']!='': thisLogon.saveIdentityName(REQUEST['IdentityName']) if REQUEST.has_key('IdentityEMail'): # and REQUEST['SignatureText']!='': thisLogon.saveIdentityEMail(REQUEST['IdentityEMail']) return self.displayIfLoggedOn('signature', REQUEST) def manage_edit(self,title,REQUEST=None): """Worldpilot settings """ self.title=title if REQUEST is not None: return MessageDialog( title='Edited', message='%s has been edited.' % self.id, action ='./manage_main', ) class WorldPilotSession( Acquisition.Implicit, AccessControl.Role.RoleManager, OFS.Folder.Folder, ): "Doc String :-)" icon='misc_/WorldPilot/worldpilot' meta_type='WorldPilot' manage_options=( {'label':'Properties','action':'manage_main'}, {'label':'View','action':''}, {'label':'Security','action':'manage_access'}, ) __ac_permissions__=( ('View management screens',('manage_tabs','manage_main')), ('Change permissions',('manage_access',)), ('Change WorldPilots',('manage_edit'),('Manager',)), ('View',('','menu','prog','logonhtml'),('Anonymous','Manager')), ) def __init__(self,id,title,user,smtpserver):#,question,choices): self.id=id self.title=title self.mail=WorldPilotMail('mail','Mail',self,smtpserver) # create user storage if necessary WorldPilot.storage.user.getUserStorage(user) #link to main storage self.storage=WorldPilot.storage.user #self.storage=Storage.LocalStorage.WorldPilotStoragesMapping('storage','Storage', # (WorldPilot.storage.user.getUserStorage(user),) # ) self.composers=Composers() MyLogons=Logons() prog__roles__=None menu__roles__=None manage_main=HTMLFile('worldpilotInfo',globals()) manage_workspace=HTMLFile('worldpilotInfo',globals()) logo=ImageFile('logo.gif',globals()) shortcut=ImageFile('shortcut.gif',globals()) pixel=ImageFile('pixel.gif',globals()) folder=ImageFile('folder.gif',globals()) wpdown=ImageFile('wpdown.gif',globals()) wpup=ImageFile('wpup.gif',globals()) wpleft=ImageFile('wpleft.gif',globals()) wpright=ImageFile('wpright.gif',globals()) wpidxup=ImageFile('wpidxup.gif',globals()) wpidxdown=ImageFile('wpidxdown.gif',globals()) wparrow=ImageFile('wparrow.gif',globals()) nhlogo=ImageFile('nhlogo.gif',globals()) pbpython=ImageFile('PythonPoweredSmall.gif',globals()) pbzope=ImageFile('ZopeButton.gif',globals()) LogID="" sessions=Sessions() #storages=Storages() publicmethods=('','storage', 'logoff',) def __bobo_traverse__(self, REQUEST=None, name=None): thisLogon = self.getLogon(REQUEST) REQUEST['Session']=self #print "TRAVERSING", name return getattr(self, name) def logon(self, REQUEST=None): "logs on" if REQUEST.has_key('User') and REQUEST.has_key('Passwd'): thisLogon=Logon(REQUEST['User'], REQUEST['Passwd'], "172") if thisLogon.check(): #return str(dir(self)) WorldPilot.MyLogons.addLogon(thisLogon) REQUEST['LogonUID']=thisLogon.getUID() REQUEST['Logon']=thisLogon NewWorldPilot=WorldPilot( thisLogon.getUID(), thisLogon.getUser(), "", []) NewWorldPilot.aq_parent=self #NewWorldPilot.storage=app=Zope.app()['Storage'] p=Permission('View',WorldPilot.publicmethods, NewWorldPilot) p.setRoles(('Anonymous','Manager')) WorldPilot.sessions.addSession(REQUEST['LogonUID'],NewWorldPilot) #WorldPilot.storages.aq_parent=self return thisLogon else: return None else: return None def tpValues(self): #print "TPVALUES" return (self.mail,self.storage)#self._mountpoints['store']) def manage_workspace(self, REQUEST=None): "dfdsfdsf" return DefaultLogon.callResource('sessions_manage_workspace', client=self, mapping=REQUEST) def logoffLogin(self, REQUEST): "logs off" thisLogon = self.getLogon(REQUEST) if thisLogon: WorldPilot.sessions.delSession(thisLogon.getUID()) #WorldPilot.MyLogons.delLogon(thisLogon.getUID()) return 1 else: return 0 def checkLogonUID(self,LogonUID=None, REQUEST=None): "checks the LogonUID" if LogonUID==None: LogonUID="" return WorldPilot.MyLogons.checkUID(LogonUID, REQUEST) def checkLogon(self, thisLogon, REQUEST): REQUEST['User']=thisLogon.getUser() REQUEST['Logon']=thisLogon REQUEST['LogonUID']=thisLogon.getUID() dt=DateTime.DateTime() tz=dt._localzone REQUEST['TimeZone']=tz REQUEST['DT']=dt return thisLogon def getLogon(self, REQUEST=None): try: #return WorldPilot.MyLogons.checkLogon(self._Logon, REQUEST) return self.checkLogon(self._Logon, REQUEST) spl=string.split(REQUEST['URL0'], '/') if spl[-3]=="sessions": return self.checkLogonUID(spl[-2], REQUEST) elif len(spl)>4 and spl[-5]=="sessions": return self.checkLogonUID(spl[-4], REQUEST) else: raise KeyError except: return self.logon(REQUEST) def checkNotLoggedOn(self, REQUEST=None): if REQUEST.has_key('LogonUID') and self.checkLogonUID(REQUEST['LogonUID'], REQUEST): return 0 else: try: spl=string.split(REQUEST['URL0'], '/') if spl[-3]=="sessions" and self.checkLogonUID(spl[-2], REQUEST): return 0 elif len(spl)>4 and spl[-5]=="sessions" and self.checkLogonUID(spl[-4], REQUEST): return 0 else: raise KeyError except: if self.logon(REQUEST): return 0 else: return 1 def standard_error_message(self, REQUEST=None): return DefaultLogon.callResource('gotologon', client=self, mapping=REQUEST) def displayLogonScreen(self, REQUEST=None): return DefaultLogon.callResource('gotologon', client=self, mapping=REQUEST) def displayIfLoggedOn(self, ResourceName, REQUEST=None, LogonScreen=None, Client=None): thisLogon = self.getLogon(REQUEST) if Client is None: Client=self if not thisLogon: if not LogonScreen: LogonScreen=self.displayLogonScreen return LogonScreen(REQUEST) else: return thisLogon.callResource(ResourceName, client=Client, mapping=REQUEST) def index_html(self, REQUEST): "Doc String :-)" return self.displayIfLoggedOn('index_html', REQUEST, self._WorldPilot.logonScreen) def banner(self, REQUEST): "Doc String :-)" #return self.displayIfLoggedOn('main_banner', REQUEST, self._WorldPilot.logonScreen) return self.displayIfLoggedOn('main_banner', REQUEST, None) def menu(self, REQUEST): "Doc String :-)" #return self.displayIfLoggedOn('main_menu', REQUEST, self._WorldPilot.logonScreen) return self.displayIfLoggedOn('main_menu', REQUEST, None) def today(self, REQUEST): "Doc String :-)" return self.displayIfLoggedOn('today_frameset', REQUEST, self._WorldPilot.logonScreen) def about(self, REQUEST): "Doc String :-)" return self.displayIfLoggedOn('about_frameset', REQUEST, None) def about_handle(self, REQUEST): "Doc String :-)" return self.displayIfLoggedOn('about_handle', REQUEST, None) def about_info(self, REQUEST): "Doc String :-)" return self.displayIfLoggedOn('about_info', REQUEST, None) def getComposerID(self, REQUEST): try: spl=string.split(REQUEST['URL0'], '/') if spl[-3]=="composers": REQUEST['ComposerID']=spl[-2] return spl[-2] else: raise KeyError except: return None def logoff(self, REQUEST): "Doc String :-)" return self.displayIfLoggedOn('goodbye', REQUEST, None) #self._WorldPilot.logonScreen) class WorldPilot( Acquisition.Implicit, Persistent, AccessControl.Role.RoleManager, OFS.Folder.Folder, #OFS.SimpleItem.Item, ): """A WorldPilot product. """ icon='misc_/WorldPilot/worldpilot' meta_type='WorldPilot' manage_options=( {'label':'Properties','action':'manage_main'}, {'label':'View','action':''}, {'label':'Security','action':'manage_access'}, ) __ac_permissions__=( ('View management screens',('manage_tabs','manage_main')), ('Change permissions',('manage_access',)), ('Change WorldPilots',('manage_edit'),('Manager',)), ('View',('','menu','prog','logonhtml'),('Anonymous','Manager')), ) def __init__(self,id,title,imapserver,smtpserver): self.id=id self.title=title self.imapserver=imapserver self.smtpserver=smtpserver self.composers=Composers() MyLogons=Logons() prog__roles__=None menu__roles__=None manage_main=HTMLFile('worldpilotEdit',globals()) logo=ImageFile('logo.gif',globals()) logoonwhite=ImageFile('logoonwhite.gif',globals()) shortcut=ImageFile('shortcut.gif',globals()) pixel=ImageFile('pixel.gif',globals()) folder=ImageFile('folder.gif',globals()) wpdown=ImageFile('wpdown.gif',globals()) wpup=ImageFile('wpup.gif',globals()) wpleft=ImageFile('wpleft.gif',globals()) wpright=ImageFile('wpright.gif',globals()) wpidxup=ImageFile('wpidxup.gif',globals()) wpidxdown=ImageFile('wpidxdown.gif',globals()) LogID="" storage=Storage.LocalStorage.WorldPilotStorage("storage","Storage",MyWorldPilotUserStorage) storage.initialize() Storage.LocalStorage.storageroot=storage.user sessions=Sessions() publicmethods=('', 'logoff',) def __bobo_traverse__(self, REQUEST=None, key=None): WorldPilot.sessions.initialize(self) return getattr(self, key) def logon(self, REQUEST=None): "logs on" return WorldPilot.sessions.createWorldPilotSession(self, None, self.imapserver, self.smtpserver, REQUEST) if REQUEST.has_key('User') and REQUEST.has_key('Passwd'): thisLogon=Logon(REQUEST['User'], REQUEST['Passwd'], "172") if thisLogon.check(): return thisLogon else: return None else: return None def tpValues(self): """Returns a list of the folder's sub-folders, used by tree tag.""" WorldPilot.sessions.initialize(self) return (WorldPilot.sessions, WorldPilot.storage) def logoffLogin(self, REQUEST): "logs off" thisLogon = self.getLogon(REQUEST) if thisLogon: WorldPilot.sessions.delSession(thisLogon.getUID()) #WorldPilot.MyLogons.delLogon(thisLogon.getUID()) return 1 else: return 0 def checkLogonUID(self,LogonUID=None, REQUEST=None): "checks the LogonUID" if LogonUID==None: LogonUID="" return WorldPilot.MyLogons.checkUID(LogonUID, REQUEST) def getLogon(self, REQUEST=None): try: spl=string.split(REQUEST['URL0'], '/') if spl[-3]=="sessions": return self.checkLogonUID(spl[-2], REQUEST) elif len(spl)>4 and spl[-5]=="sessions": return self.checkLogonUID(spl[-4], REQUEST) else: raise KeyError except: return self.logon(REQUEST) def standard_error_message(self, REQUEST=None): return DefaultLogon.callResource('gotologon', client=self, mapping=REQUEST) def displayLogonScreen(self, REQUEST=None): return DefaultLogon.callResource('gotologon', client=self, mapping=REQUEST) def displayIfLoggedOn(self, ResourceName, REQUEST=None, LogonScreen=None): "Doc String :-)" thisLogon = self.getLogon(REQUEST) if not thisLogon: if not LogonScreen: LogonScreen=self.displayLogonScreen return LogonScreen(REQUEST) else: return thisLogon.callResource(ResourceName, client=self, mapping=REQUEST) def logonScreen(self, REQUEST): "Doc String :-)" return DefaultLogon.callResource('logon', client=self, mapping=REQUEST) def index_html(self, REQUEST): "Doc String :-)" return self.displayIfLoggedOn('index_html', REQUEST, self.logonScreen) def manage_edit(self,title,REQUEST=None): """Worldpilot settings """ self.title=title if REQUEST is not None: return MessageDialog( title='Edited', message='%s has been edited.' % self.id, action ='./manage_main', ) addWorldPilotForm=HTMLFile('worldpilotAdd',globals()) def addWorldPilot(self,id,title,imapserver, smtpserver, REQUEST=None): """Create a worldpilot and install it in its parent Folder" The argument 'self' will be bound to the parent Folder. """ worldpilot=WorldPilot(id, title, imapserver, smtpserver) self._setObject(id, worldpilot) if REQUEST is not None: return self.manage_main(self,REQUEST)