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
Show 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
...
...
@@ -22,8 +22,7 @@ def add(self, id='mailForm', title='Some mail thing', smtp_host=None,
class
MailForm
(
Persistent
,
Acquisition
.
Implicit
):
'a mailform...?'
manage
=
HTMLFile
(
'MailForm/manageMailForm'
)
index_html
=
HTMLFile
(
'MailForm/manageMailForm'
)
index_html
=
HTMLFile
(
'MailForm/mailForm'
)
def
__init__
(
self
):
'nothing yet'
...
...
@@ -48,49 +47,81 @@ class MailForm(Persistent, Acquisition.Implicit):
def
send
(
trueself
,
self
):
'uhh, sponges off the request and mails it..?'
messageText
=
getattr
(
self
,
self
.
mailTemplate
)(
self
,
trueself
.
REQUEST
)
headers
,
message
=
decapitate
(
messageText
)
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
MailFormError
,
"Message missing SMTP Header '%s'"
\
%
requiredHeader
trueself
.
_mailConnect
()
trueself
.
_send
(
mfrom
=
headers
[
'from'
],
mto
=
headers
[
'to'
],
SendMail
(
self
.
smtpHost
,
self
.
smtpPort
,
self
.
localHost
).
send
(
mfrom
=
headers
[
'from'
],
mto
=
headers
[
'to'
],
subj
=
headers
[
'subject'
],
body
=
messageText
)
trueself
.
_close
()
return
getattr
(
self
,
self
.
sentMailTemplate
)(
self
,
self
.
REQUEST
,
messageText
=
message
)
def
_mailConnect
(
self
):
self
.
_v_conn
=
socket
(
AF_INET
,
SOCK_STREAM
)
self
.
_v_conn
.
connect
(
self
.
smtpHost
,
self
.
smtpPort
)
self
.
_v_conn
.
send
(
"helo "
+
self
.
localHost
+
"
\
r
\
n
"
)
def
trueSend
(
trueself
,
self
=
None
,
REQUEST
=
None
,
**
kw
):
if
REQUEST
:
kw
=
REQUEST
if
not
self
:
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
MailFormError
,
"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
)
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
.
_v_
conn
.
recv
(
1024
)
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
.
_v_
conn
.
send
(
"mail from:<%s>
\
n
"
%
mfrom
)
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
.
_v_
conn
.
send
(
"rcpt to:<%s>
\
n
"
%
person
)
self
.
conn
.
send
(
"rcpt to:<%s>
\
n
"
%
person
)
self
.
_check
()
else
:
self
.
_v_
conn
.
send
(
"rcpt to:<%s>
\
n
"
%
mto
)
self
.
conn
.
send
(
"rcpt to:<%s>
\
n
"
%
mto
)
self
.
_check
()
self
.
_v_
conn
.
send
(
"data
\
n
"
)
self
.
conn
.
send
(
"data
\
n
"
)
self
.
_check
()
self
.
_v_
conn
.
send
(
body
)
self
.
_v_
conn
.
send
(
"
\
n
.
\
n
"
)
self
.
conn
.
send
(
body
)
self
.
conn
.
send
(
"
\
n
.
\
n
"
)
self
.
_check
(
'354'
)
def
_close
(
self
):
self
.
_v_
conn
.
send
(
"quit
\
n
"
)
self
.
_v_
conn
.
close
()
self
.
conn
.
send
(
"quit
\
n
"
)
self
.
conn
.
close
()
def
decapitate
(
message
,
header_re
=
regex
.
compile
(
...
...
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