Uploaded image for project: 'eZ Publish / Platform'
  1. eZ Publish / Platform
  2. EZP-21567

Blank e-mail subject line with multi-byte characters (iconv_mime_encode: Unknown error)

    Details

      Description

      In some conditions, notifications (such as sub-tree modification alerts) for content with multi-byte characters will have a blank subject line; this only (AFAIK) applies if the message is sent through the SMTP Transport class in eZ Components (which is the case if eZ Publish is configured to send messages through an SMTP server).

      After configuring MailSettings to use an SMTP server, the following script reproduces the issue:

      #!/usr/bin/env php
      <?php
       
      require 'autoload.php';
       
      $cli = eZCLI::instance();
       
      $script = eZScript::instance(
          array(
              'description' => "",
              'use-session' => false,
              'use-modules' => true,
              'use-extensions' => true
          )
      );
      $script->startup();
      $script->initialize();
       
      $mail = new eZMail();
       
      $mail->setSender('SENDER E-MAIL ADDRESS GOES HERE');
      $mail->setReceiver('RECEIVER E-MAIL ADDRESS GOES HERE');
       
      ///////////////
      $mail->setSubject('This is a test');
      $mail->setBody("1 test mail");
      eZMailTransport::send($mail);
      ///////////////
      $mail->setSubject('Folder "ログイン前トップ" は更新されました [cms.mipotecq.biz - フォト&amp;ムービー]');
      $mail->setBody("2 full subject");
      eZMailTransport::send($mail);
      ///////////////
      $mail->setSubject('Folder "ログイン前トップ" は更新されました');
      $mail->setBody("3 half left");
      eZMailTransport::send($mail);
      ///////////////
      $mail->setSubject(' [cms.mipotecq.biz - フォト&amp;ムービー]');
      $mail->setBody("4 half right");
      eZMailTransport::send($mail);
      ///////////////
      $mail->setSubject(' は更新されました [cms.mipotecq.biz');
      $mail->setBody("5 center");
      eZMailTransport::send($mail);
       
      ///////////////
      $mail->setSubject('"ログイン前トップ"');
      $mail->setBody("6 content");
      eZMailTransport::send($mail);
      ///////////////
      $mail->setSubject(' は更新されました');
      $mail->setBody("7 content type");
      eZMailTransport::send($mail);
      ///////////////
      $mail->setSubject('Folder "ログイン前トップ"');
      $mail->setBody("8 left");
      eZMailTransport::send($mail);
      ///////////////
      $mail->setSubject('Folder "ログイ');
      $mail->setBody("9 Folder");
      eZMailTransport::send($mail);
       
      $script->shutdown();
      

      Example notice displayed during script execution (repeats a few times, for each affected message):

      PHP Notice:  iconv_mime_encode(): Unknown error (7) in /var/www/ezp/500-ezp/ezpublish_legacy/lib/ezc/Mail/src/interfaces/part.php on line 381
      PHP Stack trace:
      PHP   1. {main}() /var/www/ezp/500-ezp/ezpublish_legacy/script.php:0
      PHP   2. eZMailTransport::send() /var/www/ezp/500-ezp/ezpublish_legacy/script.php:66
      PHP   3. eZSMTPTransport->sendMail() /var/www/ezp/500-ezp/ezpublish_legacy/lib/ezutils/classes/ezmailtransport.php:56
      PHP   4. ezcMailSmtpTransport->send() /var/www/ezp/500-ezp/ezpublish_legacy/lib/ezutils/classes/ezsmtptransport.php:86
      PHP   5. ezcMailPart->generate() /var/www/ezp/500-ezp/ezpublish_legacy/lib/ezc/Mail/src/transports/smtp/smtp_transport.php:490
      PHP   6. ezpMail->generateHeaders() /var/www/ezp/500-ezp/ezpublish_legacy/lib/ezc/Mail/src/interfaces/part.php:434
      PHP   7. ezcMail->generateHeaders() /var/www/ezp/500-ezp/ezpublish_legacy/kernel/private/classes/ezpmail.php:31
      PHP   8. ezcMailPart->generateHeaders() /var/www/ezp/500-ezp/ezpublish_legacy/lib/ezc/Mail/src/mail.php:381
      PHP   9. iconv_mime_encode() /var/www/ezp/500-ezp/ezpublish_legacy/lib/ezc/Mail/src/interfaces/part.php:381
      

      9 messages will be sent, some of them missing a subject line. This issue does not appear to be present when using sendmail.

        Issue Links

          Activity

          Hide
          Jérôme Cohonner (Inactive) added a comment -

          Continuing investigations for the customer, looks like PHP related bug https://bugs.php.net/bug.php?id=53891

          Show
          Jérôme Cohonner (Inactive) added a comment - Continuing investigations for the customer, looks like PHP related bug https://bugs.php.net/bug.php?id=53891
          Hide
          Jérôme Cohonner (Inactive) added a comment -

          tested with
          $value = mb_encode_mimeheader($value,$charset,"Q",ezcMailTools::lineBreak());
          instead of
          $value = iconv_mime_encode( 'dummy', $value, $preferences );
          in
          ezc/Mail/src/interfaces/part.php and it worked.

          iconv_mime_encode looks clearly the main cause of this issue when multibytes characters are contained in the string.

          Show
          Jérôme Cohonner (Inactive) added a comment - tested with $value = mb_encode_mimeheader($value,$charset,"Q",ezcMailTools::lineBreak()); instead of $value = iconv_mime_encode( 'dummy', $value, $preferences ); in ezc/Mail/src/interfaces/part.php and it worked. iconv_mime_encode looks clearly the main cause of this issue when multibytes characters are contained in the string.
          Hide
          Jérôme Cohonner (Inactive) added a comment -

          Note that iconv_mime_encode is also used in tools.php (from ezcMail component) to encode sender name. Same issue may appears if the name contains multibyte characters

          Show
          Jérôme Cohonner (Inactive) added a comment - Note that iconv_mime_encode is also used in tools.php (from ezcMail component) to encode sender name. Same issue may appears if the name contains multibyte characters
          Hide
          Paulo Bras (Inactive) added a comment - - edited

          the class ezMail() is deprecated in favor of ezpMail(), as noted on the top comment of the ezmail.php file, starting with:
          "This class will be deprecated in the next eZ Publish release, and replaced with ezcMail from eZ Components."

          using the ezpMail class the headers are properly generated, assuming that a correct charset is passed along.

          this code shows the differences:
          https://gist.github.com/pbras/6594956

          #!/usr/bin/env php
          <?php
           
          require 'autoload.php';
           
           
           
          echo "\n**************** deprecated ezMail class TEST ****************\n";
          $mail = new eZMail();
           
          $mail->setSubject('This is a test');
          $mail->setBody("1 test mail");
          print_r( $mail->Mail->generateHeaders() );// ok
           
          echo "************another:\n";
          $mail->setSubject('Folder "ログイン前トップ" は更新されま' , 'utf-8');
          $mail->setBody("2 full subject");
          print_r( $mail->Mail->generateHeaders() ); // generates PHP notice and subject is empty
           
          echo "\n**************** new class ezpMail TEST ****************\n";
          $ezpMail = new ezpMail();
          $ezpMail->setHeaderCharset( 'Subject', 'utf-8' );
          $ezpMail->setHeaderCharset( 'Content-Type', 'utf-8' );
           
          $ezpMail->subject = 'This is a test';
          $ezpMail->body = new ezcMailText( "1 test mail" , 'utf-8');
          print_r( $ezpMail->generateHeaders() ); //ok
           
          echo "************another:\n";
          $ezpMail->subject = 'Folder "ログイン前トップ" は更新されま';
          $ezpMail->body = new ezcMailText( "2 full subject",  'utf-8' );
          print_r( $ezpMail->generateHeaders() ); //also ok
          

          Show
          Paulo Bras (Inactive) added a comment - - edited the class ezMail() is deprecated in favor of ezpMail(), as noted on the top comment of the ezmail.php file, starting with: "This class will be deprecated in the next eZ Publish release, and replaced with ezcMail from eZ Components." using the ezpMail class the headers are properly generated, assuming that a correct charset is passed along. this code shows the differences: https://gist.github.com/pbras/6594956 #!/usr/bin/env php <?php   require 'autoload.php';       echo "\n**************** deprecated ezMail class TEST ****************\n"; $mail = new eZMail();   $mail->setSubject('This is a test'); $mail->setBody("1 test mail"); print_r( $mail->Mail->generateHeaders() );// ok   echo "************another:\n"; $mail->setSubject('Folder "ログイン前トップ" は更新されま' , 'utf-8'); $mail->setBody("2 full subject"); print_r( $mail->Mail->generateHeaders() ); // generates PHP notice and subject is empty   echo "\n**************** new class ezpMail TEST ****************\n"; $ezpMail = new ezpMail(); $ezpMail->setHeaderCharset( 'Subject', 'utf-8' ); $ezpMail->setHeaderCharset( 'Content-Type', 'utf-8' );   $ezpMail->subject = 'This is a test'; $ezpMail->body = new ezcMailText( "1 test mail" , 'utf-8'); print_r( $ezpMail->generateHeaders() ); //ok   echo "************another:\n"; $ezpMail->subject = 'Folder "ログイン前トップ" は更新されま'; $ezpMail->body = new ezcMailText( "2 full subject", 'utf-8' ); print_r( $ezpMail->generateHeaders() ); //also ok
          Hide
          Jérôme Cohonner (Inactive) added a comment -

          This would mean that some of the inside part of eZ are still using ezmail as they have the issue.

          Please check especially: notification, approval wfw and user creation mail.

          Show
          Jérôme Cohonner (Inactive) added a comment - This would mean that some of the inside part of eZ are still using ezmail as they have the issue. Please check especially: notification, approval wfw and user creation mail.
          Hide
          Jérôme Vieilledent (Inactive) added a comment - - edited

          Jérôme Cohonner, Paulo Bras: eZMail does use ezcMail internally. This explains why instances of eZMail were not removed at all. The comments in the class is misleading (we need to remove it).

          This might be related to EZP-19032.

          Show
          Jérôme Vieilledent (Inactive) added a comment - - edited Jérôme Cohonner , Paulo Bras : eZMail does use ezcMail internally. This explains why instances of eZMail were not removed at all. The comments in the class is misleading (we need to remove it). This might be related to EZP-19032 .
          Hide
          Jérôme Vieilledent (Inactive) added a comment -

          OK, the problem comes indeed from ZetaComponents Mail.

          Actually, the example given uses Kanji and Katakana characters, which are multi-byte. Will test solution from Jérôme Cohonner

          Show
          Jérôme Vieilledent (Inactive) added a comment - OK, the problem comes indeed from ZetaComponents Mail . Actually, the example given uses Kanji and Katakana characters, which are multi-byte. Will test solution from Jérôme Cohonner
          Hide
          Jérôme Vieilledent (Inactive) added a comment -

          PR in ZetaComponents Mail component: https://github.com/zetacomponents/Mail/pull/8

          Show
          Jérôme Vieilledent (Inactive) added a comment - PR in ZetaComponents Mail component: https://github.com/zetacomponents/Mail/pull/8
          Show
          Jérôme Vieilledent (Inactive) added a comment - Fixed in ZetaComponents Mail master: https://github.com/zetacomponents/Mail/commit/71b05a428fa448b68ab888651fd6de7176a149b6
          Hide
          Jérôme Vieilledent (Inactive) added a comment - - edited

          If on master: just do a

          php composer.phar update zetacomponents/mail
          

          If in your composer.json you have something like zetacomponents/mail: dev-master#abc1234, remove the hash reference (including # and do the update.

          Show
          Jérôme Vieilledent (Inactive) added a comment - - edited If on master: just do a php composer.phar update zetacomponents/mail If in your composer.json you have something like zetacomponents/mail: dev-master#abc1234 , remove the hash reference (including # and do the update.
          Hide
          Filipe Dobreira (Inactive) added a comment -

          QA Approved.

          Show
          Filipe Dobreira (Inactive) added a comment - QA Approved.

            People

            • Assignee:
              Unassigned
              Reporter:
              Filipe Dobreira (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 4 hours
                4h