From 0db947a0a43f3406819b45f7506e5a28b121a3aa Mon Sep 17 00:00:00 2001 From: VG Date: Thu, 19 May 2016 16:56:55 +0200 Subject: get email size and content --- climl/imap.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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']) -- cgit v1.2.3