_mimemail_url does not consider language prefixes while expanding relative URLs, thus causing a duplicate language prefixes to appear, e.g. /en/photos becomes /en/en/photos.

Comments

plach’s picture

Status: Active » Needs review
StatusFileSize
new1.06 KB

The attached patch should solve the issuo by comparing the first path segment with all the enabled languages' prefixes.

Hobbes-2’s picture

Same problem, the patch is working perfecly, thanks

Hobbes-2’s picture

Status: Needs review » Active

Is it possible to patch the next version of mimemail with this patch ?

sgabe’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Active » Needs review

I have tested this patch and looks fine for me, but I wonder if there is a better solution for this than string manipulation? Would be appreciated if somebody could confirm this.

plach’s picture

Unfortunately in D6 there is no API function to extract the language prefix from a path. If you check http://api.drupal.org/api/function/language_initialize/6 you will see that the string manipulation above mimics closely the one performed to get the current language prefix during the language negotiation process.

luksak’s picture

hi

this patch doesn't work anymore. could someone write a new one?

and maybe this should be committed since multilingual websites also send e-mails...

thanks

lukas

luksak’s picture

StatusFileSize
new721 bytes

i have written a patch myself. please let me know if anything is wrong since this one of my first ones.

sgabe’s picture

StatusFileSize
new1.34 KB

@elluca: Thanks for the patch!

--- /Users/lukas/Desktop/mimemail_2/mimemail.inc

Note that you should use the project root directory, otherwise the patch doesn't apply. See the Creating patches page in the handbook.
Furthermore you missed to pass the prefix to the url() call.

@plach: Some thoughts about your patch.

+++ mimemail.inc	29 Mar 2009 16:34:19 -0000
@@ -511,10 +511,20 @@
+  $path_segments = explode('/', $path);

I would change the $path_segments to $args which is shorter and good enough, but that's minor.

