[Zope3-checkins] CVS: Zope3/src/zope/app/mail - configure.zcml:1.1.14.2 meta.zcml:1.1.14.3 metaconfigure.py:1.2.2.3 service.py:1.2.2.4
Albertas Agejevas
alga@codeworks.lt
Sun, 22 Jun 2003 13:47:57 -0400
Update of /cvs-repository/Zope3/src/zope/app/mail
In directory cvs.zope.org:/tmp/cvs-serv25126/src/zope/app/mail
Modified Files:
Tag: cw-mail-branch
configure.zcml meta.zcml metaconfigure.py service.py
Log Message:
EP2003 sprint: finished the mail service.
Added logging to the Zope log.
=== Zope3/src/zope/app/mail/configure.zcml 1.1.14.1 => 1.1.14.2 ===
--- Zope3/src/zope/app/mail/configure.zcml:1.1.14.1 Thu May 22 04:51:40 2003
+++ Zope3/src/zope/app/mail/configure.zcml Sun Jun 22 13:47:26 2003
@@ -1,8 +1,26 @@
<zopeConfigure
xmlns="http://namespaces.zope.org/zope"
+ xmlns:mail="http://namespaces.zope.org/mail"
>
-<serviceType id="Mail"
- interface="zope.app.interfaces.mail.IMailService" />
+ <serviceType id="Mail"
+ interface="zope.app.interfaces.mail.IMailService" />
+ <permission id="zope.SendMail"
+ title="Send out mail with arbitrary from and to addresses" />
+
+ <mail:sendmailMailer name="sendmail" />
+
+ <mail:smtpMailer name="smtp" hostname="localhost" port="25" />
+
+ <--
+ <comment>
+ To send mail, uncomment the following directive and be sure to
+ create the queue directory.
+ </comment>
+
+ <mail:queuedService permission="zope.SendMail"
+ queuePath="./queue"
+ mailer="sendmail" />
+ -->
</zopeConfigure>
=== Zope3/src/zope/app/mail/meta.zcml 1.1.14.2 => 1.1.14.3 ===
--- Zope3/src/zope/app/mail/meta.zcml:1.1.14.2 Mon May 26 14:25:49 2003
+++ Zope3/src/zope/app/mail/meta.zcml Sun Jun 22 13:47:26 2003
@@ -5,32 +5,32 @@
<directive name="queuedService" handler=".metaconfigure.queuedService">
<description>
- This directive creates and registers a global queued mail service. It
- should be only called once during startup.
+ This directive creates and registers a global queued mail service. It
+ should be only called once during startup.
</description>
<attribute name="name" required="no">
<description>
- Specifies the Service name of the mail service. The default is
+ Specifies the Service name of the mail service. The default is
"Mail".
</description>
</attribute>
<attribute name="permission" required="yes">
<description>
- Defines the permission that is required to use this object.
+ Defines the permission that is required to use this object.
</description>
</attribute>
<attribute name="queuePath" required="yes">
<description>
- Defines the path for the queue directory.
+ Defines the path for the queue directory.
</description>
</attribute>
<attribute name="mailer" required="yes">
<description>
- The name of the mailer used by this service.
+ The name of the mailer used by this service.
</description>
</attribute>
@@ -39,26 +39,26 @@
<directive name="directService" handler=".metaconfigure.directService">
<description>
- This directive creates and registers a global direct mail service. It
- should be only called once during startup.
+ This directive creates and registers a global direct mail service. It
+ should be only called once during startup.
</description>
<attribute name="name" required="no">
<description>
- Specifies the Service name of the mail service. The default is
+ Specifies the Service name of the mail service. The default is
"Mail".
</description>
</attribute>
<attribute name="permission" required="yes">
<description>
- Defines the permission that is required to use this object.
+ Defines the permission that is required to use this object.
</description>
</attribute>
<attribute name="mailer" required="yes">
<description>
- Defines the mailer to be used for sending mail.
+ Defines the mailer to be used for sending mail.
</description>
</attribute>
@@ -67,18 +67,18 @@
<directive name="sendmailMailer" handler=".metaconfigure.sendmailMailer">
<description>
- Registers a new Sendmail mailer.
+ Registers a new Sendmail mailer.
</description>
<attribute name="name" required="yes">
- <description>
- Name of the mailer.
+ <description>
+ Name of the mailer.
</description>
</attribute>
<attribute name="command" required="no">
<description>
- A template command for sending out mail, containing %(from)s
+ A template command for sending out mail, containing %(from)s
and %(to)s for respective addresses.
</description>
</attribute>
@@ -88,36 +88,36 @@
<directive name="smtpMailer" handler=".metaconfigure.smtpMailer">
<description>
- Registers a new SMTP mailer.
+ Registers a new SMTP mailer.
</description>
<attribute name="name" required="yes">
- <description>
- Name of the mailer.
+ <description>
+ Name of the mailer.
</description>
</attribute>
<attribute name="hostname" required="no">
<description>
- Hostname of the SMTP host.
+ Hostname of the SMTP host.
</description>
</attribute>
<attribute name="port" required="no">
<description>
- Port of the SMTP server.
+ Port of the SMTP server.
</description>
</attribute>
<attribute name="username" required="no">
<description>
- A username for SMTP AUTH.
+ A username for SMTP AUTH.
</description>
</attribute>
<attribute name="password" required="no">
<description>
- A password for SMTP AUTH.
+ A password for SMTP AUTH.
</description>
</attribute>
=== Zope3/src/zope/app/mail/metaconfigure.py 1.2.2.2 => 1.2.2.3 ===
--- Zope3/src/zope/app/mail/metaconfigure.py:1.2.2.2 Mon May 26 14:25:49 2003
+++ Zope3/src/zope/app/mail/metaconfigure.py Sun Jun 22 13:47:26 2003
@@ -18,6 +18,7 @@
from zope.component import getService
from zope.configuration.action import Action
+from zope.configuration.exceptions import ConfigurationError
from zope.app.component.metaconfigure import provideService
from zope.app.mail.service import QueuedMailService, DirectMailService
from zope.app.mail.service import QueueProcessorThread
@@ -34,7 +35,7 @@
provideService(name, component, permission)
thread = QueueProcessorThread()
- thread.setMailer(queryMailer(mailer))
+ thread.setMailer(getMailer(mailer))
thread.setQueuePath(queuePath)
thread.setDaemon(True)
thread.start()
@@ -65,7 +66,8 @@
]
-def sendmailMailer(_context, name, command):
+def sendmailMailer(_context, name,
+ command="/usr/lib/sendmail -oem -oi -f %(from)s %(to)s"):
return [Action(discriminator=('mailer', name),
callable=provideMailer,
args=(name, SendmailMailer(command)),)
@@ -98,6 +100,11 @@
queryMailer = mailerRegistry.get
provideMailer = mailerRegistry.__setitem__
+def getMailer(mailer):
+ result = queryMailer(mailer)
+ if result is None:
+ raise ConfigurationError("Mailer lookup failed")
+ return result
# Register our cleanup with Testing.CleanUp to make writing unit tests simpler.
try:
=== Zope3/src/zope/app/mail/service.py 1.2.2.3 => 1.2.2.4 ===
--- Zope3/src/zope/app/mail/service.py:1.2.2.3 Sun Jun 22 10:23:15 2003
+++ Zope3/src/zope/app/mail/service.py Sun Jun 22 13:47:26 2003
@@ -20,7 +20,8 @@
import rfc822
import threading
import os.path
-from os import listdir
+import logging
+from os import listdir, unlink
from cStringIO import StringIO
from random import randrange
from time import strftime
@@ -117,8 +118,12 @@
"""This thread is started at configuration time from the
mail:queuedService directive handler.
"""
+ log = logging.getLogger("QueueProcessorThread")
def setMaildir(self, maildir):
+ """Set the maildir.
+
+ This method is used just to provide a maildir stubs ."""
self.maildir = maildir
def setQueuePath(self, path):
@@ -156,22 +161,26 @@
def run(self, forever=True):
while True:
- for message in self.maildir:
- try:
-
- fromaddr, toaddrs, message = self._parseMessage(message)
- self.mailer.send(fromaddr, toaddrs, message)
- # XXX add log reporting
+ for filename in self.maildir:
+ try:
+ file = open(filename)
+ message = file.read()
+ file.close()
+ fromaddr, toaddrs, message = self._parseMessage(message)
+ self.mailer.send(fromaddr, toaddrs, message)
+ unlink(filename)
+ # XXX maybe log the Message-Id of the message sent
+ self.log.info("Mail from %s to %s sent.",
+ fromaddr, ", ".join(toaddrs))
# Blanket except because we don't want this thread to ever die
- except:
- from traceback import print_exc
- print_exc()
- # XXX maybe throw away erroring messages here?
- # XXX add log reporting
- pass
- else:
+ except:
+ # XXX maybe throw away erroring messages here?
+ self.log.error("Error while sending mail from %s to %s.",
+ fromaddr, ", ".join(toaddrs), exc_info=1)
+ else:
+ if forever:
sleep(3)
- # A testing plug
- if not forever:
- break
+ # A testing plug
+ if not forever:
+ break