Example #1
0
def deliver (key):
    count_delivered ()
    wlelog.log (3, 'Unblocking mail with key %s' % key)
    return move_message_from_queue (key, 'mailbox',
                                    'Confirmed (%s)' % \
                                    time.ctime (time.time()),
                                    True)
Example #2
0
def deliver(key):
    count_delivered()
    wlelog.log(3, 'Unblocking mail with key %s' % key)
    return move_message_from_queue (key, 'mailbox',
                                    'Confirmed (%s)' % \
                                    time.ctime (time.time()),
                                    True)
Example #3
0
def confirmation (m, key):
    recipient = wlemail.senders(m)[0]
    recipient_email = recipient[1]
    if not can_send_confirmation (recipient_email):
        wlelog.log (3, "Not sending duplicate confirmation to %s" % \
                    email.Utils.formataddr (recipient))
        return None
    wlelog.log (3, "Sending confirmation request to %s" % \
                email.Utils.formataddr (recipient))
    r = MIMEMultipart ()
    subject = m.get ('subject')
    if not subject: subject = '...'
    rsubject = '[confirm #%s] %s' % (key, wlemail.make_answer (subject))
    r['X-WLE-confirmation'] = 'yes'
    r['Precedence'] = 'bulk'
    rfrom = email.Utils.formataddr \
            ((wleconfig.config.get ('DEFAULT', 'myname'),
              confirmation_sender (m)))
    rto = email.Utils.formataddr (recipient)
    wlemail.complete_message (r, rfrom, rto, rsubject)
    try: r['In-Reply-To'] = m.get ('message-id')
    except: pass
    excuse = MIMEText (makeup_excuse (key), 'plain',
                       wleconfig.config.get ('DEFAULT', 'charset'))
    excuse['Content-Disposition'] = 'inline'
    r.attach (excuse)
    origin = MIMEMessage (m)
    origin['Content-Disposition'] = 'attachment'
    r.attach (origin)
    db = wledb.connect_db ()
    c = db.cursor ()
    c.execute ("insert into confirmations values ('%s', %f)" %
               (recipient_email, time.time ()))
    db.commit ()
    return r
Example #4
0
def handle_confirmation(m, key):
    wlelog.log(3, 'Confirmation found with key %s' % key)
    unqueued = wleconfirm.deliver(key)
    wlelists.snoop_addresses(unqueued)
    wleconfirm.check_discuss(unqueued)
    if wleconfig.config.getboolean('DEFAULT', 'allow_confirmer'):
        wlelists.snoop_addresses(m)
    wleconfirm.deliver_mail(m, 'confirmedbox')
Example #5
0
def handle_confirmation (m, key):
    wlelog.log (3, 'Confirmation found with key %s' % key)
    unqueued = wleconfirm.deliver (key)
    wlelists.snoop_addresses (unqueued)
    wleconfirm.check_discuss (unqueued)
    if wleconfig.config.getboolean ('DEFAULT', 'allow_confirmer'):
        wlelists.snoop_addresses (m)
    wleconfirm.deliver_mail (m, 'confirmedbox')
Example #6
0
def remove_message (key):
    wlelog.log (5, "Removing queue file %s" % key)
    os.unlink (queue_path (key))
    db = wledb.connect_db ()
    c = db.cursor ()
    c.execute ("insert into old_requests values ('%s', %f)" %
               (key, time.time()))
    db.commit ()
Example #7
0
def remove_message(key):
    wlelog.log(5, "Removing queue file %s" % key)
    os.unlink(queue_path(key))
    db = wledb.connect_db()
    c = db.cursor()
    c.execute("insert into old_requests values ('%s', %f)" %
              (key, time.time()))
    db.commit()
Example #8
0
def deliver_mail (m, mailbox):
    mn = wleconfig.config.get ('DEFAULT', mailbox)
    if mn[0] == '|':
        wlelog.log (4, "Delivering to program %s" % string.strip (mn[1:]))
        fd = os.popen (mn[1:], 'w')
    else:
        wlelog.log (4, "Delivering to mailbox %s" % string.strip (mn))
        fd = open (mn, 'a')
    fd.write (m.as_string (True))
