Creating mboxscrub.pl

The beginning of the script is simple, since we have already decided which modules to use. In the opening lines, we make sure that we have access to the features of those modules:

#!/usr/local/bin/perl

use MIME::Parser;                 # The MIME-Tools Parser (reads/writes
                                  # MIME entities).
use Term::ReadLine;               # ReadLine library (used/or user input).
use Getopt:: Std;                 # Used to get command line arguments.

Note

Determining which modules are available can be more difficult than using them. A periodic review of the CPAN, perhaps with the excellent regular expression-based search features of the CPAN Perl module (try perl -MCPAN -e shell) is useful.

Naturally, the first line is needed only under Unix. Next, we will need to set some initial variables. This is good practice, although not strictly required in a scripting language like Perl. We will need to have some flags to tell us where we are in the parsing process and what the user has requested (such as a flag for whether or not we are compressing the output file). We will also need to set up object instances for each of the modules that we are using, since they use Perl’s object-oriented interface. Many modules have their own requirements; refer to their perldoc documentation to see initialization and usage examples in detail.

In general, MIME-tools is used by creating an object instance of MIME::Parser, in order to read a message. Later we will see how to get objects for each MIME entity. MIME::Parser requires that a temporary ...

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.