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
49514924
Commit
49514924
authored
Sep 09, 1997
by
Jeffrey Shell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Seperated SMTP calls into seperate class, added (hopefully) working
good python-callable interface.
parent
ad86a253
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
156 additions
and
125 deletions
+156
-125
lib/python/Products/MailHost/MailForm.py
lib/python/Products/MailHost/MailForm.py
+156
-125
No files found.
lib/python/Products/MailHost/MailForm.py
View file @
49514924
...
@@ -6,133 +6,164 @@ smtpError = "SMTP Error"
...
@@ -6,133 +6,164 @@ 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/manageMailForm'
)
def
__init__
(
self
):
def
__init__
(
self
):
'nothing yet'
'nothing yet'
pass
pass
def
_init
(
self
,
localHost
,
smtpHost
,
smtpPort
,
mailTemplate
,
errorTemplate
,
def
_init
(
self
,
localHost
,
smtpHost
,
smtpPort
,
mailTemplate
,
errorTemplate
,
sentMailTemplate
):
sentMailTemplate
):
self
.
localHost
=
localHost
self
.
localHost
=
localHost
self
.
smtpHost
=
smtpHost
self
.
smtpHost
=
smtpHost
self
.
smtpPort
=
smtpPort
self
.
smtpPort
=
smtpPort
self
.
mailTemplate
=
mailTemplate
self
.
mailTemplate
=
mailTemplate
self
.
errorTemplate
=
errorTemplate
self
.
errorTemplate
=
errorTemplate
self
.
sentMailTemplate
=
sentMailTemplate
self
.
sentMailTemplate
=
sentMailTemplate
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
(
'Changes made'
,
'Changes made...'
)
return
(
'Changes made'
,
'Changes made...'
)
def
send
(
trueself
,
self
):
def
send
(
trueself
,
self
):
'uhh, sponges off the request and mails it..?'
'uhh, sponges off the request and mails it..?'
if
trueself
.
REQUEST
.
has_key
(
'd_template'
):
messageText
=
getattr
(
self
,
self
.
mailTemplate
)(
self
,
trueself
.
REQUEST
)
mtemplate
=
getattr
(
self
,
trueself
.
REQUEST
[
'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
,
trueself
.
REQUEST
)
raise
MailFormError
,
"Message missing SMTP Header '%s'"
\
headers
,
message
=
decapitate
(
messageText
)
%
requiredHeader
for
requiredHeader
in
(
'to'
,
'from'
,
'subject'
):
trueself
.
_mailConnect
()
if
not
headers
.
has_key
(
requiredHeader
):
trueself
.
_send
(
mfrom
=
headers
[
'from'
],
mto
=
headers
[
'to'
],
raise
MailFormError
,
"Message missing SMTP Header '%s'"
\
subj
=
headers
[
'subject'
],
body
=
messageText
)
%
requiredHeader
trueself
.
_close
()
return
getattr
(
self
,
self
.
sentMailTemplate
)(
self
,
self
.
REQUEST
,
SendMail
(
self
.
smtpHost
,
self
.
smtpPort
,
self
.
localHost
).
send
(
messageText
=
message
)
mfrom
=
headers
[
'from'
],
mto
=
headers
[
'to'
],
subj
=
headers
[
'subject'
],
body
=
messageText
)
def
_mailConnect
(
self
):
self
.
_v_conn
=
socket
(
AF_INET
,
SOCK_STREAM
)
return
getattr
(
self
,
self
.
sentMailTemplate
)(
self
,
self
.
REQUEST
,
self
.
_v_conn
.
connect
(
self
.
smtpHost
,
self
.
smtpPort
)
messageText
=
message
)
self
.
_v_conn
.
send
(
"helo "
+
self
.
localHost
+
"
\
r
\
n
"
)
self
.
_check
(
'220'
)
def
trueSend
(
trueself
,
self
=
None
,
REQUEST
=
None
,
**
kw
):
if
REQUEST
:
kw
=
REQUEST
def
_check
(
self
,
lev
=
'250'
):
if
not
self
:
self
=
trueself
data
=
self
.
_v_conn
.
recv
(
1024
)
if
kw
.
has_key
(
'd_template'
):
if
data
[:
3
]
!=
lev
:
mtemplate
=
getattr
(
self
,
kw
[
'd_template'
])
raise
smtpError
,
"Expected %s, got %s from SMTP"
%
(
lev
,
data
[:
3
])
else
:
mtemplate
=
getattr
(
self
,
trueself
.
mailTemplate
)
def
_send
(
self
,
mfrom
,
mto
,
subj
,
body
):
messageText
=
mtemplate
(
self
,
kw
)
self
.
_v_conn
.
send
(
"mail from:<%s>
\
n
"
%
mfrom
)
headers
,
message
=
decapitate
(
messageText
)
self
.
_check
()
for
requiredHeader
in
(
'to'
,
'from'
,
'subject'
):
if
type
(
mto
)
==
type
([
1
,
2
]):
if
not
headers
.
has_key
(
requiredHeader
):
for
person
in
mto
:
raise
MailFormError
,
"Message missing SMTP Header '%s'"
\
self
.
_v_conn
.
send
(
"rcpt to:<%s>
\
n
"
%
person
)
%
requiredHeader
self
.
_check
()
else
:
SendMail
(
trueself
.
smtpHost
,
trueself
.
smtpPort
,
self
.
_v_conn
.
send
(
"rcpt to:<%s>
\
n
"
%
mto
)
trueself
.
localHost
).
send
(
self
.
_check
()
mfrom
=
headers
[
'from'
],
mto
=
headers
[
'to'
],
self
.
_v_conn
.
send
(
"data
\
n
"
)
subj
=
headers
[
'subject'
],
body
=
messageText
self
.
_check
()
)
self
.
_v_conn
.
send
(
body
)
self
.
_v_conn
.
send
(
"
\
n
.
\
n
"
)
return
getattr
(
trueself
,
trueself
.
sentMailTemplate
)(
self
,
kw
,
self
.
_check
(
'354'
)
messageText
=
message
)
def
_close
(
self
):
class
SendMail
:
self
.
_v_conn
.
send
(
"quit
\
n
"
)
def
__init__
(
self
,
smtpHost
,
smtpPort
,
localHost
=
"localhost"
):
self
.
_v_conn
.
close
()
self
.
conn
=
socket
(
AF_INET
,
SOCK_STREAM
)
self
.
conn
.
connect
(
smtpHost
,
smtpPort
)
self
.
conn
.
send
(
"helo "
+
localHost
+
"
\
r
\
n
"
)
self
.
_check
(
'220'
)
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
]
+
\
)
'),
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
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