Scrubbing Unwanted MIME Attachments
The script at hand is to remove unwanted MIME attachments from an mbox-style mailbox. To be obvious, we’ll call it mboxscrub.pl. For this example, we will assume that the relevant criterion is size. In other words, we will offer to delete all MIME attachments greater than a certain size.
The script will need to walk through a mailbox in mbox format, reading each message one at a time. That means we will have to take a mailbox somehow as input. Each message in turn will be broken into its component parts. (As in Chapter 4, Creating MIME-Compliant Messages, we will use the terms “part,” “entity,” and “attachments” as synonyms.) Each MIME entity will be evaluated to see if it is too big. That means we will have to ask the user to decide, somehow, what “too big” means. The easiest way to do this is to simply ask for a size (a number of bytes), below which MIME entities will be kept without user interaction and above which the user will be asked whether the attachment should be deleted. Finally, we will have to ask the user to confirm which attachments to delete. We could automate this task, but that seems risky.
The script should create a copy of the original mailbox file with the changes made. This allows the user to be certain before deleting the original. If we are archiving the mailbox, we should have a way to compress it as well. This should be an option only; we may wish to keep using the mailbox with our MUA. For this example, we will use the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access