Hi,

First off thanks drupal team, very nice piece of software.

I was hoping for some help to change a few things.

Every member of the site I'm working on has a text pager that can recieve emails, however the subject line of drupal sends tons of garbage that makes the page unreadable. Where could I modify the thing that sends out emails? I would like to also make it where members cannot change their email addresses and so that a requested password can only be retrieved by typing in the correct email (not just username).

Thanks a lot!

Comments

Steven’s picture

Check user_mail_encode(). In the CVS version, we do not use the UTF-8 escaping unless necessary:

if (!preg_match('/^[\x20-\x7E]*$/', $string)) {
   ...
}
JBxFINAL’s picture

Forgive me, what file would that be in?

Also I am using version 4.4.0, as I use fantastico in cpanel.

katin’s picture

I was after the same fix... as it turns out, most of the spam filters reject the emails from Drupal if they have the garbage subject lines, and I was unable to use Drupal until I got it fixed (as no one would ever get their registration/password emails, welcome emails, etc.). Thanks to the clue above and the correct code (above) help, I was able to find and fix it. Now my group loves Drupal. :)

For you non-programmers, the file is "modules/user.module". At line 246 (in ver 4.4.2, other versions may be a different line number), update the user_mail_encode() function so it looks like this:

function user_mail_encode($string, $charset = "UTF-8") {

  /*

  ** Used to encodes mail headers that contain non US- ASCII

  ** characters.

  ** http://www.rfc-editor.org/rfc/rfc2047.txt

  **

  ** Notes:

  ** - The chunks come in groupings of 4 bytes when using base64

  ** encoded.

  ** - trim() is used to ensure that no extra spacing is added by

  ** chunk_split() or preg_replace().

  ** - Using \n as the chunk separator may cause problems on some

  ** systems and may have to be changed to \r\n or \r.

  */

  if (!preg_match('/^[\x20-\x7E]*$/', $string)) {

    $chunk_size = 75 - 7 - strlen($charset);

    $chunk_size -= $chunk_size % 4;

    $string = trim(chunk_split(base64_encode($string), $chunk_size, "\n"));

    $string = trim(preg_replace('/^(.*)$/m', " =?$charset?B?\\1?=", $string));

  }

  return $string;

}

As always, the brackets and punctuation are critical, make sure they are exact. Save the file and run Drupal, and you'll find the subject lines come thru just fine.

Hope this helps.
Cheers!

sepeck’s picture

For the benefit of us non-programmers, could you submit this as a bug/feature report against core? Perhaps they could add a setting for this so that people don't have to edit files, just choose a setting...

It would be great for 4.5

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide

Steven’s picture

As I said, this is already in CVS/4.5.

sepeck’s picture

doh, missed that in your post. Or forgot by the time I read the last.

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide

tenney’s picture

I wish that it were in here at drupal.org
(i.e. I signed up today and got a UTF-8 subject message)

Glenn

sepeck’s picture

To be fair, 4.5 hasn't hit code freeze yet. So while they generally do run on the latest, let's not run the production site on development code when there is no code freeze. :)

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide

tenney’s picture

Oh, I do agree... I was just viewing this as a "patch" that should be applied (whether it is technically a patch / bug-fix or not). To me, it's a "bug".

Glenn

Steven’s picture

I must say that I think the choice of spam filters to see encoded subjects as spam is a bad one. Only unaccented english matches that. Encoding subjects is perfectly legal according to the RFCs.

sepeck’s picture

Yes it is (I admin a decent sized email system in my day job) but I suspect that there are several other factors. The encoded subject may just be one scoring part of a filtering system. ie, no reverse lookup.... multiple host server that was banned, no MX record, etc. Other content filtering, size of the message, sending name meets filter x criterea....

For email to pagers it may be part of a filtering system to protect pagers from getting garbage characters (at least in the USA where English centric little flexibility is often found).

-Steven too....

-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide

katin’s picture

And, of course, I have little control over the spam filters that my clients, users and thier ISP's are using...