From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30276 invoked from network); 8 Sep 2004 17:25:09 -0000 Received: from unknown (HELO lists.gnu.org) (199.232.76.165) by sourceware.org with SMTP; 8 Sep 2004 17:25:09 -0000 Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1C56HE-00063k-FD for listarch-gnats-devel@sources.redhat.com; Wed, 08 Sep 2004 13:30:36 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1C56Gy-00060O-MK for help-gnats@gnu.org; Wed, 08 Sep 2004 13:30:20 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1C56Gv-000602-CP for help-gnats@gnu.org; Wed, 08 Sep 2004 13:30:20 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1C56Gv-0005zu-9G for help-gnats@gnu.org; Wed, 08 Sep 2004 13:30:17 -0400 Received: from [66.60.176.161] (helo=sierralogic.com) by monty-python.gnu.org with smtp (Exim 4.34) id 1C56BE-0002wV-4y for help-gnats@gnu.org; Wed, 08 Sep 2004 13:24:25 -0400 Received: (qmail 5943 invoked from network); 8 Sep 2004 17:24:20 -0000 Received: from unknown (HELO wizard) (192.168.174.221) by 0 with SMTP; 8 Sep 2004 17:24:20 -0000 From: "Stuart Stevens" To: "'Adam Cade'" , Date: Fri, 10 Sep 2004 17:01:00 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook, Build 11.0.5510 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 thread-index: AcSVinQna6kbAWvcQoihamTD7yctdQAPMelQ In-Reply-To: <413ED819.2060001@gointernet.co.uk> Message-Id: Cc: Subject: RE: Gnats email can't handle attachments? X-BeenThere: help-gnats@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General discussion about GNU GNATS List-Archive: List-Post: List-Help: List-Subscribe: , Sender: help-gnats-bounces+listarch-gnats-devel=sources.redhat.com@gnu.org Errors-To: help-gnats-bounces+listarch-gnats-devel=sources.redhat.com@gnu.org X-SW-Source: 2004-q3/txt/msg00059.txt.bz2 Adam There is a special section on MIME on the GNATS home page http://www.gnu.org/software/gnats/ . See http://www.gnu.org/software/gnats/mimedecode.html Text follows: GNATS > DECODING MIME E-MAIL=20 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 =E6, =F6, =DF, =E5 etc. are used in= the subject field of PRs submitted by e-mail. Such messages get a synopsis containing the rather ugly looking string "=3D?iso-8859-1?Q?", underscores instead of spaces and the special letters themselves replaced by strings such as =3DF8, =3DE8 etc. In the message body, all special characters are replaced by =3DXX 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: MIME-Base64=20 MIME-tools=20 #!/usr/bin/perl # # parsemime.pl -- Yngve Svendsen, May 2001 # # Script to decode MIME-encoded mail messages. Fully decodes header # fields according to RFC2047. Merges multi-line header fields into # single lines. Decodes the message body, saving binary parts to disk. # Outputs a new message body, consisting of the plaintext message parts # and references detailing the location of the saved stripped-out # non-plaintext parts. use MIME::Parser; use File::Basename; undef $/; # We want to treat everything read from STDIN as one line $input =3D <>; $/ =3D "\n"; ($headers, $body) =3D split (/\n\n/, $input, 2); # Split MIME-multipart messages and store the parts in subdirectories # under the directory indicated by $output_path. Depending on which # mail system your site uses, the directory specified by $output_path might # have to have special permissions. If you have qmail, the dir should # be owned by the user 'alias'. Sendmail should be content with 'root' # as owner. my $output_path =3D '/path/to/archive/directory'; my ($parsed) =3D (basename($0))[0]; my $parser =3D MIME::Parser->new(); # Permission mask for output files. # These permissions are very lax. Replace with what is appropriate # for your system. $oldumask =3D umask 0002; $parser->output_under($output_path); $parser->output_prefix($parsed); $parser->output_to_core(); my $entity =3D $parser->parse_data($input);=20 # Permissions for the directory containing the output files. # These permissions are very lax. Replace with what is appropriate # for your system. chmod 0775, ($parser->output_dir); # Process the headers: $procheaders =3D $headers; $procheaders =3D~ s/\?=3D\s\n/\?=3D\n/g; # Lines ending with an encoded-word # have an extra space at the end. Remove it. $procheaders =3D~ s/\n[ |\t]//g; # Merge multi-line headers into a single line. $transheaders =3D ''; foreach $line (split(/\n/, $procheaders)) { while ($line =3D~ m/=3D\?[^?]+\?(.)\?([^?]*)\?=3D/) { $encoding =3D $1; $txt =3D $2; $str_before =3D $`; $str_after =3D $'; # Base64 if ($encoding =3D~ /b/i) { require MIME::Base64; MIME::Base64->import(decode_base64); $txt =3D decode_base64($txt); } # QP elsif ($encoding =3D~ /q/i) { require MIME::QuotedPrint; MIME::QuotedPrint->import(decode_qp); $txt =3D decode_qp($txt); } $line =3D $str_before . $txt . $str_after; } # The decode above does not do underline-to-space translation: $line =3D~ tr/_/ /; $transheaders .=3D $line . "\n"; } # Reconstruct the message, made from headers and the MIME text parts # we saved earlier. Add references in the message body to the non-text # parts that have been stripped out and stored. The purgeable method # returns the full path of the files constructed from the different # message parts. print $transheaders . "\n"; foreach $file ($parser->filer->purgeable) { # Strip trailing spaces from filenames: $file =3D~ /(\S*)\s*$/; $file =3D $1; if ($file =3D~ /\.txt\s*$/) { # We have found a plaintext part. Include it in the new body: open PART, $file; while () { print; } close PART; # Build list of files included in the new body. We will delete # these files further down. unshift @purgeables, $file; } else { # We have found a non-plaintext part. Add a reference to it in the # new body: print "\n\n** Attachment decoded and saved to \n** $file\n\n"; } } # Make the list we built the new list of purgeable files: $parser->filer->purgeable(\@purgeables); # Delete them: $parser->filer->purge; umask $oldumask; =20 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):=20 | /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. ---------------------------------------------------------------------------- ---- GNATS > DECODING MIME E-MAIL=20 =20 First published: Wednesday, 09-May-2001 23:38:00 MET DST Last modified: Wednesday, 09-May-2001 23:38:00 MET DST yngve.svendsen@clustra.com =20 -----Original Message----- From: help-gnats-bounces+stuart_stevens=3Dsierralogic.com@gnu.org [mailto:help-gnats-bounces+stuart_stevens=3Dsierralogic.com@gnu.org] On Beh= alf Of Adam Cade Sent: Wednesday, September 08, 2004 3:00 AM To: help-gnats@gnu.org Subject: Gnats email can't handle attachments? Hi guys! Need your need! GnatsWeb seems to be coding the e-mail attachments wrong. Any binary format seems to come out like: >How-To-Repeat: >Fix: Unknown >Unformatted: ----gnatsweb-attachment---- Content-Type: image/pjpeg; name=3D"AmendJobError.jpg" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=3D"AmendJobError.jpg" =20=20=20 =20 /9j/4AAQSkZJRgABAQEAYABgAAD//gAcU29mdHdhcmU6IE1pY3Jvc29mdCBPZmZpY2X/2wBDAAoH =20 BwgHBgoICAgLCgoLDhgQDg0NDh0VFhEYIx8lJCIfIiEmKzcvJik0KSEiMEExNDk7Pj4+JS5ESUM8 =20 SDc9Pjv/2wBDAQoLCw4NDhwQEBw7KCIoOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7 =20 Ozs7Ozs7Ozs7Ozs7Ozs7Ozv/wAARCAMABAADASIAAhEBAxEB/8QAHAABAAIDAQEBAAAAAAAAAAAA =20 AAQFAgMGBwEI/8QAXBAAAQMCAgQKBAgMAwcCBAQHAQACAwQRBRIGEyExFBUWIkFRVZTR0lRhldMy =20 NlNxgZKToRcjM0JSc3SRo7Kz8Ac0ViRDYnKDscFFwjV14fElJkRjZKKCljfD4v/EABoBAQEBAQEB =20 AQAAAAAAAAAAAAACAQMEBQb/xAA4EQACAQIDBAgGAgEFAQEBAAAAAQIDERITUSExkbEEQVJhgaHR =20 4RQVMnHB8AUiNCMzQmLxgiRy/90ABAAo/9oADAMBAAIRAxEAPwDl9B4KWbH81fhcuI0ccR1scbA4 =20 gnY3eRtLrAAG5OwXXozNHtHMawevFFo3BT1URytjM2WQAncdhyPsD0EA7L3DgOA0QfV4jWUuE0bK =20=20 etc etc.... Any one have any help? Thanks, -- Adam Cade , Go Internet Ltd email: adam@gointernet.co.uk voice: +44 (0)20 7419 0001 fax : +44 (0)20 7419 6519 web : www.gointernet.co.uk _______________________________________________ Help-gnats mailing list Help-gnats@gnu.org http://lists.gnu.org/mailman/listinfo/help-gnats _______________________________________________ Help-gnats mailing list Help-gnats@gnu.org http://lists.gnu.org/mailman/listinfo/help-gnats