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