def test_ignore_sender(self): from fuglu.shared import Suspect v = Vacation() v.ignoresender = u"unittests.fuglu.org [email protected]" v.awayuser = u'*****@*****.**' v.created = datetime.now() v.start = datetime.now() v.end = v.start + timedelta(days=2) v.subject = u'gone for good' v.body = u'outta here' self.session.add(v) self.session.flush() self.session.expunge_all() self.refreshcache() suspect = Suspect('*****@*****.**', '*****@*****.**', '/dev/null') suspect.set_tag('nobounce', True) candidatevacation = self.candidate.on_vacation(suspect) self.assertTrue(candidatevacation != None, "Vacation object not found in database") # TODO had to disable due to sqlalchemy error # Instance <Vacation at 0x2938890> is not bound to a Session; attribute refresh operation cannot proceed #self.assertEqual(v.ignoresender,candidatevacation.ignoresender,"Vacation object did not get ignore list") self.assertTrue( self.candidate.ignore_sender(candidatevacation, suspect), "Test Message should generate vacation reply(ignored sender)") self.assertFalse( self.candidate.should_send_vacation_message(suspect), "Sender on ignorelist, still wants to send message?!")
def test_localpartblacklist(self): """test messages from mailer-daemon""" from fuglu.shared import Suspect import email v = Vacation() v.ignoresender = u"" v.awayuser = u'*****@*****.**' v.created = datetime.now() v.start = datetime.now() v.end = v.start + timedelta(days=2) v.subject = u'awaaay' v.body = u'cya' self.session.add(v) self.session.flush() self.session.expunge_all() self.refreshcache() botmsg = """From: [email protected] Subject: mailinglist membership reminder... """ suspect = Suspect('*****@*****.**', '*****@*****.**', '/dev/null') suspect.set_tag('nobounce', True) suspect.set_source(botmsg) candidatevacation = self.candidate.on_vacation(suspect) self.assertTrue(candidatevacation != None, "Vacation object not found in database") self.assertFalse( self.candidate.should_send_vacation_message(suspect), "Test Message should NOT generate vacation reply(automated)")
def test_ignore_sender(self): from fuglu.shared import Suspect v = Vacation() v.ignoresender = u"unittests.fuglu.org [email protected]" v.awayuser = u'*****@*****.**' v.created = datetime.now() v.start = datetime.now() v.end = v.start + timedelta(days=2) v.subject = u'gone for good' v.body = u'outta here' self.session.add(v) self.session.flush() self.session.expunge_all() self.refreshcache() suspect = Suspect( '*****@*****.**', '*****@*****.**', '/dev/null') suspect.set_tag('nobounce', True) candidatevacation = self.candidate.on_vacation(suspect) self.assertTrue( candidatevacation != None, "Vacation object not found in database") # TODO had to disable due to sqlalchemy error # Instance <Vacation at 0x2938890> is not bound to a Session; attribute refresh operation cannot proceed #self.assertEqual(v.ignoresender,candidatevacation.ignoresender,"Vacation object did not get ignore list") self.assertTrue(self.candidate.ignore_sender( candidatevacation, suspect), "Test Message should generate vacation reply(ignored sender)") self.assertFalse(self.candidate.should_send_vacation_message( suspect), "Sender on ignorelist, still wants to send message?!")
def test_localpartblacklist(self): """test messages from mailer-daemon""" from fuglu.shared import Suspect import email v = Vacation() v.ignoresender = u"" v.awayuser = u'*****@*****.**' v.created = datetime.now() v.start = datetime.now() v.end = v.start + timedelta(days=2) v.subject = u'awaaay' v.body = u'cya' self.session.add(v) self.session.flush() self.session.expunge_all() self.refreshcache() botmsg = """From: [email protected] Subject: mailinglist membership reminder... """ suspect = Suspect('*****@*****.**', '*****@*****.**', '/dev/null') suspect.set_tag('nobounce', True) suspect.set_source(botmsg) candidatevacation = self.candidate.on_vacation(suspect) self.assertTrue( candidatevacation != None, "Vacation object not found in database") self.assertFalse(self.candidate.should_send_vacation_message( suspect), "Test Message should NOT generate vacation reply(automated)")
def test_vacation(self): """Test simple vacation use case""" from fuglu.shared import Suspect v = Vacation() v.ignoresender = "" v.awayuser = u'*****@*****.**' v.created = datetime.now() v.start = datetime.now() v.end = v.start + timedelta(days=2) v.subject = u'awaaay' v.body = u'cya' self.session.add(v) self.session.flush() self.session.expunge_all() self.refreshcache() suspect = Suspect(u'*****@*****.**', '*****@*****.**', '/dev/null') suspect.set_tag('nobounce', True) candidatevacation = self.candidate.on_vacation(suspect) self.assertTrue(candidatevacation != None, "Vacation object not found in database") self.assertTrue(self.candidate.should_send_vacation_message(suspect), "Test Message should generate vacation reply") self.candidate.log_bounce(suspect, candidatevacation) # TODO: had to disable due to sqlalchemy error # Instance <Vacation at 0x2938890> is not bound to a Session; attribute refresh operation cannot proceed #self.assertFalse(self.candidate.should_send_vacation_message(suspect),"2nd test Message should NOT generate vacation reply") suspect2 = Suspect(u'*****@*****.**', '*****@*****.**', '/dev/null') suspect2.set_tag('nobounce', True) candidatevacation = self.candidate.on_vacation(suspect2) self.assertFalse( candidatevacation != None, "There should be no vacation object for this recipient") self.assertFalse(self.candidate.should_send_vacation_message(suspect2), "test Message should NOT generate vacation reply")
def test_vacation(self): """Test simple vacation use case""" from fuglu.shared import Suspect v = Vacation() v.ignoresender = "" v.awayuser = u'*****@*****.**' v.created = datetime.now() v.start = datetime.now() v.end = v.start + timedelta(days=2) v.subject = u'awaaay' v.body = u'cya' self.session.add(v) self.session.flush() self.session.expunge_all() self.refreshcache() suspect = Suspect( u'*****@*****.**', '*****@*****.**', '/dev/null') suspect.set_tag('nobounce', True) candidatevacation = self.candidate.on_vacation(suspect) self.assertTrue( candidatevacation != None, "Vacation object not found in database") self.assertTrue(self.candidate.should_send_vacation_message( suspect), "Test Message should generate vacation reply") self.candidate.log_bounce(suspect, candidatevacation) # TODO: had to disable due to sqlalchemy error # Instance <Vacation at 0x2938890> is not bound to a Session; attribute refresh operation cannot proceed #self.assertFalse(self.candidate.should_send_vacation_message(suspect),"2nd test Message should NOT generate vacation reply") suspect2 = Suspect( u'*****@*****.**', '*****@*****.**', '/dev/null') suspect2.set_tag('nobounce', True) candidatevacation = self.candidate.on_vacation(suspect2) self.assertFalse(candidatevacation != None, "There should be no vacation object for this recipient") self.assertFalse(self.candidate.should_send_vacation_message( suspect2), "test Message should NOT generate vacation reply")
open(tmpfile, 'w').write(mailmessage.as_string()) logging.info("Input file created as %s" % tmpfile) suspect = Suspect(opts.sender, opts.recipients[0], tmpfile) suspect.recipients = opts.recipients # tags if opts.tags: for tagpair in opts.tags: nme, valstr = tagpair.split(':', 1) if valstr == 'TRUE': val = True elif valstr == 'FALSE': val = False else: val = valstr suspect.set_tag(nme, val) scannerlist = mc.plugins for pluginstance in mc.prependers: logging.info("*** Running prepender: %s ***" % pluginstance) result = pluginstance.pluginlist(suspect, scannerlist) if result != None: origset = set(scannerlist) resultset = set(result) removed = list(origset - resultset) added = list(resultset - origset) if len(removed) > 0: logging.info( 'Prepender %s removed plugins: %s' % (pluginstance, list(map(str, removed)))) if len(added) > 0:
logging.info("Input file created as %s" % tmpfile) suspect = Suspect(opts.sender, opts.recipients[0], tmpfile) suspect.recipients = opts.recipients # tags if opts.tags: for tagpair in opts.tags: nme, valstr = tagpair.split(':', 1) if valstr == 'TRUE': val = True elif valstr == 'FALSE': val = False else: val = valstr suspect.set_tag(nme, val) scannerlist = mc.plugins for pluginstance in mc.prependers: logging.info("*** Running prepender: %s ***" % pluginstance) result = pluginstance.pluginlist(suspect, scannerlist) if result != None: origset = set(scannerlist) resultset = set(result) removed = list(origset - resultset) added = list(resultset - origset) if len(removed) > 0: logging.info('Prepender %s removed plugins: %s' % (pluginstance, list(map(str, removed)))) if len(added) > 0: