aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--climl/imap.py16
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'])