Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
41d13927
Commit
41d13927
authored
Sep 10, 1997
by
Jeffrey Shell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added new decapitate method to handle some strange errors in some messages
got new interface up to specs:
parent
030628e5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
189 additions
and
215 deletions
+189
-215
lib/python/Products/MailHost/MailHost.py
lib/python/Products/MailHost/MailHost.py
+189
-215
No files found.
lib/python/Products/MailHost/MailHost.py
View file @
41d13927
...
@@ -2,233 +2,207 @@ from Globals import Persistent, HTMLFile, HTML
...
@@ -2,233 +2,207 @@ from Globals import Persistent, HTMLFile, HTML
from
socket
import
*
from
socket
import
*
import
Acquisition
,
sys
,
regex
,
string
import
Acquisition
,
sys
,
regex
,
string
#$Id: MailHost.py,v 1.
2 1997/09/09 21:33:41
jeffrey Exp $
#$Id: MailHost.py,v 1.
3 1997/09/10 15:05:35
jeffrey Exp $
__version__
=
"$Revision: 1.
2
$"
[
11
:
-
2
]
__version__
=
"$Revision: 1.
3
$"
[
11
:
-
2
]
smtpError
=
"SMTP Error"
smtpError
=
"SMTP Error"
MailHostError
=
"MailHost Error"
MailHostError
=
"MailHost Error"
addForm
=
HTMLFile
(
'MailHost/addMailHost_form'
)
addForm
=
HTMLFile
(
'MailHost/addMailHost_form'
)
def
add
(
self
,
id
=
'aMailHost'
,
title
=
'Some mail thing'
,
smtp_host
=
None
,
def
add
(
self
,
id
=
'aMailHost'
,
title
=
'Some mail thing'
,
smtp_host
=
None
,
localhost
=
'localhost'
,
smtp_port
=
25
,
REQUEST
):
localhost
=
'localhost'
,
smtp_port
=
25
,
REQUEST
):
' add a MailHost into the system '
' add a MailHost into the system '
i
=
MailHost
()
#create new mail host
i
=
MailHost
()
#create new mail host
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
)
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
MailHost
(
Persistent
,
Acquisition
.
Implicit
):
class
MailHost
(
Persistent
,
Acquisition
.
Implicit
):
'a mailhost...?'
'a mailhost...?'
manage
=
HTMLFile
(
'MailHost/manageMailHost'
)
manage
=
HTMLFile
(
'MailHost/manageMailHost'
)
index_html
=
HTMLFile
(
'MailHost/mailHost'
)
index_html
=
HTMLFile
(
'MailHost/mailHost'
)
icon
=
"MailHost/MailHost_icon.gif"
icon
=
"MailHost/MailHost_icon.gif"
def
__init__
(
self
):
def
__init__
(
self
):
'nothing yet'
'nothing yet'
pass
pass
def
_init
(
self
,
localHost
,
smtpHost
,
smtpPort
):
def
_init
(
self
,
localHost
,
smtpHost
,
smtpPort
):
self
.
localHost
=
localHost
self
.
localHost
=
localHost
self
.
smtpHost
=
smtpHost
self
.
smtpHost
=
smtpHost
self
.
smtpPort
=
smtpPort
self
.
smtpPort
=
smtpPort
self
.
sentMessages
=
0
self
.
sentMessages
=
0
def
manage_makeChanges
(
self
,
title
,
localHost
,
smtpHost
,
smtpPort
):
def
manage_makeChanges
(
self
,
title
,
localHost
,
smtpHost
,
smtpPort
):
'make the changes'
'make the changes'
self
.
title
=
title
self
.
title
=
title
self
.
localHost
=
localHost
self
.
localHost
=
localHost
self
.
smtpHost
=
smtpHost
self
.
smtpHost
=
smtpHost
self
.
smtpPort
=
smtpPort
self
.
smtpPort
=
smtpPort
return
self
.
manage
(
self
,
REQUEST
)
return
self
.
manage
(
self
,
REQUEST
)
def
__log
(
self
):
def
__log
(
self
):
self
.
sentMessages
=
self
.
sentMessages
+
1
self
.
sentMessages
=
self
.
sentMessages
+
1
def
sendTemplate
(
trueself
,
self
,
messageTemplate
,
def
sendTemplate
(
trueself
,
self
,
messageTemplate
,
statusTemplate
=
None
,
mto
=
None
,
mfrom
=
None
,
REQUEST
):
statusTemplate
=
None
,
mto
=
None
,
mfrom
=
None
,
REQUEST
):
'render a mail template, then send it...'
'render a mail template, then send it...'
mtemplate
=
getattr
(
self
,
messageTemplate
)
mtemplate
=
getattr
(
self
,
messageTemplate
)
messageText
=
mtemplate
(
self
,
trueself
.
REQUEST
)
messageText
=
mtemplate
(
self
,
trueself
.
REQUEST
)
headers
,
message
=
decapitate
(
messageText
)
headers
,
message
=
newDecapitate
(
messageText
)
if
mto
:
headers
[
'to'
]
=
mto
if
mto
:
headers
[
'to'
]
=
mto
if
mfrom
:
headers
[
'from'
]
=
mfrom
if
mfrom
:
headers
[
'from'
]
=
mfrom
for
requiredHeader
in
(
'to'
,
'from'
,
'subject'
):
for
requiredHeader
in
(
'to'
,
'from'
,
'subject'
):
if
not
headers
.
has_key
(
requiredHeader
):
if
not
headers
.
has_key
(
requiredHeader
):
raise
MailHostError
,
"Message missing SMTP Header '%s'"
\
raise
MailHostError
,
"Message missing SMTP Header '%s'"
\
%
requiredHeader
%
requiredHeader
SendMail
(
trueself
.
smtpHost
,
trueself
.
smtpPort
,
SendMail
(
trueself
.
smtpHost
,
trueself
.
smtpPort
,
trueself
.
localHost
).
send
(
trueself
.
localHost
).
send
(
mfrom
=
headers
[
'from'
],
mto
=
headers
[
'to'
],
mfrom
=
headers
[
'from'
],
mto
=
headers
[
'to'
],
subj
=
headers
[
'subject'
],
body
=
messageText
subj
=
headers
[
'subject'
],
body
=
messageText
)
)
self
.
__log
()
self
.
__log
()
return
(
"sent"
,
"sent..."
)
return
(
"sent"
,
"sent..."
)
#return getattr(self,statusTemplate)(self, self.REQUEST,
#return getattr(self,statusTemplate)(self, self.REQUEST,
# messageText=message)
# messageText=message)
def
send
(
self
,
messageText
,
mto
=
None
,
mfrom
=
None
):
def
send
(
self
,
messageText
,
mto
=
None
,
mfrom
=
None
):
'send a rendered message'
'send a rendered message'
headers
,
message
=
decapitate
(
messageText
)
headers
,
message
=
newDecapitate
(
messageText
)
if
mto
:
headers
[
'to'
]
=
mto
if
mto
:
headers
[
'to'
]
=
mto
if
mfrom
:
headers
[
'from'
]
=
mfrom
if
mfrom
:
headers
[
'from'
]
=
mfrom
for
requiredHeader
in
(
'to'
,
'from'
,
'subject'
):
for
requiredHeader
in
(
'to'
,
'from'
,
'subject'
):
if
not
headers
.
has_key
(
requiredHeader
):
if
not
headers
.
has_key
(
requiredHeader
):
raise
MailHostError
,
"Message missing SMTP Header '%s'"
\
raise
MailHostError
,
"Message missing SMTP Header '%s'"
\
%
requiredHeader
%
requiredHeader
SendMail
(
self
.
smtpHost
,
self
.
smtpPort
,
self
.
localHost
).
send
(
SendMail
(
self
.
smtpHost
,
self
.
smtpPort
,
self
.
localHost
).
send
(
mfrom
=
headers
[
'from'
],
mto
=
headers
[
'to'
],
mfrom
=
headers
[
'from'
],
mto
=
headers
[
'to'
],
subj
=
headers
[
'subject'
],
body
=
messageText
)
subj
=
headers
[
'subject'
],
body
=
messageText
)
self
.
__log
()
self
.
__log
()
return
(
"sent"
,
"sent..."
)
return
(
"sent"
,
"sent..."
)
#return getattr(self,statusTemplate)(self, self.REQUEST,
#return getattr(self,statusTemplate)(self, self.REQUEST,
# messageText=message)
# messageText=message)
def
simple_send
(
self
,
mto
,
mfrom
,
subject
,
body
):
def
simple_send
(
self
,
mto
,
mfrom
,
subject
,
body
):
'like the simplist send or something'
'like the simplist send or something'
body
=
"subject: %s
\
n
\
n
%s"
%
(
subject
,
body
)
body
=
"subject: %s
\
n
\
n
%s"
%
(
subject
,
body
)
SendMail
(
self
.
smtpHost
,
self
.
smtpPort
,
self
.
localHost
).
send
(
SendMail
(
self
.
smtpHost
,
self
.
smtpPort
,
self
.
localHost
).
send
(
mfrom
=
mfrom
,
mto
=
mto
,
subj
=
subject
,
body
=
body
)
mfrom
=
mfrom
,
mto
=
mto
,
subj
=
subject
,
body
=
body
)
self
.
__log
()
self
.
__log
()
return
(
"sent"
,
"sent..."
)
return
(
"sent"
,
"sent..."
)
# def send(trueself, self):
class
SendMail
:
# 'uhh, sponges off the request and mails it..?'
def
__init__
(
self
,
smtpHost
,
smtpPort
,
localHost
=
"localhost"
):
# if trueself.REQUEST.has_key('d_template'):
self
.
conn
=
socket
(
AF_INET
,
SOCK_STREAM
)
# mtemplate = getattr(self, trueself.REQUEST['d_template'])
self
.
conn
.
connect
(
smtpHost
,
smtpPort
)
# else:
self
.
conn
.
send
(
"helo "
+
localHost
+
"
\
r
\
n
"
)
# mtemplate = getattr(self, trueself.mailTemplate)
self
.
_check
(
'220'
)
# messageText = mtemplate(self, trueself.REQUEST)
# headers, message = decapitate(messageText)
def
__del__
(
self
):
# for requiredHeader in ('to', 'from', 'subject'):
self
.
close
()
# if not headers.has_key(requiredHeader):
# raise MailHostError, "Message missing SMTP Header '%s'" \
def
_check
(
self
,
lev
=
'250'
):
# % requiredHeader
data
=
self
.
conn
.
recv
(
1024
)
#
if
data
[:
3
]
!=
lev
:
# SendMail(trueself.smtpHost, trueself.smtpPort,
raise
smtpError
,
"Expected %s, got %s from SMTP"
%
(
lev
,
data
[:
3
])
# trueself.localHost).send(
# mfrom=headers['from'], mto=headers['to'],
def
send
(
self
,
mfrom
,
mto
,
subj
,
body
):
# subj=headers['subject'], body=messageText
self
.
conn
.
send
(
"mail from:<%s>
\
n
"
%
mfrom
)
# )
self
.
_check
()
#
if
type
(
mto
)
==
type
([
1
,
2
]):
# return getattr(self,self.sentMailTemplate)(self, self.REQUEST,
for
person
in
mto
:
# messageText=message)
self
.
conn
.
send
(
"rcpt to:<%s>
\
n
"
%
person
)
#
self
.
_check
()
# def trueSend(trueself, self=None, REQUEST=None, **kw):
else
:
# if REQUEST: kw=REQUEST
self
.
conn
.
send
(
"rcpt to:<%s>
\
n
"
%
mto
)
# if self == None: self=trueself
self
.
_check
()
# if kw.has_key('d_template'):
self
.
conn
.
send
(
"data
\
n
"
)
# mtemplate = getattr(self, kw['d_template'])
self
.
_check
()
# else:
self
.
conn
.
send
(
body
)
# mtemplate = getattr(self, trueself.mailTemplate)
self
.
conn
.
send
(
"
\
n
.
\
n
"
)
# messageText = mtemplate(self, kw)
self
.
_check
(
'354'
)
# headers, message = decapitate(messageText)
# for requiredHeader in ('to', 'from', 'subject'):
def
_close
(
self
):
# if not headers.has_key(requiredHeader):
self
.
conn
.
send
(
"quit
\
n
"
)
# raise MailHostError, "Message missing SMTP Header '%s'" \
self
.
conn
.
close
()
# % requiredHeader
#
def
newDecapitate
(
message
):
# SendMail(trueself.smtpHost, trueself.smtpPort,
blank_re
=
regex
.
compile
(
'^[%s]+$'
%
string
.
whitespace
)
# trueself.localHost).send(
header_re
=
regex
.
symcomp
(
'^
\
(<he
a
derName>[^
\
0
- <>:]+
\
):
\
(<headerText>.*
\
)$
'
)
# mfrom=headers['from'], mto=headers['to'],
# subj=headers['subject'], body=messageText
linecount=0; headerDict={}
# )
maxwell=map(lambda x: string.strip(x),string.split(message,'
\
n
'))
#
# return getattr(trueself,trueself.sentMailTemplate)(self, kw,
for line in maxwell:
# messageText=message)
if not line: break
if blank_re.match(line) >= 0: break
class
SendMail
:
if header_re.match(line) >=0:
def
__init__
(
self
,
smtpHost
,
smtpPort
,
localHost
=
"localhost"
):
headerDict[string.lower(header_re.group('
headerName
'))] =
\
self
.
conn
=
socket
(
AF_INET
,
SOCK_STREAM
)
string.strip(header_re.group('
headerText
'))
self
.
conn
.
connect
(
smtpHost
,
smtpPort
)
linecount=linecount+1
self
.
conn
.
send
(
"helo "
+
localHost
+
"
\
r
\
n
"
)
self
.
_check
(
'220'
)
body=string.join(maxwell[linecount:],'
\
n
')
return headerDict, body
def
__del__
(
self
):
self
.
close
()
def
_check
(
self
,
lev
=
'250'
):
data
=
self
.
conn
.
recv
(
1024
)
if
data
[:
3
]
!=
lev
:
raise
smtpError
,
"Expected %s, got %s from SMTP"
%
(
lev
,
data
[:
3
])
def
send
(
self
,
mfrom
,
mto
,
subj
,
body
):
self
.
conn
.
send
(
"mail from:<%s>
\
n
"
%
mfrom
)
self
.
_check
()
if
type
(
mto
)
==
type
([
1
,
2
]):
for
person
in
mto
:
self
.
conn
.
send
(
"rcpt to:<%s>
\
n
"
%
person
)
self
.
_check
()
else
:
self
.
conn
.
send
(
"rcpt to:<%s>
\
n
"
%
mto
)
self
.
_check
()
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
]
+
\
)
'),
#r'
(([
^
\
0
-
<>
:]
+
:[
^
\
n
]
*
\
n
|
[
\
t
]
+
[
^
\
0
-
][
^
\
n
]
*
\
n
)
+
)[
\
t
]
*
\
n
([
\
0
-
\
377
]
+
)
'
name_re=regex.compile('
\
([
^
\
0
-
<>
:]
+
\
):
\
([
^
\
n
]
*
\
)
'),
space_re=regex.compile('
\
([
\
t
]
+
\
)
'),
):
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
')
headerDict={}
headers=string.split(headers,'
\
n
')
headerDict={}
i=1
while i < len(headers):
i=1
if not headers[i]:
while i < len(headers):
del headers[i]
if not headers[i]:
elif space_re.match(headers[i]) >= 0:
del headers[i]
headers[i-1]="%s %s" % (headers[i-1],
elif space_re.match(headers[i]) >= 0:
headers[i][len(space_re.group(1)):])
headers[i-1]="%s %s" % (headers[i-1],
del headers[i]
headers[i][len(space_re.group(1)):])
else:
del headers[i]
i=i+1
else:
i=i+1
for i in range(len(headers)):
if name_re.match(headers[i]) >= 0:
for i in range(len(headers)):
k, v = name_re.group(1,2)
if name_re.match(headers[i]) >= 0:
k=string.lower(k); v=string.strip(v)
k, v = name_re.group(1,2)
headerDict[k]=v
k=string.lower(k); v=string.strip(v)
else:
headerDict[k]=v
raise ValueError, '
Invalid
Header
(
%
d
):
%
s
' % (i,headers[i])
else:
raise ValueError, '
Invalid
Header
(
%
d
):
%
s
' % (i,headers[i])
if headerDict.has_key('
to
'):
headerDict['
to
']=map(
if headerDict.has_key('
to
'):
lambda x: string.strip(x),
headerDict['
to
']=map(
string.split(headerDict['
to
'], '
,
')
lambda x: string.strip(x),
)
string.split(headerDict['
to
'], '
,
')
)
return headerDict, body
return (headerDict, body)
#$Log: MailHost.py,v $
#$Log: MailHost.py,v $
#Revision 1.
2 1997/09/09 21:33:41
jeffrey
#Revision 1.
3 1997/09/10 15:05:35
jeffrey
#
New send features _somewhat_ working. simple_send works (litely),
#
added new decapitate method to handle some strange errors in some messages
#
sentTemplate works, but does not (yet) completely overthrow the to: from:
#
#
headers...
#
got new interface up to specs:
#
#
#Revision 1.1 1997/09/09 20:50:29
jeffrey
#Revision 1.1 1997/09/09 20:50:29
jeffrey
#Managed changing of names.
#Managed changing of names.
#
#
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment