def test_modified_message(self): """Test if the modified message gets archived correctly""" from fuglu.shared import Suspect import shutil import tempfile tempfilename=tempfile.mktemp(suffix='archive', prefix='fuglu-unittest', dir='/tmp') shutil.copy('testdata/helloworld.eml',tempfilename) self.tempfiles.append(tempfilename) # self.config.set('ArchivePlugin', 'storeoriginal', '0') candidate=ArchivePlugin(self.config) suspect=Suspect('*****@*****.**', '*****@*****.**', tempfilename) origmessage=suspect.getSource() #modify the mesg msgrep= suspect.get_message_rep() msgrep['X-Changed-Something']='Yes' suspect.setMessageRep(msgrep) filename=candidate.archive(suspect) self.assertTrue(filename!=None and filename) self.tempfiles.append(filename) archivedmessage=open(filename,'r').read() self.assertNotEqual(origmessage.strip(),archivedmessage.strip()),'Archived message should have stored modified message'
#now run examine logging.info("Running plugin: %s"%pluginstance) if opts.appender: #todo: maybe make DUNNO configurable? 2nd argument? pluginstance.process(suspect,DUNNO) else: ans = pluginstance.examine(suspect) message="" if type(ans) is tuple: result,message=ans else: result=ans if result==None: result=DUNNO logging.info("Result: %s %s",actioncode_to_string(result), message) logging.info(suspect) if suspect.is_modified(): outfilename='/tmp/fuglu_dummy_message_out.eml' out=open(outfilename,'wb') out.write(suspect.getSource()) out.close() logging.info("Plugin modified the source -> modified message available as %s"%outfilename) if opts.console: run_debugconsole(suspect=suspect, plugin=pluginstance, result=result, config=config)