[Rt-commit] rt branch, 4.4/rescue-outlook-html, updated. rt-4.4.3-60-g16d9ab6f0
Gergely Nagy
algernon at bestpractical.com
Thu Oct 4 15:56:20 EDT 2018
The branch, 4.4/rescue-outlook-html has been updated
via 16d9ab6f04d5f9d4913a7493c71290e29ea6f287 (commit)
via 9f9fcdc0af08107a5faceb99ddf1bb1ca81cf73b (commit)
via 6b7bf535552a29d7c6823008900830cbd7eab8bf (commit)
via d152254b9db08978293f2a4f1d2e4b78d2c72981 (commit)
via adcf9cc3fc1c713757db22c7973bf84e9395f989 (commit)
via d80959407fbc0a66fae976aed5e1a495cc234727 (commit)
via c3a6c9d1fa6197763d1cede0cbf9472ca09bdc8f (commit)
from ef5edd6018d379cc5138e2d740340a462af9991c (commit)
Summary of changes:
lib/RT/EmailParser.pm | 70 +++++++++++++++++++++++----------------------------
t/mail/outlook.t | 56 ++++++++++++++++++++++++++++++++++++++---
2 files changed, 85 insertions(+), 41 deletions(-)
- Log -----------------------------------------------------------------
commit c3a6c9d1fa6197763d1cede0cbf9472ca09bdc8f
Author: Gergely Nagy <algernon at bestpractical.com>
Date: Thu Oct 4 21:14:57 2018 +0200
.
Signed-off-by: Gergely Nagy <algernon at bestpractical.com>
diff --git a/lib/RT/EmailParser.pm b/lib/RT/EmailParser.pm
index 0c0d68b95..dc57f33ea 100644
--- a/lib/RT/EmailParser.pm
+++ b/lib/RT/EmailParser.pm
@@ -678,13 +678,9 @@ sub RescueOutlook {
# 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} ||
- $mime->head->get('Content-Type') =~ m{text/plain}) {
+ elsif ( ($mime->head->get('Content-Transfer-Encoding')||'') =~ m{base64} ) {
$text_part = $mime; # Assuming single part, already decoded.
}
- elsif ( $mime->head->get('Content-Type') =~ m{text/html} ) {
- $html_part = $mime;
- }
my $content;
my $ret;
commit d80959407fbc0a66fae976aed5e1a495cc234727
Author: Gergely Nagy <algernon at bestpractical.com>
Date: Thu Oct 4 21:15:08 2018 +0200
whitespace stuff, revert at the end
Signed-off-by: Gergely Nagy <algernon at bestpractical.com>
diff --git a/lib/RT/EmailParser.pm b/lib/RT/EmailParser.pm
index dc57f33ea..cf5a812cd 100644
--- a/lib/RT/EmailParser.pm
+++ b/lib/RT/EmailParser.pm
@@ -116,7 +116,7 @@ sub SmartParseMIMEEntityFromScalar {
}
if ($fh) {
- #thank you, windows
+ #thank you, windows
binmode $fh;
$fh->autoflush(1);
print $fh $args{'Message'};
@@ -177,7 +177,7 @@ sub ParseMIMEEntityFromFileHandle {
return $self->_ParseMIMEEntity( shift, 'parse', @_ );
}
-=head2 ParseMIMEEntityFromFile
+=head2 ParseMIMEEntityFromFile
Parses a mime entity from a filename passed in as an argument
@@ -220,7 +220,7 @@ sub _ParseMIMEEntity {
sub _DecodeBodies {
my $self = shift;
return unless $self->{'entity'};
-
+
my @parts = $self->{'entity'}->parts_DFS;
$self->_DecodeBody($_) foreach @parts;
}
@@ -249,7 +249,7 @@ sub _DecodeBody {
my $source = $old->open('r') or die "couldn't open body: $!";
my $destination = $new->open('w') or die "couldn't open body: $!";
- {
+ {
local $@;
eval { $decoder->decode($source, $destination) };
$RT::Logger->error($@) if $@;
@@ -269,7 +269,7 @@ cleans up and postprocesses a newly parsed MIME Entity
sub _PostProcessNewEntity {
my $self = shift;
- #Now we've got a parsed mime object.
+ #Now we've got a parsed mime object.
_DetectAttachedEmailFiles($self->{'entity'});
@@ -348,7 +348,7 @@ sub _DetectAttachedEmailFiles {
=head2 IsRTaddress ADDRESS
-Takes a single parameter, an email address.
+Takes a single parameter, an email address.
Returns true if that address matches the C<RTAddressRegexp> config option.
Returns false, otherwise.
@@ -401,42 +401,42 @@ sub CullRTAddresses {
# LookupExternalUserInfo is a site-definable method for synchronizing
-# incoming users with an external data source.
+# incoming users with an external data source.
#
# This routine takes a tuple of EmailAddress and FriendlyName
# EmailAddress is the user's email address, ususally taken from
# an email message's From: header.
-# FriendlyName is a freeform string, ususally taken from the "comment"
+# FriendlyName is a freeform string, ususally taken from the "comment"
# portion of an email message's From: header.
#
-# If you define an AutoRejectRequest template, RT will use this
+# If you define an AutoRejectRequest template, RT will use this
# template for the rejection message.
=head2 LookupExternalUserInfo
LookupExternalUserInfo is a site-definable method for synchronizing
- incoming users with an external data source.
+ incoming users with an external data source.
This routine takes a tuple of EmailAddress and FriendlyName
EmailAddress is the user's email address, ususally taken from
an email message's From: header.
- FriendlyName is a freeform string, ususally taken from the "comment"
+ FriendlyName is a freeform string, ususally taken from the "comment"
portion of an email message's From: header.
It returns (FoundInExternalDatabase, ParamHash);
- FoundInExternalDatabase must be set to 1 before return if the user
+ FoundInExternalDatabase must be set to 1 before return if the user
was found in the external database.
- ParamHash is a Perl parameter hash which can contain at least the
- following fields. These fields are used to populate RT's users
+ ParamHash is a Perl parameter hash which can contain at least the
+ following fields. These fields are used to populate RT's users
database when the user is created.
- EmailAddress is the email address that RT should use for this user.
- Name is the 'Name' attribute RT should use for this user.
+ EmailAddress is the email address that RT should use for this user.
+ Name is the 'Name' attribute RT should use for this user.
'Name' is used for things like access control and user lookups.
- RealName is what RT should display as the user's name when displaying
+ RealName is what RT should display as the user's name when displaying
'friendly' names
=cut
@@ -468,7 +468,7 @@ sub Head {
return $self->Entity->head;
}
-=head2 Entity
+=head2 Entity
Return the parsed Entity from this message
@@ -492,13 +492,13 @@ A private instance method which sets up a mime parser to do its job
## need to put each msg as an in-core scalar before saving it to
## the database, don't we?
- ## At the same time, we should make sure that we nuke attachments
+ ## At the same time, we should make sure that we nuke attachments
## Over max size and return them
sub _SetupMIMEParser {
my $self = shift;
my $parser = shift;
-
+
# Set up output directory for files; we use $RT::VarPath instead
# of File::Spec->tmpdir (e.g., /tmp) beacuse it isn't always
# writable.
@@ -547,8 +547,8 @@ doesn't handle local-only email addresses (when users pass
in just usernames on the RT system in fields that expect
Email Addresses)
-We don't handle the case of
-bob, fred at bestpractical.com
+We don't handle the case of
+bob, fred at bestpractical.com
because we don't want to fail parsing
bob, "Falcone, Fred" <fred at bestpractical.com>
The next release of Email::Address will have a new method
@@ -626,7 +626,7 @@ sub CleanupAddresses {
return @_;
}
-=head2 RescueOutlook
+=head2 RescueOutlook
Outlook 2007/2010 have a bug when you write an email with the html format.
it will send a 'multipart/alternative' with both 'text/plain' and 'text/html'
commit adcf9cc3fc1c713757db22c7973bf84e9395f989
Author: Gergely Nagy <algernon at bestpractical.com>
Date: Thu Oct 4 21:19:13 2018 +0200
code cleanup
Signed-off-by: Gergely Nagy <algernon at bestpractical.com>
diff --git a/lib/RT/EmailParser.pm b/lib/RT/EmailParser.pm
index cf5a812cd..45eefe6c8 100644
--- a/lib/RT/EmailParser.pm
+++ b/lib/RT/EmailParser.pm
@@ -648,8 +648,7 @@ sub RescueOutlook {
return unless $mime && $self->LooksLikeMSEmail($mime);
- my $text_part;
- my $html_part;
+ my ($text_part, $html_part);
if ( $mime->head->get('Content-Type') =~ m{multipart/mixed} ) {
my $first = $mime->parts(0);
@@ -682,22 +681,21 @@ sub RescueOutlook {
$text_part = $mime; # Assuming single part, already decoded.
}
- my $content;
my $ret;
if ($text_part) {
# use the unencoded string
- $content = $text_part->bodyhandle->as_string;
+ my $text_content = $text_part->bodyhandle->as_string;
- if ( $content =~ s/\n\n/\n/mg ) {
+ if ( $text_content =~ s/\n\n/\n/mg ) {
# Outlook puts a space on extra newlines, remove it
- $content =~ s/\ +$//mg;
+ $text_content =~ s/\ +$//mg;
# only write only if we did change the content
if ( my $io = $text_part->open("w") ) {
- $io->print($content);
+ $io->print($text_content);
$io->close;
$RT::Logger->debug(
"Removed extra newlines from MS Outlook message.");
@@ -712,13 +710,13 @@ sub RescueOutlook {
if ($html_part) {
# use the unencoded string
- $content = $html_part->bodyhandle->as_string;
+ my $html_content = $html_part->bodyhandle->as_string;
- if ( $content =~ s{<p(\s+style="[^"]*")?><br>\n?</p>}{}mg ) {
+ if ( $html_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") ) {
- $io->print($content);
+ $io->print($html_content);
$io->close;
$RT::Logger->debug(
"Removed extra newlines from MS Outlook message.");
commit d152254b9db08978293f2a4f1d2e4b78d2c72981
Author: Gergely Nagy <algernon at bestpractical.com>
Date: Thu Oct 4 21:42:53 2018 +0200
tests: html-first, text-second
Signed-off-by: Gergely Nagy <algernon at bestpractical.com>
diff --git a/t/mail/outlook.t b/t/mail/outlook.t
index 8f3b71bc8..e9bd5c41b 100644
--- a/t/mail/outlook.t
+++ b/t/mail/outlook.t
@@ -1,7 +1,7 @@
use strict;
use warnings;
-use RT::Test tests => 66;
+use RT::Test tests => 78;
RT->Config->Set('CheckMoreMSMailHeaders', 1);
@@ -39,6 +39,52 @@ Content-Transfer-Encoding: quoted-printable
<html>this is fake</html>
+------=_NextPart_000_0004_01CB045C.A5A075D0--
+
+EOF
+
+ my $content = <<EOF;
+here is the content
+
+blahmm
+another line
+EOF
+ test_email( $text, $content,
+ $mailer . ' with multipart/alternative, \n\n are replaced' );
+ }
+
+ diag "Test mail with multipart/alternative";
+ {
+ my $text = <<EOF;
+From: root\@localhost
+X-Mailer: $mailer
+To: rt\@@{[RT->Config->Get('rtname')]}
+Subject: outlook basic test
+Content-Type: multipart/alternative;
+\tboundary="----=_NextPart_000_0004_01CB045C.A5A075D0"
+
+------=_NextPart_000_0004_01CB045C.A5A075D0
+Content-Type: text/html;
+\tcharset="us-ascii"
+Content-Transfer-Encoding: quoted-printable
+
+<html>this is fake</html>
+
+
+------=_NextPart_000_0004_01CB045C.A5A075D0
+Content-Type: text/plain;
+\tcharset="us-ascii"
+Content-Transfer-Encoding: 7bit
+
+here is the content
+
+
+
+blahmm
+
+another line
+
+
------=_NextPart_000_0004_01CB045C.A5A075D0--
EOF
commit 6b7bf535552a29d7c6823008900830cbd7eab8bf
Author: Gergely Nagy <algernon at bestpractical.com>
Date: Thu Oct 4 21:46:17 2018 +0200
t/mail/outlook.t: Make it possible to select the part type with test_email
Normally, we want to test against the `text/plain` part of a multipart email,
but there are cases where we'd rather test against the `text/html` part. To make
this possible, `test_email` takes an additional argument:
`$check_type` (defaulting to `text/plain` if unspecified).
Signed-off-by: Gergely Nagy <algernon at bestpractical.com>
diff --git a/t/mail/outlook.t b/t/mail/outlook.t
index e9bd5c41b..e686761d7 100644
--- a/t/mail/outlook.t
+++ b/t/mail/outlook.t
@@ -433,7 +433,7 @@ EOF
}
sub test_email {
- my ( $text, $content, $msg ) = @_;
+ my ( $text, $content, $msg, $check_type ) = @_;
my ( $status, $id ) = RT::Test->send_via_mailgate($text);
is( $status >> 8, 0, "The mail gateway exited normally" );
ok( $id, "Created ticket" );
@@ -446,6 +446,6 @@ sub test_email {
$txns->Limit( FIELD => 'Type', VALUE => 'Create' );
my $txn = $txns->First;
- is( $txn->Content, $content, $msg );
+ is( $txn->Content(Type => $check_type || "text/plain"), $content, $msg );
}
commit 9f9fcdc0af08107a5faceb99ddf1bb1ca81cf73b
Author: Gergely Nagy <algernon at bestpractical.com>
Date: Thu Oct 4 21:55:31 2018 +0200
fixup
Signed-off-by: Gergely Nagy <algernon at bestpractical.com>
diff --git a/t/mail/outlook.t b/t/mail/outlook.t
index e686761d7..a354e808c 100644
--- a/t/mail/outlook.t
+++ b/t/mail/outlook.t
@@ -53,7 +53,7 @@ EOF
$mailer . ' with multipart/alternative, \n\n are replaced' );
}
- diag "Test mail with multipart/alternative";
+ diag "Test mail with multipart/alternative, html first";
{
my $text = <<EOF;
From: root\@localhost
commit 16d9ab6f04d5f9d4913a7493c71290e29ea6f287
Author: Gergely Nagy <algernon at bestpractical.com>
Date: Thu Oct 4 21:55:41 2018 +0200
add a html test
Signed-off-by: Gergely Nagy <algernon at bestpractical.com>
diff --git a/t/mail/outlook.t b/t/mail/outlook.t
index a354e808c..0cd139540 100644
--- a/t/mail/outlook.t
+++ b/t/mail/outlook.t
@@ -1,7 +1,7 @@
use strict;
use warnings;
-use RT::Test tests => 78;
+use RT::Test tests => 90;
RT->Config->Set('CheckMoreMSMailHeaders', 1);
@@ -36,21 +36,25 @@ Content-Type: text/html;
\tcharset="us-ascii"
Content-Transfer-Encoding: quoted-printable
-<html>this is fake</html>
-
+<html><body><p>here is the content</p><p><br></p><p>another paragraph</p></body></html>
------=_NextPart_000_0004_01CB045C.A5A075D0--
EOF
- my $content = <<EOF;
+ my $text_content = <<EOF;
here is the content
blahmm
another line
EOF
- test_email( $text, $content,
- $mailer . ' with multipart/alternative, \n\n are replaced' );
+ my $html_content = <<EOF;
+<p>here is the content</p><p>another paragraph</p>
+EOF
+ test_email( $text, $text_content,
+ $mailer . ' with multipart/alternative, \n\n are replaced' );
+ test_email( $text, $html_content,
+ $mailer . ' with multipart/alternative, line-break-only paragraphs removed from the HTML part', "text/html" );
}
diag "Test mail with multipart/alternative, html first";
-----------------------------------------------------------------------
More information about the rt-commit
mailing list