Chapter 16. Archiving and Cleaning a Mailbox

In this chapter:

  • Scrubbing Unwanted MIME Attachments

  • Creating mboxscrub.pl

  • Extending and Enhancing mboxscrub.pl

So what can we do with our new-found ability to script email? We can send mail, as the last chapter showed. We can receive mail, too, by creating a custom MTA that allows a program to receive and operate on mail messages. However, let’s look at another use of email knowledge altogether. We can use our understanding of RFC 822 message formats, MIME, and the common mbox message format to sort an existing mailbox. In our example, we will show how this can be used to remove large and unwanted attachments from mailboxes to save storage space or increase the speed of an MUA reading the mailbox. Most MUAs will allow one to delete an entire message but not a selected MIME entity. How many times have you wanted to keep a record of a correspondence but not really wanted the 2 MB Word document at tached to it?

The last chapter provided an in-depth look at low-level implementation of MIME encoding. While this is valuable background information, this level of programming is often unnecessary since Perl modules are available that handle the details of email protocols and formats. In this chapter we look at the use of some of those modules, showing the development of a script that exploits them to handle some typical mail management tasks.

By heavily exploiting existing modules, this short script is well suited as an introduction to email scripting ...

Get Programming Internet Email now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.