def delete(self):
     dayto = datetime.datetime.now()
     datefrom = DateUtils.getDate(dayto, constants.TIME_LIMIT)
     sql = "delete from mails where (state=%s or state<0) and finish_time < '%s'::timestamp" % (
         constants.MAIL_SUCCESS, datefrom)
     #print sql
     return dbconn().delete(sql)
def isContinue(mail):
    dayto = datetime.datetime.now()
    datefrom = DateUtils.getDate(dayto, constants.TIME_LIMIT)
    
    sql = "select count(*) as count from mails where smtp_host='%s' and state=5 and finish_time between '%s'::timestamp and '%s'::timestamp" % (mail['smtp_host'], datefrom, dayto)
    result = dbconn().getOne(sql)
    if result['count'] >= constants.TIME_MAX_COUNT:
        return True
    else:
        return False    
    def isContinue(self, mail):
        dayto = datetime.datetime.now()
        datefrom = DateUtils.getDate(dayto, constants.TIME_LIMIT)

        sql = "select count(*) as count from mails where smtp_host='%s' and state=5 and finish_time between '%s'::timestamp and '%s'::timestamp" % (
            mail['smtp_host'], datefrom, dayto)
        result = dbconn().getOne(sql)
        if result['count'] >= constants.TIME_MAX_COUNT:
            return True
        else:
            return False
 def delete(self):
     dayto = datetime.datetime.now()
     datefrom = DateUtils.getDate(dayto, constants.TIME_LIMIT)
     sql = "delete from mails where (state=%s or state<0) and finish_time < '%s'::timestamp"% (constants.MAIL_SUCCESS, datefrom)
     #print sql
     return dbconn().delete(sql)