Changeset 21:41e7bbc16e32 in mailjam


Ignore:
Timestamp:
May 22, 2012, 1:29:55 PM (13 years ago)
Author:
Borja Lopez <borja@…>
Branch:
default
Phase:
public
Message:

Improved the mailjam-mta and mailjam-server scripts, adding argparse
definitions for the proper parameters available for both scripts.

Location:
bin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • bin/mailjam-mta

    • Property exe set to *
    r16 r21  
    11#!/usr/bin/env python
    22#
    3 # Run the Postman MTA client
     3# Run the Mailjam MTA client
    44
    5 import sys
    6 from postman.mta import MTAClient
     5import argparse, sys
     6from mailjam.mta import MTAClient
    77
    8 def usage():
    9     print """
    10     Usage: postman-mta address < raw_email_data
     8msg = 'mailjam-mta: Mailing lists MTA client'
     9parser = argparse.ArgumentParser(description=msg)
     10parser.add_argument('-c', '--config', action='store', dest='config',
     11                    help='Set the path to a valid mailjam mta client configuration file')
     12parser.add_argument('-v', '--version', action='version',
     13                    version='mailjam mta client 0.1.0')
     14parser.add_argument('-a', '--address', action='store', dest='address',
     15                    required=True,
     16                    help='Set the address of the mailing list we want to manage')
    1117
    12     address is a valid mailing list address
    13 
    14     raw_email_data is the raw data (txt) that contains the information of
    15     the email to be sent
    16     """
    17     return True
     18parser.add_argument('-i', '--input', type=argparse.FileType('r'),
     19                    default='-', required=True, dest='input',
     20                    help="Pass the raw email to be send to the mailing list, Use - to allow incoming raw mails from a pipe")
    1821
    1922if __name__ == '__main__':
    20     if len(sys.argv) < 2:
    21         usage()
    22         raise SystemExit
    23     try:
    24         raw_email = sys.stdin.read()
    25     except:
    26         usage()
    27         raise SystemExit
    28     mta_client = MTAClient(address=sys.argv[1])
    29     mta_client.get_raw_email(raw_email)
     23    results = parser.parse_args()
     24    if results.config:
     25        mta_client = MTAClient(address=results.address,
     26                               configfile=results.config)
     27    else:
     28        mta_client = MTAClient(address=results.address)
     29    mta_client.get_raw_email(results.input.read())
    3030    mta_client.run()
    3131
  • bin/mailjam-server

    r16 r21  
    11#!/usr/bin/env python
    22#
    3 # Run the Postman XML-RPC server
     3# Run the Mailjam XML-RPC server
     4#
    45
    5 from postman.daemon import PostmanDaemon
     6import argparse
     7
     8from mailjam.daemon import MailjamDaemon
     9
     10msg = 'mailjam-server: Mailing lists management server'
     11parser = argparse.ArgumentParser(description=msg)
     12parser.add_argument('-c', '--config', action='store', dest='config',
     13                    help='Set the path to a valid mailjam configuration file')
     14parser.add_argument('-v', '--version', action='version',
     15                    version='mailjam server 0.1.0')
    616
    717if __name__ == '__main__':
    8     daemon = PostmanDaemon()
     18    results = parser.parse_args()
     19    if results.config:
     20        daemon = MailjamDaemon(configfile=results.config)
     21    else:
     22        daemon = MailjamDaemon()
    923    daemon.run()
Note: See TracChangeset for help on using the changeset viewer.