Initial commit
Benjamin Renard authored 13 years ago
|
13)
14) parser = OptionParser()
15)
16) parser.add_option('-v',
17) '--verbose',
18) action="store_true",
19) dest="verbose",
20) help="Enable verbose mode")
21)
22) parser.add_option('-d',
23) '--daemon',
24) action="store_true",
25) dest="daemon",
26) help="Start in daemon mode")
27)
28) parser.add_option('--pid',
29) action="store",
30) type="string",
31) dest="pidfile",
32) help="The logfile path",
33) default=None)
34)
35) parser.add_option('-c',
36) '--configfile',
37) action="store",
38) type="string",
39) dest="configfile",
40) help="The logfile path",
41) default=None)
42)
43) parser.add_option('-l',
44) '--logfile',
45) action="store",
46) type="string",
47) dest="logfile",
48) help="The logfile path",
49) default=None)
50)
51) parser.add_option('-H',
52) '--address',
53) action="store",
54) type="string",
55) dest="bind_address",
56) help="The bind address",
57) default="127.0.0.1")
58)
59) parser.add_option('-p',
60) '--port',
61) action="store",
62) type="int",
63) dest="port",
64) help="The bind port",
65) default=1025)
66)
|
Added parameter to save rec...
Benjamin Renard authored 12 years ago
|
67) parser.add_option('-s',
68) '--save',
69) action="store",
70) type="string",
71) dest="save_dir",
72) help="Save all message receive in this directory",
73) default=None)
74)
75)
|
Initial commit
Benjamin Renard authored 13 years ago
|
76) (options, args) = parser.parse_args()
77)
78)
79) logformat = '%(asctime)s - MantisMailServer - %(levelname)s - %(message)s'
80) if options.verbose:
81) loglevel = logging.DEBUG
82) else:
83) loglevel = logging.INFO
84)
85) if options.logfile:
86) logging.basicConfig(filename=options.logfile,level=loglevel,format=logformat)
87) else:
88) logging.basicConfig(level=loglevel,format=logformat)
89)
90) server = MantisSMTPServer.MantisSMTPServer((options.bind_address, options.port), None)
91)
92)
93) if options.daemon and options.pidfile is None:
94) logging.error("Can't daemonize without pid file parameter (--pid)")
95) sys.exit(3)
96)
97) if options.configfile:
98) try:
99) fd=open(options.configfile,'rb')
100) config_text=fd.read()
101) fd.close()
102) except:
103) logging.error('Error reading config file %s.' % options.configfile)
104) sys.exit(1)
105)
106) try:
107) config=json.loads(config_text)
108) except:
109) logging.error('Error parsing config file %s.' % options.configfile)
110) sys.exit(2)
111)
112) try:
|
Initial commit
Benjamin Renard authored 13 years ago
|
114) if param in config:
115) server.set_option(param,config[param])
116)
117) if 'projects' in config:
118) for project in config['projects']:
119) if 'project_name' not in config['projects'][project]:
120) logging.warning('Project %s in config file does not have "project_name" parameter. Pass.' % project)
121) continue
122) if 'category' in config['projects'][project]:
123) server.add_project(project,config['projects'][project]['project_name'],category=config['projects'][project]['category'])
124) else:
125) server.add_project(project,config['projects'][project]['project_name'])
126) except:
127) logging.error('Error loading config parameters from %s' % options.configfile)
128) sys.exit(3)
129) else:
130) logging.warning('No config file supply. Running with default configuration...')
131)
|