Handling MIME e-mail messages in GNATS

A well-known problem for many users of GNATS is that MIME-ified mail
messages are handled badly by GNATS. MIME is a standard way for "rich" content
to be transferred by e-mail . This content might consist of arbitrary
attachments with content such as images, sounds, executable files or plain
text. A typical MIME e-mail message contains a plaintext part first, and then
one or more parts containing attachments.

Currently, GNATS makes no attempt to decode these messages. This is
especially noticeable when letters such æ, ö, ß, å etc.
are used in the subject field of PRs submitted by e-mail. Such messages get a
synopsis containing the rather ugly looking string "=?iso-8859-1?Q?",
underscores instead of spaces and the special letters themselves replaced by
strings such as =F8, =E8 etc. In the message body, all special characters are
replaced by =XX strings. These strings are commonly referred to as quoted
printables. Thus, quoted printables will also be present in the Description
field of the PR if the message body contained international characters.

Most modern e-mail clients decode MIME e-mail messages properly,
removing the iso string, translating underscores back to spaces and quoted
printables to their special letter counterparts. However, GNATS does not
contain functionality for this, so e-mail messages are filed directly into the
database without any translation.

Another big problem arises when users submit PRs by e-mail, containing
attachments. Those parts of the message that contain binary data is simply
dumped as long encoded blocks of data into the PR description, together with
whatever plaintext the message might contain.

The easiest way to solve this is by placing a parser script at the
beginning of the line in the GNATS mail alias that pipes messages into
queue-pr. The following Perl script uses Perl MIME modules to decode the
message. It fully decodes headers and bodies of messages, stripping out parts
of a message that are not plain text, decoding those parts and saving them to
an archive directory. Separate directories are made to hold the contents of
each message. A reference is then inserted into the original message, stating
the location of the saved file. The parts of the message that were originally
in plaintext get their quoted printables translated and are otherwise left
alone.

In order to use the script below, you need to download and install the
following Perl modules on your system. Get the latest versions listed on the
following pages:

Set up the mail alias which receives bug reports to pipe messages
through this script before it is piped into queue-pr. Like this (you should
modify the path to queue-pr to fit your installation):

| /path-to-script/script.pl | /usr/local/libexec/gnats/queue-pr -q

Warning: Using this filter causes PRs to be stored in the Gnats database
in a decoded format which might not be supported properly by all UNIXes.
Outgoing mail from GNATS will also be unencoded, possibly resulting in problems
when mail is transferred over the Internet. Some mail clients may also have
problems with it. In short: your mileage may vary.