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!

Comments

jbjaaz’s picture

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

jbjaaz’s picture

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"?

jbjaaz’s picture

Status: Active » Needs review
StatusFileSize
new853 bytes

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.

dman’s picture

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.

jbjaaz’s picture

Status: Needs review » Reviewed & tested by the community

It's such a simple fix.

sutharsan’s picture

Project: Simplenews » Mime Mail
Version: 5.x-1.1 » 5.x-1.x-dev
Status: Reviewed & tested by the community » 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.

shiraz dindar’s picture

Thanks for catching this. Saved me some work.

jerdavis’s picture

Status: Needs review » 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.

jerdavis’s picture

StatusFileSize
new522 bytes

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.

allie micka’s picture

Status: Reviewed & tested by the community » Fixed

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

Anonymous’s picture

Status: Fixed » Closed (fixed)

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