--- old-rsvp.module 2006-01-11 11:47:17.000000000 +0800 +++ rsvp.module 2006-01-11 13:58:50.000000000 +0800 @@ -1252,11 +1252,12 @@ function _rsvp_mail($invite) { if($webmaster) { $webmaster = "-f".$webmaster; } - $from = $user->name .' <'. $user->mail .'>'; + $from = user_mail_encode($user->name) .' <'. $user->mail .'>'; $subject = $site ." - ". t('Event Invitation'); $to = $invite->email; $body = t("Hello!\n\nYou have been invited to attend an event by %owner at %site.\n\nYou can view the event itself by following this link: \n%eventurl\n\nYou can view the full invitation by following this link: \n%url\n\nHere is the invitation message:\n", array('%owner'=>$user->name, '%site'=>$site, '%eventurl'=>url("node/$invite->nid", NULL, NULL, 1), '%url'=>url("rsvp/email/$invite->hash", NULL, NULL, 1))) .$invite->invite_text; - return mail($to, $subject, $body, "From: $from\nReply-to: $from\nX-Mailer: Drupal (rsvp.module)\nReturn-path: <$from>\nErrors-to: $from\n",$webmaster); +$subject = user_mail_encode($subject); + return mail($to, $subject, $body, "From: $from\nReply-to: $from\nX-Mailer: Drupal (rsvp.module)\nReturn-path: <$from>\nErrors-to: $from\nContent-Type: text/plain; charset=utf-8\n",$webmaster); } /** @@ -1273,8 +1274,8 @@ function _rsvp_message_rsvp($edit) { if($webmaster) { $webmaster = "-f".$webmaster; } - $from = $user->name .' <'. $user->mail .'>'; - $subject = $site ." - ". $edit['subject']; + $from = user_mail_encode($user->name) .' <'. $user->mail .'>'; + $subject = user_mail_encode($site ." - ". $edit['subject']); $status['success'] = array(); $status['failed'] = array(); @@ -1286,7 +1287,7 @@ function _rsvp_message_rsvp($edit) { $body = t("Hello!\n\nYou have been sent a message by %sender at %site.\n\nYou can view the invitation from where it originated by following this link: \n%url\n\nHere is the message:\n", array('%sender'=>$user->name, '%site'=>$site, '%url'=>url("rsvp/email/$invite->hash", NULL, NULL, 1))) . $edit['body']; $to = "$attendee->email <". $attendee->email .'>'; - if(mail($to, $subject, $body, "From: $from\nReply-to: $from\nX-Mailer: Drupal (rsvp.module)\nReturn-path: <$from>\nErrors-to: $from\n",$webmaster)) { + if(mail($to, $subject, $body, "From: $from\nReply-to: $from\nX-Mailer: Drupal (rsvp.module)\nReturn-path: <$from>\nErrors-to: $from\nContent-Type: text/plain; charset=utf-8\n",$webmaster)) { $status['success'][$invite->email] = substr($invite->email, 0, strpos($invite->email, '@')); } else { @@ -1296,4 +1297,26 @@ function _rsvp_message_rsvp($edit) { return $status; } +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; +} ?>