CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMail (Moderator: Piotr Szotkowski) »
  • Text messages contain dodgy URLs when generated from HTML messages
Pages: [1]

Author Topic: Text messages contain dodgy URLs when generated from HTML messages  (Read 2015 times)

ken

  • I live on this forum
  • *****
  • Posts: 916
  • Karma: 53
    • City Bible Forum
  • CiviCRM version: 4.6.3
  • CMS version: Drupal 7.36
  • MySQL version: 5.5.41
  • PHP version: 5.3.10
Text messages contain dodgy URLs when generated from HTML messages
August 26, 2010, 03:36:50 pm
We send out HTML messages and don't set the text portion: we let CiviMail generate that for us from the HTML content. But we find the links that are generated are dodgy (under both the Joomla and Drupal versions for 3.1.5). Here's an example...

Quote
     City Bible Forum [1]

        SYDNEY MELBOURNE BRISBANE PERTH

        National office:  Level 4, 5 Elizabeth St
Sydney, NSW 2000

 02 9232 8700  

        This email was sent to Ken West  To pass this email
to a friend, you can forward [2] it.
 To stop receiving messages on this topic, you can unsubscribe [3].
 To start receiving messages again on this topic, you can resubscribe
[4].
 To never receive any future messages from us on any topic, you can
opt out [5].  

 

Links:
------
[1] https://www.citybibleforum.org/administrator/components/com_civicrm/civicrm/extern/url.php?u=xxx&qid=yyy
[2] http://www.citybibleforum.org/https://www.citybibleforum.org/index.php?option=com_civicrm&task=civicrm/mailing/forward&reset=1&jid=zzz&qid=yyy&h=ttt
[3] http://www.citybibleforum.org/https://www.citybibleforum.org/index.php?option=com_civicrm&task=civicrm/mailing/unsubscribe&reset=1&jid=zzz&qid=yyy&h=ttt
[4] http://www.citybibleforum.org/https://www.citybibleforum.org/index.php?option=com_civicrm&task=civicrm/mailing/resubscribe&reset=1&jid=zzz&qid=yyy&h=ttt
[5] http://www.citybibleforum.org/https://www.citybibleforum.org/index.php?option=com_civicrm&task=civicrm/mailing/optout&reset=1&jid=zzz&qid=yyy&h=ttt

Note the links at the bottom of this quote which look like http://www.citybibleforum.org/https://www.citybibleforum.org/index.php...

The mailing footer that generates this text is...

Code: [Select]
<div class="footer-layout footer-text">
<a href="http://www.citybibleforum.org">City Bible Forum</a><br>
<table class="footer-text">
  <tbody>
    <tr>
      <td colspan="2">
        <strong>Sydney&nbsp;&nbsp;&nbsp;
        Melbourne&nbsp;&nbsp;&nbsp;
        Brisbane&nbsp;&nbsp;&nbsp;
        Perth</strong>
      </td>
    </tr>
    <tr>
      <td>
        National office:
      </td>
      <td>
        {domain.address}<br/>
        {domain.phone}
      </td>
    </tr>
  </tbody>
</table>
<table class="footer-text">
  <tbody>
    <tr>
      <td>
        This email was sent to {contact.display_name}
      </td>
      <td>
        To pass this email to a friend, you can <a href="{action.forward}">forward</a> it.<br/>
        To stop receiving messages on this topic, you can <a href="{action.unsubscribeUrl}">unsubscribe</a>.<br/>
        To start receiving messages again on this topic, you can <a href="{action.resubscribeUrl}">resubscribe</a>.<br/>
        To never receive any future messages from us on any topic, you can <a href="{action.optOutUrl}">opt out</a>.
      </td>
    </tr>
  </tbody>
</table>
</div>

So link [1] is generated correctly from the HREF property of an A element, but [2] etc are generated from tokens such as {action.forward}.
« Last Edit: August 26, 2010, 03:39:21 pm by ken »

Piotr Szotkowski

  • Moderator
  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: Text messages contain dodgy URLs when generated from HTML messages
September 10, 2010, 04:47:42 am
When do you plan to upgrade to CiviCRM 3.2? It would be best to see whether it’s reproducible in CiviCRM 3.2.3.
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

ken

  • I live on this forum
  • *****
  • Posts: 916
  • Karma: 53
    • City Bible Forum
  • CiviCRM version: 4.6.3
  • CMS version: Drupal 7.36
  • MySQL version: 5.5.41
  • PHP version: 5.3.10
