heres a patch that works well enough to get all my friends using mail2web.

it handles yahoo mail and other webmail client's tendency to strip the message id and in-reply-to headers. causing the "Received an email with no parameters"

it puts the message id in the footer of the email and checks it if the header is stripped.

it also fixes blank bodies in html replies and borrows some code from og2list.

it has some additional stripping of "original message" quotes on various webmail clients.

let me know what you think. some of the reg. expressions could be improved.

some caveats:
-be sure to use html corrector filter to close any remaining junk tags from yahoo, etc. http://drupal.org/project/htmlcorrector
-make sure this filter is being applied by checking the filter on incoming comments.. various access permissions may cancel it. best to just put html corrector on your default filter as well just in case.
-be sure your outbound mail has full headers to start with.. i use the simple_mail messaging and have to modify drupal_mail on my special host to get full headers, see http://drupal.org/node/186522 ... i have also seen phpmailer and mimemail not send full headers, or not pickup the message_alter hook... ie: be sure that messageid looks like 1.35.72.1217632941.9810b0b2c5d32e4d9a1dac96ccd44df2@example.com if it looks like 20080801221443.E2139CA0046@example.com (only one period), or if the return-path is www@ then its wrong...
here is what my drupal_mail mod looks like: (in includes/common.inc line 1991) from http://drupal.org/node/186522

//full header fix
    $extraparam='-f'. $defaults['Reply-To'];
    return mail(
      $to,
      mime_header_encode($subject),
      str_replace("\r", '', $body),
      join("\n", $mimeheaders),
      $extraparam
    );

Comments

jose reyero’s picture

Title: patch for mail2web html and webmail improvements » Extend mail2web support for mail clients (Yahoo mail) and some html cleaning up

The patch looks ok.

However its big and needs some more testing with some different e-mail clients (Help wanted).

Saganesque’s picture

Thanks, I'll look into this soon. What is the "html corrector filter"?

Saganesque’s picture

I'm occasionally getting a PHP error as follows:

Cannot modify header information - headers already sent by ([...]/notifications/notifications_mail2web/notifications_mail2web.module:257) in /homepages/41/d173730136/htdocs/realrational/includes/common.inc on line 314.

But the message does now seem to be making it into the DB.

jose reyero’s picture

Project: Notifications » Mail to Web
Version: 5.x-1.0-rc1 » 5.x-1.0-beta1

Moved the module to a different project

Veggieryan’s picture

StatusFileSize
new9.18 KB

here is an updated patch that also checks to make sure hook_mailhandler only gets run IF the mailbox is the mail2web default.

this allows you to use mail2web without breaking other mailboxes in mailhandler.

the message-id in body solution is still the only way I can think of around the new yahoo mail's ridiculous stripping of the message-id header.

please test and +1 as this is working well for me across all tested clients

Ian Ward’s picture

Ryan, I'm weighing the costs/benefits of putting these message-cleaners (for Yahoo, Mail.app, Outlook, Gmail, Lotus, etc., etc.) into a separate directory and including them. The aim would be to provide cleaners for several mail clients w/ mail2web, but then if someone wants support for a client that's not been considered, they can write the small plugin and stick it in this directory. This gets around each person having to hack the module directly if they find they want to support X mail client. I need to take a closer look, but I believe it could be as straight-forward as looping through any plugins in the /cleaners directory and setting a flag upon first match.

Thoughts?

Veggieryan’s picture

I agree that filters should be placed in .inc files, provided that all or most filters are enabled by default.

The focus of my patch was mostly to embed the message id in the email body for the new yahoo mail and some other webmail clients so they dont loose threading, and to make the mailhandler hook only run on the mail2web box so as not to break other mailboxes.

The regular expressions could use some beefing up to work in more tricky situations such as linebreaks and
tags in the wrong places, etc.

I also think the filter should wrap the text to be deleted in special tags that jquery can collapse just in case there is important quoted data that an editor needs to bring back. Quotes above the cutoff can get a special blockquote styling to highlight the quote since this is widely used, while quotes below the cutoff are simply collapsed with a small link to expand just in case.

The quotes below the cutoff can also be stripped from outgoing emails to avoid yahoo group style junk in list replies. But on the site the data is simply collapsed in case somebody pasted a string in the wrong place... etc. We dont want to loose any data.

As for the code, simply look at how other modules handle .inc files.

I would love to test a patch. I'm actively switching to mail2web as my mailing list solution for all my groups.

I should probably break my patch into 3 individual patches to get the message id and hook_mailhandler fixes committed separately... hmmm.

Ian Ward’s picture

Ryan, I'm going to take a look at this this week. In regards to embedding the message id which is the crux of your patch, I'll try to use what you have here. I'll then break out the message cleaning into includes. Please let me know if you've already broken up the patch. Otherwise, I'll proceed later in the week.

Veggieryan’s picture

StatusFileSize
new3.49 KB

Ian,
Here is the patch with the message cleaning removed.
Only the message id in body and protection against running hook_mailhandler on wrong mailboxes is in this patch.
Let me know what you are up to.

Thanks,
ryan.
www.thefractal.org

Ian Ward’s picture

Ryan, I've committed fixes for returning the node, using parts of your patch, on the dev version of Drupal 5. Will do Drupal 6 soon. As for the part of the patch that adds the headers to the message, how can I get this issue to repeat? You say it happens in Yahoo Mail?

