Hack of the day: auto-filing IMAP “Sent Items” folder

By | December 30, 2009

I file my email in different IMAP folders, grouped by topic rather than the “received messages in one folder, sent in another” model imposed nowadays by most mail clients.  It’s easy to keep the messages I receive organized by topic — when I’m done handling a message, I simply move it into the appropriate folder.

On the other hand, organizing the copies of message I’ve sent is less straightforward.  Visiting my “Sent Items” folder every time I send a message and filing the message I’ve just sent is gross.  What I’ve done in the past is to leave all the copies in “Sent Items” and periodically file all of them one at a time.  This is time-consuming and error-prone, and what’s more, it could be at least partially automated — if I file a message I received in a particular folder, then something ought to be smart enough to figure out that the response I sent should go into the same folder.

After spending over an hour this morning filing “Sent Items” messages, my annoyance threshold was finally exceeded and I decided to automate the process as much as I could.  The result is file-sent-items.pl.  In a nutshell, this script reads each message in your “Sent Items” folder (or whatever it’s called), grabs the message IDs in the “Message-ID”, “Resent-Message-ID”, “In-Reply-To” and/or “References” headers, looks for a message with one of those IDs in your other folders, and if one is found, moves the sent message into its folder.  There’s a bit more too it than that, of course, which you can find out by reading the comment at the top of the script and running it with the “–help” option to get a usage message.

Of course, this script won’t be able to file messages that aren’t part of conversations already filed into other folders, but it still reduces by a lot the amount of filing you have to do by hand.

Share and enjoy!

Print Friendly, PDF & Email

7 thoughts on “Hack of the day: auto-filing IMAP “Sent Items” folder

  1. Claud Zatarain

    Excellent article. I agree with author completely, especially last section. Keep posting posts like this one.

  2. Pingback: Microsoft Outlook and IMAP: When a Message ID isn’t a Message ID « Something better to do

  3. Nate

    Jik – you can make a rule in outlook to have outgoing messages copied to the inbox as well as sent items, and it works correctly with grouping by thread etc. I do this at work, and it’s awesome. It’s so much easier when I can see my own replies to threads as well as everyone else’s. I can show you / email you it when I get to work on Monday.

    1. jik Post author

      @Nate: First of all, why would I want to see two copies of every outgoing message, one in my Inbox and one in Sent Items?

      Second, even if I do want to display messages by thread in my Inbox (which I don’t; see below), why would I need messages I’ve sent included in that display? I know what I said, and replies to my messages almost always include it below the reply.

      Third, I tend to prefer strict chronological message displays in my Inbox (most recent first) rather than threaded displays. Occasionally when I’ve been offline for a while and entire conversations have occurred in my absence, I switch to threaded display briefly to group them, but once I’m caught up, I switch back to chronological.

      I suppose that if I did regularly use threaded display in my Inbox, then I could configure Outlook as you’ve described and configure Thunderbird and my other email clients (e.g., Tiggit on my BlackBerry) to put sent messages in Inbox instead of Sent Items to avoid the BCC spam filter issue described above, and then file my sent messages along with the messages I’ve received all at once when filing the entire thread. But given that I prefer chronological display in my Inbox, doing things that way would just mean more time spent filing messages.

  4. JonT

    hmm.. You could clear the BCC field on such messages, but then, you might sometimes forget to do that.

    You have my sympathy if you’re forced to use Outhouselook. The vast majority of people at my current job use it. I figured I could get used to it, so I forced myself to use it at first, but after a few months, I gave up. Exchange servers can use IMAP for mail and LDAP for contacts, so I’ve bounced between Kmail, Thunderbird and Evolution ever since.

  5. JonT

    I always just set my mail client to automatically BCC me for all outgoing messages — that way, my sent messages always get viewed along with my received messages, and I can view them together in thread-views.

    1. jik Post author

      I used to do that, but it messes with my spam filter. For example, if a piece of spam gets through my spam filter and I submit it to SpamCop by email, if a copy gets BCC’d to me, then either my spam filter will classify it as spam, in which case I’ll never see it, or as non-spam, in which case it’ll automatically “train” itself to consider the keywords in the message, including all of the spam’s keywords, as non-spam keywords, which will reduce its accuracy significantly.

      In addition, I don’t actually want my spam filter to train itself even on non-spam outgoing messages. The keyword profile of my outgoing messages is somewhat different from the keyword profile of incoming messages, and the closer the spam filter’s keyword profile matches my incoming message stream, the better job it’ll do filtering the spam.

      And then there’s the fact that Outlook, which I use at work to access both home and work email, doesn’t support BCC’ing copies of outgoing messages, at least not as far as I can tell.


Leave a Reply

Your email address will not be published. Required fields are marked *