Projects
Kolab:16:Testing:Candidate
pykolab-python3
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 12
View file
pykolab-0.9.0.tar.gz/wallace/__init__.py
Changed
@@ -154,6 +154,51 @@ break +class WallaceSMTPChannel(_smtpd.SMTPChannel): + callback = None + def __init__(self, connection, address, callback): + self.callback = callback + if conf.debuglevel > 8: + smtpd.DEBUGSTREAM = pykolab.logger.StderrToLogger(log) + super().__init__(self, connection, address) + + def data_header(self, mailfrom, rcpttos): + COMMASPACE = ', ' + return "X-Kolab-From: " + mailfrom + "\r\n" + \ + "X-Kolab-To: " + COMMASPACE.join(rcpttos) + "\r\n" + + def process_message(self, peer, mailfrom, rcpttos, data, **kwargs): + """ + We have retrieved the message. This should be as fast as possible, + and not ever block. + """ + + header = self.data_header(mailfrom, rcpttos) + + try: + (fp, filename) = tempfile.mkstemp(dir="/var/spool/pykolab/wallace/") + + # @TODO: and add line separator (\n or \r\n?) + # we should make sure there's only one line separator between + # kolab headers and the original message (data) + os.write(fp, bytes(header.encode("UTF-8"))) + os.write(fp, bytes(data.encode("UTF-8"))) + except Exception as errmsg: + log.warning( + _l("failed to write to file: %s" % (errmsg)) + ) + finally: + os.close(fp) + + log.debug(_l("Started processing accepted message %s") % filename, level=8) + self.callback(filename) + + return "250 OK Message %s queued" % (filename) + + def loop(self): + asyncore.loop() + + class WallaceDaemon: heartbeat = None timer = None @@ -356,14 +401,14 @@ self.current_connections += 1 connection, address = pair - _smtpd = smtpd - # Set DEBUGSTREAM of smtpd to log to pykolab logger - if conf.debuglevel > 8: - _smtpd.DEBUGSTREAM = pykolab.logger.StderrToLogger(log) - log.debug(_l("Creating SMTPChannel for accepted message"), level=8) - _smtpd.SMTPChannel(self, connection, address) - asyncore.loop() + + def callback(filename): + self.pool.apply_async(pickup_message, (filename, (self.modules))) + self.current_connections -= 1 + + channel = WallaceSMTPChannel(connection, address, callback) + channel.loop() else: log.error(_l("Socket accepted, but (conn, address) tuple is None.")) @@ -378,13 +423,6 @@ self.timer.cancel() self.timer.join() - # pylint: disable=no-self-use - def data_header(self, mailfrom, rcpttos): - COMMASPACE = ', ' - - return "X-Kolab-From: " + mailfrom + "\r\n" + \ - "X-Kolab-To: " + COMMASPACE.join(rcpttos) + "\r\n" - def pickup_spool_messages(self, sync=False): # Mind you to include the trailing slash pickup_path = '/var/spool/pykolab/wallace/' @@ -474,30 +512,6 @@ self.current_connections -= 1 - def process_message(self, peer, mailfrom, rcpttos, data): - """ - We have retrieved the message. This should be as fast as possible, - and not ever block. - """ - - header = self.data_header(mailfrom, rcpttos) - - (fp, filename) = tempfile.mkstemp(dir="/var/spool/pykolab/wallace/") - - # @TODO: and add line separator (\n or \r\n?) - # we should make sure there's only one line separator between - # kolab headers and the original message (data) - os.write(fp, header) - os.write(fp, data) - os.close(fp) - - log.debug(_l("Started processing accepted message %s") % filename, level=8) - self.pool.apply_async(pickup_message, (filename, (self.modules))) - - self.current_connections -= 1 - - return "250 OK Message %s queued" % (filename) - def reload_config(self, *args, **kwargs): pass
View file
pykolab-0.9.0.tar.gz/wallace/modules.py
Changed
@@ -140,6 +140,11 @@ # NOTE: Use "127.0.0.1" here for IPv6 (see also the service # definition in master.cf). + # Sanity check. We run into this if we end up reading an empty file, because sender ends up being an empty list + if not sender or not recipients: + log.warning(_("Sending email failed from %r to %r") % (sender, recipients), level=8) + return False + sl = pykolab.logger.StderrToLogger(log) smtplib.stderr = sl
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.