Check Your IMAP Quota Using Python Imaplib

July 16, 2010 at 6:05 pm | PROGRAMMING, PYTHON | 1 comment

pythonThe python-imaplib module defines three classes, IMAP4, IMAP4_SSL and IMAP4_stream, which encapsulate a connection to an IMAP4 server and implement a large subset of the IMAP4rev1 client protocol as defined in RFC 2060.

Here’s a code sample that returns your gmail quota details.

import getpass, imaplib, re
 
p = re.compile('\d+')
 
IMAP_SERVER='imap.gmail.com'
IMAP_PORT=993
IMAP_USERNAME='username@gmail.com'
 
M = imaplib.IMAP4_SSL(IMAP_SERVER, IMAP_PORT)
M.login(IMAP_USERNAME, getpass.getpass())
quotaStr = M.getquotaroot("INBOX")[1][1][0]
r = p.findall(quotaStr)
if r == []:
  print "Unlimited Quota Account"
  r.append(0)
  r.append(0)
 
print 'Allotted = %f MB'%(float(r[1])/1024)
print 'Used = %f MB'%(float(r[0])/1024)
M.logout()

The script will ask your gmail password and the output will be something like this:

Allotted = 7476.760000 MB
Used = 961.390000 MB
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Technorati
  • Yahoo! Bookmarks
  • Twitter
  • Blogosphere News
  • FriendFeed
  • FSDaily
  • Yahoo! Buzz

Related posts:

  1. Playing With Python And Gmail – Part 1
  2. Playing With Python And Gmail – Part 2
  3. Catch Invisible Friends On GTalk The Python Way

Tags: , , ,

One Response to “Check Your IMAP Quota Using Python Imaplib”

  1. [...] more: Check Your IMAP Quota Using Python Imaplib | segfault.in IMAP, module-defines, python, ratings, stars, [...]

Leave a Reply

Sponsors