예제 #1
0
def queue(m):
    key = secret(m)
    fd = open(queue_path(key), 'w')
    wlemail.add_action(m, "Queued (%s)" % time.ctime(time.time()))
    fd.write(m.as_string())
    fd.close()
    confirm = confirmation(m, key)
    if confirm: wlemail.send_message(confirm)
예제 #2
0
def queue (m):
    key = secret (m)
    fd = open (queue_path (key), 'w')
    wlemail.add_action (m, "Queued (%s)" % time.ctime (time.time()))
    fd.write (m.as_string ())
    fd.close ()
    confirm = confirmation (m, key)
    if confirm: wlemail.send_message (confirm)
예제 #3
0
def move_message_from_queue(key, mailbox, action, magic=False):
    m = open_by_key(key)
    wlemail.add_action(m, action)
    if magic:
        wlemail.add_magic(m)
        wlevacation.handle_incoming(m)
    deliver_mail(m, mailbox)
    remove_message(key)
    return m
예제 #4
0
def move_message_from_queue (key, mailbox, action, magic = False):
    m = open_by_key (key)
    wlemail.add_action (m, action)
    if magic:
        wlemail.add_magic (m)
        wlevacation.handle_incoming (m)
    deliver_mail (m, mailbox)
    remove_message (key)
    return m
예제 #5
0
def vacation_message (m):
    db = wledb.connect_db ()
    recipient = wlemail.senders(m)[0]
    recipient_email = recipient[1]
    target = email.Utils.formataddr (recipient)
    c = db.cursor ()
    c.execute ("select stamp from vacation where email='%s'" % recipient_email)
    if c.rowcount > 0 and time.time () - float(c.fetchone()[0]) < \
       86400 * wleconfig.config.getint ('DEFAULT', 'vacation_days'):
        wlelog.log (8, "Not sending duplicate vacation message to %s" % target)
        return None
    c.execute ("insert into vacation values ('%s', %f)" %
               (recipient_email, time.time ()))
    db.commit ()
    my_name = wleconfig.config.get ('DEFAULT', 'myname')
    my_addr = wleconfirm.confirmation_sender (m)
    subject = m['subject'] or "..."
    subject = wleconfirm.decoded_header (subject)
    trimmed_subject = wlemail.canonical_subject (subject)
    t = open (wleconfig.config.get('DEFAULT', 'vacation_msg'), 'r').read() % \
        {'target_name' :    recipient[0],
         'target_email':    recipient_email,
         'target':          target,
         'subject':         subject,
         'trimmed_subject': trimmed_subject,
         'my_name':         my_name,
         'my_addr':         my_addr}
    r = MIMEText (t, 'plain', wleconfig.config.get ('DEFAULT', 'charset'))
    try: r['In-Reply-To'] = m.get ('message-id')
    except: pass
    rsubject = wlemail.make_answer (subject)
    r['Precedence'] = 'junk'
    rfrom = email.Utils.formataddr ((my_name, my_addr))
    wlelog.log (3, "Sending vacation message to %s" % target)
    wlemail.complete_message (r, rfrom, target, rsubject)
    wlemail.add_action (m, "Vacation message sent")
    return r
