URL displayed twice in email
taite11 - May 29, 2009 - 17:29
| Project: | Simplenews |
| Version: | 6.x-1.0-rc6 |
| Component: | Miscellaneous |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | fixed |
Description
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.

#1
Is this when sendind plain text emails or HTML emails? In case of HTML, what module do you use for it?
#2
plain text.
#3
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;
}
#4
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?
#5
Thanks to burn_ru for investigation and code. Please test the attached patch and I will be happy to commit.
#6
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,
$labelactually contains a trimmed version of$url, so they won't match.The code below is a slight re-write. Instead of checking if
$labeland$urlare 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.
#7
The cut-off length is configurable. So I suggest to remove any existing ellipsis and then match the two strings.
#8
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.
#9
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.
#10
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.
#11
(Edited the issue settings to make sure you see my post above. If it's in the patch, set it back to "fixed.")
#12
@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.
#13
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."