<s> """<STR_LIT>""" <EOL> import sys <EOL> import os . path <EOL> import optparse <EOL> import logging <EOL> import logging . handlers <EOL> import socket <EOL> import asyncore <EOL> import traceback <EOL> import select <EOL> import asimap <EOL> import asimap . user_server <EOL> import asimap . utils <EOL> def setup_option_parser ( ) : <EOL> """<STR_LIT>""" <EOL> parser = optparse . OptionParser ( usage = "<STR_LIT>" , <EOL> version = asimap . __version__ ) <EOL> parser . set_defaults ( port = None , ssl_port = <NUM_LIT> , <EOL> interface = "<STR_LIT>" , debug = False , <EOL> ssl = True , ssl_certificate = None , <EOL> daemonize = True , <EOL> test_mode = False , <EOL> pidfile = "<STR_LIT>" , <EOL> logdir = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , action = "<STR_LIT:store>" , type = "<STR_LIT:int>" , dest = "<STR_LIT:port>" , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , action = "<STR_LIT:store>" , type = "<STR_LIT:int>" , dest = "<STR_LIT:port>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , action = "<STR_LIT:store>" , type = "<STR_LIT:string>" , <EOL> dest = "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , action = "<STR_LIT:store>" , type = "<STR_LIT:string>" , <EOL> dest = "<STR_LIT>" , help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , action = "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , action = "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , action = "<STR_LIT:store>" , type = "<STR_LIT:string>" , <EOL> dest = "<STR_LIT>" , help = "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , action = "<STR_LIT:store>" , type = "<STR_LIT:string>" , <EOL> dest = "<STR_LIT>" , help = "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return parser <EOL> def main ( ) : <EOL> """<STR_LIT>""" <EOL> parser = setup_option_parser ( ) <EOL> ( options , args ) = parser . parse_args ( ) <EOL> if options . daemonize : <EOL> print "<STR_LIT>" <EOL> asimap . utils . daemonize ( ) <EOL> if options . debug : <EOL> level = logging . DEBUG <EOL> else : <EOL> level = logging . INFO <EOL> log = logging . getLogger ( "<STR_LIT>" ) <EOL> log . setLevel ( level ) <EOL> if options . logdir == "<STR_LIT>" : <EOL> h = logging . StreamHandler ( ) <EOL> else : <EOL> log_file_basename = os . path . join ( options . logdir , "<STR_LIT>" ) <EOL> h = logging . handlers . RotatingFileHandler ( log_file_basename , <EOL> maxBytes = <NUM_LIT> , <EOL> backupCount = <NUM_LIT:5> ) <EOL> h . setLevel ( level ) <EOL> formatter = logging . Formatter ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> h . setFormatter ( formatter ) <EOL> log . addHandler ( h ) <EOL> log . info ( "<STR_LIT>" ) <EOL> import asimap . server <EOL> try : <EOL> with open ( options . pidfile , "<STR_LIT>" ) as f : <EOL> f . write ( "<STR_LIT>" % os . getpid ( ) ) <EOL> log . info ( "<STR_LIT>" % ( os . getpid ( ) , <EOL> options . pidfile ) ) <EOL> except Exception , e : <EOL> log . error ( "<STR_LIT>" % ( options . pidfile , <EOL> str ( e ) ) ) <EOL> if options . ssl and options . ssl_certificate is None : <EOL> log . error ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> exit ( - <NUM_LIT:1> ) <EOL> user_server_program = os . path . abspath ( os . path . join ( os . path . dirname ( sys . argv [ <NUM_LIT:0> ] ) , "<STR_LIT>" ) ) <EOL> if not os . path . exists ( user_server_program ) or not os . path . isfile ( user_server_program ) : <EOL> log . error ( "<STR_LIT>" % user_server_program ) <EOL> exit ( - <NUM_LIT:1> ) <EOL> log . debug ( "<STR_LIT>" % user_server_program ) <EOL> asimap . user_server . set_user_server_program ( user_server_program ) <EOL> try : <EOL> if options . port : <EOL> non_ssl_server = asimap . server . IMAPServer ( options . interface , <EOL> options . port , <EOL> options ) <EOL> if options . ssl : <EOL> ssl_server = asimap . server . IMAPServer ( options . interface , <EOL> options . ssl_port , <EOL> options , <EOL> options . ssl_certificate ) <EOL> except socket . error , e : <EOL> log . error ( "<STR_LIT>" "<STR_LIT>" % ( options . interface , options . port , e ) ) <EOL> return <EOL> asyncore . loop ( ) <EOL> return <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
