diff options
Diffstat (limited to 'yarnhelper.py')
-rw-r--r-- | yarnhelper.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/yarnhelper.py b/yarnhelper.py index ee2a901..8f9da19 100644 --- a/yarnhelper.py +++ b/yarnhelper.py @@ -16,7 +16,10 @@ # =*= License: GPL-3+ =*= +import email +import imaplib import os +import subprocess import urlparse import requests @@ -94,6 +97,30 @@ class YarnHelper(object): if a == b: raise Error('assertion {!r} != {!r} failed'.format(a, b)) + def get_password_with_pass(self, pass_home, pass_name): # pragma: no cover + p = subprocess.Popen( + ['env', 'HOME={}'.format(pass_home), 'pass', 'show', pass_name], + stdout=subprocess.PIPE) + stdout, stderr = p.communicate() + password = stdout.rstrip() + return password + + def iterate_mails_in_imap_mailbox( + self, address, user, password, callback, exp): # pragma: no cover + 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) + callback(m, num, msg) + if exp: + m.expunge() + m.close() + m.logout() + class Error(Exception): |