Beispiel #1
0
def get_arguments():
    # Get arguments and create link to server
    from optparse import OptionParser
    parser = OptionParser(usage="%prog [options] <mailboxname> [<mailboxname> ...]")
    parser.add_option("-s", "--server",dest='server',help='IMAP server')
    parser.add_option("-p", "--port",  dest='port',  help='IMAP server port', type='int')
    parser.add_option("-x", "--ssl",   dest='ssl',   action="store_true", help='Use SSL')
    parser.add_option("-u", "--user",  dest='user',  help='IMAP user name')
    parser.add_option("-w", "--password", dest='password',  help='IMAP password (Will prompt if not specified)')
    parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="Verbose mode")
    parser.add_option("-n", "--dry-run", dest="dry_run", action="store_true", 
                        help="Don't actually do anything, just report what would be done")
    parser.add_option("-c", "--checksum", dest="use_checksum", action="store_true", 
                        help="Use a checksum of several mail headers, instead of the Message-ID")
    parser.add_option("-m", "--checksum-with-id", dest="use_id_in_checksum", action="store_true", 
                        help="Include the Message-ID (if any) in the -c checksum.")
    parser.add_option("-l", "--list", dest="just_list", action="store_true", 
                                            help="Just list mailboxes")

    parser.set_defaults(verbose=False, ssl=False, dry_run=False, just_list=False)
    (options, args) = parser.parse_args()
    if (not options.server) or (not options.user):
        sys.stderr.write("\nError: Must specify server, user, password and at least one mailbox.\n\n")
        parser.print_help()
        sys.exit(1)
    if not options.password:
        options.password = getpass.getpass()

    return (options, args)
Beispiel #2
0
def get_arguments():

    from optparse import OptionParser
    parser = OptionParser(usage="%prog options ")
    parser.add_option("-f","--config",    dest='config_file',      help='Config File ')
    parser.add_option("-s","--src-server",dest='src_server',help='Source IMAP server')
    parser.add_option("-S","--dst-server",dest='dst_server',help='Destination IMAP server')
    parser.add_option("-p","--src-port",  dest='src_port',  help='Source IMAP server port', type='int')
    parser.add_option("-P","--dst-port",  dest='dst_port',  help='Destination IMAP server port', type='int')
    parser.add_option("-u","--src-user",  dest='src_user',  help='Source IMAP user')
    parser.add_option("-U","--dst-user",  dest='dst_user',  help='Destination IMAP user')
    parser.add_option("-w","--src-password",  dest='src_password',  help='Source IMAP password',type="string")
    parser.add_option("-W","--dst-password",  dest='dst_password',  help='Destination IMAP password',type="string")
    parser.add_option("-x", "--src-ssl",   dest='src_ssl',   action="store_true", help='Use SSL')
    parser.add_option("-X", "--dst-ssl",   dest='dst_ssl',   action="store_true", help='Use SSL')
    parser.add_option("-d","--start-date", dest='start_date',help='Start from date YYYYMMDD ')
    parser.add_option("-D","--end-date"  , dest='end_date',  help='End date YYYYMMDD')
    parser.add_option("-v", "--verbose",   dest="verbose",   action="store_true", help="Verbose mode")
    parser.add_option("-c", "--checksum", dest="use_checksum", action="store_true", 
                        help="Use a checksum of several mail headers, instead of the Message-ID")
    parser.add_option("-m", "--checksum-with-id", dest="use_id_in_checksum", action="store_true", 
                        help="Include the Message-ID (if any) in the -c checksum.")
    parser.add_option("-l", "--list", dest="just_list", action="store_true", 
                                            help="Just list mailboxes on Source Server")

    parser.set_defaults(verbose=False, ssl=False, dry_run=False, just_list=False,src_port=143,dst_port=143)
    (options, args) = parser.parse_args()
  
    config = ConfigParser.ConfigParser()    
    #Load Data from config file
    if options.config_file:
        config.read(options.config_file)
        for a in config.items("IMAPCopy"):
            setattr(options, a[0],a[1])
              
    if (not options.start_date) or (not options.end_date):
            sys.stderr.write("\nError: Must specify Start and End dates. \n")
            parser.print_help()
            sys.exit(1)
         
    
    if options.just_list:
        if (not options.src_server) or (not options.src_user) :
            sys.stderr.write("\nError: Must specify src-server, src-users, src-passwords.\n")
            parser.print_help()
            sys.exit(1)
    else:
        if (not options.src_server) or (not options.dst_server) or (not options.src_user) or (not options.dst_user):
            sys.stderr.write("\nError: Must specify servers, users, passwords .\n\n")
            parser.print_help()
            sys.exit(1)


    return (options, args)
