Gmail supports the IMAP COMPRESS Extension (RFC4978), specifically the DEFLATE algorithm (RFC1951) aka zlib/gzip.
I'm not normally a Python programmer but I threw a quick test script together using Piers Lauder's imaplib2 to determine performance with or without compression enabled.
from time import time
import imaplib2, string
def cb((response, cb_arg, error)):
typ, data = response
#print 'Message %s\n%s\n' % (cb_arg, data[0][5])
IMAP_SERVER='imap.gmail.com'
IMAP_PORT=993
IMAP_USERNAME='*********'
IMAP_PASSWORD='*********'
def gogmail(compress):
start = time()
M = imaplib2.IMAP4_SSL(IMAP_SERVER, IMAP_PORT, debug=0)
M.login(IMAP_USERNAME, IMAP_PASSWORD)
if(compress):
M.enable_compression()
M.SELECT(readonly=True)
typ, data = M.SEARCH(None, 'ALL')
fetch_list = string.split(data[0])[-100:]
for num in fetch_list:
M.FETCH(num, '(RFC822)', callback=cb, cb_arg=num)
M.LOGOUT()
end = time()
print end - start
print 'Compressed '
print '------------'
for x in range(0, 50):
gogmail(1)
print 'Uncompressed'
print '------------'
for x in range(0, 50):
gogmail(0)
If I have made a glaring newbie error in my Python code please correct me.
I've run this test script a couple of times. Sometimes the mean average of compressed accesses is faster, sometimes not. There is never very much difference in mean average and a great deal of variation in access times (a single inbox access of 100 messages can take anywhere between 4 and 17 seconds). Consistent results would make my decision easier! Access is via SSL I was thinking that maybe there is some inherent compression in that (I don't know).
Do you think it is worthwhile using compression when accessing Gmail IMAP?
Incidentally, I would like to use JavaMail (rather than Python) but I understand I would need to customise JavaMail significantly to support compression (maybe using Jessie). Has somebody done this already? Would it be worthwhile?
I appreciate the feedback. Many Thanks.