Example #9
0
def deliver_mail(m, mailbox):
    mn = wleconfig.config.get('DEFAULT', mailbox)
    if mn[0] == '|':
        wlelog.log(4, "Delivering to program %s" % string.strip(mn[1:]))
        fd = os.popen(mn[1:], 'w')
    else:
        wlelog.log(4, "Delivering to mailbox %s" % string.strip(mn))
        fd = open(mn, 'a')
    fd.write(m.as_string(True))
Example #10
0
def complete_and_send(m, subject, content):
    sender = wleconfirm.confirmation_sender(m)
    wlelog.log(3, 'Sending %s to %s' % (subject, sender))
    rfrom = "WLE email program <%s>" % sender
    rto = email.Utils.formataddr \
          ((wleconfig.config.get ('DEFAULT', 'myname'), sender))
    r = MIMEText(content, 'plain', wleconfig.config.get('DEFAULT', 'charset'))
    wlemail.complete_message(r, rfrom, rto, subject)
    wlemail.add_magic(r)
    wleconfirm.deliver_mail(r, 'mailbox')
Example #11
0
def complete_and_send (m, subject, content):
    sender = wleconfirm.confirmation_sender (m)
    wlelog.log (3, 'Sending %s to %s' % (subject, sender))
    rfrom = "WLE email program <%s>" % sender
    rto = email.Utils.formataddr \
          ((wleconfig.config.get ('DEFAULT', 'myname'), sender))
    r = MIMEText (content, 'plain',
                  wleconfig.config.get ('DEFAULT', 'charset'))
    wlemail.complete_message (r, rfrom, rto, subject)
    wlemail.add_magic (r)
    wleconfirm.deliver_mail (r, 'mailbox')
Example #12
0
def handle_action(action, key):
    if not wleconfirm.is_key(key):
        wlelog.log(4, "%s is not a valid key, ignoring" % key)
        return
    if action == 'W':
        unqueued = wleconfirm.deliver(key)
        wlelists.snoop_addresses(unqueued)
    elif action == 'D':
        wleconfirm.deliver(key)
    elif action == 'R':
        try:
            wleconfirm.move_message_from_queue(key, 'junkbox',
                                               'Removed or expired')
        except:
            pass
        count_junk()
Example #13
0
def handle_action (action, key):
    if not wleconfirm.is_key (key):
        wlelog.log (4, "%s is not a valid key, ignoring" % key)
        return
    if action == 'W':
        unqueued = wleconfirm.deliver (key)
        wlelists.snoop_addresses (unqueued)
    elif action == 'D':
        wleconfirm.deliver (key)
    elif action == 'R':
        try:
            wleconfirm.move_message_from_queue (key, 'junkbox',
                                                'Removed or expired')
        except:
            pass
        count_junk ()
Example #14
0
def add_confirmed(l):
    db = wledb.connect_db()
    c = db.cursor()
    wl = wleconfig.config.getboolean('DEFAULT', 'confirm_whitelist')
    for i in l:
        if not _well_formed_re.match(i): continue
        m = email.Message.Message()
        m['From'] = i
        wlemail.parse_message(m)
        if not wl and is_in_list(m, 'whitelist'): continue
        if wleconfirm.is_mine([i]): continue
        if not is_in_confirmed_list([i], c):
            wlelog.log(2, 'Adding %s as authorized address' % i)
            c.execute("insert into confirmed values ('%s', %f)" %
                      (i.lower(), time.time()))
            count_authorized()
            wleconfirm.also_unblock(i)
    db.commit()
Example #15
0
def add_confirmed (l):
    db = wledb.connect_db ()
    c = db.cursor ()
    wl = wleconfig.config.getboolean ('DEFAULT', 'confirm_whitelist')
    for i in l:
        if not _well_formed_re.match (i): continue
        m = email.Message.Message ()
        m['From'] = i
        wlemail.parse_message (m)
        if not wl and is_in_list (m, 'whitelist'): continue
        if wleconfirm.is_mine ([i]): continue
        if not is_in_confirmed_list ([i], c):
            wlelog.log (2, 'Adding %s as authorized address' % i)
            c.execute ("insert into confirmed values ('%s', %f)" %
                       (i.lower(), time.time ()))
            count_authorized ()
            wleconfirm.also_unblock (i)            
    db.commit ()
