bgneal@4
|
1 Introducing weighmail
|
bgneal@4
|
2 #####################
|
bgneal@4
|
3
|
bgneal@4
|
4 :date: 2012-05-24 19:30
|
bgneal@4
|
5 :tags: Python, Gmail, IMAPClient, weighmail
|
bgneal@4
|
6 :slug: introducing-weighmail
|
bgneal@4
|
7 :author: Brian Neal
|
bgneal@4
|
8
|
bgneal@4
|
9 Recently my wife approached me and told me that Gmail was warning her that she
|
bgneal@4
|
10 was using 95% of her (free) quota. This was a bit surprising, but my wife does a
|
bgneal@4
|
11 lot of photography, and sends lots of photos through the mail to various people.
|
bgneal@4
|
12 So I began helping her trying to find her large messages. It was then that I
|
bgneal@4
|
13 learned that Gmail provides no easy way to do this. You can't sort by size. You
|
bgneal@4
|
14 can search for specific attachments, for example .psd or .jpg, and that is what
|
bgneal@4
|
15 she ended up doing.
|
bgneal@4
|
16
|
bgneal@4
|
17 Surely I thought there must be an easier way. I thought that perhaps Gmail might
|
bgneal@4
|
18 have an API like their other products. A bit of searching turned up that the
|
bgneal@4
|
19 only API to Gmail is IMAP_. I didn't know anything about IMAP, but I do know
|
bgneal@4
|
20 some Python. And sure enough, Python has a library for IMAP called imaplib_.
|
bgneal@4
|
21 Glancing through imaplib I got the impression it was a very low-level library
|
bgneal@4
|
22 and I began to get a bit discouraged.
|
bgneal@4
|
23
|
bgneal@4
|
24 I continued doing some searching and I quickly found IMAPClient_, a high-level
|
bgneal@4
|
25 and friendlier library for working with IMAP. This looked like it could work
|
bgneal@4
|
26 very well for me!
|
bgneal@4
|
27
|
bgneal@4
|
28 I started thinking about writing an application to find big messages in a Gmail
|
bgneal@4
|
29 account. The most obvious and natural way to flag large messages would be to
|
bgneal@4
|
30 slap a Gmail label on them. But could IMAPClient do this? It didn't look like
|
bgneal@4
|
31 it. It turns out that labels are part of a set of `custom Gmail IMAP
|
bgneal@4
|
32 extensions`_, and IMAPClient didn't support them. Yet.
|
bgneal@4
|
33
|
bgneal@4
|
34 I contacted the author of IMAPClient, `Menno Smits`_, and quickly learned he is
|
bgneal@4
|
35 a very friendly and encouraging guy. I decided to volunteer a patch, as this
|
bgneal@4
|
36 would give me a chance to learn something about IMAP. He readily agreed and I
|
bgneal@4
|
37 dove in.
|
bgneal@4
|
38
|
bgneal@4
|
39 The short version of the story is I learned a heck of a lot from reading the
|
bgneal@4
|
40 source to IMAPClient, and was able to contribute a patch for Gmail label support
|
bgneal@4
|
41 and even some tests!
|
bgneal@4
|
42
|
bgneal@4
|
43 After the patch was accepted I went to work on my application, which I have
|
bgneal@4
|
44 dubbed weighmail_. I was even able to figure out how to put `weighmail up on
|
bgneal@4
|
45 PyPI`_ thanks to Menno's example.
|
bgneal@4
|
46
|
bgneal@4
|
47 So if you need a program to categorize your Gmail by message size, I hope
|
bgneal@4
|
48 weighmail will meet your needs. Please try it out and feel free to send me
|
bgneal@4
|
49 feedback and feature requests on the Bitbucket issue tracker.
|
bgneal@4
|
50
|
bgneal@4
|
51 I have used it maybe a half-dozen times on my Gmail account now. My Gmail
|
bgneal@4
|
52 account is only about 26% full and I have about 26,300 messages in my "All Mail"
|
bgneal@4
|
53 folder. Run times for weighmail have varied from six to 15 minutes when adding 3
|
bgneal@4
|
54 label categories for size. I was (and am) kind of worried that Gmail may lock me
|
bgneal@4
|
55 out of my account for accessing it too heavily, but knock on wood it hasn't yet.
|
bgneal@4
|
56 Perhaps they rate limit the responses and that is why the run times vary so
|
bgneal@4
|
57 much.
|
bgneal@4
|
58
|
bgneal@4
|
59 In any event, I hope you find it useful. A big thank you to Menno Smits for his
|
bgneal@4
|
60 IMAPClient library, his advice, and working with me on the patch. Hooray for
|
bgneal@4
|
61 open source!
|
bgneal@4
|
62
|
bgneal@4
|
63 .. _IMAP: http://en.wikipedia.org/wiki/Internet_Message_Access_Protocol
|
bgneal@4
|
64 .. _imaplib: http://docs.python.org/library/imaplib.html
|
bgneal@4
|
65 .. _IMAPClient: http://imapclient.freshfoo.com/
|
bgneal@4
|
66 .. _custom Gmail IMAP extensions: https://developers.google.com/google-apps/gmail/imap_extensions
|
bgneal@4
|
67 .. _weighmail: https://bitbucket.org/bgneal/weighmail/
|
bgneal@4
|
68 .. _weighmail up on PyPI: http://pypi.python.org/pypi/weighmail/0.1.0
|
bgneal@4
|
69 .. _Menno Smits: http://freshfoo.com/blog/
|