summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2017-01-31 21:00:18 +0200
committerLars Wirzenius <liw@liw.fi>2017-01-31 21:00:18 +0200
commitb196e3ae50133ef0939d00e9147f9f56344f21bc (patch)
tree01194d50fb02e62183c161c1378abd1e40e82aab
parent3fe2aadd2a1c58435fdda78b2c789781ab1fb769 (diff)
downloadserver-yarns-b196e3ae50133ef0939d00e9147f9f56344f21bc.tar.gz
Delete test mails
-rw-r--r--100-mail.yarn9
-rw-r--r--900-implements.yarn32
2 files changed, 41 insertions, 0 deletions
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()