I'm using the "Full HTML" input format. When I include a link in the format "www.example.com" or "http://www.example.com", the link will show up in the email twice. If I include the link as "example.com" it will only show up once.

Comments

sutharsan’s picture

Is this when sendind plain text emails or HTML emails? In case of HTML, what module do you use for it?

OneTwoTait’s picture

plain text.

burn_ru’s picture

If node text contain single url html filter convert it to a href tag with link_label == url

After that simplenews convert it to plain text in format $label.' '.$url

According this single url in plain text mail message write twice

I fixed this in_simplenews_absolute_mail_urls function in simplenews.module

old code:

   return $label .' '. $url;

new code:

  if ($label == $url) {
    return $url;
  }
  else {
   return $label .' '. $url;
  }
Karlheinz’s picture

Some things to check:

Likely your problem is how links are converted to plaintext in your newsletter's settings. Go to "Administer > Content management > Newsletters." For each newsletter, click on "Edit Newsletter." At the bottom you will see radio-buttons labeled "Hyperlink conversion." Try changing it to "Append hyperlinks as a numbered reference list" and see what happens.

Also, the input format of the Newsletter body might be converting URL's to clickable links. You can turn this off, but it will be site-wide, not just for newsletters. Go to "Administer > Site configuration > Input formats" and edit your input format's setting. If "URL filter" is checked, un-check it.

In any case - The code posted by burn_ru is a good idea. Any way to implement it without hacking simplenews.module?

sutharsan’s picture

Status: Active » Needs review
StatusFileSize
new888 bytes

Thanks to burn_ru for investigation and code. Please test the attached patch and I will be happy to commit.

Karlheinz’s picture

I found a slight problem with burn_ru's code.

When converting a URL to a clickable link, Drupal will trim the displayed URL to no longer than 72 characters. For example:
http://www.example.com/content/this-is-a-very-long-url-that-would-wrap-in-the-users-browser-screen/
...becomes:
http://www.example.com/content/this-is-a-very-long-url-that-wo...

In other words, $label actually contains a trimmed version of $url, so they won't match.

The code below is a slight re-write. Instead of checking if $label and $url are the same, it checks to see if their leftmost 69 characters are the same (72 minus 3 for the trailing dots).

if (substr($label, 0, 69) == substr($url, 0, 69)) {
    return $url;
}
else {
    return $label .' '. $url;
}

Sorry, I don't have CVS going right now, or I'd put this in a form of a patch.

sutharsan’s picture

Status: Needs review » Needs work

The cut-off length is configurable. So I suggest to remove any existing ellipsis and then match the two strings.

Karlheinz’s picture

Done...

$elipses_pos = strpos($label, '...');
if ( ($elipses_pos !== false) && (substr($label, 0, $elipses_pos - 1) == substr($url, 0, $elipses_pos - 1) ) {
    return $url;
}
else {
    return $label .' '. $url;
}

It seems like there must be a way to get the URL length from the filter module. I found this code in the API for the _filter_url_trim function:
variable_get('filter_url_length_' . $format, 72)
...but I have no idea how you would get what input format was used to create the newsletter.

sutharsan’s picture

Status: Needs work » Fixed
StatusFileSize
new1.22 KB

The latest code does misses two cases: name@example.com and www.example.com. Thanks to bjarchuck in #512850: Links in my emails are doubled who noted the mailto case. Thanks to all who contributed code!

The attached patch is committed to HEAD and 6.x-1.x-dev.

Karlheinz’s picture

Crap, I just realized there's something wrong with my code. It now checks long URL's, but not URL's without the elipses.

The could should be:

$elipses_pos = strpos($label, '...');
if ( ($elipses_pos !== false) && (substr($label, 0, $elipses_pos - 1) == substr($url, 0, $elipses_pos - 1) ) {
    return $url;
}
elseif ($label == $url) {
    return $url;
}
else {
    return $label .' '. $url;
}

Hopefully you caught this before I did, and put it in the latest patch. If not... sorry, I guess you'll have to make another patch.

Karlheinz’s picture

Status: Fixed » Needs review

(Edited the issue settings to make sure you see my post above. If it's in the patch, set it back to "fixed.")

sutharsan’s picture

@Karlheinz, please test the patch in #9 (or download 6.x-1.x-dev tarball). In my sandbox it works with short and long URLs, with and without http://, with and without www, also with emails, and checked for both plain and HTML format.

Karlheinz’s picture

Status: Needs review » Fixed

I did not test the patch (no CVS ATM), but I DID look at the code inside. It does not have my mistakes in it (it's actually a lot more elegant than mine, in fact).

I will either make the changes by hand, or download the DEV version. Either way I'm going to switch this back to "Fixed."

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.