summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorghendricks%novell.com <>2007-02-06 04:55:45 +0100
committerghendricks%novell.com <>2007-02-06 04:55:45 +0100
commite0f4e652619de64f3d16463a5f6ff053dafa1581 (patch)
tree8a2b5a72108a4d30e9a85d4b20f4dd335353b939
parente4ec2589ba499568ebb1c548690f2f3907148369 (diff)
downloadbugzilla-e0f4e652619de64f3d16463a5f6ff053dafa1581.tar.gz
bugzilla-e0f4e652619de64f3d16463a5f6ff053dafa1581.tar.xz
patch by Guzmán Brasó
r=ghendricks, a=LpSolit
-rwxr-xr-ximportxml.pl26
1 files changed, 16 insertions, 10 deletions
diff --git a/importxml.pl b/importxml.pl
index c19f6d96f..6dff2af7f 100755
--- a/importxml.pl
+++ b/importxml.pl
@@ -1178,16 +1178,22 @@ Debug( "Reading xml", DEBUG_LEVEL );
local ($/);
$xml = <>;
-# If the email was encoded (Mailer::MessageToMTA() does it when using UTF-8),
-# we have to decode it first, else the XML parsing will fail.
-my $parser = MIME::Parser->new;
-$parser->output_to_core(1);
-$parser->tmp_to_core(1);
-my $entity = $parser->parse_data($xml);
-my $bodyhandle = $entity->bodyhandle;
-$xml = $bodyhandle->as_string;
-
-# remove everything in file before xml header (i.e. remove the mail header)
+# If there's anything except whitespace before <?xml then we guess it's a mail
+# and MIME::Parser should parse it. Else don't.
+if ($xml =~ m/\S.*<\?xml/s ) {
+
+ # If the email was encoded (Mailer::MessageToMTA() does it when using UTF-8),
+ # we have to decode it first, else the XML parsing will fail.
+ my $parser = MIME::Parser->new;
+ $parser->output_to_core(1);
+ $parser->tmp_to_core(1);
+ my $entity = $parser->parse_data($xml);
+ my $bodyhandle = $entity->bodyhandle;
+ $xml = $bodyhandle->as_string;
+
+}
+
+# remove everything in file before xml header
$xml =~ s/^.+(<\?xml version.+)$/$1/s;
Debug( "Parsing tree", DEBUG_LEVEL );