A html anchor link gets the site URL prepended, breaking it

greg_y - July 24, 2007 - 02:46
Project:Mime Mail
Version:5.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

It's fairly common in newsletters to have an initial table of contents with anchor links to the articles below:

In This Newsletter ...
<a href="#1">What's New</a>
<a href="#2">Breaking News</a>
..etc

now the body of the email ...

<h2 id="1">What's New</h2><br>
... some text here ...

<h2 id="2">Breaking News</h2><br>
... some text here ...

When I do this using SimpleNews / MimeMail, the links in the test email get my site $URL (http://lifetwo.com/production) prepended to them so that the first anchor link, for example, is no longer "#1" but "http://lifetwo.com/production/#1." Of course, that's not what we want -- we want the user to click on the #1 anchor and jump down to that section of the email, not get linked back to the site. It's also a nonexistent URL.

Although I'm composing and sending the test newsletter in html mode, I can see that the same problem exists for the plaintext links.

On the actual node page for the newsletter, the link is fully formed and behaves correctly -- clicking on it jumps you down the page to the appropriate anchor.

If this is an issue w/ MimeMail or some other module, please let me know and I'll cross post there. I thought SimpleNews was the most likely suspect since the change log indicated that work was done with internal links a while back.

thanks!

#1

jbjaaz - August 23, 2007 - 20:32

Did you ever figure out why this was happening? I'm having to deal with the same thing.

#2

jbjaaz - August 23, 2007 - 21:09

After digging around, I found that the following code in mimemail.inc is the culprit

  //expand all local links
  $pattern = '/(<a[^>]+href=")([^"]*)/emi';
  $body = preg_replace($pattern, '"\\1"._mimemail_url("\2")', $body);

So, I get the idea. A newsletter might be sprinkled with links pointing back to your site and this would make the links work properly. I think its safe to assume though that if the anchor href is "#text", chances are it's not pointing back to the site.

Any ideas how to enhance the regex pattern to not catch "#text"?

#3

jbjaaz - August 23, 2007 - 22:40
Status:active» patch (code needs review)

alright, I have a fix.

In mimemail.inc, look for the function "_mimemail_url($url)".

I added the following code prior to the return statement

  if (empty($path) && !empty($fragment)) {
    return '#' . $fragment;
  } 
}

Basically, I assume that a url with just the fragment is a jump link within the email. The reason I check that $path is empty is so that urls like "services#mytarget" are properly converted.

AttachmentSize
mimemail.inc - don't convert jump links - 161600 - 3.patch853 bytes

#4

dman - August 24, 2007 - 01:34

That looks like a good fix.
Yes, most embedded links in an email should be expected to be fully-justified.
But, purely anchor tags can probably be exempted.
Good idea.

#5

jbjaaz - January 15, 2008 - 16:07
Status:patch (code needs review)» patch (reviewed & tested by the community)

It's such a simple fix.

#6

Sutharsan - January 16, 2008 - 23:46
Project:Simplenews» Mime Mail
Version:5.x-1.1» 5.x-1.x-dev
Status:patch (reviewed & tested by the community)» patch (code needs review)

jbjaaz, I can agree with you that it is a simple patch. However it is not good practice to set your own patches to RTBC when you are not the module (co-)maintainer. But you have overlooked the most important fact. That this patch is for mimemail and it is currently in simplenews issue queue. Therefore I transfer it.

I recommend that this bug get fixed. The patch looks Ok to me from reviewing the code. Not tested.

#7

Shiraz Dindar - February 6, 2008 - 21:53

Thanks for catching this. Saved me some work.

#8

jerdavis - February 16, 2008 - 23:48
Status:patch (code needs review)» patch (reviewed & tested by the community)

Tested this patch and verified that it resolves the issue mentioned above. Patch applies successfully and behavior is as expected - this should be clear to commit.

#9

jerdavis - February 17, 2008 - 02:25

Uploading an updates patch, this patch takes into account the "Code Cleanup" patch from: http://drupal.org/node/220432

This update requires that patch prior to being applied.

AttachmentSize
mimemail_jumplinks_update.patch522 bytes

#10

Allie Micka - February 18, 2008 - 00:44
Status:patch (reviewed & tested by the community)» fixed

Committed to HEAD, will roll a D5 release soon. Thanks!

#11

Anonymous (not verified) - March 3, 2008 - 00:52
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.