[Rt-commit] rt branch, 3.8-trunk, updated. rt-3.8.8-75-g58dfb2b

? sunnavy sunnavy at bestpractical.com
Sat Jun 5 04:48:39 EDT 2010


The branch, 3.8-trunk has been updated
       via  58dfb2bbe12cf3979ae1682842af2407cbbbdf78 (commit)
       via  aa6a2bacda85fe246dc1086efc854f052ea18e09 (commit)
      from  b6aae89492d9e2b0cacdd3a60a034fe95ed73582 (commit)

Summary of changes:
 lib/RT/EmailParser.pm |   61 +++++++++++
 t/mail/outlook.t      |  270 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 331 insertions(+), 0 deletions(-)
 create mode 100644 t/mail/outlook.t

- Log -----------------------------------------------------------------
commit aa6a2bacda85fe246dc1086efc854f052ea18e09
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Jun 5 16:45:38 2010 +0800

    tests for the \n\n bug in outlook

diff --git a/t/mail/outlook.t b/t/mail/outlook.t
new file mode 100644
index 0000000..23706e6
--- /dev/null
+++ b/t/mail/outlook.t
@@ -0,0 +1,270 @@
+#!/usr/bin/perl -w
+# BEGIN BPS TAGGED BLOCK {{{
+# 
+# COPYRIGHT:
+#  
+# This software is Copyright (c) 1996-2004 Best Practical Solutions, LLC 
+#                                          <jesse.com>
+# 
+# (Except where explicitly superseded by other copyright notices)
+# 
+# 
+# LICENSE:
+# 
+# This work is made available to you under the terms of Version 2 of
+# the GNU General Public License. A copy of that license should have
+# been provided with this software, but in any event can be snarfed
+# from www.gnu.org.
+# 
+# This work is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 or visit their web page on the internet at
+# http://www.gnu.org/copyleft/gpl.html.
+# 
+# 
+# CONTRIBUTION SUBMISSION POLICY:
+# 
+# (The following paragraph is not intended to limit the rights granted
+# to you to modify and distribute this software under the terms of
+# the GNU General Public License and is only of importance to you if
+# you choose to contribute your changes and enhancements to the
+# community by submitting them to Best Practical Solutions, LLC.)
+# 
+# By intentionally submitting any modifications, corrections or
+# derivatives to this work, or any other work intended for use with
+# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+# you are the copyright holder for those contributions and you grant
+# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
+# royalty-free, perpetual, license to use, copy, create derivative
+# works based on those contributions, and sublicense and distribute
+# those contributions and any derivatives thereof.
+# 
+# END BPS TAGGED BLOCK }}}
+
+=head1 NAME
+
+rt-mailgate - Mail interface to RT3.
+
+=cut
+
+use strict;
+use warnings;
+
+use RT::Test tests => 25;
+my ($baseurl, $m) = RT::Test->started_ok;
+diag "Test mail with multipart/alternative" if $ENV{'TEST_VERBOSE'};
+{
+    my $text = <<EOF;
+From: root\@localhost
+X-Mailer: Microsoft Office Outlook 12.0
+To: rt\@@{[RT->Config->Get('rtname')]}
+Subject: outlook basic test
+Content-Type: multipart/alternative;
+	boundary="----=_NextPart_000_0004_01CB045C.A5A075D0"
+
+------=_NextPart_000_0004_01CB045C.A5A075D0
+Content-Type: text/plain;
+	charset="us-ascii"
+Content-Transfer-Encoding: 7bit
+
+here is the content
+
+
+
+blahmm
+
+another line
+
+
+------=_NextPart_000_0004_01CB045C.A5A075D0
+Content-Type: text/html;
+	charset="us-ascii"
+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,
+        'outlook with multipart/alternative, \n\n will not be replaced' );
+}
+
+diag "Test mail with multipart/mixed, with multipart/alternative in it"
+  if $ENV{'TEST_VERBOSE'};
+{
+    my $text = <<EOF;
+From: root\@localhost
+X-Mailer: Microsoft Office Outlook 12.0
+To: rt\@@{[RT->Config->Get('rtname')]}
+Subject: outlook basic test
+Content-Type: multipart/mixed;
+	boundary="----=_NextPart_000_000F_01CB045E.5222CB40"
+X-Mailer: Microsoft Office Outlook 12.0
+
+------=_NextPart_000_000F_01CB045E.5222CB40
+Content-Type: multipart/alternative;
+	boundary="----=_NextPart_001_0010_01CB045E.5222CB40"
+
+
+------=_NextPart_001_0010_01CB045E.5222CB40
+Content-Type: text/plain;
+	charset="us-ascii"
+Content-Transfer-Encoding: 7bit
+
+foo
+
+
+
+bar
+
+baz
+
+
+------=_NextPart_001_0010_01CB045E.5222CB40
+Content-Type: text/html;
+	charset="us-ascii"
+Content-Transfer-Encoding: quoted-printable
+
+<html>this is fake</html>
+
+------=_NextPart_001_0010_01CB045E.5222CB40--
+
+------=_NextPart_000_000F_01CB045E.5222CB40
+Content-Type: text/plain;
+	name="att.txt"
+Content-Transfer-Encoding: quoted-printable
+Content-Disposition: attachment;
+	filename="att.txt"
+
+this is the attachment! :)=0A=
+
+------=_NextPart_000_000F_01CB045E.5222CB40--
+EOF
+
+    my $content = <<EOF;
+foo
+
+bar
+baz
+EOF
+    test_email( $text, $content,
+        'outlook with multipart/multipart, \n\n will not be replaced' );
+}
+
+diag "Test mail with with outlook, but the content type is text/plain"
+  if $ENV{'TEST_VERBOSE'};
+{
+    my $text = <<EOF;
+From: root\@localhost
+X-Mailer: Mutt
+To: rt\@@{[RT->Config->Get('rtname')]}
+Subject: outlook basic test
+Content-Type: text/plain; charset="us-ascii"
+Content-Transfer-Encoding: 7bit
+
+foo
+
+
+
+bar
+
+baz
+
+EOF
+
+    my $content = <<EOF;
+foo
+
+
+
+bar
+
+baz
+
+EOF
+    test_email( $text, $content,
+        'outlook with only text/plain, \n\n will not be replaced' );
+}
+
+diag "Test mail with with multipart/alternative but x-mailer is not outlook "
+  if $ENV{'TEST_VERBOSE'};
+{
+    my $text = <<EOF;
+From: root\@localhost
+X-Mailer: Mutt
+To: rt\@@{[RT->Config->Get('rtname')]}
+Subject: outlook basic test
+Content-Type: multipart/alternative;
+	boundary="----=_NextPart_000_0004_01CB045C.A5A075D0"
+
+------=_NextPart_000_0004_01CB045C.A5A075D0
+Content-Type: text/plain;
+	charset="us-ascii"
+Content-Transfer-Encoding: 7bit
+
+foo
+
+
+
+bar
+
+baz
+
+
+------=_NextPart_000_0004_01CB045C.A5A075D0
+Content-Type: text/html;
+	charset="us-ascii"
+Content-Transfer-Encoding: quoted-printable
+
+<html>this is fake</html>
+
+
+------=_NextPart_000_0004_01CB045C.A5A075D0--
+
+EOF
+
+    my $content = <<EOF;
+foo
+
+
+
+bar
+
+baz
+
+EOF
+    test_email( $text, $content, 'without outlook, \n\n will not be replaced' );
+}
+
+sub test_email {
+    my ( $text, $content, $msg ) = @_;
+    my ( $status, $id ) = RT::Test->send_via_mailgate($text);
+    is( $status >> 8, 0, "The mail gateway exited normally" );
+    ok( $id, "Created ticket" );
+
+    my $ticket = RT::Test->last_ticket;
+    isa_ok( $ticket, 'RT::Ticket' );
+    is( $ticket->Id, $id, "correct ticket id" );
+    is( $ticket->Subject, 'outlook basic test', "subject of ticket $id" );
+    my $txns = $ticket->Transactions;
+    $txns->Limit( FIELD => 'Type', VALUE => 'Create' );
+    my $txn     = $txns->First;
+
+    is( $txn->Content, $content, $msg );
+}
+

