[Rt-commit] rt branch, 4.4/rescue-outlook-html, updated. rt-4.4.3-53-gef5edd601
Gergely Nagy
algernon at bestpractical.com
Thu Oct 4 13:14:41 EDT 2018
The branch, 4.4/rescue-outlook-html has been updated
via ef5edd6018d379cc5138e2d740340a462af9991c (commit)
from 98ff7e87e8a7d10868749df2bf151bd24e4fb937 (commit)
Summary of changes:
lib/RT/EmailParser.pm | 59 ++++++++++++++++++++++++++++-----------------------
1 file changed, 33 insertions(+), 26 deletions(-)
- Log -----------------------------------------------------------------
commit ef5edd6018d379cc5138e2d740340a462af9991c
Author: Gergely Nagy <algernon at bestpractical.com>
Date: Thu Oct 4 19:14:31 2018 +0200
WIP: fixup
Signed-off-by: Gergely Nagy <algernon at bestpractical.com>
diff --git a/lib/RT/EmailParser.pm b/lib/RT/EmailParser.pm
index c4c2103b9..0c0d68b95 100644
--- a/lib/RT/EmailParser.pm
+++ b/lib/RT/EmailParser.pm
@@ -648,46 +648,53 @@ sub RescueOutlook {
return unless $mime && $self->LooksLikeMSEmail($mime);
- my $text_part, $html_part;
+ my $text_part;
+ my $html_part;
+
if ( $mime->head->get('Content-Type') =~ m{multipart/mixed} ) {
my $first = $mime->parts(0);
if ( $first->head->get('Content-Type') =~ m{multipart/alternative} )
{
- my $inner_first = $first->parts(0);
- if ( $inner_first->head->get('Content-Type') =~ m{text/plain} )
- {
- $text_part = $inner_first;
- }
- my $inner_second = $first->parts(1);
- if ( $inner_second->head->get('Content-Type') =~ m{text/html} )
- {
- $html_part = $inner_second;
+ foreach my $part ($first->parts) {
+ if ( $part->head->get('Content-Type') =~ m{text/plain} && !$text_part) {
+ $text_part = $part;
+ }
+ if ( $part->head->get('Content-Type') =~ m{text/html} && !$html_part) {
+ $html_part = $part;
+ }
}
}
}
elsif ( $mime->head->get('Content-Type') =~ m{multipart/alternative} ) {
- my $first = $mime->parts(0);
- if ( $first->head->get('Content-Type') =~ m{text/plain} ) {
- $text_part = $first;
- }
- my $second = $mime->parts(0);
- if ( $second->head->get('Content-Type') =~ m{text/html} ) {
- $html_part = $second;
+ foreach my $part ($mime->parts) {
+ if ( $part->head->get('Content-Type') =~ m{text/plain} && !$text_part) {
+ $text_part = $part;
+ }
+ if ( $part->head->get('Content-Type') =~ m{text/html} && !$html_part) {
+ $html_part = $part;
+ }
}
}
-
# Add base64 since we've seen examples of double newlines with
# this type too. Need an example of a multi-part base64 to
# handle that permutation if it exists.
- elsif ( ($mime->head->get('Content-Transfer-Encoding')||'') =~ m{base64} ) {
+ elsif ( ($mime->head->get('Content-Transfer-Encoding')||'') =~ m{base64} ||
+ $mime->head->get('Content-Type') =~ m{text/plain}) {
$text_part = $mime; # Assuming single part, already decoded.
}
+ elsif ( $mime->head->get('Content-Type') =~ m{text/html} ) {
+ $html_part = $mime;
+ }
+
+ my $content;
+ my $ret;
if ($text_part) {
# use the unencoded string
- my $content = $text_part->bodyhandle->as_string;
- if ( $content =~ s/\n\n/\n/g ) {
+ $content = $text_part->bodyhandle->as_string;
+
+ if ( $content =~ s/\n\n/\n/mg ) {
# Outlook puts a space on extra newlines, remove it
$content =~ s/\ +$//mg;
@@ -698,7 +705,7 @@ sub RescueOutlook {
$io->close;
$RT::Logger->debug(
"Removed extra newlines from MS Outlook message.");
- return 1;
+ $ret = 1;
}
else {
$RT::Logger->error("Can't write to body to fix newlines");
@@ -709,9 +716,9 @@ sub RescueOutlook {
if ($html_part) {
# use the unencoded string
- my $content = $html_part->bodyhandle->as_string;
+ $content = $html_part->bodyhandle->as_string;
- if ( $content =~ s{<p(\s*style="[^"]*")><br>\n</p>}{}mg ) {
+ if ( $content =~ s{<p(\s+style="[^"]*")?><br>\n?</p>}{}mg ) {
# only write only if we did change the content
if ( my $io = $html_part->open("w") ) {
@@ -719,7 +726,7 @@ sub RescueOutlook {
$io->close;
$RT::Logger->debug(
"Removed extra newlines from MS Outlook message.");
- return 1;
+ $ret = 1;
}
else {
$RT::Logger->error("Can't write to body to fix newlines");
@@ -727,7 +734,7 @@ sub RescueOutlook {
}
}
- return;
+ return $ret;
}
=head1 LooksLikeMSEmail
-----------------------------------------------------------------------
More information about the rt-commit
mailing list