def process_queued_msgs(msgids, action, direction, *args): "Process queued messages" try: logger = process_queued_msgs.get_logger() eximcmd = get_config_option('Sendmail2') if direction == 2 else 'exim' if 'exim' not in eximcmd: logger.info("Invalid exim command: %s" % eximcmd) return if direction == 1 and action not in ['bounce', 'delete']: logger.info("Invalid action: %s" % action) return exim_user = config.get('baruwa.mail.user', 'exim') queue = EximQueue('sudo -u %s %s' % (exim_user, eximcmd)) func = getattr(queue, action) msgids = [msgid for msgid in msgids if EXIM_MSGID_RE.match(msgid)] func(msgids, *args) for result in queue.results: logger.info("STDOUT: %s" % result) if queue.errors: for errmsg in queue.errors: logger.info("STDERR: %s" % errmsg) hostname = system_hostname() update_queue_stats(hostname) except TypeError, error: logger.info("Invalid input: %s" % error)
def clean_sphinx_q(query): "reformat special chars" if '@' in query and not CLEANQRE.match(query): query = query.replace('@', '\@') if EXIM_MSGID_RE.match(query): query = query.replace('-', '\-') return query
def main(argv): "Main function" parser = OptionParser() parser.add_option('-c', '--config', dest="settingsfile", help="Baruwa configuration file", default='/etc/baruwa/production.ini') parser.add_option('-e', '--disable-exim-messageid', dest="eximid", help="Disable the filtering of exim message id's", action="store_false", default=True) parser.add_option('-d', '--delete-ophans', dest="delmsg", help="Delete ophaned messages", action="store_true", default=False) options, _ = parser.parse_args(argv) basepath = os.path.dirname(os.path.dirname(__file__)) configfile = os.path.join(basepath, options.settingsfile) if not os.path.exists(configfile): print parser.print_help() print "The config file %s does not exist" % configfile sys.exit(2) config = load_config(configfile) sqlalchemyurl = config.get('app:main', 'sqlalchemy.url', vars=dict(here=basepath)) engine = create_engine(sqlalchemyurl) Session = sessionmaker(bind=engine) session = Session() quarantine = get_config_option('QuarantineDir') count = 0 for (dirname, _, files) in os.walk(quarantine): for mail in files: if mail == 'message': mail = os.path.dirname(dirname) if mail.startswith('.'): continue if options.eximid and not EXIM_MSGID_RE.match(mail): continue count += 1 msg = session.query(Message.id)\ .filter(Message.messageid == mail)\ .all() if not msg: msg = session.query(Archive.id)\ .filter(Archive.messageid == mail)\ .all() if not msg: print "%(m)s not found" % dict(m=mail) filename = os.path.join(dirname, mail) if options.delmsg: os.unlink(filename) print '-' * 100 print '%(c)d messages found' % dict(c=count)
def process_queued_msgs(msgids, action, direction, *args): "Process queued messages" try: logger = process_queued_msgs.get_logger() eximcmd = get_config_option('Sendmail2') if direction == 2 else 'exim' if not 'exim' in eximcmd: logger.info(_("Invalid exim command: %s") % eximcmd) return if direction == 1 and action not in ['bounce', 'delete']: logger.info(_("Invalid action: %s") % action) return queue = EximQueue('sudo -u exim ' + eximcmd) func = getattr(queue, action) msgids = [msgid for msgid in msgids if EXIM_MSGID_RE.match(msgid)] func(msgids, *args) for result in queue.results: logger.info(_("STDOUT: %s") % result) if queue.errors: for errmsg in queue.errors: logger.info(_("STDERR: %s") % errmsg) update_queue_stats() except TypeError, error: logger.info(_("Invalid input: %s") % error)