Skip to content
Browse files

Edit Mail class to utf8 charset for online email cliens

- add base64 subject
- quoted printable (humanized) name encode
- and plain text header charset correction

Signed-off-by: Gergely <t-gely@freemail.hu>
  • Loading branch information...
1 parent 370188f commit 274c4e349d74c029a3d60b8ac910b52a8ca56cf5 @tgely committed Apr 10, 2011
Showing with 12 additions and 7 deletions.
  1. +12 −7 osCommerce/OM/Core/Mail.php
View
19 osCommerce/OM/Core/Mail.php
@@ -22,7 +22,7 @@ class Mail {
$_headers = array('X-Mailer' => 'osCommerce'),
$_body,
$_content_transfer_encoding = '7bit',
- $_charset = 'iso-8859-1';
+ $_charset = 'utf-8';
public function __construct($to = null, $to_email_address = null, $from = null, $from_email_address = null, $subject = null) {
if ( !empty($to_email_address) ) {
@@ -36,7 +36,7 @@ public function __construct($to = null, $to_email_address = null, $from = null,
}
if ( !empty($subject) ) {
- $this->_subject = $subject;
+ $this->_subject = "=?" . $this->_charset . '?B?' . base64_encode($subject) . "?=";
}
}
@@ -252,6 +252,7 @@ function send() {
$this->_body = $this->_body_html . "\n";
} else {
+ $this->_headers['Content-Type'] = 'text/plain; charset="' . $this->_charset . '"'; // set correct header of plain text
$this->_body = $this->_body_plain . "\n";
}
}
@@ -270,7 +271,7 @@ function send() {
if ( empty($to['name']) ) {
$to_email_addresses[] = $to['email_address'];
} else {
- $to_email_addresses[] = '"' . $to['name'] . '" <' . $to['email_address'] . '>';
+ $to_email_addresses[] = '"' . $this->_name_encode($to['name']) . '" <' . $to['email_address'] . '>';
}
}
@@ -282,7 +283,7 @@ function send() {
if ( empty($cc['name']) ) {
$cc_email_addresses[] = $cc['email_address'];
} else {
- $cc_email_addresses[] = '"' . $cc['name'] . '" <' . $cc['email_address'] . '>';
+ $cc_email_addresses[] = '"' . $this->_name_encode($cc['name']) . '" <' . $cc['email_address'] . '>';
}
}
@@ -294,7 +295,7 @@ function send() {
if ( empty($bcc['name']) ) {
$bcc_email_addresses[] = $bcc['email_address'];
} else {
- $bcc_email_addresses[] = '"' . $bcc['name'] . '" <' . $bcc['email_address'] . '>';
+ $bcc_email_addresses[] = '"' . $this->_name_encode($bcc['name']) . '" <' . $bcc['email_address'] . '>';
}
}
@@ -303,7 +304,7 @@ function send() {
if ( empty($this->_from['name']) ) {
$this->addHeader('From', $this->_from['email_address']);
} else {
- $this->addHeader('From', '"' . $this->_from['name'] . '" <' . $this->_from['email_address'] . '>');
+ $this->addHeader('From', '"' . $this->_name_encode($this->_from['name']) . '" <' . $this->_from['email_address'] . '>');
}
if ( !empty($cc_email_addresses) ) {
@@ -327,7 +328,7 @@ function send() {
if ( empty($this->_from['name']) ) {
@ini_set('sendmail_from', $this->_from['email_address']);
} else {
- @ini_set('sendmail_from', '"' . $this->_from['name'] . '" <' . $this->_from['email_address'] . '>');
+ @ini_set('sendmail_from', '"' . $this->_name_encode($this->_from['name']) . '" <' . $this->_from['email_address'] . '>');
}
@mail(implode(', ', $to_email_addresses), $this->_subject, $this->_body, $headers);
@@ -371,5 +372,9 @@ function _build_image($image, $boundary) {
'Content-Transfer-Encoding: base64' . "\n\n" .
$image['data'] . "\n\n";
}
+
+ function _name_encode($e_name) {
+ return '=?' . $this->_charset . '?Q?' . str_replace("+", "_", str_replace("%", "=", urlencode(quoted_printable_decode($e_name)))) . '?= '; // Quoted-printable string
@haraldpdl
haraldpdl added a note Apr 14, 2011

Is it possible to use base64_encode() here as well, as is performed for the subject?

@Gergely
Gergely added a note Apr 14, 2011

Look at an example in mime header

To: "=?utf-8?Q?Gergely_T=C3=B3th?= " t-gely@freemail.hu
Subject: =?utf-8?B?UmVuZGVsw6lzaSBmb2x5YW1hdA==?=
X-Mailer: osCommerce
Content-Type: text/plain; charset="utf-8"
From: "=?utf-8?Q?tgely?= " info@oscom.hu

The subjects can contain "=" and "?" characters so this is better than quoted printable. The names not contain these characters so easy to read as human. Of course we can use everywhere base64_encode()

function _name_encode($_name) {
return '=?' . $this->_charset . '?B?' . base64_encode($e_name) . '?= '; //Base64 encoding
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ }
}
?>

0 comments on commit 274c4e3

Please sign in to comment.
Something went wrong with that request. Please try again.