#!/usr/bin/env python

"""Generate a tagged (keyword-style) e-mail address.

Usage:  %(program)s [-c <file>] [-a <address>] [-h] keyword

Where:
	-c <file>
	--config-file <file>
	   Specify a different configuration file other than ~/.tmdarc.

	-a <address>
	--address <address>
	   Specify a different address as the basis for the tagged address.
			 
	--help
	-h
	   Print this help message and exit.
"""

import getopt
import os
import sys


program = sys.argv[0]

def usage(code, msg=''):
    print __doc__ % globals()
    if msg:
        print msg
    sys.exit(code)

try:
    opts, args = getopt.getopt(sys.argv[1:],
                                   'c:a:h', ['config-file=','address=','help'])
except getopt.error, msg:
    usage(1, msg)

if len(args) <> 1:
    usage(1)

address = None
for opt, arg in opts:
    if opt in ('-h', '--help'):
        usage(0)
    elif opt in ('-c', '--config-file'):
        os.environ['TMDARC'] = arg
    elif opt in ('-a', '--address'):
	address = arg


try:
    import paths
except ImportError:
    pass

from TMDA import Cookie
from TMDA import Defaults

def main():
    
    global address
    
    keyword = args[0]
    if not address:
	address = Defaults.USERNAME + '@' + Defaults.HOSTNAME
    keyword_address = Cookie.make_keyword_address(address, keyword)
    sys.stdout.write(keyword_address)


if __name__ == '__main__':
    main()
