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
Show 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,8 +2,8 @@ from Globals import Persistent, HTMLFile, HTML
from
socket
import
*
import
Acquisition
,
sys
,
regex
,
string
#$Id: MailHost.py,v 1.
2 1997/09/09 21:33:41
jeffrey Exp $
__version__
=
"$Revision: 1.
2
$"
[
11
:
-
2
]
#$Id: MailHost.py,v 1.
3 1997/09/10 15:05:35
jeffrey Exp $
__version__
=
"$Revision: 1.
3
$"
[
11
:
-
2
]
smtpError
=
"SMTP Error"
MailHostError
=
"MailHost Error"
...
...
@@ -52,7 +52,7 @@ class MailHost(Persistent, Acquisition.Implicit):
mtemplate
=
getattr
(
self
,
messageTemplate
)
messageText
=
mtemplate
(
self
,
trueself
.
REQUEST
)
headers
,
message
=
d
ecapitate
(
messageText
)
headers
,
message
=
newD
ecapitate
(
messageText
)
if
mto
:
headers
[
'to'
]
=
mto
if
mfrom
:
headers
[
'from'
]
=
mfrom
for
requiredHeader
in
(
'to'
,
'from'
,
'subject'
):
...
...
@@ -73,7 +73,7 @@ class MailHost(Persistent, Acquisition.Implicit):
def
send
(
self
,
messageText
,
mto
=
None
,
mfrom
=
None
):
'send a rendered message'
headers
,
message
=
d
ecapitate
(
messageText
)
headers
,
message
=
newD
ecapitate
(
messageText
)
if
mto
:
headers
[
'to'
]
=
mto
if
mfrom
:
headers
[
'from'
]
=
mfrom
for
requiredHeader
in
(
'to'
,
'from'
,
'subject'
):
...
...
@@ -98,51 +98,6 @@ class MailHost(Persistent, Acquisition.Implicit):
self
.
__log
()
return
(
"sent"
,
"sent..."
)
# def send(trueself, self):
# 'uhh, sponges off the request and mails it..?'
# if trueself.REQUEST.has_key('d_template'):
# mtemplate = getattr(self, trueself.REQUEST['d_template'])
# else:
# mtemplate = getattr(self, trueself.mailTemplate)
# messageText = mtemplate(self, trueself.REQUEST)
# headers, message = decapitate(messageText)
# for requiredHeader in ('to', 'from', 'subject'):
# if not headers.has_key(requiredHeader):
# raise MailHostError, "Message missing SMTP Header '%s'" \
# % requiredHeader
#
# SendMail(trueself.smtpHost, trueself.smtpPort,
# trueself.localHost).send(
# mfrom=headers['from'], mto=headers['to'],
# subj=headers['subject'], body=messageText
# )
#
# return getattr(self,self.sentMailTemplate)(self, self.REQUEST,
# messageText=message)
#
# def trueSend(trueself, self=None, REQUEST=None, **kw):
# if REQUEST: kw=REQUEST
# if self == None: self=trueself
# if kw.has_key('d_template'):
# mtemplate = getattr(self, kw['d_template'])
# else:
# mtemplate = getattr(self, trueself.mailTemplate)
# messageText = mtemplate(self, kw)
# headers, message = decapitate(messageText)
# for requiredHeader in ('to', 'from', 'subject'):
# if not headers.has_key(requiredHeader):
# raise MailHostError, "Message missing SMTP Header '%s'" \
# % requiredHeader
#
# SendMail(trueself.smtpHost, trueself.smtpPort,
# trueself.localHost).send(
# mfrom=headers['from'], mto=headers['to'],
# subj=headers['subject'], body=messageText
# )
#
# return getattr(trueself,trueself.sentMailTemplate)(self, kw,
# messageText=message)
class
SendMail
:
def
__init__
(
self
,
smtpHost
,
smtpPort
,
localHost
=
"localhost"
):
self
.
conn
=
socket
(
AF_INET
,
SOCK_STREAM
)
...
...
@@ -178,6 +133,24 @@ class SendMail:
self
.
conn
.
send
(
"quit
\
n
"
)
self
.
conn
.
close
()
def
newDecapitate
(
message
):
blank_re
=
regex
.
compile
(
'^[%s]+$'
%
string
.
whitespace
)
header_re
=
regex
.
symcomp
(
'^
\
(<he
a
derName>[^
\
0
- <>:]+
\
):
\
(<headerText>.*
\
)$
'
)
linecount=0; headerDict={}
maxwell=map(lambda x: string.strip(x),string.split(message,'
\
n
'))
for line in maxwell:
if not line: break
if blank_re.match(line) >= 0: break
if header_re.match(line) >=0:
headerDict[string.lower(header_re.group('
headerName
'))] =
\
string.strip(header_re.group('
headerText
'))
linecount=linecount+1
body=string.join(maxwell[linecount:],'
\
n
')
return headerDict, body
def decapitate(message,
header_re=regex.compile(
'
\
(
\
(
'
...
...
@@ -186,6 +159,7 @@ def decapitate(message,
'
[
\
t
]
+
[
^
\
0
-
][
^
\
n
]
*
\
n
'
'
\
)
+
\
)[
\
t
]
*
\
n
\
([
\
0
-
\
377
]
+
\
)
'
),
#r'
(([
^
\
0
-
<>
:]
+
:[
^
\
n
]
*
\
n
|
[
\
t
]
+
[
^
\
0
-
][
^
\
n
]
*
\
n
)
+
)[
\
t
]
*
\
n
([
\
0
-
\
377
]
+
)
'
space_re=regex.compile('
\
([
\
t
]
+
\
)
'),
name_re=regex.compile('
\
([
^
\
0
-
<>
:]
+
\
):
\
([
^
\
n
]
*
\
)
'),
):
...
...
@@ -221,13 +195,13 @@ def decapitate(message,
string.split(headerDict['
to
'], '
,
')
)
return headerDict, body
return (headerDict, body)
#$Log: MailHost.py,v $
#Revision 1.
2 1997/09/09 21:33:41
jeffrey
#
New send features _somewhat_ working. simple_send works (litely),
#
sentTemplate works, but does not (yet) completely overthrow the to: from:
#
headers...
#Revision 1.
3 1997/09/10 15:05:35
jeffrey
#
added new decapitate method to handle some strange errors in some messages
#
#
got new interface up to specs:
#
#Revision 1.1 1997/09/09 20:50:29 jeffrey
#Managed changing of names.
...
...
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