Source code for uw.local.outgoing.bin.dump_message

"""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.
"""

import argparse

from uw.sql.wrap import open_psycopg2_db_service_cursor

from ..cursor import Cursor
from .send_mail import assemble_message

[docs]def main (): parser = argparse.ArgumentParser () parser.add_argument ('--msg', type=int, required=True, metavar='msg_id') args = parser.parse_args () msg_id = args.msg cursor = open_psycopg2_db_service_cursor (cursor_class=Cursor) message = cursor.get_message_by_id (msg_id=msg_id) if message is None: print ("No such message: %d" % msg_id) else: msg = assemble_message (cursor, message) print (msg.as_string ())