summaryrefslogtreecommitdiff
path: root/900-implements.yarn
diff options
context:
space:
mode:
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()