Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-13690

html2text fails to convert Mailing token links

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Minor
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.4.0
    • Fix Version/s: 4.4.1
    • Component/s: CiviMail
    • Labels:
      None

      Description

      When sending a CiviMail with no text part, the text part is generated from the HTML part using the html2text package.

      This conversion occurs before token replacement, so html2text has to process links of the form "

      {action.forward}". html2text thinks these are relative links so it prefixes them giving "http://example.org/{action.forward}

      ". The token processing then converts this to "http://example.org/http://example.org/civicrm/mailing/forward?..." which is invalid.

      Here's a patch ...

      -----------------------------------------------------------------
      — /data/Download/CiviCRM/civicrm-4.4.0-drupal/./CRM/Utils/String.php 2013-10-24 07:53:25.000000000 +1100
      +++ /data/Work/IT/CiviCRM/Local/4.4.0/cbf/php/./CRM/Utils/String.php 2013-10-29 07:56:40.574785938 +1100
      @@ -410,8 +410,11 @@
      */
      static function htmlToText($html) {
      require_once 'packages/html2text/rcube_html2text.php';

      • $converter = new rcube_html2text($html);
      • return $converter->get_text();
        + $token_html = preg_replace('!{([a-z_.]+)}!i', 'token:{$1}', $html);
        + $converter = new rcube_html2text($token_html);
        + $token_text = $converter->get_text();
        + $text = preg_replace('!token\:{([a-z_.]+)}!i', '{$1}', $token_text);
        + return $text;
        }

      static function extractName($string, &$params) {
      -----------------------------------------------------------------

      What it does is...

      • Convert tokens in the HTML to a format html2text thinks is an absolute URL (" {action.unsubscribeUrl}" -> "token:{action.unsubscribeUrl}

        ")

      • Run html2text over that
      • Convert the Text to undo the first step ("token: {action.unsubscribeUrl}" -> "{action.unsubscribeUrl}

        ")

      • Return the Text

      Can someone who knows the token code better than I check ...

      • The regular expressions for recognising tokens are OK
      • The change doesn't interfere with other parts of the HTML (eg, "{" in CSS)

        Attachments

          Activity

            People

            • Assignee:
              monish.deb Monish Deb
              Reporter:
              ken Ken West
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: