Download & Extend

mime_header_encode function used for encoding mail subject produces output incompatible with PHP mail function

Project:Drupal core
Version:6.17
Component:user.module
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed (won't fix)

Issue Summary

Drupal uses function user_mail to send e-mails to users. ie for registering users. it uses also mime_header_encode function to encode utf-8 message subject. BUT function mime_header_encode may return strings incompatible with PHP mail() function requirements. Each message subject that contains non ascii chars is encoded using RFC2047. Drupal splits longer strings into chunks no longer than 75 chars and separates them with "\n" (newline) char. According to documentation on PHP website - http://pl.php.net/manual/en/function.mail.php

Subject of the email to be sent.
Caution
This must not contain any newline characters, or the mail may not be sent properly.

if message subject contains newline characters then PHP refuses to send an e-mail. the fix is needed to encode long message subjects without splitting them into chunks.

my proposition is to alter mime_header_encode and add second optional parameter so new one would look like this:

<?php
function mime_header_encode($string, $split = true) {
  if (
preg_match('/[^\x20-\x7E]/', $string)) {
    if (!
$split)
      return
' =?UTF-8?B?'. base64_encode($string) ."?=";
   
$chunk_size = 47; // floor((75 - strlen("=?UTF-8?B??=")) * 0.75);
   
$len = strlen($string);
   
$output = '';
    while (
$len > 0) {
     
$chunk = truncate_utf8($string, $chunk_size);
     
$output .= ' =?UTF-8?B?'. base64_encode($chunk) ."?=\n";
     
$c = strlen($chunk);
     
$string = substr($string, $c);
     
$len -= $c;
    }
    return
trim($output);
  }
  return
$string;
}
?>

then user.module should be modified to fix user_mail fuction so it wont split message subjects:

<?php
function user_mail($mail, $subject, $message, $header) {
/* ... */
  
return mail(
     
$mail,
     
mime_header_encode($subject, false),
     
str_replace("\r", '', $message),
     
"MIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8; format=flowed\nContent-transfer-encoding: 8Bit\n" . $header
   
);
?>

Comments

#1

subscribing

#2

Status:active» closed (won't fix)

This version is not supported. Reopen or create a new issue if the problem exists in any recent version (version equal or above Drupal 5)

#3

Version:4.7.4» 6.17

Returns:
Invalid address: "=?UTF-8
could be an issue of international characters like ščć

nobody click here