Exemplo n.º 1
0
        def _do_error_type(self):
            """
            根据错误类型进行相应操作,
            在日志回传保存的 server.py中调用
            :return:
            """
            # 保存无效地址
            redis = get_redis_connection()
            if self.error_type == 2:
                InvalidMail.objects.get_or_create(mail=self.mail_to.lower())

            # 垃圾邮件发送者 加入动态spam检测队列
            if self.error_type == 5:
                redis_key = 'relay_spam_sender_history'
                mail_from = self.mail_from.lower()
                s = redis.hget(redis_key, mail_from)
                if s:
                    s = '{},{}'.format(int(time.time()), s)
                else:
                    s = str(int(time.time()))
                redis.hset(redis_key, mail_from, s)
                redis.hset(redis_key, 'is_need_update', 'True')
                # if not redis.hexists(redis_key, mail_from):
                # redis.hset('relay_spam_sender', mail_from, time.time())

            # spf错误域名 保存到SpfError
            if self.error_type == 7:
                domain = self.mail_from.split('@')[-1]
                SpfError.objects.get_or_create(domain=domain, customer=self.customer)
Exemplo n.º 2
0
 def can_undo(self):
     """客户每天误判操作不能超过100次"""
     key = 'customer_pass_undo'
     redis = get_redis_connection()
     try:
         undo_count = int(redis.hget(key, self.customer.id))
     except:
         undo_count = 0
     return undo_count < 100
Exemplo n.º 3
0
def _do_review(ids, result, request):
    """
    :param ids: 审核的ID列表
    :param result: 审核结果
    :param flag: 是否正常流程操作, 默认:True, 如果是误判操作,则为False
    :return:
    """
    keys = {}
    redis = get_redis_connection()
    reviewer = request.user
    review_time = datetime.datetime.now()
    msg = u'通过' if result == 'pass' else u'拒绝'
    mails = LocalizedMail.objects.filter(id__in=ids, state='review')
    count = mails.count()
    if result == 'pass':
        mails.update(state='passing', reviewer=reviewer, review_time=review_time)
    elif result == 'reject':
        mails.update(state='rejecting', reviewer=reviewer, review_time=review_time)
    map(lambda key: redis.lpush('control_review_result', key), ids)
    return msg, count
Exemplo n.º 4
0
def mail_summary(request):
    # for m in get_mail_model('20170531').objects.filter(customer_id=2291):
    #     LocalizedMail.objects.create(customer_id=2291, mail_from=m.mail_from,
    #                                  mail_to=m.mail_to, state=m.state,
    #                                  created=m.created, subject=m.subject,
    #                                  check_result=m.check_result, check_message=m.check_message,
    #                                  mail_id=m.date_id()
    #     )
    if request.method == "POST":
        action = request.POST.get("action", '')
        if action == "refresh":
            redis = get_redis_connection()
            map(lambda k: redis.delete(k),
                filter(lambda k: k.startswith(':1:_cache:localized_mail_status'), redis.keys()))
            return HttpResponseRedirect(request.get_full_path())
    start = request.GET.get('start', '')
    end = request.GET.get('end', '')
    date_end = datetime.datetime.today()
    date_start = date_end - datetime.timedelta(days=14)
    if start or end:
        if start:
            date_start = datetime.datetime.strptime(start, '%Y-%m-%d')
        if end:
            date_end = datetime.datetime.strptime(end, '%Y-%m-%d')
        if end and not start:
            date_end = date_end - datetime.timedelta(days=30)

    index = 1
    date = date_start
    res = {}
    while True:
        if index > 30 or date > date_end:
            break
        res[date.strftime('%Y-%m-%d')] = get_state_data(date)

        date = date + datetime.timedelta(days=1)
        index += 1

    return render_to_response("localized_mail/mail_summary.html", {
        'res': res
    }, context_instance=RequestContext(request))
Exemplo n.º 5
0
def mail_summary(request):
    if request.method == "POST":
        action = request.POST.get("action", '')
        if action == "refresh":
            redis = get_redis_connection()
            map(
                lambda k: redis.delete(k),
                filter(lambda k: k.startswith(':1:_cache:collect_mail_status'),
                       redis.keys()))
            return HttpResponseRedirect(request.get_full_path())
    start = request.GET.get('start', '')
    end = request.GET.get('end', '')
    date_end = datetime.datetime.today()
    date_start = date_end - datetime.timedelta(days=14)
    if start or end:
        if start:
            date_start = datetime.datetime.strptime(start, '%Y-%m-%d')
        if end:
            date_end = datetime.datetime.strptime(end, '%Y-%m-%d')
        if end and not start:
            date_end = date_end - datetime.timedelta(days=30)

    index = 1
    date = date_start
    res = {}
    while True:
        if index > 30 or date > date_end:
            break
        date_str = date.strftime('%Y-%m-%d')
        res[date_str] = get_state_data(date_str)

        date = date + datetime.timedelta(days=1)
        index += 1

    return render_to_response("collect_mail/mail_summary.html", {'res': res},
                              context_instance=RequestContext(request))