Ejemplo n.º 1
0
def can_send_confirmation(recipient):
    db = wledb.connect_db()
    c = db.cursor()
    c.execute("select stamp from confirmations where email='%s' " % recipient)
    if c.rowcount == 0: return True
    mdh = wleconfig.config.getfloat('DEFAULT', 'minimum_delay_hours')
    return (time.time() - float(c.fetchone()[0])) / 3600 >= mdh
Ejemplo n.º 2
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
Ejemplo n.º 3
0
def can_send_confirmation (recipient):
    db = wledb.connect_db ()
    c = db.cursor ()
    c.execute ("select stamp from confirmations where email='%s' " % recipient)
    if c.rowcount == 0: return True
    mdh = wleconfig.config.getfloat ('DEFAULT', 'minimum_delay_hours')
    return (time.time () - float (c.fetchone()[0])) / 3600 >= mdh
Ejemplo n.º 4
0
def cleanup_dbs():
    min = time.time () - \
          86400 * wleconfig.config.getfloat ('DEFAULT', 'cleanup_days')
    db = wledb.connect_db()
    c = db.cursor()
    c.execute("delete from confirmations where stamp < %f" % min)
    c.execute("delete from old_requests where stamp < %f" % min)
    db.commit()
Ejemplo n.º 5
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()
Ejemplo n.º 6
0
def cleanup_dbs ():
    min = time.time () - \
          86400 * wleconfig.config.getfloat ('DEFAULT', 'cleanup_days')
    db = wledb.connect_db ()
    c = db.cursor ()
    c.execute ("delete from confirmations where stamp < %f" % min)
    c.execute ("delete from old_requests where stamp < %f" % min)
    db.commit ()
Ejemplo n.º 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 ()
Ejemplo n.º 8
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 ()
Ejemplo n.º 9
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()
Ejemplo n.º 10
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
Ejemplo n.º 11
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