()
Main entry point, run the milter and start the background logging daemon
Main entry point, run the milter and start the background logging daemon
Main entry point run the milter and start the background logging daemon
def main():
    """Main entry point, run the milter and start the background logging daemon"""

    try:
        debug = configParser.getboolean('main', 'debug')

        # Exit if the main thread have been already created
        if os.path.exists(PID_FILE_PATH):
            print("pid file {} already exists, exiting".format(PID_FILE_PATH))
            os.exit(-1)

        lgThread = Thread(target=loggingThread)
        lgThread.start()
        timeout = 600

        # Register to have the Milter factory create new instances
        Milter.factory = MarkAddressBookMilter

        # For this milter, we only add headers
        flags = Milter.ADDHDRS
        Milter.set_flags(flags)

        # Get the parent process ID and remember it
        pid = os.getpid()
        with open(PID_FILE_PATH, "w") as pidFile:
            pidFile.write(str(pid))
            pidFile.close()

        print("Started RoundCube address book search and tag milter (pid={}, debug={})".format(pid, debug))
        sys.stdout.flush()

        # Start the background thread
        Milter.runmilter("milter-rc-abook", SOCKET_PATH, timeout)
        GlobalLogQueue.put(None)

        #  Wait until the logging thread terminates
        lgThread.join()

        # Log the end of process
        print("Stopped RoundCube address book search and tag milter (pid={})".format(pid))

    except Exception as error:
        print("Exception when running the milter: {}".format(error.message))

    # Make sure to remove the pid file even if an error occurs
    # And close the database connection if opened
    finally:
        if os.path.exists(PID_FILE_PATH):
            os.remove(PID_FILE_PATH)
def main ( ) : try : debug = configParser . getboolean ( 'main' , 'debug' ) # Exit if the main thread have been already created if os . path . exists ( PID_FILE_PATH ) : print ( "pid file {} already exists, exiting" . format ( PID_FILE_PATH ) ) os . exit ( - 1 ) lgThread = Thread ( target = loggingThread ) lgThread . start ( ) timeout = 600 # Register to have the Milter factory create new instances Milter . factory = MarkAddressBookMilter # For this milter, we only add headers flags = Milter . ADDHDRS Milter . set_flags ( flags ) # Get the parent process ID and remember it pid = os . getpid ( ) with open ( PID_FILE_PATH , "w" ) as pidFile : pidFile . write ( str ( pid ) ) pidFile . close ( ) print ( "Started RoundCube address book search and tag milter (pid={}, debug={})" . format ( pid , debug ) ) sys . stdout . flush ( ) # Start the background thread Milter . runmilter ( "milter-rc-abook" , SOCKET_PATH , timeout ) GlobalLogQueue . put ( None ) #  Wait until the logging thread terminates lgThread . join ( ) # Log the end of process print ( "Stopped RoundCube address book search and tag milter (pid={})" . format ( pid ) ) except Exception as error : print ( "Exception when running the milter: {}" . format ( error . message ) ) # Make sure to remove the pid file even if an error occurs # And close the database connection if opened finally : if os . path . exists ( PID_FILE_PATH ) : os . remove ( PID_FILE_PATH )