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
1fb42a5f
Commit
1fb42a5f
authored
Feb 18, 1999
by
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added RFC821 compliance patch submitted by Martijn Pieters.
parent
7bd5f595
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
18 deletions
+64
-18
lib/python/Products/MailHost/MailHost.py
lib/python/Products/MailHost/MailHost.py
+64
-18
No files found.
lib/python/Products/MailHost/MailHost.py
View file @
1fb42a5f
...
...
@@ -95,8 +95,8 @@ from Scheduler.OneTimeEvent import OneTimeEvent
from
ImageFile
import
ImageFile
from
cStringIO
import
StringIO
#$Id: MailHost.py,v 1.3
7 1999/02/16 19:13:15
brian Exp $
__version__
=
"$Revision: 1.3
7
$"
[
11
:
-
2
]
#$Id: MailHost.py,v 1.3
8 1999/02/18 13:46:01
brian Exp $
__version__
=
"$Revision: 1.3
8
$"
[
11
:
-
2
]
smtpError
=
"SMTP Error"
MailHostError
=
"MailHost Error"
...
...
@@ -257,7 +257,7 @@ def Send(host, port, localhost, timeout, from_, to, subject, body):
SendMail
(
host
,
port
,
localhost
,
timeout
).
send
(
from_
,
to
,
subject
,
body
)
class
SendMail
:
singledots
=
re
.
compile
(
'^
\
.$
'
)
singledots
=
re
.
compile
(
'^
\
.$
'
, re.M
)
def __init__(self, smtpHost, smtpPort, localHost="localhost", timeout=1):
self.conn = socket(AF_INET, SOCK_STREAM)
...
...
@@ -291,8 +291,7 @@ class SendMail:
except:
raise smtpError,
\
"Cannot convert line from SMTP: %s" % line
if code > 400: # my change...
if code > 400:
raise smtpError,
\
"Recieved error code %s from SMTP: %s"
\
% (code, line)
...
...
@@ -310,20 +309,27 @@ class SendMail:
self._check()
self.conn.send("data
\
015
\
012
")
self._check()
replace=string.replace
bfile = StringIO(body)
mo=rfc822.Message(bfile)
for k, v in mo.items():
self.conn.send('
%
s
:
%
s
\
015
\
012
' % (string.capitalize(k), v))
# Add some Mime headers if not present
if not mo.has_key('
Mime
-
Version
'):
self.conn.send('
Mime
-
Version
:
1.0
\
015
\
012
')
if not mo.has_key('
Content
-
Type
'):
self.conn.send(
'
Content
-
Type
:
text
/
plain
;
charset
=
"iso-8859-1"
\
015
\
012
')
if not mo.has_key('
Content
-
Transfer
-
Encoding
'):
self.conn.send(
'
Content
-
Transfer
-
Encoding
:
quoted
-
printable
\
015
\
012
')
self.conn.send('
\
015
\
012
')
body=bfile.read()
body=self.singledots.sub('
..
', body)
body=replace(body, '
\
r
\
n
', '
\
n
')
body=replace(body, '
\
r', '
\
n
')
# This snippet encodes the body as quoted-printable; there
# seem to be some issues with this, so I'
m
leaving
it
out
# for now.
# inbody=StringIO(body)
# outbody=StringIO()
# quopri.encode(inbody, outbody, 0)
# body=outbody.getvalue()
body
=
replace
(
body
,
'
\
n
'
,
'
\
015
\
012
'
)
body=string.replace(body, '
\
r
\
n
', '
\
n
')
body=string.replace(body, '
\
r', '
\
n
')
body=encode(body, 0)
body=string.replace(body, '
\
n
', '
\
015
\
012
')
self.conn.send(body)
self.conn.send("
\
015
\
012
.
\
015
\
012
")
self._check('
354
')
...
...
@@ -333,6 +339,46 @@ class SendMail:
self.conn.close()
ESCAPE = '
=
'
MAXLINESIZE = 76
HEX = '
0123456789
ABCDEF
'
def needsquoting(c, quotetabs):
if c == '
\
t
':
return not quotetabs
return c == ESCAPE or not('
' <= c <= '
~
')
def quote(c):
if c == ESCAPE:
return ESCAPE * 2
else:
i = ord(c)
return ESCAPE + HEX[i/16] + HEX[i%16]
def encode(input, quotetabs):
"""Encode a string to Quoted-Printable"""
output = ''
for line in string.split(input, '
\
n
'):
new = ''
prev = ''
for c in line:
if needsquoting(c, quotetabs):
c = quote(c)
if len(new) + len(c) >= MAXLINESIZE:
output = output + new + ESCAPE + '
\
n
'
new = ''
new = new + c
prev = c
if prev in ('
', '
\
t
'):
output = output + new + ESCAPE + '
\
n
\
n
'
else:
output = output + new + '
\
n
'
return output
def decapitate(message):
# split message into headers / body
mfile=StringIO(message)
...
...
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