thanks,
Ian

cglusky’s picture

I suspect that the message id is also being stripped when using the iPhone's mail.app.

Ian,
I can help port this to D6 as I am in the same boat as @Veggieryan in that I am moving all my projects to mailhandler/mail2web for mailing-list-like features.

R,
Coby

cglusky’s picture

[Edited for clarity]

I changed the backup message id function a bit for d6. it should work for d5 as well but note the leading underscore to indicate a private function.

/**
 * Find the message id in the body if mail client stripped it out of the headers.
 *  
 * @param $body
 *   raw email body
 *
 */
function _mail2web_get_backup_messageid($body) {
  if (preg_match("/([0-9]+\.){4}+[a-z0-9]+@([a-z0-9-]+\.[a-z]{2,5})/i",$body,$matches)) {
  	//  Check to make sure the match has our mail2web domain
    $domain = variable_get('mail2web_server_string', 'example.com');
    if ($matches[2] == $domain) {
      $backup_messageid = $matches[0];
      // We have a match for the messageid and the mail2web domain string so we are good
      return $backup_messageid;   	
    }
  }	
  else {
	// No matches found so assume we have no messageid and node->threading is not set
    return false;
  }  
}  

Might be a matter of semantics but I had to rebuild it to understand it and ended up with a bit different answer; I think this is a bit more efficient:

1) We need only run preg_match with my regex as it looks for an exact match. If we have more than one match we might have bigger issues.
2) Using parentheses in the pattern will allow us to use the matches array to do a few more checks.
3) Value returned for the backup id is set explicitly

r,
coby

cglusky’s picture

OK, here is some code that works for iphone and other clients that may add stuff to the to header when replying. This is working on the D6 version but should also work for D5? The first and last if statements are just for context.

 if (!$node->threading) { 
     $node->threading = _mail2web_get_backup_messageid($node->body);
  }
  //  Some mail clients (iPhone) change the toaddress from example@example.com to 
  //  "example@example.com"<example@example.com>
  //  @TODO This may need to be addressed in mailhandler?
  //  @TODO Should we be using strpos or stripos - I think we already have PHP 5 dependency?
  //  Check to see if it starts with something like a double quote and if the mailbox name is in the string
  if (strpos($header->toaddress, $mbox_name) != 0 && strpos($header->toaddress, $mbox_name) !== FALSE ) {
    //  Just set it to the mailbox
        $header->toaddress = $mbox_name;
  }
  if ($header->toaddress == $mbox_name && $node->threading && ....

There should be a better way to do that but it works for now. Thoughts?

I do apologize for not putting up patches. I need to go back and build some more incremental stuff for the D6 version. In the meantime I do not want to hijack this thread for the D6 version, so I will upload my working D6 version here #351260: Proposed Changes For D6 Version and you can track my public repository here: http://github.com/cglusky/metanomy/tree/mail2web_mid - I am learning git so sniff around the different branches for the latest commits, but for now that's it.

Veggieryan’s picture

cglusky: the problem of dropping messageid is one that exist in many email clients, most famously the new yahoo mail beta, not just the iphone. I see no way around it other than embedding the messageid in the body of the email in the footer area as you can see in my patch above. It works in every client I have tested. Did you try my patch out?

I'm not seeing how the code in you post would solve the problem....

thanks for the interest, like you I see mail2web as the future of email list integration in drupal, which in many cases is the only way to get lazy or normal people to contribute to posts in the real world. I use it for everything.

RE:Ian in #10 http://drupal.org/node/290214#comment-1028624
-- you simply have to reply to an email using the new yahoo mail beta, or mosso's webmail, or roundcube webmail to see that the messageid header is stripped in the reply sent by said email clients, therefore $node->threading is null and mail2web simply breaks.

I really want to get this committed so let me know what needs to happen... I think wrapping the messageid string in the html body with a small font tag would be nice to make it less clutter... perhaps encrypting it for security purposes is a good idea? ;)

cglusky’s picture

The problem with the iPhone was not dropping the messageid it was that it changed the toaddress and mail2web uses that string to make sure we are working against the mail2web mailbox (per your patch I believe:-). My "fix" in #13 just checks to see if the mail2web mailbox string is in the toadress if they are not initially an exact match. Will not argue that it's a crap fix - my string manipulation skills are not Kung Fu Enabled.

For example:

mail2web mailbox = example@example.com and should be set as the toaddress

iPhone toaddress = "example@example.com"<example@example.com>

That causes this check to fail when it should not:

...
 // The In-reply-to header is cleaned and passed in $node->threading
  if ($header->toaddress == $mbox_name && ...

[EDIT] My impression is that this may need to be handled in MailHandler. There is code there to clean In Reply To and we may need to clean the toaddress?

Sorry a bunch of edits to correct my semantics - need more coffee:)

Ian Ward’s picture

Status: Needs review » Fixed

This is fixed and will be available in the next release. If you want it now for further testing/review, it is necessary that you run the dev versions of messaging/notifications. This will be released for 5 and 6 in the next release of mail2web at the end of this week.

Thanks for the patches and testing!

Ian

Status: Fixed » Closed (fixed)

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

Ian Ward’s picture

Project: Mail to Web » Mail Comment
Version: 5.x-1.0-beta1 » 5.x-1.0-beta3

Switch to mailcomment project. Mail2web is now known as "mailcomment" due to a trademark issue with the name mail2web.