commit 58dfb2bbe12cf3979ae1682842af2407cbbbdf78
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Jun 5 16:48:45 2010 +0800

    fix the \n\n bug in mail outlook sends

diff --git a/lib/RT/EmailParser.pm b/lib/RT/EmailParser.pm
index 63c7698..8c303f2 100755
--- a/lib/RT/EmailParser.pm
+++ b/lib/RT/EmailParser.pm
@@ -130,6 +130,8 @@ sub SmartParseMIMEEntityFromScalar {
         }
     };
 
+    $self->RescueOutlook;
+
     #If for some reason we weren't able to parse the message using a temp file
     # try it with a scalar
     if ( $@ || !$self->Entity ) {
@@ -558,6 +560,65 @@ sub ParseEmailAddress {
 
 }
 
+=head2 RescueOutlook 
+
+Outlook 2007 has a bug when you write an email with the html format.
+it will send a 'multipart/alternative' with both 'text/plain' and 'text/html'
+in it.  it's cool to have a 'text/plain' part, but the problem is the part is
+not so right: all the "\n" in your main message will become "\n\n" :/
+
+this method will fix this bug, i.e. replaces "\n\n" to "\n".
+return 1 if it does find the problem in the entity and get it fixed.
+
+=cut
+
+
+sub RescueOutlook {
+    my $self = shift;
+    my $mime = $self->Entity();
+    return unless $mime;
+
+    my $mailer = $mime->head->get('X-Mailer');
+    if ( $mailer && $mailer =~ /Microsoft Office Outlook 12\./ ) {
+        my $text_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;
+                }
+            }
+        }
+        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;
+            }
+        }
+
+        if ($text_part) {
+
+            # use the unencoded string
+            my $content = $text_part->bodyhandle->as_string;
+            if ( $content =~ s/\n\n/\n/g ) {
+                # only write only if we did change the content
+                if ( my $io = $text_part->open("w") ) {
+                    $io->print($content);
+                    $io->close;
+                    return 1;
+                }
+                else {
+                    $RT::Logger->error("can't write to body");
+                }
+            }
+        }
+    }
+    return;
+}
+
 
 sub DESTROY {
     my $self = shift;

-----------------------------------------------------------------------


More information about the Rt-commit mailing list