Beispiel #3
0
def parse_options():
    parser = OptionParser(usage = "usage: %prog [options]")
    parser.set_defaults(port = LISTEN_PORT, timeout = CHK_TIMEOUT,
            pcc_endpoint = PCC_ENDPOINT, xds_endpoint = XDS_ENDPOINT)
    parser.add_option("-p", action="store", dest="port", type="int",
                      help='The TCP port to listen to for the HTTP interface. Default: %s'% LISTEN_PORT)
    parser.add_option("-x", action="store", dest="xds_endpoint", 
                      help='The server endpoint for sending the XDS (Provide & Register) messages. Default: %s'% XDS_ENDPOINT)
    parser.add_option("-c", action="store", dest="pcc_endpoint", 
                      help='The server endpoint for sending the PCC-9 messages. Default: %s'% PCC_ENDPOINT)
    parser.add_option("-t", action="store", dest="timeout", type="int",
                      help='Timeout in seconds to be used for the periodic check. Default: %s (i.e. %s minutes).  Minimum: 5 seconds.'%
                      (CHK_TIMEOUT, CHK_TIMEOUT/60))
    (options, args) = parser.parse_args()
    if options.timeout < 5:
        options.timeout = 5
    return options
Beispiel #4
0
def parse_options():
    parser = OptionParser(usage="usage: %prog [options]")
    parser.set_defaults(port=LISTEN_PORT,
                        timeout=CHK_TIMEOUT,
                        pcc_endpoint=PCC_ENDPOINT,
                        xds_endpoint=XDS_ENDPOINT)
    parser.add_option(
        "-p",
        action="store",
        dest="port",
        type="int",
        help='The TCP port to listen to for the HTTP interface. Default: %s' %
        LISTEN_PORT)
    parser.add_option(
        "-x",
        action="store",
        dest="xds_endpoint",
        help=
        'The server endpoint for sending the XDS (Provide & Register) messages. Default: %s'
        % XDS_ENDPOINT)
    parser.add_option(
        "-c",
        action="store",
        dest="pcc_endpoint",
        help='The server endpoint for sending the PCC-9 messages. Default: %s'
        % PCC_ENDPOINT)
    parser.add_option(
        "-t",
        action="store",
        dest="timeout",
        type="int",
        help=
        'Timeout in seconds to be used for the periodic check. Default: %s (i.e. %s minutes).  Minimum: 5 seconds.'
        % (CHK_TIMEOUT, CHK_TIMEOUT / 60))
    (options, args) = parser.parse_args()
    if options.timeout < 5:
        options.timeout = 5
    return options
Beispiel #5
0
def get_arguments(args):
    # Get arguments and create link to server
    from optparse import OptionParser
    parser = OptionParser(usage="%prog [options] <mailboxname> [<mailboxname> ...]")
    parser.add_option("-P", "--process",dest='process', help='IMAP process to access mailboxes')
    parser.add_option("-s", "--server",dest='server',help='IMAP server')
    parser.add_option("-p", "--port",  dest='port',  help='IMAP server port', type='int')
    parser.add_option("-x", "--ssl",   dest='ssl',   action="store_true", help='Use SSL')
    parser.add_option("-a", "--authuser", dest='authuser', help='IMAP admin user (e.g. for Zimbra)')
    parser.add_option("-u", "--user",  dest='user',  help='IMAP user name')
    parser.add_option("-w", "--password", dest='password',  help='IMAP password (Will prompt if not specified)')
    parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="Verbose mode")
    parser.add_option("-n", "--dry-run", dest="dry_run", action="store_true",
                        help="Don't actually do anything, just report what would be done")
    parser.add_option("-c", "--checksum", dest="use_checksum", action="store_true",
                        help="Use a checksum of several mail headers, instead of the Message-ID")
    parser.add_option("-m", "--checksum-with-id", dest="use_id_in_checksum", action="store_true",
                        help="Include the Message-ID (if any) in the -c checksum.")
    parser.add_option("",   "--no-close",  dest='no_close', action="store_true",
                        help='Do not "close" mailbox when done. Some servers will purge deleted messages on a close command.')
    parser.add_option("-l", "--list", dest="just_list", action="store_true",
                                            help="Just list mailboxes")

    parser.set_defaults(verbose=False, ssl=False, dry_run=False, no_close=False, just_list=False)
    (options, mboxes) = parser.parse_args(args)
    if ((not options.server) or (not options.user)) and not options.process:
        sys.stderr.write("\nError: Must specify server, user, and at least one mailbox.\n\n")
        parser.print_help()
        sys.exit(1)
    if not options.password and not options.process:
        # Read from IMAPDEDUP_PASSWORD env variable, or prompt for one.
        options.password = os.getenv("IMAPDEDUP_PASSWORD") or getpass.getpass()

    if options.use_id_in_checksum and not options.use_checksum:
        sys.stderr.write("\nError: If you use -m you must also use -c.\n")
        sys.exit(1)

    return (options, mboxes)
