From: gustavf Date: Sun, 2 Apr 2000 17:58:53 +0000 (+0000) Subject: Now setting charset also in headers when sending mail. X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=commitdiff_plain;h=c3084273bb0288cb93df25e4e0c29c00c96225a8;ds=sidebyside Now setting charset also in headers when sending mail. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@377 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/functions/mime.php b/functions/mime.php index ecbc6abc..ac0ad306 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -238,4 +238,28 @@ return ($string); } + // Encode a string according to RFC 1522 for use in headers if it + // contains 8-bit characters + function encodeHeader ($string) { + global $default_charset; + + // Encode only if the string contains 8-bit characters + if (ereg("[\200-\377]", $string)) { + $newstring = "=?$default_charset?Q?"; + $newstring .= str_replace(" ", "_", $string); + + while (ereg("([\200-\377])", $newstring, $regs)) { + $replace = $regs[1]; + $insert = "=" . bin2hex($replace); + $newstring = str_replace($replace, $insert, $newstring); + } + + $newstring .= "?="; + + return $newstring; + } + + return $string; + } + ?> diff --git a/functions/smtp.php b/functions/smtp.php index 04e92bf0..24570bec 100644 --- a/functions/smtp.php +++ b/functions/smtp.php @@ -134,6 +134,10 @@ $from = "<$from_addr>"; else $from = $from . " <$from_addr>"; + + /* Encoding 8-bit characters */ + $subject = encodeHeader($subject); + $from = encodeHeader($from); /* This creates an RFC 822 date */ $date = date("D, j M Y H:i:s ", mktime()) . timezone();