Example #16
0
def confirmation(m, key):
    recipient = wlemail.senders(m)[0]
    recipient_email = recipient[1]
    if not can_send_confirmation(recipient_email):
        wlelog.log (3, "Not sending duplicate confirmation to %s" % \
                    email.Utils.formataddr (recipient))
        return None
    wlelog.log (3, "Sending confirmation request to %s" % \
                email.Utils.formataddr (recipient))
    r = MIMEMultipart()
    subject = m.get('subject')
    if not subject: subject = '...'
    rsubject = '[confirm #%s] %s' % (key, wlemail.make_answer(subject))
    r['X-WLE-confirmation'] = 'yes'
    r['Precedence'] = 'bulk'
    rfrom = email.Utils.formataddr \
            ((wleconfig.config.get ('DEFAULT', 'myname'),
              confirmation_sender (m)))
    rto = email.Utils.formataddr(recipient)
    wlemail.complete_message(r, rfrom, rto, rsubject)
    try:
        r['In-Reply-To'] = m.get('message-id')
    except:
        pass
    excuse = MIMEText(makeup_excuse(key), 'plain',
                      wleconfig.config.get('DEFAULT', 'charset'))
    excuse['Content-Disposition'] = 'inline'
    r.attach(excuse)
    origin = MIMEMessage(m)
    origin['Content-Disposition'] = 'attachment'
    r.attach(origin)
    db = wledb.connect_db()
    c = db.cursor()
    c.execute("insert into confirmations values ('%s', %f)" %
              (recipient_email, time.time()))
    db.commit()
    return r
Example #17
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
Example #18
0
        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

try:
    wleconfig.read_config ()
    wlelog.log (9, 'Starting')
    wlelock.lock ()
    wlelog.log (9, 'Lock taken')
    try:
        logic (email.Parser.Parser().parse(sys.stdin))
    except:
        wlelog.log (1, 'Exception raised')
        t, v, tb = sys.exc_info ()
        import traceback
        lines = traceback.format_exception (t, v, tb)
        for i in lines:
            sys.stderr.write (i)
            wlelog.log (2, i[:-1])
        sys.exit (1)
finally:
    wlelog.log (9, 'Releasing lock')
Example #19
0
def handle_command_queue_status (m):
    wlelog.log (3, 'Working on queue')
    lines = string.split (m.as_string(), '\n')
    for i in lines:
        x = _command_re.search (i)
        if x: handle_action (x.group(1).upper(), x.group(2))
Example #20
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
Example #21
0
def log_summary(m):
    for i in ['From', 'Subject', 'To', 'Cc', 'Bcc', 'Message-Id']:
        if m.has_key(i):
            wlelog.log(5, '%s: %s' % (i, m[i]))
Example #22
0
def handle_command_queue_status(m):
    wlelog.log(3, 'Working on queue')
    lines = string.split(m.as_string(), '\n')
    for i in lines:
        x = _command_re.search(i)
        if x: handle_action(x.group(1).upper(), x.group(2))
Example #23
0
        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


try:
    wleconfig.read_config()
    wlelog.log(9, 'Starting')
    wlelock.lock()
    wlelog.log(9, 'Lock taken')
    try:
        logic(email.Parser.Parser().parse(sys.stdin))
    except:
        wlelog.log(1, 'Exception raised')
        t, v, tb = sys.exc_info()
        import traceback
        lines = traceback.format_exception(t, v, tb)
        for i in lines:
            sys.stderr.write(i)
            wlelog.log(2, i[:-1])
        sys.exit(1)
finally:
    wlelog.log(9, 'Releasing lock')
Example #24
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
Example #25
0
def log_summary (m):
    for i in ['From', 'Subject', 'To', 'Cc', 'Bcc', 'Message-Id']:
        if m.has_key (i):
            wlelog.log (5, '%s: %s' % (i, m[i]))
Example #26
0
def add_action(m, action):
    wlelog.log(4, 'Adding action: %s' % action)
    m['X-WLE-Action'] = action
Example #27
0
def add_action (m, action):
    wlelog.log (4, 'Adding action: %s' % action)
    m['X-WLE-Action'] = action