def dspam_pass(key, get_model): rkey = '{}_pass'.format(key) tmp_rkey = '{}_pass_temp'.format(key) while True: try: j = redis.brpoplpush(rkey, tmp_rkey) date, id = j.split(',')[:2] mail = get_model(date).objects.get(id=id) if mail.mail_id == 0: dspamc(file_path=mail.get_mail_path(), report='innocent', sig=mail.dspam_sig) mail.dspam_study = 2 mail.save(update_fields=['dspam_study']) redis.lrem(tmp_rkey, 0, j) # 将mail_id=0的邮件 保存到POP目录 if mail.mail_id == 0: mail.save_mail_for_pop() outinfo('{}: {}'.format(rkey, j)) if key.find('collect') == -1: _do_save_review_resutl(mail, 'pass') except BaseException as e: outerror('exception: {}'.format(j)) outerror(traceback.format_exc())
def dspam_reject_from_path(dspam_path, get_model): while True: mails = os.listdir(dspam_path) if not mails: gevent.sleep(1) continue for mail in mails: try: mail_path = os.path.join(dspam_path, mail) if not os.path.exists(mail_path): continue try: date, id = mail.split(',')[:2] sig = get_model(date).objects.get(id=id).dspam_sig except Exception, e: sig = '' dspamc(file_path=mail_path, report='spam', sig=sig) outinfo('{}: imap reject'.format(mail)) try: os.remove(mail_path) except: outerror('remove error: {}'.format(mail)) outerror(traceback.format_exc()) except BaseException as e: outerror('exception: {}'.format(mail)) outerror(traceback.format_exc())
def _dspamc(self): if setting.dspam_max_size and self.size > setting.dspam_max_size: return False res = dspamc(self.mail_path) #self.mail_obj.dspam_sig = res.get('signature', '') result = res.get('class', '') if result in ['virus', 'spam']: message = res.get('message', '') self.mail_obj.check_result = result self.mail_obj.check_message = message outinfo('[Dspam] {}: {}'.format(self.task, message)) return True return False
def dspam_reject(key, get_model): rkey = '{}_reject'.format(key) tmp_rkey = '{}_reject_temp'.format(key) while True: try: j = redis.brpoplpush(rkey, tmp_rkey) date, id = j.split(',')[:2] mail = get_model(date).objects.get(id=id) if mail.check_result not in ['spam', 'virus' ] and mail.mail_id == 0: dspamc(file_path=mail.get_mail_path(), report='spam', sig=mail.dspam_sig) mail.dspam_study = 1 mail.customer_report = 2 mail.save(update_fields=['dspam_study', 'customer_report']) redis.lrem(tmp_rkey, 0, j) outinfo('{}: {}'.format(rkey, j)) if key.find('collect') == -1: _do_save_review_resutl(mail, 'reject') except BaseException as e: outerror('exception: {}'.format(j)) outerror(traceback.format_exc())
def check_dspam(): while True: h = int(time.strftime('%H')) if h < 5: gevent.sleep(600) continue res = dspamc(eml_file_path) outinfo(res) sig = res.get('result', '') if not sig: outinfo('restart server') outinfo('restart postgres') subprocess.call('/etc/init.d/postgresql_dspam restart', shell=True) outinfo('restart dsapm') subprocess.call('/etc/init.d/dspam restart', shell=True) outinfo('restart server end') gevent.sleep(600)
def _dspamc(self): if not self.customer_setting.check_dspam: return False if setting.dspam_max_size and self.size > setting.dspam_max_size: return False try: with gevent.Timeout(60): #res = dspamc2(self.mail_content) res = dspamc(self.mail_path) #self.mail_obj.dspam_sig = res.get('signature', '') result = res.get('class', '') if result in ['virus', 'spam']: message = res.get('message', '') self.mail_obj.check_result = result self.mail_obj.check_message = message outinfo(u'[Dspam] {}: {}'.format(self.task_info, message)) return True except gevent.Timeout: outerror(u'dspam check time out :{}'.format(self.task_info)) outerror(traceback.format_exc()) except BaseException as e: outerror(u'dspam check error :{}'.format(self.task_info)) outerror(traceback.format_exc()) return False