Commit c47a68e8 authored by Jens Vagelpohl's avatar Jens Vagelpohl

Refactor MailHost construction and initialization

parent e48dee99
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
############################################################################## ##############################################################################
"""SMTP mail objects """SMTP mail objects
$Id: MailHost.py,v 1.65 2002/01/15 04:05:12 jens Exp $""" $Id: MailHost.py,v 1.66 2002/01/15 04:23:08 jens Exp $"""
__version__ = "$Revision: 1.65 $"[11:-2] __version__ = "$Revision: 1.66 $"[11:-2]
from Globals import Persistent, DTMLFile, MessageDialog, InitializeClass from Globals import Persistent, DTMLFile, MessageDialog, InitializeClass
from smtplib import SMTP from smtplib import SMTP
...@@ -30,25 +30,13 @@ smtpError = "SMTP Error" ...@@ -30,25 +30,13 @@ smtpError = "SMTP Error"
MailHostError = "MailHost Error" MailHostError = "MailHost Error"
manage_addMailHostForm=DTMLFile('dtml/addMailHost_form', globals()) manage_addMailHostForm=DTMLFile('dtml/addMailHost_form', globals())
def manage_addMailHost(self, id, title='', smtp_host=None, def manage_addMailHost( self, id, title='', smtp_host='localhost'
localhost='localhost', smtp_port=25, , localhost='localhost', smtp_port=25
timeout=1.0, REQUEST=None): , timeout=1.0, REQUEST=None ):
' add a MailHost into the system ' ' add a MailHost into the system '
i = MailHost( id, title, smtp_host, smtp_port ) #create new mail host
self._setObject( id,i ) #register it
id=str(id)
title=str(title)
if smtp_host is not None:
smtp_host=str(smtp_host)
if type(smtp_port) is not type(1):
smtp_port=string.atoi(smtp_port)
i=MailHost() #create new mail host
i.id=id #give it id
i.title=title #title
i._init(smtp_host=smtp_host, smtp_port=smtp_port)
self=self.this()
self._setObject(id,i) #register it
if REQUEST is not None: if REQUEST is not None:
REQUEST['RESPONSE'].redirect(self.absolute_url()+'/manage_main') REQUEST['RESPONSE'].redirect(self.absolute_url()+'/manage_main')
...@@ -75,10 +63,14 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager): ...@@ -75,10 +63,14 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
) )
def __init__(self): def __init__( self, id='', title='', smtp_host='localhost', smtp_port=25 ):
'nothing yet' """Initialize a new MailHost instance """
pass self.id = id
self.title = title
self.smtp_host = str( smtp_host )
self.smtp_port = str( smtp_port )
# staying for now... (backwards compatibility)
def _init(self, smtp_host, smtp_port): def _init(self, smtp_host, smtp_port):
self.smtp_host=smtp_host self.smtp_host=smtp_host
self.smtp_port=smtp_port self.smtp_port=smtp_port
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
# FOR A PARTICULAR PURPOSE # FOR A PARTICULAR PURPOSE
# #
############################################################################## ##############################################################################
__rcs_id__='$Id: SendMailTag.py,v 1.13 2001/11/28 15:50:59 matt Exp $' __rcs_id__='$Id: SendMailTag.py,v 1.14 2002/01/15 04:23:08 jens Exp $'
__version__='$Revision: 1.13 $'[11:-2] __version__='$Revision: 1.14 $'[11:-2]
from MailHost import MailBase from MailHost import MailBase
from DocumentTemplate.DT_Util import parse_params,render_blocks from DocumentTemplate.DT_Util import parse_params,render_blocks
...@@ -109,8 +109,7 @@ class SendMailTag: ...@@ -109,8 +109,7 @@ class SendMailTag:
if self.mailhost: if self.mailhost:
mhost=md[self.mailhost] mhost=md[self.mailhost]
elif self.smtphost: elif self.smtphost:
mhost=MailBase() mhost=MailBase( self.smtphost, self.port )
mhost._init(self.smtphost, self.port)
mhost.send(render_blocks(self.section.blocks, md), mhost.send(render_blocks(self.section.blocks, md),
self.mailto, self.mailfrom, self.mailto, self.mailfrom,
......
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