예제 #6
0
def logic(m):
    count_received()
    wlemail.parse_message(m)
    log_summary(m)
    if wleconfirm.is_old_confirm(m):
        wlemail.add_action(m, 'Related to an old confirmation request')
        wleconfirm.deliver_mail(m, 'confirmedbox')
        return
    if wlemail.from_mailerdaemon(m):
        key = wleconfirm.is_confirm(m)
        if key:
            wlemail.add_action(m, 'Bounce of confirmation request')
            count_junk()
            wleconfirm.deliver_mail(m, 'junkbox')
            if wleconfig.config.getboolean('DEFAULT', 'auto_delete_bounce'):
                count_rejected()
                try:
                    wleconfirm.move_message_from_queue(key, 'junkbox',
                                                       'Confirmation bounced')
                except:
                    pass
            return
        if wlemail.sent_to_me(m):
            wlemail.add_action(m, 'Mailer daemon get through')
            wlemail.add_magic(m)
            wleconfirm.deliver_mail(m, 'mailbox')
            return
        else:
            wlemail.add_action(m, 'Suspect mailer daemon message')
            wleconfirm.deliver_mail(m, 'junkbox')
            return
    key = wleconfirm.is_confirm(m)
    if key:
        if not wlemail.is_junk(m):
            count_confirmed()
            wlelog.log(3, 'Found key in mail')
            handle_confirmation(m, key)
            return
        wlelog.log(3, 'Will not accept confirmation from junk message')
    x = wlelists.is_in_list(m, 'ignorelist')
    if x:
        wlemail.add_action(m, 'Ignore list (%s), junk box' % x)
        wleconfirm.deliver_mail(m, 'junkbox')
        count_junk()
        return
    x = wlemail.contains_command(m)
    if x:
        x(m)
        return
    if wlemail.contains_magic(m):
        wlemail.add_action(m, 'Message contains magic number')
        handle_ok(m)
        if wleconfig.config.getboolean('DEFAULT', 'magic_add_sender'):
            wlelists.snoop_addresses(m)
        return
    x = wlelists.is_in_list(m, 'whitelist')
    if x:
        wlemail.add_action(m, 'White list (%s)' % x)
        handle_ok(m)
        if wleconfig.config.getboolean('DEFAULT', 'confirm_whitelist'):
            wlelists.add_confirmed(m.msenders)
        return
    if wlelists.is_in_confirmed_list(m.msenders):
        wlemail.add_action(m, 'Sender found in authorized list')
        handle_ok(m)
        return
    if wlemail.from_mailinglist(m):
        wlemail.add_action(m, 'Bulk mail')
        wleconfirm.deliver_mail(m, 'bulkbox')
        count_bulk()
        return
    if wlemail.is_junk(m):
        wlemail.add_action(m, 'Junk mail')
        wleconfirm.deliver_mail(m, 'junkbox')
        count_junk()
        return
    # A new confirmation request is a good time to cleanup databases
    wleconfirm.cleanup_dbs()
    wleconfirm.queue(m)
    count_queued()
    return
예제 #7
0
파일: wle.py 프로젝트: samueltardieu/wle
def logic (m):
    count_received ()
    wlemail.parse_message (m)
    log_summary (m)
    if wleconfirm.is_old_confirm (m):
        wlemail.add_action (m, 'Related to an old confirmation request')
        wleconfirm.deliver_mail (m, 'confirmedbox')
        return
    if wlemail.from_mailerdaemon (m):
        key = wleconfirm.is_confirm (m)
        if key:
            wlemail.add_action (m, 'Bounce of confirmation request')
            count_junk ()
            wleconfirm.deliver_mail (m, 'junkbox')
            if wleconfig.config.getboolean ('DEFAULT', 'auto_delete_bounce'):
                count_rejected ()
                try:
                    wleconfirm.move_message_from_queue (key,
                                                        'junkbox',
                                                        'Confirmation bounced')
                except:
                    pass
            return
	if wlemail.sent_to_me (m):
	    wlemail.add_action (m, 'Mailer daemon get through')
	    wlemail.add_magic (m)
	    wleconfirm.deliver_mail (m, 'mailbox')
	    return
	else:
	    wlemail.add_action (m, 'Suspect mailer daemon message')
	    wleconfirm.deliver_mail (m, 'junkbox')
	    return
    key = wleconfirm.is_confirm (m)
    if key:
        if not wlemail.is_junk (m):
            count_confirmed ()
            wlelog.log (3, 'Found key in mail')
            handle_confirmation (m, key)
            return
        wlelog.log (3, 'Will not accept confirmation from junk message')
    x = wlelists.is_in_list (m, 'ignorelist')
    if x:
        wlemail.add_action (m, 'Ignore list (%s), junk box' % x)
        wleconfirm.deliver_mail (m, 'junkbox')
        count_junk ()
        return
    x = wlemail.contains_command (m)
    if x:
        x (m)
        return
    if wlemail.contains_magic (m):
        wlemail.add_action (m, 'Message contains magic number')
        handle_ok (m)
        if wleconfig.config.getboolean ('DEFAULT', 'magic_add_sender'):
            wlelists.snoop_addresses (m)
        return
    x = wlelists.is_in_list (m, 'whitelist')
    if x:
        wlemail.add_action (m, 'White list (%s)' % x)
        handle_ok (m)
        if wleconfig.config.getboolean ('DEFAULT', 'confirm_whitelist'):
            wlelists.add_confirmed (m.msenders)
        return
    if wlelists.is_in_confirmed_list (m.msenders):
        wlemail.add_action (m, 'Sender found in authorized list')
        handle_ok (m)
        return
    if wlemail.from_mailinglist (m):
        wlemail.add_action (m, 'Bulk mail')
        wleconfirm.deliver_mail (m, 'bulkbox')
        count_bulk ()
        return
    if wlemail.is_junk (m):
        wlemail.add_action (m, 'Junk mail')
        wleconfirm.deliver_mail (m, 'junkbox')
        count_junk ()
        return
    # A new confirmation request is a good time to cleanup databases
    wleconfirm.cleanup_dbs ()
    wleconfirm.queue (m)
    count_queued ()
    return