diff options
author | VG <vg@devys.org> | 2016-05-19 16:56:55 +0200 |
---|---|---|
committer | VG <vg@devys.org> | 2016-05-19 16:56:55 +0200 |
commit | 0db947a0a43f3406819b45f7506e5a28b121a3aa (patch) | |
tree | b4f3a41268acd269ee813194f1df92b074d89653 /climl/imap.py | |
parent | c22ba520026b4f9b96d205d86ba207e39fc49d1b (diff) | |
download | climl-0db947a0a43f3406819b45f7506e5a28b121a3aa.tar.gz climl-0db947a0a43f3406819b45f7506e5a28b121a3aa.tar.bz2 climl-0db947a0a43f3406819b45f7506e5a28b121a3aa.zip |
get email size and content
Diffstat (limited to 'climl/imap.py')
-rw-r--r-- | climl/imap.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/climl/imap.py b/climl/imap.py index 36668d4..68a6e9b 100644 --- a/climl/imap.py +++ b/climl/imap.py @@ -118,6 +118,8 @@ def main(callback=None): password = subprocess.check_output(password_command, shell=True) password = password.rstrip().decode('utf8') print('got pasword:', password) + maxsize = conf.get('mail.maxsize', 100*1024) # 100k default + maxsize = int(maxsize) while True: print('connection...') try: @@ -129,8 +131,20 @@ def main(callback=None): print('initial idlist: ', idlist) for oneid in idlist: print('new mail:', oneid) + print('checking size of mail...') + response = connection.fetch([oneid], ['RFC822.SIZE']) + size = int(response[oneid][b'RFC822.SIZE']) + print('message size: {} bytes'.format(size)) + if size > maxsize: + print('message is too big, skip and mark it seen') + connection.add_flags([oneid], ['\Seen']) + continue + print('getting mail...') + response = connection.fetch([oneid], ['RFC822']) + data = response[oneid][b'RFC822'] print('calling callback...') - callback('mail: ' + str(oneid)) + callback('mail: ' + str(oneid) + ': ' + str(data)) + data = None while True: imap_waiter(connection) idlist = connection.search(['UNSEEN']) |