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

          Filipe Dobreira (Inactive) created issue -
          Filipe Dobreira (Inactive) made changes -
          Field Original Value New Value
          Summary iconv_mime_encode: Unknown error - Blank e-mail subject line with multi-byte characters Blank e-mail subject line with multi-byte characters (iconv_mime_encode: Unknown error)
          Filipe Dobreira (Inactive) made changes -
          Status Open [ 1 ] Confirmed [ 10037 ]
          Gunnstein Lye made changes -
          Status Confirmed [ 10037 ] InputQ [ 10001 ]
          Gunnstein Lye made changes -
          Rank Ranked higher
          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
          Paulo Bras (Inactive) made changes -
          Status InputQ [ 10001 ] Development [ 3 ]
          Assignee Paulo Bras [ paulo.bras@ez.no ]
          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 .
          Jérôme Vieilledent (Inactive) made changes -
          Link This issue relates to EZP-19032 [ EZP-19032 ]
          Jérôme Vieilledent (Inactive) made changes -
          Assignee Paulo Bras [ paulo.bras@ez.no ] Jérôme Vieilledent [ jerome.vieilledent@ez.no ]
          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
          Jérôme Vieilledent (Inactive) made changes -
          Remote Link This issue links to "https://github.com/zetacomponents/Mail/pull/8 (Web Link)" [ 12519 ]
          Jérôme Vieilledent (Inactive) made changes -
          Status Development [ 3 ] Development review [ 10006 ]
          Jérôme Vieilledent (Inactive) made changes -
          Remote Link This issue links to "https://github.com/zetacomponents/Mail/pull/8 (Web Link)" [ 12705 ]
          Show
          Jérôme Vieilledent (Inactive) added a comment - Fixed in ZetaComponents Mail master: https://github.com/zetacomponents/Mail/commit/71b05a428fa448b68ab888651fd6de7176a149b6
          Jérôme Vieilledent (Inactive) made changes -
          Status Development review [ 10006 ] Development Review done [ 10028 ]
          Affects Version/s 5.1 [ 11280 ]
          Affects Version/s 5.2-beta1 [ 12684 ]
          Fix Version/s 5.2-rc1 [ 12781 ]
          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.
          Jérôme Vieilledent (Inactive) made changes -
          Status Development Review done [ 10028 ] Documentation done [ 10011 ]
          Joao Pingo (Inactive) made changes -
          Status Documentation done [ 10011 ] QA [ 10008 ]
          Assignee Jérôme Vieilledent [ jerome.vieilledent@ez.no ] Joao Pingo [ joao.pingo@ez.no ]
          Joao Pingo (Inactive) logged work - 01/Oct/13 10:15 AM - edited
          • Time Spent:
            3 hours
             

            Testing

          Jérôme Vieilledent (Inactive) made changes -
          Fix Version/s 5.0 Maintenance [ 11287 ]
          Fix Version/s 5.1 Maintenance [ 12301 ]
          Joao Pingo (Inactive) made changes -
          Remaining Estimate 0 minutes [ 0 ]
          Time Spent 3 hours [ 10800 ]
          Worklog Id 40643 [ 40643 ]
          Joao Pingo (Inactive) made changes -
          Worklog Id 40643 [ 40643 ]
          Joao Pingo (Inactive) made changes -
          Status QA [ 10008 ] InputQ [ 10001 ]
          Assignee Joao Pingo [ joao.pingo@ez.no ]
          Joao Pingo (Inactive) made changes -
          Status InputQ [ 10001 ] Documentation [ 10010 ]
          Assignee Joao Pingo [ joao.pingo@ez.no ]
          Joao Pingo (Inactive) made changes -
          Status Documentation [ 10010 ] Documentation done [ 10011 ]
          Joao Pingo (Inactive) made changes -
          Status Documentation done [ 10011 ] QA [ 10008 ]
          Joao Pingo (Inactive) made changes -
          Rank Ranked higher
          Joao Pingo (Inactive) made changes -
          Status QA [ 10008 ] InputQ [ 10001 ]
          Assignee Joao Pingo [ joao.pingo@ez.no ]
          Joao Pingo (Inactive) made changes -
          Time Spent 3 hours [ 10800 ] 4 hours [ 14400 ]
          Worklog Id 40775 [ 40775 ]
          Joao Pingo (Inactive) logged work - 03/Oct/13 2:49 PM
          • Time Spent:
            1 hour
             

            Tested 5.0 and sent back

          Jérôme Vieilledent (Inactive) made changes -
          Status InputQ [ 10001 ] Development [ 3 ]
          Assignee Jérôme Vieilledent [ jerome.vieilledent@ez.no ]
          Jérôme Vieilledent (Inactive) made changes -
          Status Development [ 3 ] Documentation done [ 10011 ]
          Filipe Dobreira (Inactive) made changes -
          Status Documentation done [ 10011 ] QA [ 10008 ]
          Assignee Jérôme Vieilledent [ jerome.vieilledent@ez.no ] Filipe Dobreira [ filipe.dobreira@ez.no ]
          Hide
          Filipe Dobreira (Inactive) added a comment -

          QA Approved.

          Show
          Filipe Dobreira (Inactive) added a comment - QA Approved.
          Filipe Dobreira (Inactive) made changes -
          Assignee Filipe Dobreira [ filipe.dobreira@ez.no ]
          Status QA [ 10008 ] Closed [ 6 ]
          Resolution Fixed [ 1 ]
          André Rømcke made changes -
          Workflow eZ Engineering Scrumban Workflow [ 58965 ] EZ* Development Workflow [ 84240 ]
          Alex Schuster made changes -
          Workflow EZ* Development Workflow [ 84240 ] EZEE Development Workflow [ 122885 ]
          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open Confirmed Confirmed
          1m 32s 1 Filipe Dobreira (Inactive) 16/Sep/13 11:58 AM
          Confirmed Confirmed InputQ InputQ
          3h 3m 1 Gunnstein Lye 16/Sep/13 3:01 PM
          Development Development Development Review Development Review
          6d 1h 42m 1 jerome.vieilledent@ez.no 23/Sep/13 3:40 PM
          Development Review Development Review Development Review done Development Review done
          6d 19h 50m 1 jerome.vieilledent@ez.no 30/Sep/13 11:30 AM
          Development Review done Development Review done Documentation Review done Documentation Review done
          12m 35s 1 jerome.vieilledent@ez.no 30/Sep/13 11:43 AM
          InputQ InputQ Documentation Documentation
          43s 1 Joao Pingo (Inactive) 03/Oct/13 12:34 PM
          Documentation Documentation Documentation Review done Documentation Review done
          2m 59s 1 Joao Pingo (Inactive) 03/Oct/13 12:37 PM
          QA QA InputQ InputQ
          3d 55m 2 Joao Pingo (Inactive) 03/Oct/13 1:45 PM
          InputQ InputQ Development Development
          5d 18h 41m 2 jerome.vieilledent@ez.no 08/Oct/13 9:31 AM
          Development Development Documentation Review done Documentation Review done
          11s 1 jerome.vieilledent@ez.no 08/Oct/13 9:31 AM
          Documentation Review done Documentation Review done QA QA
          2h 3m 3 Filipe Dobreira (Inactive) 08/Oct/13 10:32 AM
          QA QA Closed Closed
          1d 3h 1 Filipe Dobreira (Inactive) 09/Oct/13 1:33 PM

            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