Re: Text messages contain dodgy URLs when generated from HTML messages
September 11, 2010, 12:13:06 am
Piotr,

I hope to upgrade in mid-October.

Ken

Piotr Szotkowski

  • Moderator
  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: Text messages contain dodgy URLs when generated from HTML messages
September 16, 2010, 04:59:31 am
Can you check whether your resource URLs are specified as starting with https://?

Also, can you try rearranging the URLs to see whether it’s working for {action.forward} or whether it’s working for the first URL encountered?
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

ken

  • I live on this forum
  • *****
  • Posts: 916
  • Karma: 53
    • City Bible Forum
  • CiviCRM version: 4.6.3
  • CMS version: Drupal 7.36
  • MySQL version: 5.5.41
  • PHP version: 5.3.10
Re: Text messages contain dodgy URLs when generated from HTML messages
October 10, 2010, 01:24:00 am
Piotr,

I think I've discovered why this is happening...
  • My email only has an HTML-part and no text-part
  • My HTML footer contains <a href="{action.unsubscribeUrl}">unsubscribe</a>
  • When this is converted from HTML to text, the link is listed as [2] http://www.example.com/{action.unsubscribeUrl} (if it's the second link in the list)
  • When the token replacement is done, this is converted to [2] http://www.example.com/https://www.example.com/index.php?q=civicrm/mailing/unsubscribe&reset=1&jid=___&qid=___&h=___

Looking at the 3.2.3 code ...

In CRM/Mailing/BAO/Mailing.php starting on line 988, getPreparedTemplates is called before getTokenData...

Code: [Select]
        $pTemplates = $this->getPreparedTemplates();
        $pEmails = array( );

        foreach( $pTemplates as $type => $pTemplate ) {
            $html = ($type == 'html') ? true : false;
            $pEmails[$type] = array( );
            $pEmail   =& $pEmails[$type];
            $template =& $pTemplates[$type]['template'];
            $tokens   =& $pTemplates[$type]['tokens'];
            $idx = 0;
            if ( !empty( $tokens ) ) {
                foreach ($tokens as $idx => $token) {
                    $token_data = $this->getTokenData($token, $html, $contact, $verp, $urls, $event_queue_id);
                    array_push($pEmail, $template[$idx]);
                    array_push($pEmail, $token_data);
                }
            } else {
                array_push($pEmail, $template[$idx]);
            }
           
            if ( isset( $template[($idx + 1)] ) ) {
                array_push($pEmail, $template[($idx + 1)]);
            }
        }

getPreparedTemplates invokes the code which (when no text-part is supplied) creates the text-part from the HTML-part.

getTokenData converts the unsubscribe token (among others) to a URL.

ken

  • I live on this forum
  • *****
  • Posts: 916
  • Karma: 53
    • City Bible Forum
  • CiviCRM version: 4.6.3
  • CMS version: Drupal 7.36
  • MySQL version: 5.5.41
  • PHP version: 5.3.10
Re: Text messages contain dodgy URLs when generated from HTML messages
October 10, 2010, 02:38:35 am
Piotr,

A couple of suggestions...

  • The function CRM_Mailing_BAO_Mailing::getTemplates currently constructs the text-part of an email from the HTML-part, if no text-part is supplied. The way this is done is incorrect in that the header and footer used are not the text-versions, but are the HTML-versions converted to text. If no text-part is supplied, it should be constructed by concatenating the text-header, the converted HTML body, and the text-footer (each separated by new-lines).
  • The previous suggestion stops the behaviour I see when a (unsubscribe, etc) token is placed in the header or footer, but not in the body. Another option would be to modify html2text::_build_link_list in packages/html2text/class.html2text.inc to be aware of tokens. This could be done by adding an extra condition to the first if-statement: substr($link, 0, 1) == '{' || ... It appears this function is only used when processing emails or email events, so that might be an appropriate change.

Ken

Piotr Szotkowski

  • Moderator
  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: Text messages contain dodgy URLs when generated from HTML messages
November 02, 2010, 10:52:11 am
Hey, thanks a lot for the thorough investigation and detailed descriptions – and apologies for the late reply!

I filed CRM-7025 and will fix it ASAP, probably as per your second suggestion – I’ll have to ponder on the first one a bit (it assumes all HTML headers and footers have equivalent text parts, which might not be the case in installs that heavily rely on HTML – and in this case it might actually be beneficial to create the text header/footer from the HTML one, as it is basically done today).
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMail (Moderator: Piotr Szotkowski) »
  • Text messages contain dodgy URLs when generated from HTML messages

This forum was archived on 2017-11-26.