From b196e3ae50133ef0939d00e9147f9f56344f21bc Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 31 Jan 2017 21:00:18 +0200 Subject: Delete test mails --- 100-mail.yarn | 9 +++++++++ 900-implements.yarn | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/100-mail.yarn b/100-mail.yarn index 0e1b6cc..4385aff 100644 --- a/100-mail.yarn +++ b/100-mail.yarn @@ -19,33 +19,42 @@ utility. Each password should be stored using a name GIVEN large random number R WHEN someone sends mail to postmaster@pieni.net with subject $R THEN mailbox of liw has a mail with subject $R + AND mails for liw with subject $R get deleted GIVEN large random number R WHEN someone sends mail to root@pieni.net with subject $R THEN mailbox of liw has a mail with subject $R + AND mails for liw with subject $R get deleted GIVEN large random number R WHEN someone sends mail to abuse@pieni.net with subject $R THEN mailbox of liw has a mail with subject $R + AND mails for liw with subject $R get deleted GIVEN large random number R WHEN someone sends mail to postmaster@pieni.net with subject $R THEN mailbox of liw has a mail with subject $R + AND mails for liw with subject $R get deleted GIVEN server is also known as liw.fi GIVEN large random number R WHEN someone sends mail to postmaster@liw.fi with subject $R THEN mailbox of liw has a mail with subject $R + AND mails for liw with subject $R get deleted GIVEN large random number R WHEN someone sends mail to abuse@liw.fi with subject $R THEN mailbox of liw has a mail with subject $R + AND mails for liw with subject $R get deleted GIVEN large random number R WHEN someone sends mail to liw@liw.fi with subject $R THEN mailbox of liw has a mail with subject $R + AND mails for liw with subject $R get deleted WHEN someone sends mail to bugs@liw.fi with subject $R THEN mailbox of distix has a mail with subject $R AND mailbox of liw has a mail with subject $R + AND mails for distix with subject $R get deleted + AND mails for liw with subject $R get deleted diff --git a/900-implements.yarn b/900-implements.yarn index da6d961..fd9ea26 100644 --- a/900-implements.yarn +++ b/900-implements.yarn @@ -151,3 +151,35 @@ m.close() m.logout() h.assertEqual(got_it, True) + +## Delete mails + + IMPLEMENTS THEN mails for (\S+) with subject \$(\S+) get deleted + import email, imaplib, os, subprocess, yarnhelper + h = yarnhelper.YarnHelper() + user = h.get_next_match() + subject_key = h.get_next_match() + subject = h.get_variable(subject_key) + print 'Wanted:', subject + address = os.environ['ADDRESS'] + pass_name = 'server-yarns/imap/{}@{}'.format(user, address) + pass_home = os.environ['PASS_HOME'] + p = subprocess.Popen( + ['env', 'HOME={}'.format(pass_home), 'pass', 'show', pass_name], + stdout=subprocess.PIPE) + stdout, stderr = p.communicate() + password = stdout.rstrip() + m = imaplib.IMAP4_SSL(address) + m.login(user, password) + m.select('INBOX', False) + typ, data = m.search(None, 'ALL') + for num in data[0].split(): + typ, data = m.fetch(num, '(RFC822)') + typ, text = data[0] + msg = email.message_from_string(text) + print 'Subject:', msg['Subject'] + if msg['Subject'] == subject: + m.store(num, '+FLAGS', '(\\Deleted)') + m.expunge() + m.close() + m.logout() -- cgit v1.2.1