Commit 9d82bbdc authored by Jeffrey Shell's avatar Jeffrey Shell

updated with icon

parent b920982c
...@@ -2,175 +2,183 @@ from Globals import Persistent, HTMLFile, HTML ...@@ -2,175 +2,183 @@ from Globals import Persistent, HTMLFile, HTML
from socket import * from socket import *
import Acquisition, sys, regex, string import Acquisition, sys, regex, string
#$Id: MailForm.py,v 1.3 1997/09/09 16:09:13 jeffrey Exp $ #$Id: MailForm.py,v 1.4 1997/09/09 18:40:34 jeffrey Exp $
__version__ = "$Revision: 1.3 $"[11:-2] __version__ = "$Revision: 1.4 $"[11:-2]
smtpError = "SMTP Error" smtpError = "SMTP Error"
addForm=HTMLFile('MailForm/addMailForm_form') addForm=HTMLFile('MailForm/addMailForm_form')
def add(self, id='mailForm', title='Some mail thing', smtp_host=None, def add(self, id='mailForm', title='Some mail thing', smtp_host=None,
localhost='localhost', smtp_port=25, mailTemplate=None, localhost='localhost', smtp_port=25, mailTemplate=None,
errorTemplate=None, sentMailTemplate=None, REQUEST): errorTemplate=None, sentMailTemplate=None, REQUEST):
' add a MailForm into the system ' ' add a MailForm into the system '
i=MailForm() #create new mailform i=MailForm() #create new mailform
i.id=id #give it id i.id=id #give it id
i.title=title #title i.title=title #title
i._init(localHost=localhost, smtpHost=smtp_host, smtpPort=smtp_port, i._init(localHost=localhost, smtpHost=smtp_host, smtpPort=smtp_port,
mailTemplate=mailTemplate, errorTemplate=errorTemplate, mailTemplate=mailTemplate, errorTemplate=errorTemplate,
sentMailTemplate=sentMailTemplate) sentMailTemplate=sentMailTemplate)
self._setObject(id,i) #register it self._setObject(id,i) #register it
return self.manage_main(self,REQUEST) #and whatever this does.. :) return self.manage_main(self,REQUEST) #and whatever this does.. :)
class MailForm(Persistent, Acquisition.Implicit): class MailForm(Persistent, Acquisition.Implicit):
'a mailform...?' 'a mailform...?'
manage=HTMLFile('MailForm/manageMailForm') manage=HTMLFile('MailForm/manageMailForm')
index_html=HTMLFile('MailForm/mailForm') index_html=HTMLFile('MailForm/mailForm')
icon="MailForm/MailForm_icon.gif"
def __init__(self):
'nothing yet' def __init__(self):
pass 'nothing yet'
pass
def _init(self,localHost, smtpHost, smtpPort, mailTemplate, errorTemplate,
sentMailTemplate): def _init(self,localHost, smtpHost, smtpPort, mailTemplate, errorTemplate,
self.localHost=localHost sentMailTemplate):
self.smtpHost=smtpHost self.localHost=localHost
self.smtpPort=smtpPort self.smtpHost=smtpHost
self.mailTemplate=mailTemplate self.smtpPort=smtpPort
self.errorTemplate=errorTemplate self.mailTemplate=mailTemplate
self.sentMailTemplate=sentMailTemplate self.errorTemplate=errorTemplate
self.sentMailTemplate=sentMailTemplate
def manage_makeChanges(self, title, localHost, smtpHost, smtpPort):
'make the changes' def manage_makeChanges(self, title, localHost, smtpHost, smtpPort):
self.title=title 'make the changes'
self.localHost=localHost self.title=title
self.smtpHost=smtpHost self.localHost=localHost
self.smtpPort=smtpPort self.smtpHost=smtpHost
return ('Changes made','Changes made...') self.smtpPort=smtpPort
return ('Changes made','Changes made...')
def send(trueself, self):
'uhh, sponges off the request and mails it..?' def send(trueself, self):
if trueself.REQUEST.has_key('d_template'): 'uhh, sponges off the request and mails it..?'
mtemplate = getattr(self, trueself.REQUEST['d_template']) if trueself.REQUEST.has_key('d_template'):
else: mtemplate = getattr(self, trueself.REQUEST['d_template'])
mtemplate = getattr(self, trueself.mailTemplate) else:
messageText = mtemplate(self, trueself.REQUEST) mtemplate = getattr(self, trueself.mailTemplate)
headers, message = decapitate(messageText) messageText = mtemplate(self, trueself.REQUEST)
for requiredHeader in ('to', 'from', 'subject'): headers, message = decapitate(messageText)
if not headers.has_key(requiredHeader): for requiredHeader in ('to', 'from', 'subject'):
raise MailFormError, "Message missing SMTP Header '%s'" \ if not headers.has_key(requiredHeader):
% requiredHeader raise MailFormError, "Message missing SMTP Header '%s'" \
% requiredHeader
SendMail(self.smtpHost, self.smtpPort, self.localHost).send(
mfrom=headers['from'], mto=headers['to'], SendMail(trueself.smtpHost, trueself.smtpPort,
subj=headers['subject'], body=messageText) trueself.localHost).send(
mfrom=headers['from'], mto=headers['to'],
return getattr(self,self.sentMailTemplate)(self, self.REQUEST, subj=headers['subject'], body=messageText
messageText=message) )
def trueSend(trueself, self=None, REQUEST=None, **kw): return getattr(self,self.sentMailTemplate)(self, self.REQUEST,
if REQUEST: kw=REQUEST messageText=message)
if not self: self=trueself
if kw.has_key('d_template'): def trueSend(trueself, self=None, REQUEST=None, **kw):
mtemplate = getattr(self, kw['d_template']) if REQUEST: kw=REQUEST
else: if self == None: self=trueself
mtemplate = getattr(self, trueself.mailTemplate) if kw.has_key('d_template'):
messageText = mtemplate(self, kw) mtemplate = getattr(self, kw['d_template'])
headers, message = decapitate(messageText) else:
for requiredHeader in ('to', 'from', 'subject'): mtemplate = getattr(self, trueself.mailTemplate)
if not headers.has_key(requiredHeader): messageText = mtemplate(self, kw)
raise MailFormError, "Message missing SMTP Header '%s'" \ headers, message = decapitate(messageText)
% requiredHeader for requiredHeader in ('to', 'from', 'subject'):
if not headers.has_key(requiredHeader):
SendMail(trueself.smtpHost, trueself.smtpPort, raise MailFormError, "Message missing SMTP Header '%s'" \
trueself.localHost).send( % requiredHeader
mfrom=headers['from'], mto=headers['to'],
subj=headers['subject'], body=messageText SendMail(trueself.smtpHost, trueself.smtpPort,
) trueself.localHost).send(
mfrom=headers['from'], mto=headers['to'],
return getattr(trueself,trueself.sentMailTemplate)(self, kw, subj=headers['subject'], body=messageText
messageText=message) )
class SendMail: return getattr(trueself,trueself.sentMailTemplate)(self, kw,
def __init__(self, smtpHost, smtpPort, localHost="localhost"): messageText=message)
self.conn = socket(AF_INET, SOCK_STREAM)
self.conn.connect(smtpHost, smtpPort) def kwikHack(self, mfid, REQUEST):
self.conn.send("helo "+localHost+"\r\n") 'quick and ugly hack to test da system'
self._check('220') jj=getattr(self, mfid)
return jj.trueSend(self=self, REQUEST=REQUEST)
def __del__(self):
self.close() class SendMail:
def __init__(self, smtpHost, smtpPort, localHost="localhost"):
def _check(self, lev='250'): self.conn = socket(AF_INET, SOCK_STREAM)
data = self.conn.recv(1024) self.conn.connect(smtpHost, smtpPort)
if data[:3] != lev: self.conn.send("helo "+localHost+"\r\n")
raise smtpError, "Expected %s, got %s from SMTP"%(lev, data[:3]) self._check('220')
def send(self, mfrom, mto, subj, body): def __del__(self):
self.conn.send("mail from:<%s>\n"%mfrom) self.close()
self._check()
if type(mto) == type([1,2]): def _check(self, lev='250'):
for person in mto: data = self.conn.recv(1024)
self.conn.send("rcpt to:<%s>\n" % person) if data[:3] != lev:
self._check() raise smtpError, "Expected %s, got %s from SMTP"%(lev, data[:3])
else:
self.conn.send("rcpt to:<%s>\n"%mto) def send(self, mfrom, mto, subj, body):
self._check() self.conn.send("mail from:<%s>\n"%mfrom)
self.conn.send("data\n") self._check()
self._check() if type(mto) == type([1,2]):
self.conn.send(body) for person in mto:
self.conn.send("\n.\n") self.conn.send("rcpt to:<%s>\n" % person)
self._check('354') self._check()
else:
def _close(self): self.conn.send("rcpt to:<%s>\n"%mto)
self.conn.send("quit\n") self._check()
self.conn.close() self.conn.send("data\n")
self._check()
self.conn.send(body)
self.conn.send("\n.\n")
self._check('354')
def _close(self):
self.conn.send("quit\n")
self.conn.close()
def decapitate(message, def decapitate(message,
header_re=regex.compile( header_re=regex.compile(
'\(\(' '\(\('
'[^\0- <>:]+:[^\n]*\n' '[^\0- <>:]+:[^\n]*\n'
'\|' '\|'
'[ \t]+[^\0- ][^\n]*\n' '[ \t]+[^\0- ][^\n]*\n'
'\)+\)[ \t]*\n\([\0-\377]+\)' '\)+\)[ \t]*\n\([\0-\377]+\)'
), ),
space_re=regex.compile('\([ \t]+\)'), space_re=regex.compile('\([ \t]+\)'),
name_re=regex.compile('\([^\0- <>:]+\):\([^\n]*\)'), name_re=regex.compile('\([^\0- <>:]+\):\([^\n]*\)'),
): ):
if header_re.match(message) < 0: return message if header_re.match(message) < 0: return message
headers, body = header_re.group(1,3) headers, body = header_re.group(1,3)
headers=string.split(headers,'\n') headers=string.split(headers,'\n')
headerDict={} headerDict={}
i=1 i=1
while i < len(headers): while i < len(headers):
if not headers[i]: if not headers[i]:
del headers[i] del headers[i]
elif space_re.match(headers[i]) >= 0: elif space_re.match(headers[i]) >= 0:
headers[i-1]="%s %s" % (headers[i-1], headers[i-1]="%s %s" % (headers[i-1],
headers[i][len(space_re.group(1)):]) headers[i][len(space_re.group(1)):])
del headers[i] del headers[i]
else: else:
i=i+1 i=i+1
for i in range(len(headers)): for i in range(len(headers)):
if name_re.match(headers[i]) >= 0: if name_re.match(headers[i]) >= 0:
k, v = name_re.group(1,2) k, v = name_re.group(1,2)
k=string.lower(k); v=string.strip(v) k=string.lower(k); v=string.strip(v)
headerDict[k]=v headerDict[k]=v
else: else:
raise ValueError, 'Invalid Header (%d): %s ' % (i,headers[i]) raise ValueError, 'Invalid Header (%d): %s ' % (i,headers[i])
if headerDict.has_key('to'): if headerDict.has_key('to'):
headerDict['to']=map( headerDict['to']=map(
lambda x: string.strip(x), lambda x: string.strip(x),
string.split(headerDict['to'], ',') string.split(headerDict['to'], ',')
) )
return headerDict, body return headerDict, body
#$Log: MailForm.py,v $ #$Log: MailForm.py,v $
#Revision 1.3 1997/09/09 16:09:13 jeffrey #Revision 1.4 1997/09/09 18:40:34 jeffrey
#minor fixings #updated with icon
# #
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment