#6 UTF-8 Mailer

open-accepted
nobody
7
2010-01-17
2007-09-22
ohwada
No

Now
XoopsMultiMailer <- XoopsMailerLocal

This patch
XoopsMultiMailer <- XoopsMailerUtf8 <- XoopsMailerLocal

class/mail/xoops_mailer_utf8.php

class XoopsMailerUtf8 extends XoopsMailer
{
function XoopsMailerUtf8()
{
if (function_exists('mb_language')) {
mb_language('uni');
}

$this->multimailer = new XoopsMultiMailerUtf8();
$this->reset();
$this->charSet = 'UTF-8';
$this->encoding = 'BASE64';
$this->multimailer->CharSet = $this->charSet;
$this->multimailer->Encoding = $this->encoding;
$this->set_language();
}

// set phpmailer's lang file
function set_language()
{
global $xoopsConfig;
$XOOPS_LANGUAGE = $xoopsConfig['language'];
$file = '/class/mail/phpmailer/language/phpmailer.lang-' . $XOOPS_LANGUAGE . '.php';
if( file_exists(XOOPS_ROOT_PATH . $file) ) {
$this->multimailer->SetLanguage( $XOOPS_LANGUAGE, XOOPS_ROOT_PATH . '/class/mail/phpmailer/language/' );
} else {
$this->multimailer->SetLanguage( "en", XOOPS_ROOT_PATH . '/class/mail/phpmailer/language/' );
}
}
}

class XoopsMultiMailerUtf8 extends XoopsMultiMailer
{
var $mail_overload = false;

function XoopsMultiMailerUtf8()
{
$this->XoopsMultiMailer();

// check mbstring.func_overload
if (function_exists('mb_convert_encoding')) {
$mb_overload = ini_get('mbstring.func_overload');
if (($this->Mailer == 'mail') && (intval($mb_overload) & 1)) {
$this->mail_overload = true;
}
}
}

function AddrFormat($addr)
{
if(empty($addr[1])) {
$formatted = $addr[0];
} else {
$formatted = $this->EncodeHeader($addr[1], 'text', true) . " <" .
$addr[0] . ">";
}
return $formatted;
}

function EncodeHeader($str, $position = 'text', $force=false)
{
if (function_exists('mb_encode_mimeheader')) {
if ( $force || !$this->mail_overload ) {
$encoded = mb_encode_mimeheader($str);
} else {
$encoded = $str;
}
} else {
$encoded = parent::EncodeHeader($str, $position);
}
return $encoded;
}

// remove Content-Type if mail func_overload
// mb_send_mail() ecncode wrong if php version 5
function CreateHeader()
{
$result = parent::CreateHeader();
if ($this->mail_overload) {
$result = preg_replace("/Content-Type:(.+)/", '', $result);
}
return $result;
}

// no encoding if mail func_overload
function CreateBody()
{
if ( $this->mail_overload ) {
return $this->Body;
}
return parent::CreateBody();
}

}

language/xxx/xoopsmailerlocal.php

class XoopsMailerLocal extends XoopsMailerUtf8
{
function XoopsMailerLocal()
{
$this->XoopsMailerUtf8();
}
}

class XoopsMultiMailerLocal extends XoopsMultiMailerUtf8
{
function XoopsMultiMailerLocal()
{
$this->XoopsMultiMailerUtf8();
}
}
=====

Discussion

  • minahito
    minahito
    2007-10-25

    Logged In: YES
    user_id=1102607
    Originator: NO

    I don't know what issue this patch works for.

    Where should I insert this patch to? All utf-8 languages? (extra/japanese, extra/freanch, extra/korean and greek?)

    Under these languages, does the default mailer work pefectly?

     
  • minahito
    minahito
    2007-10-25

    • priority: 5 --> 7
     
  • minahito
    minahito
    2007-10-25

    Logged In: YES
    user_id=1102607
    Originator: NO

    And, it seems that this patch causes troubles for some languages that uses XoopsMultiMailer directly. Is that OK?

     
  • minahito
    minahito
    2010-01-17

    We will put this new class to XoopsMailer classes for developers who want to prepare utf-8 languages.

     
  • minahito
    minahito
    2010-01-17

    • labels: --> Enhancement
    • milestone: --> Legacy 2.1.x modules
    • status: open --> open-accepted