uw.local.outgoing.bin package

Submodules

uw.local.outgoing.bin.dump_message module

Dump a message.

A simple utility to dump a message to stdout exactly as it would be fed to sendmail by the usual mail sending process.

uw.local.outgoing.bin.dump_message.main()[source]

uw.local.outgoing.bin.loopback2 module

Loopback monitor implementation.

This module implements the loopback handler. Email received by the loopback address is processed by this module, which notes the corresponding email request within the system as having been received on loopback. This provides verification that the email has in fact been handled by the email system. Of course, nothing can guarantee the message isn’t lost elsewhere, but it at least guarantees the message made it as far as the first mail server.

uw.local.outgoing.bin.loopback2.assign_message_id(cursor, msg_id)[source]

Assign the loopback header value for a designated message.

Parameters
  • cursor – DB connection cursor.

  • msg_id (int) – the sequential database message ID.

If the message already has its loopback header value assigned, no change is made.

uw.local.outgoing.bin.loopback2.get_message_id(cursor, msg_id)[source]

Get the loopback header for a designated message.

Parameters
  • cursor – DB connection cursor.

  • msg_id (int) – the sequential database message ID.

This just reads the SMTP Message ID for the specified message from the database.

uw.local.outgoing.bin.loopback2.get_message_loopback(msg)[source]

Read the loopback header information from a message.

Parameters

msg (email.message.Message) – the received email message.

This reads the loopback header and extracts the sequential database message ID, or None if the header is not in the required format.

uw.local.outgoing.bin.loopback2.main()[source]

Program entry point for receiving messages on loopback.

Opens a database connection, parses the incoming message to object the Message ID, then records receipt of the message in the database.

uw.local.outgoing.bin.loopback2.record_message_loopback(cursor, msg_id)[source]

Record in the database the receipt of a message loopback.

Parameters
  • cursor – DB connection cursor.

  • msg_id (int) – the sequential database message ID.

uw.local.outgoing.bin.loopback2.set_message_loopback(msg, cursor, msg_id)[source]

Apply the message loopback header to a message.

Parameters
  • msg (email.message.Message) – the received email message.

  • cursor – DB connection cursor.

  • msg_id (int) – the sequential database message ID.

Sets the Message-Id of the message to the one stored in the database for the specified message ID. If there is already a Message-Id it is replaced. This is used by the mail sending process to set the Message-Id on outgoing messages.

uw.local.outgoing.bin.send_mail module

Outgoing mail handler sending process implementation.

This module implements the process which actually sends the mail messages previously stored in the database.

uw.local.outgoing.bin.send_mail.assemble_message(cursor, message_row)[source]

Assemble an email message corresponding to a given message DB row.

Parameters
  • cursor – DB connection cursor.

  • message_row – message as an _outgoing.mail_message row.

Obtain the attachments and recipients by calling other routines, and build an email object using the standard email.mime module. Return the assembled email object.

uw.local.outgoing.bin.send_mail.get_recipients(cursor, msg_id)[source]

Get the recipients of the specified message.

Parameters
  • cursor – DB connection cursor.

  • msg_id (int) – the message ID of the message.

Returns a list of recipients in a simple tuple-based layout. Each recipient is represented as (type, (name, email)). The (name, email) part of that is compatible with functions provided by the email module.

uw.local.outgoing.bin.send_mail.main()[source]

Program entry point for mail sending cron job.

Opens a database connection, then loops, obtaining and sending one message at a time until there are no more messages to send.

uw.local.outgoing.bin.send_mail.print_message_by_id(cursor, msg_id)[source]

Print out a message for debugging purposes.

Parameters
  • cursor – DB connection cursor.

  • msg_id (int) – the message ID of the message.

Obtain the basic message information from the database. If there is no such message, return without doing anything. If the message does exist, assemble it using assemble_message() then print out what would be fed to sendmail.

uw.local.outgoing.bin.send_mail.send_message(cursor, message_row)[source]

Actually send a message constructed from a given message DB row.

Parameters
  • cursor – DB connection cursor.

  • message_row – message as an _outgoing.mail_message row.

Assemble the message, then send it using /usr/lib/sendmail. Assuming sendmail completes successfully, mark the message as sent in the database. This is where the system leaves transactional control: it is possible for the message to be sent using sendmail, yet this process could crash before recording the fact that it has been sent. On the other hand, this process could record the message as sent, but sendmail or any part of the mail system could lose it entirely.

uw.local.outgoing.bin.send_mail.send_message_by_id(cursor, msg_id)[source]

Send the specified message.

Parameters
  • cursor – DB connection cursor.

  • msg_id (int) – the message ID of the message.

Obtain the basic message information from the database. If there is no such message, return without doing anything. If the message does exist, send it using send_message().

Module contents