def main(): mainloop = GLib.MainLoop() daemon = None set_procname(PROGNAME) GObject.threads_init() DBusGMainLoop(set_as_default = True) GLib.unix_signal_add(GLib.PRIORITY_HIGH, signal.SIGTERM, sigterm_handler, mainloop) # Get commandline arguments args = get_args() # Shut down an (possibly) already running Mailnag daemon # (must be called before instantiation of the DBUSService). shutdown_existing_instance() # Note: don't start logging before an existing Mailnag # instance has been shut down completely (will corrupt logfile). init_logging(not args.quiet) try: if not cfg_exists(): logging.critical( "Cannot find configuration file. " + \ "Please run mailnag-config first.") exit(1) wait_for_inet_connection() def fatal_error_hdlr(ex): # Note: don't raise an exception # (e.g InvalidOperationException) # in the error handler. mainloop.quit() def shutdown_request_hdlr(): if not mainloop.is_running(): raise InvalidOperationException( "Mainloop is not running") mainloop.quit() daemon = MailnagDaemon( fatal_error_hdlr, shutdown_request_hdlr) daemon.init() # start mainloop for DBus communication mainloop.run() except KeyboardInterrupt: pass # ctrl+c pressed finally: logging.info('Shutting down...') cleanup(daemon)
def main(): set_procname("mailnag-config") confwin = ConfigWindow() Gtk.main() if confwin.daemon_enabled: try: # the launched daemon shuts down # an already running daemon print "Launching Mailnag daemon." subprocess.Popen(os.path.join(BIN_DIR, "mailnagd")) except: print "ERROR: Failed to launch Mailnag daemon." else: DBusGMainLoop(set_as_default = True) # shutdown running Mailnag daemon shutdown_existing_instance()
def main(): global mailchecker, mainloop, idlers mainloop = None set_procname("mailnag") GObject.threads_init() signal.signal(signal.SIGTERM, sig_handler) try: write_pid() # write Mailnag's process id to file cfg = read_config() if (cfg == None): print 'Error: Cannot find configuration file. Please run mailnag_config first.' exit(1) accounts = AccountList() accounts.load_from_cfg(cfg, enabled_only = True) mailchecker = MailChecker(cfg, accounts) # immediate check mailchecker.check(firstcheck = True) # start polling thread for POP3 accounts and # IMAP accounts without idle support if sum(1 for acc in accounts if ((not acc.imap ) or (acc.imap and not acc.idle))) > 0: check_interval = int(cfg.get('general', 'check_interval')) GObject.timeout_add_seconds(60 * check_interval, mailchecker.check) # start idler threads for IMAP accounts with idle support if sum(1 for acc in accounts if (acc.imap and acc.idle)) > 0: idlers = Idlers(accounts, mailchecker.check) idlers.run() mainloop = GObject.MainLoop() mainloop.run() except KeyboardInterrupt: pass # ctrl+c pressed finally: cleanup()
def main(): set_procname("mailnag_config") confwin = ConfigWindow() Gtk.main()
def main(): global mainloop, mailchecker, idlers set_procname("mailnag") GObject.threads_init() signal.signal(signal.SIGTERM, sig_handler) try: write_pid() # write Mailnag's process id to file cfg = read_config() if (cfg == None): print 'Error: Cannot find configuration file. Please run mailnag_config first.' exit(1) if not is_online(): print 'Waiting for internet connection...' while not is_online(): time.sleep(5) accounts = AccountList() accounts.load_from_cfg(cfg, enabled_only = True) mailchecker = MailChecker(cfg) # immediate check, check *all* accounts mailchecker.check(accounts) idle_accounts = filter(lambda acc: acc.imap and acc.idle, accounts) non_idle_accounts = filter(lambda acc: (not acc.imap) or (acc.imap and not acc.idle), accounts) # start polling thread for POP3 accounts and # IMAP accounts without idle support if len(non_idle_accounts) > 0: def poll_func(): try: mailchecker.check(non_idle_accounts) except: traceback.print_exc() return True check_interval = int(cfg.get('general', 'check_interval')) GObject.timeout_add_seconds(60 * check_interval, poll_func) # start idler threads for IMAP accounts with idle support if len(idle_accounts) > 0: def sync_func(account): try: mailchecker.check([account]) except: traceback.print_exc() idlers = Idlers(idle_accounts, sync_func) idlers.run() mainloop = GObject.MainLoop() mainloop.run() except KeyboardInterrupt: pass # ctrl+c pressed finally: cleanup()