+++ mimemail.inc	29 Mar 2009 16:34:19 -0000
@@ -511,10 +511,20 @@
+  foreach (language_list() as $lang) {

Split this and get just the enabled languages apart, so it will be usable in the url() call.
Furthermore here we can check against the array keys.

+++ mimemail.inc	29 Mar 2009 16:34:19 -0000
@@ -511,10 +511,20 @@
+  $url = url($path, array('prefix' => $prefix, 'query' => $query, 'fragment' => $fragment, 'absolute' => TRUE));

Move the prefix to the end of the array, so the modification will be unambiguous.

However I did some additional testing with this and the patch needed some work:

  • Depending on the language negotiation setting the language_url_rewrite() function kills this entirely and generates URLs irrespectively of the options if a language object is not passed to the url().
  • In some cases it generates URLs like ennode/1, so a trailing slash should be added to the end of the prefix.

I am attaching a revised patch with these modifications.

sgabe’s picture

Title: _mimemail_url does not consider language prefixes » Language prefix is not taken into account
luksak’s picture

thanks for pointing that out, i was thinking this can't be right.

for me, your revised patch doesnt work while mine does. it removes the prefix.

sgabe’s picture

See, that is why this isn't committed yet. ;)

How did I test:

  • Enabled three different languages: English, German, Hungarian. Default is English.
  • Created a new story with German and Hungarian translations and set a path alias for the Hungarian node.
  • Placed links to these nodes in a newsletter (/node/1 and /hu/loremipsum and /de/node/3)
  • Sent test messages with language negotiation set to None, Path prefix only and Path prefix with language fallback viewing the site in English, German, Hungarian.

The results seemed fine. How did you test it? Can you give more information how to reproduce?

luksak’s picture

i am sorry, mine doesn't work either :)

i use the cck link field and it is being rendered by a view, but i guess this doesn't matter.

i use simplenews and when i did test earlier today, i used "send test newsletter". i did this with the backend in the same language as the mail. but since simplenews newsletters are being sent via cron, this is not the case. so this is a special use case we would have to take into account.

ideas?

thanks

sgabe’s picture

Status: Needs review » Needs work

Seems like this needs work, then.

luksak’s picture

have you got an idea how i could find out if it is a simplenews mail?

sgabe’s picture

I am not sure that I understand your question right.

luksak’s picture

if we can check inside _mimemail_url() if we are sending a mail for simplenews. and if we do, get the node language and modify the language variable according to that.

sgabe’s picture

That is not good for us, we need a general solution irrespectively of the origin of the message.

luksak’s picture

hi sgabe

what do you think, how much time will it take to fix this issue? you want to take a generic approach?

thanks

lukas

mastermint’s picture

First, sorry for my bad english...

I have no solution patch, but another way to afford this job (sendind newsletters in MULTI-Languaje drupal enviroment) with EXCELLENT results and correct "PATHS", cause I've had the same problem with languaje prefix, so I made this things:

I've created alias server for each languaje (Apache configuration) i.e.: http://es.example.com, http://en.example.com and http://cat.example.com for languajes Spanish, English and Catalan.
All subservers pointing the same root directory (/var/www)

Then, I changed the LANGUAJE settings (/admin/settings/language/configure) from "Path prefix with language fallback" to "Domain name only" and edited every languaje setting individually to point its own name server with the option "Language-specific URL, with protocol" (VERY important to write the http:// statement too) in "/admin/settings/language/edit/en", es, ca, etc...

It does NOT solve the problem in the module, but you can start sending newsletters and mails with correct paths in all links.

Good luck solving programatic way, I'm waiting for a solution too.

YK85’s picture

subscribing

eric.chenchao’s picture

Hi all, I have encountered the same issue and I use mimemail and simplenews to send newsletter. When views inserted in a node is dynamically generate content, the mimemail module will convert relative links into absolute links and then send the mail to subscribers.

My point is all the relative links included within the content are created properly and work well in the scope of website. Maybe we should just add a base url to get the full path.

function _mimemail_url($url, $embed_file = NULL) {
  global $base_url;
  $url = urldecode($url);

  // If the URL is absolute or a mailto, return it as-is.
  if (strpos($url, '://') !== FALSE || preg_match('!mailto:!', $url)) {
    $url = str_replace(' ', '%20', $url);
    return $url;
  }

//  $url = preg_replace( '!^'. base_path() .'!', '', $url, 1);

  // If we're processing to embed the file, we're done here so return.
//  if ($embed_file) return $url;
  if ($embed_file) return preg_replace( '!^'. base_path() .'!', '', $url, 1);


  return $base_url . $url;

//  if (!preg_match('!^\?q=*!', $url)) {
//    $strip_clean = TRUE;
//  }
//
//  $url = str_replace('?q=', '', $url);
//  list($url, $fragment) = explode('#', $url, 2);
//  list($path, $query) = explode('?', $url, 2);
//
//  // If we're dealing with an intra-document reference, return it.
//  if (empty($path) && !empty($fragment)) {
//    return '#'. $fragment;
//  }
//
//  // If we have not yet returned, then let's clean things up and leave.
//  $url = url($path, array('query' => $query, 'fragment' => $fragment, 'absolute' => TRUE));
//
//
//  // If url() added a ?q= where there should not be one, remove it.
//  if ($strip_clean) $url = preg_replace('!\?q=!', '', $url);
//
//  $url = str_replace('+', '%20', $url);
//  return $url;
}

I promise I will go to learn how to use patch next time;)

pol’s picture

The patch in #8 is working with 6.x-1.0-beta2.

Here is the patch for 6.x-1.x-dev.

Thanks !

pol’s picture

And this is the same patch for 6.x-1.0-beta2.

sgabe’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Needs work » Fixed
StatusFileSize
new1.17 KB

The attached patch works for me perfectly. Committed to D6.

pol’s picture

Hello Sgabe,

Please, include authoring informations (found on the user profile) when you commit, so we can see on our profile that we worked on the module.

For this patch, you should have include the plach authoring informations: --author="plach <plach@183211.no-reply.drupal.org>"

This parameter must be added to the commit line.

Thanks.

chicodasilva’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Fixed » Needs work

Patch on #24 needs to have some modifications for D7 for languages in which prefix is different of language definition (ex: pt-pt with prefix 'pt').

$languages = language_list('enabled');
  $languages = $languages[1];

  // Check language prefix.
  $prefix = '';
  $args = explode('/', $path);
  foreach ($languages as $lang) {  //validation
    if ($args[0] == $lang->prefix) {  //validation
      $prefix = array_shift($args) .'/';
      $language = $languages[$lang];
      $path = implode('/', $args);
      break;
    }
  }
sgabe’s picture

Would you provide a patch?

sgabe’s picture

Status: Needs work » Needs review
StatusFileSize
new1.28 KB

This seems to do the rick on D7.

khumbu’s picture

Did a quick test and path seems to work for D7. Will provide better test results in a few days.

Anyway thx for thre great work...

edit:

Tested the patch on a 2 language dev site (drupal 7.9), using simplenews (7.x-1.0-alpha1), mimemail (7.x-1.x-dev)and simplenews content selection (simplenews_content_selection-7.x-1.x-dev.tar_.gz).

Everything works for now

sgabe’s picture

Status: Needs review » Fixed

Committed to D7. Thank you for testing, Khumbu!

Status: Fixed » Closed (fixed)

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

tobiasb’s picture

Issue summary: View changes
Status: Closed (fixed) » Needs review
StatusFileSize
new537 bytes

Houston we have a problem, there is a bug. ;-)

In case you have a path like /en/drupal, then the explode('/', $args) build the following array.

Array
(
    [0] => 
    [1] => en
    [2] => drupal
)

Therefore the check if $args[0] can not work.

I added a patch which fix this use case.

sgabe’s picture

Status: Needs review » Closed (fixed)