def test_global_override(self): """Test basic config overrdide functionality""" suspect = Suspect( u'*****@*****.**', '*****@*****.**', '/dev/null') candidate = DBConfig(self.config, suspect) candidate.add_section('testsection') candidate.set('testsection', 'nooverride', '100') candidate.set('testsection', 'override', '100') self.clear_table() self.insert_override( '*****@*****.**', 'testsection', 'override', '200') self.insert_override( '%unittests.fuglu.org', 'testsection', 'override', '300') self.insert_override('$GLOBAL', 'testsection', 'override', '400') self.assertEqual(candidate.getint('testsection', 'nooverride'), 100) self.assertEqual(candidate.getint('testsection', 'override'), 400)
def test_global_override(self): """Test basic config overrdide functionality""" suspect = Suspect(u'*****@*****.**', '*****@*****.**', '/dev/null') candidate = DBConfig(self.config, suspect) candidate.add_section('testsection') candidate.set('testsection', 'nooverride', '100') candidate.set('testsection', 'override', '100') self.clear_table() self.insert_override('*****@*****.**', 'testsection', 'override', '200') self.insert_override('%unittests.fuglu.org', 'testsection', 'override', '300') self.insert_override('$GLOBAL', 'testsection', 'override', '400') self.assertEqual(candidate.getint('testsection', 'nooverride'), 100) self.assertEqual(candidate.getint('testsection', 'override'), 400)
def examine(self, suspect): # check if someone wants to skip sa checks if suspect.get_tag('SAPlugin.skip') == True: self.logger.debug( 'Skipping SA Plugin (requested by previous plugin)') suspect.set_tag( 'SAPlugin.skipreason', 'requested by previous plugin') return runtimeconfig = DBConfig(self.config, suspect) spamsize = suspect.size maxsize = self.config.getint(self.section, 'maxsize') spamheadername = self.config.get(self.section, 'spamheader') if spamsize > maxsize: self.logger.info('%s Size Skip, %s > %s' % (suspect.id, spamsize, maxsize)) suspect.debug('Too big for spamchecks. %s > %s' % (spamsize, maxsize)) prependheader = self.config.get('main', 'prependaddedheaders') suspect.addheader( "%sSA-SKIP" % prependheader, 'Too big for spamchecks. %s > %s' % (spamsize, maxsize)) suspect.set_tag('SAPlugin.skipreason', 'size skip') return self.check_sql_blacklist(suspect) forwardoriginal = self.config.getboolean( self.section, 'forwardoriginal') if self.config.getboolean(self.section, 'scanoriginal'): spam = suspect.get_original_source() else: spam = suspect.get_source() # prepend temporary headers set by other plugins tempheader = suspect.get_tag('SAPlugin.tempheader') if tempheader != None: if type(tempheader) == list: tempheader = "\r\n".join(tempheader) tempheader = tempheader.strip() if tempheader != '': spam = tempheader + '\r\n' + spam if forwardoriginal: ret = self.safilter_report(spam, suspect.to_address) if ret == None: suspect.debug('SA report Scan failed - please check error log') self.logger.error('%s SA report scan FAILED' % suspect.id) suspect.addheader( '%sSA-SKIP' % self.config.get('main', 'prependaddedheaders'), 'SA scan failed') suspect.set_tag('SAPlugin.skipreason', 'scan failed') return self._problemcode() isspam, spamscore, report = ret suspect.tags['SAPlugin.report'] = report else: filtered = self.safilter(spam, suspect.to_address) content = None if filtered == None: suspect.debug('SA Scan failed - please check error log') self.logger.error('%s SA scan FAILED' % suspect.id) suspect.addheader( '%sSA-SKIP' % self.config.get('main', 'prependaddedheaders'), 'SA scan failed') suspect.set_tag('SAPlugin.skipreason', 'scan failed') return self._problemcode() else: content = filtered newmsgrep = email.message_from_string(content) suspect.set_source(content) isspam, spamscore = self._extract_spamstatus( newmsgrep, spamheadername, suspect) action = DUNNO message = None if isspam: self.logger.debug('Message is spam') suspect.debug('Message is spam') configaction = string_to_actioncode( runtimeconfig.get(self.section, 'lowspamaction'), self.config) if configaction != None: action = configaction values = dict(spamscore=spamscore) message = apply_template( self.config.get(self.section, 'rejectmessage'), suspect, values) else: self.logger.debug('Message is not spam') suspect.debug('Message is not spam') suspect.tags['spam']['SpamAssassin'] = isspam suspect.tags['highspam']['SpamAssassin'] = False if spamscore != None: suspect.tags['SAPlugin.spamscore'] = spamscore highspamlevel = runtimeconfig.getint(self.section, 'highspamlevel') if spamscore >= highspamlevel: suspect.tags['highspam']['SpamAssassin'] = True configaction = string_to_actioncode( runtimeconfig.get(self.section, 'highspamaction'), self.config) if configaction != None: action = configaction return action, message
def examine(self, suspect): # check if someone wants to skip sa checks if suspect.get_tag('SAPlugin.skip') == True: self.logger.debug( 'Skipping SA Plugin (requested by previous plugin)') suspect.set_tag('SAPlugin.skipreason', 'requested by previous plugin') return runtimeconfig = DBConfig(self.config, suspect) spamsize = suspect.size maxsize = self.config.getint(self.section, 'maxsize') spamheadername = self.config.get(self.section, 'spamheader') if spamsize > maxsize: self.logger.info('%s Size Skip, %s > %s' % (suspect.id, spamsize, maxsize)) suspect.debug('Too big for spamchecks. %s > %s' % (spamsize, maxsize)) prependheader = self.config.get('main', 'prependaddedheaders') suspect.addheader( "%sSA-SKIP" % prependheader, 'Too big for spamchecks. %s > %s' % (spamsize, maxsize)) suspect.set_tag('SAPlugin.skipreason', 'size skip') return self.check_sql_blacklist(suspect) forwardoriginal = self.config.getboolean(self.section, 'forwardoriginal') if self.config.getboolean(self.section, 'scanoriginal'): spam = suspect.get_original_source() else: spam = suspect.get_source() # prepend temporary headers set by other plugins tempheader = suspect.get_tag('SAPlugin.tempheader') if tempheader != None: if type(tempheader) == list: tempheader = "\r\n".join(tempheader) tempheader = tempheader.strip() if tempheader != '': spam = tempheader + '\r\n' + spam if forwardoriginal: ret = self.safilter_report(spam, suspect.to_address) if ret == None: suspect.debug('SA report Scan failed - please check error log') self.logger.error('%s SA report scan FAILED' % suspect.id) suspect.addheader( '%sSA-SKIP' % self.config.get('main', 'prependaddedheaders'), 'SA scan failed') suspect.set_tag('SAPlugin.skipreason', 'scan failed') return self._problemcode() isspam, spamscore, report = ret suspect.tags['SAPlugin.report'] = report else: filtered = self.safilter(spam, suspect.to_address) content = None if filtered == None: suspect.debug('SA Scan failed - please check error log') self.logger.error('%s SA scan FAILED' % suspect.id) suspect.addheader( '%sSA-SKIP' % self.config.get('main', 'prependaddedheaders'), 'SA scan failed') suspect.set_tag('SAPlugin.skipreason', 'scan failed') return self._problemcode() else: content = filtered newmsgrep = email.message_from_string(content) suspect.set_source(content) isspam, spamscore = self._extract_spamstatus( newmsgrep, spamheadername, suspect) action = DUNNO message = None if isspam: self.logger.debug('Message is spam') suspect.debug('Message is spam') configaction = string_to_actioncode( runtimeconfig.get(self.section, 'lowspamaction'), self.config) if configaction != None: action = configaction values = dict(spamscore=spamscore) message = apply_template( self.config.get(self.section, 'rejectmessage'), suspect, values) else: self.logger.debug('Message is not spam') suspect.debug('Message is not spam') suspect.tags['spam']['SpamAssassin'] = isspam suspect.tags['highspam']['SpamAssassin'] = False if spamscore != None: suspect.tags['SAPlugin.spamscore'] = spamscore highspamlevel = runtimeconfig.getint(self.section, 'highspamlevel') if spamscore >= highspamlevel: suspect.tags['highspam']['SpamAssassin'] = True configaction = string_to_actioncode( runtimeconfig.get(self.section, 'highspamaction'), self.config) if configaction != None: action = configaction return action, message
def examine(self,suspect): #check if someone wants to skip sa checks if suspect.get_tag('SAPlugin.skip')==True: self.logger.debug('Skipping SA Plugin (requested by previous plugin)') suspect.set_tag('SAPlugin.skipreason','requested by previous plugin') return runtimeconfig=DBConfig(self.config, suspect) spamsize=suspect.size maxsize=self.config.getint(self.section, 'maxsize') spamheadername=self.config.get(self.section,'spamheader') if spamsize>maxsize: self.logger.info('%s Size Skip, %s > %s'%(suspect.id,spamsize,maxsize)) suspect.debug('Too big for spamchecks. %s > %s'%(spamsize,maxsize)) prependheader=self.config.get('main','prependaddedheaders') suspect.addheader("%sSA-SKIP"%prependheader, 'Too big for spamchecks. %s > %s'%(spamsize,maxsize)) suspect.set_tag('SAPlugin.skipreason','size skip') return self.check_sql_blacklist(suspect) starttime=time.time() forwardoriginal=self.config.getboolean(self.section,'forwardoriginal') if self.config.getboolean(self.section,'scanoriginal'): spam=suspect.getOriginalSource() else: spam=suspect.getSource() #prepend temporary headers set by other plugins tempheader=suspect.get_tag('SAPlugin.tempheader') if tempheader!=None: if type(tempheader)==list: tempheader="\r\n".join(tempheader) tempheader=tempheader.strip() if tempheader!='': spam=tempheader+'\r\n'+spam if forwardoriginal: ret=self.safilter_report(spam, suspect.to_address) if ret==None: suspect.debug('SA report Scan failed - please check error log') self.logger.error('%s SA report scan FAILED'%suspect.id) suspect.addheader('%sSA-SKIP'%self.config.get('main','prependaddedheaders'),'SA scan failed') suspect.set_tag('SAPlugin.skipreason','scan failed') return self._problemcode() isspam,spamscore,report=ret suspect.tags['SAPlugin.report']=report else: filtered=self.safilter(spam,suspect.to_address) content=None if filtered==None: suspect.debug('SA Scan failed - please check error log') self.logger.error('%s SA scan FAILED'%suspect.id) suspect.addheader('%sSA-SKIP'%self.config.get('main','prependaddedheaders'),'SA scan failed') suspect.set_tag('SAPlugin.skipreason','scan failed') return self._problemcode() else: content=filtered newmsgrep=email.message_from_string(content) suspect.setSource(content) isspam=False spamheader=newmsgrep[spamheadername] spamscore=None if spamheader==None: self.logger.warning('Did not find Header %s in returned message from SA'%spamheadername) else: if len(spamheader)>2 and 'yes' in spamheader.lower(): isspam=True patt=re.compile('Score=([\-\d\.]+)',re.IGNORECASE) m=patt.search(spamheader) if m !=None: spamscore=float(m.group(1)) self.logger.debug('Spamscore: %s'%spamscore) suspect.debug('Spamscore: %s'%spamscore) else: self.logger.warning('Could not extract spam score from header: %s'%spamheader) suspect.debug('Could not read spam score from header %s'%spamheader) action=DUNNO message=None if isspam: self.logger.debug('Message is spam') suspect.debug('Message is spam') configaction=string_to_actioncode(runtimeconfig.get(self.section,'lowspamaction'),self.config) if configaction!=None: action=configaction values=dict(spamscore=spamscore) message=apply_template(self.config.get(self.section,'rejectmessage'), suspect, values) else: self.logger.debug('Message is not spam') suspect.debug('Message is not spam') suspect.tags['spam']['SpamAssassin']=isspam suspect.tags['highspam']['SpamAssassin']=False if spamscore != None: suspect.tags['SAPlugin.spamscore']=spamscore highspamlevel=runtimeconfig.getint(self.section,'highspamlevel') if spamscore>=highspamlevel: suspect.tags['highspam']['SpamAssassin']=True configaction=string_to_actioncode(runtimeconfig.get(self.section,'highspamaction'),self.config) if configaction!=None: action=configaction endtime=time.time() difftime=endtime-starttime suspect.tags['SAPlugin.time']="%.4f"%difftime return action,message