My gmail is getting full... I need a method to find out the biggest email from the Inbox and delete it. However, in the web interface of gmail, what I can do is to find out the emails with attachments first, and then check the attachement size one by one.
The efficiency is too low!
I also find a python script which could log in my gmail account and retrieve emails, via imap protocol, but I didn't find a way to check the attachment size.
Could someone help me? Thanks in advance.
Imap library has search method. There is almost ready to use code for you.
#!/usr/bin/env python
import imaplib
from re import findall
MAXSIZE = 1000
MINSIZE = 1
m = imaplib.IMAP4_SSL('imap.gmail.com')
m.login('[email protected]','testPassword')
m.select()
typ, data = m.search(None, 'ALL')
typ, data = m.search(None,'(SMALLER %d) (LARGER %d)' % (MAXSIZE * 1000,MINSIZE * 1000))
for num in data[0].split():
typ, data = m.fetch(num, '(RFC822)')
print 'Message %s\n%s\n' % (num, len(data[0][1]))
m.close()
m.logout()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With