summaryrefslogtreecommitdiff
path: root/900-implements.yarn
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 /900-implements.yarn
parent3fe2aadd2a1c58435fdda78b2c789781ab1fb769 (diff)
downloadserver-yarns-b196e3ae50133ef0939d00e9147f9f56344f21bc.tar.gz
Delete test mails
Diffstat (limited to '900-implements.yarn')
-rw-r--r--900-implements.yarn32
1 files changed, 32 insertions, 0 deletions
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()