+# This module is part of debbugs, and is released
+# under the terms of the GPL version 2, or any later
+# version at your option.
+# See the file README and COPYING for more information.
+#
+# [Other people have contributed to this file; their copyrights should
+# go here too.]
+# Copyright 2006 by Don Armstrong <don@donarmstrong.com>.
+
+
package Debbugs::MIME;
use strict;
BEGIN {
$VERSION = 1.00;
- @EXPORT_OK = qw(parse decode_rfc1522 encode_rfc1522 convert_to_utf8 create_mime_message);
+ @EXPORT_OK = qw(parse decode_rfc1522 encode_rfc1522 convert_to_utf8 create_mime_message getmailbody);
}
use File::Path;
# for encode_rfc1522
use MIME::Words qw();
-sub getmailbody ($);
-sub getmailbody ($)
+sub getmailbody
{
my $entity = shift;
my $type = $entity->effective_type;
return undef;
}
-sub parse ($)
+sub parse
{
# header and decoded body respectively
my (@headerlines, @bodylines);
- my $parser = new MIME::Parser;
+ my $parser = MIME::Parser->new();
mkdir "mime.tmp.$$", 0777;
$parser->output_under("mime.tmp.$$");
my $entity = eval { $parser->parse_data($_[0]) };
]));
}
-sub decode_rfc1522 ($)
-{
+sub decode_rfc1522 {
my ($string) = @_;
+ # this is craptacular, but leading space is hacked off by unmime.
+ # Save it.
+ my $leading_space = '';
+ $leading_space = $1 if $string =~ s/^(\s+)//;
# unmime calls the default MIME::WordDecoder handler set up at
# initialization time.
- return MIME::WordDecoder::unmime($string);
+ return $leading_space . MIME::WordDecoder::unmime($string);
}
=head2 encode_rfc1522
# We cannot use MIME::Words::encode_mimewords because that function
# does not handle spaces properly at all.
-sub encode_rfc1522 ($) {
+sub encode_rfc1522 {
my ($rawstr) = @_;
+ # handle being passed undef properly
+ return undef if not defined $rawstr;
# We process words in reverse so we can preserve spacing between
# encoded words. This regex splits on word|nonword boundaries and
# nonword|nonword boundaries.