Beispiel #6
0
def get_arguments(args):
    # Get arguments and create link to server
    from optparse import OptionParser
    parser = OptionParser(usage="%prog [options] <mailboxname> [<mailboxname> ...]")
    parser.add_option("-P", "--process",dest='process', help='IMAP process to access mailboxes')
    parser.add_option("-s", "--server",dest='server',help='IMAP server')
    parser.add_option("-p", "--port",  dest='port',  help='IMAP server port', type='int')
    parser.add_option("-x", "--ssl",   dest='ssl',   action="store_true", help='Use SSL')
    parser.add_option("-u", "--user",  dest='user',  help='IMAP user name')
    parser.add_option("-w", "--password", dest='password',  help='IMAP password (Will prompt if not specified)')
    parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="Verbose mode")
    parser.add_option("-n", "--dry-run", dest="dry_run", action="store_true",
                        help="Don't actually do anything, just report what would be done")
    parser.add_option("-c", "--checksum", dest="use_checksum", action="store_true",
                        help="Use a checksum of several mail headers, instead of the Message-ID")
    parser.add_option("-m", "--checksum-with-id", dest="use_id_in_checksum", action="store_true",
                        help="Include the Message-ID (if any) in the -c checksum.")
    parser.add_option("",   "--no-close",  dest='no_close', action="store_true",
                        help='Do not "close" mailbox when done. Some servers will purge deleted messages on a close command.')
    parser.add_option("-l", "--list", dest="just_list", action="store_true",
                                            help="Just list mailboxes")

    parser.set_defaults(verbose=False, ssl=False, dry_run=False, no_close=False, just_list=False)
    (options, mboxes) = parser.parse_args(args)
    if ((not options.server) or (not options.user)) and not options.process:
        sys.stderr.write("\nError: Must specify server, user, and at least one mailbox.\n\n")
        parser.print_help()
        sys.exit(1)
    if not options.password and not options.process:
        # Read from IMAPDEDUP_PASSWORD env variable, or prompt for one.
        options.password = os.getenv("IMAPDEDUP_PASSWORD") or getpass.getpass()

    if options.use_id_in_checksum and not options.use_checksum:
        sys.stderr.write("\nError: If you use -m you must also use -c.\n")
        sys.exit(1)

    return (options, mboxes)
Beispiel #7
0
def get_arguments():
    # Get arguments and create link to server
    from optparse import OptionParser
    parser = OptionParser(
        usage="%prog [options] <mailboxname> [<mailboxname> ...]")
    parser.add_option("-s", "--server", dest='server', help='IMAP server')
    parser.add_option("-p",
                      "--port",
                      dest='port',
                      help='IMAP server port',
                      type='int')
    parser.add_option("-x",
                      "--ssl",
                      dest='ssl',
                      action="store_true",
                      help='Use SSL')
    parser.add_option("-u", "--user", dest='user', help='IMAP user name')
    parser.add_option("-w",
                      "--password",
                      dest='password',
                      help='IMAP password (Will prompt if not specified)')
    parser.add_option("-v",
                      "--verbose",
                      dest="verbose",
                      action="store_true",
                      help="Verbose mode")
    parser.add_option(
        "-n",
        "--dry-run",
        dest="dry_run",
        action="store_true",
        help="Don't actually do anything, just report what would be done")
    parser.add_option(
        "-c",
        "--checksum",
        dest="use_checksum",
        action="store_true",
        help="Use a checksum of several mail headers, instead of the Message-ID"
    )
    parser.add_option(
        "-m",
        "--checksum-with-id",
        dest="use_id_in_checksum",
        action="store_true",
        help="Include the Message-ID (if any) in the -c checksum.")
    parser.add_option("-l",
                      "--list",
                      dest="just_list",
                      action="store_true",
                      help="Just list mailboxes")

    parser.set_defaults(verbose=False,
                        ssl=False,
                        dry_run=False,
                        just_list=False)
    (options, args) = parser.parse_args()
    if (not options.server) or (not options.user):
        sys.stderr.write(
            "\nError: Must specify server, user, password and at least one mailbox.\n\n"
        )
        parser.print_help()
        sys.exit(1)
    if not options.password:
        options.password = getpass.getpass()

    return (options, args)
Beispiel #8
0
    except Exception as e:
        logger.exception('Unknown exception occured.')
        sys.exit("Unknown exception occured. Shutting down.")


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='MIO e-mail response parser')
    parser.add_argument('eml',
                        nargs='+',
                        type=argparse.FileType('rb'),
                        help='input emls')
    parser.add_argument('-d',
                        '--debug',
                        action="store_true",
                        help="Enable debug message.")
    parser.set_defaults(logging_level='INFO')

    args = parser.parse_args()

    # set logger
    _lvl = args.logging_level
    if args.debug:
        _lvl = logging.DEBUG
        httplib2.debuglevel = 4

    _cformatter = logging.Formatter(stdout_fmt)
    _ch = logging.StreamHandler()
    _ch.setLevel(logging.INFO)
    _ch.setFormatter(_cformatter)
    _file_formatter = logging.Formatter(file_fmt)
    _fh = logging.handlers.RotatingFileHandler(APPLICATION_NAME + '.log',