Commit 035d39fa authored by 's avatar

Added Martijn Pieters patches to 1.11.0

parent b339fd13
......@@ -88,15 +88,15 @@ from Globals import Persistent, HTMLFile, HTML, MessageDialog
from socket import *; from select import select
from AccessControl.Role import RoleManager
from operator import truth
import Acquisition, sys, ts_regex, string, types, rfc822
import OFS.SimpleItem, re, quopri
import Acquisition, sys, ts_regex, string, types, mimetools
import OFS.SimpleItem, re, quopri, rfc822
import Globals
from Scheduler.OneTimeEvent import OneTimeEvent
from ImageFile import ImageFile
from cStringIO import StringIO
#$Id: MailHost.py,v 1.39 1999/03/10 00:15:24 klm Exp $
__version__ = "$Revision: 1.39 $"[11:-2]
#$Id: MailHost.py,v 1.40 1999/03/22 20:39:53 brian Exp $
__version__ = "$Revision: 1.40 $"[11:-2]
smtpError = "SMTP Error"
MailHostError = "MailHost Error"
......@@ -162,11 +162,12 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
target ='manage_main')
def sendTemplate(trueself, self, messageTemplate,
statusTemplate=None, mto=None, mfrom=None, REQUEST=None):
statusTemplate=None, mto=None, mfrom=None,
encode=None, REQUEST=None):
'render a mail template, then send it...'
mtemplate = getattr(self, messageTemplate)
messageText = mtemplate(self, trueself.REQUEST)
messageText=_encode(messageText, encode)
headers, message = decapitate(messageText)
if mto: headers['to'] = mto
if mfrom: headers['from'] = mfrom
......@@ -174,7 +175,6 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
if not headers.has_key(requiredHeader):
raise MailHostError,"Message missing SMTP Header '%s'"\
% requiredHeader
Globals.Scheduler.schedule(OneTimeEvent(
Send,
(trueself.smtpHost, trueself.smtpPort,
......@@ -193,7 +193,8 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
except:
return "SEND OK"
def send(self, messageText, mto=None, mfrom=None, subject=None):
def send(self, messageText, mto=None, mfrom=None, subject=None,
encode=None):
headers, message = decapitate(messageText)
if not headers['subject']:
......@@ -210,13 +211,14 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
if not headers.has_key(requiredHeader):
raise MailHostError,"Message missing SMTP Header '%s'"\
% requiredHeader
messageText=_encode(messageText, encode)
sm=SendMail(self.smtpHost, self.smtpPort, self.localHost, self.timeout)
sm.send(mfrom=headers['from'], mto=headers['to'],
subj=headers['subject'] or 'No Subject',
body=messageText)
def scheduledSend(self, messageText, mto=None, mfrom=None, subject=None):
def scheduledSend(self, messageText, mto=None, mfrom=None, subject=None,
encode=None):
headers, message = decapitate(messageText)
if not headers['subject']:
......@@ -233,7 +235,7 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
if not headers.has_key(requiredHeader):
raise MailHostError,"Message missing SMTP Header '%s'"\
% requiredHeader
messageText=_encode(messageText, encode)
Globals.Scheduler.schedule(OneTimeEvent(
Send,
(self.smtpHost, self.smtpPort, self.localHost, self.timeout,
......@@ -309,26 +311,9 @@ class SendMail:
self._check()
self.conn.send("data\015\012")
self._check()
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=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")
......@@ -340,43 +325,21 @@ class SendMail:
ESCAPE = '='
MAXLINESIZE = 76
HEX = '0123456789ABCDEF'
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 _encode(body, encode=None):
if encode is None:
return body
mfile=StringIO(body)
mo=mimetools.Message(mfile)
if mo.getencoding() != '7bit':
raise MailHostError, 'Message already encoded'
newmfile=StringIO()
newmfile.write(string.joinfields(mo.headers, ''))
newmfile.write('Content-Transfer-Encoding: %s\n' % encode)
if not mo.has_key('Mime-Version'):
newmfile.write('Mime-Version: 1.0\n')
newmfile.write('\n')
mimetools.encode(mfile, newmfile, encode)
return newmfile.getvalue()
def decapitate(message):
......
......@@ -4,3 +4,5 @@ MailHost
The MailHost product provides support for sending email from
within the Zope environment using MailHost objects.
Email can optionally be encoded using Base64, Quoted-Printable
or UUEncode encoding.
......@@ -82,8 +82,8 @@
# attributions are listed in the accompanying credits file.
#
##############################################################################
__rcs_id__='$Id: SendMailTag.py,v 1.5 1999/03/10 00:15:24 klm Exp $'
__version__='$Revision: 1.5 $'[11:-2]
__rcs_id__='$Id: SendMailTag.py,v 1.6 1999/03/22 20:39:53 brian Exp $'
__version__='$Revision: 1.6 $'[11:-2]
from MailHost import MailBase
from DocumentTemplate.DT_Util import *
......@@ -121,15 +121,21 @@ class SendMailTag:
* subject -- optional subject. If not specified, there **must** be a
subject: header in the message.
* encode -- optional encoding. Possible values are: 'base64',
'quoted-printable' and 'uuencode'.
'''
name='sendmail'
blockContinuations=()
encode=None
def __init__(self, blocks):
tname, args, section=blocks[0]
args=parse_params(args, mailhost=None, mailto=None, mailfrom=None,
subject=None, smtphost=None, port='25')
subject=None, smtphost=None, port='25',
encode=None)
for key in ('mailto', 'mailfrom', 'subject', 'smtphost', 'port'):
if not args.has_key(key):args[key]=''
......@@ -141,6 +147,12 @@ class SendMailTag:
elif has_key(''): mailhost=args['mailhost']=args['']
else: raise MailHostError, 'No mailhost was specified in tag'
if has_key('encode') and args['encode'] not in \
('base64', 'quoted-printable', 'uuencode', 'x-uuencode',
'uue', 'x-uue'):
raise MailHostError, (
'An unsupported encoding was specified in tag')
if not smtphost:
self.__name__=self.mailhost=mailhost
self.smtphost=None
......@@ -158,7 +170,10 @@ class SendMailTag:
self.port=args['port']=25
else:
self.port=args['port']
if has_key('encode'):
self.encode=args['encode']
else: self.encode=None
def render(self, md):
args=self.args
has_key=args.has_key
......@@ -171,7 +186,7 @@ class SendMailTag:
smtpPort=self.port)
mhost.send(self.section(md.this, md), self.mailto, self.mailfrom,
self.subject)
self.subject, self.encode)
return ' '
......
......@@ -83,8 +83,8 @@
#
##############################################################################
__doc__='''MailHost Product Initialization
$Id: __init__.py,v 1.10 1999/03/10 00:15:24 klm Exp $'''
__version__='$Revision: 1.10 $'[11:-2]
$Id: __init__.py,v 1.11 1999/03/22 20:39:53 brian Exp $'''
__version__='$Revision: 1.11 $'[11:-2]
import MailHost, SendMailTag
from ImageFile import ImageFile
......@@ -103,3 +103,9 @@ methods={
misc_={
'MHIcon': ImageFile("www/MailHost_icon.gif", globals())
}
__ac_permissions__=(
('Add MailHost objects', ('manage_addMailHost_form', 'manage_addMailHost')),
('Change configuration', ()),
('Use mailhost services',()),
)
MailHost 1.0.1 Release Notes
Features Added
- MailHost objects now have an adjustable 'timeout' parameter that
sets how long to wait to connect to the SMTP server before
timing out.
MailHost 1.0.1 Release Notes
Features Added
......
MailHost 1.1.0 Release Notes
Features Added
- Sendmail tag now has optional encode attribute, which results
in the body of the email message being encoded using the
designated encoding, and the proper headers being added.
Choices are: base64, quoted-printable and uuencode.
Bugs Fixed
- MailHost object permissions now show op in the security list of
Folder objects.
MailHost 1.0.1 Release Notes
Features Added
- MailHost objects now have an adjustable 'timeout' parameter that
sets how long to wait to connect to the SMTP server before
timing out.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment