You are here: Foswiki>Tasks Web>Item11134 (17 Dec 2011, GeorgeClark)Edit Attach

Item11134: Configure: test emails are broken

pencil
Priority: Urgent
Current State: Closed
Released In: 1.1.4
Target Release: patch
Applies To: Engine
Component:
Branches:
Reported By: TimotheLitt
Waiting For:
Last Change By: GeorgeClark
I just spent an evening trying to get the (useful) configure "send test email" tab to work.

With S/MIME enabled, it failed miserably.

Issues:
  • The multipart/mixed test message was syntactically incorrect. No end boundary (--boundary--) tag at the end. This caused the signature to be put into the body in the wrong place, with dire consequence. Fixing that allowed openssl to validate the e-mail. (openssl is what underlies S/MIME verification by several clients, including SquirrelMail.)
  • But wait, there's more. Outlook (2003 for sure) refuses to open the test e-mail, complaining about the format of the signature. Actually, complaining about something else, but the problem was its misperception of the signature.

Digging into the second problem was unpleasant. Sparing you the waypoints, the conclusion is that Outlook doesn't like multipart/mixed with only a single body-part. At least, when the multipart/mixed is embedded in multipart/signed. I can't find anything in the RFCs that supports the Outlook behavior, but it is what it is frown, sad smile

This all results in the following patch (to trunk), which does the following:

  • Changes from MIME with multi-part/mixed to MIME with text/plain
  • Adds a debug dump in _sendEmailBySendmail. This is especially useful with S/MIME enabled, because it shows the message after the S/MIME transformations and signing. (S/MIME re-arranges headers and turns any message into a 2-part multipart/signed, where the first part is what you started with, and the second is a pseudo-attachment with the signature.)

It actually might be nice to have a config item for mail program debug flags - that would allow sendmail -OLogLevel=15 -X tmpfile capture a protocol trace as is done with Net::SMTP.

Anyhow, here's the patch:

Index: core/lib/Foswiki/Net.pm
===================================================================
--- core/lib/Foswiki/Net.pm     (revision 12524)
+++ core/lib/Foswiki/Net.pm     (working copy)
@@ -464,11 +464,11 @@

     # send with sendmail
     my ( $header, $body ) = split( "\n\n", $text, 2 );
-    $header =~
-s/([\n\r])(From|To|CC|BCC)(\:\s*)([^\n\r]*)/$1.$2.$3._fixLineLength($4)/geois;
+    $header =~ s/([\n\r])(From|To|CC|BCC)(\:\s*)([^\n\r]*)/$1.$2.$3._fixLineLength($4)/geois;
     $text = "$header\n\n$body";    # rebuild message

     $this->_smimeSignMessage($text) if ( $Foswiki::cfg{Email}{EnableSMIME} );
+    print STDERR $text if( $Foswiki::cfg{SMTP}{Debug} );

     my $MAIL;
     open( $MAIL, '|-', $Foswiki::cfg{MailProgram} )
Index: core/bin/configure
===================================================================
--- core/bin/configure  (revision 12524)
+++ core/bin/configure  (working copy)
@@ -837,15 +837,10 @@
 To: $Foswiki::cfg{WebMasterEmail}
 Subject: Test of Foswiki e-mail facility from configure
 MIME-Version: 1.0
-Content-Type: multipart/mixed; boundary="------------2D594AE113AD25493C2C7246"
-
-This is a multi-part message in MIME format.
---------------2D594AE113AD25493C2C7246
 Content-Type: text/plain; charset=$charset
 Content-Transfer-Encoding: 8bit

 It Works!  Test message from Foswiki.
-
 MAIL

         if ( $Foswiki::cfg{WebMasterEmail} ) {

Note that any other code that is sloppy about creating MIME messages could get into similar trouble...

Enjoy.

-- TimotheLitt - 18 Sep 2011

Thanks Timothe, I'll get these patches applied. Was there a change to the regex? The split line is a perltidy-ism. Thanks for getting this all tested.

-- GeorgeClark - 19 Sep 2011

Regarding the sendmail debug parameters, I suspect that this is specific to the real sendmail implementation? Trying them on my test system which uses ssmpt, -X tmpfile is mis-interpreted and tries to send a message to user tmpfile. And on my live server using Postfix, -X option is documented as ignored - Use the debug_peer_list and debug_peer_level configuration parameters instead. 0 for 2 for some fairly common configurations.

-- GeorgeClark - 19 Sep 2011

Thanks for digging in.

No change to the regex, emacs and pertldy disagreed. Sorry about that.

By the way, I did confirm that multipart/mixed DOES work when you add a second body part with identical text, though Outlook then takes the second part as an attachment. The wonders of standards...

I meant -X by way of example. I was suggesting a config item, perhaps "{MailProgramDebugFlags}" that we add to the command line when {SMTP}{Debug} is on. That way whatever magic a given program requires can be entered. Sendmail defaults would seem reasonable. Also, it occured to me that given the way you set things up to capture STDERR, we could use /dev/fd/2, avoiding the tempfile... In sendmail, -X redirects logging to the specified file, and the OLogLevel=15 gives a protocol trace - pretty similar to what Net::SMTP does. So with a config item, someone using Postix would, I suppose use some number of -v flags, or perhaps -c with a debug config. I don't run Postix, but an postfix person could recomend some flags for the doc. At least an item would provide the mechanism. Of course one could argue that the solution is to modify the command line option for debug. But that requires knowledge/magic. And it seems better to have a one-click "get a trace for the mail expert" than to demand that the mail expert become a wiki expert too...

-- TimotheLitt - 19 Sep 2011
 

ItemTemplate edit

Summary Configure: test emails are broken
ReportedBy TimotheLitt
Codebase 1.1.3, trunk
SVN Range
AppliesTo Engine
Component
Priority Urgent
CurrentState Closed
WaitingFor
Checkins distro:f04264fef0a1 distro:50e36a42e853 Rev 12578 not found
TargetRelease patch
ReleasedIn 1.1.4
Topic revision: r10 - 17 Dec 2011, GeorgeClark
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy