1: <?php
2: if (!defined('XOOPS_ROOT_PATH')) exit();
3: if ( !defined('LEGACY_MAIL_LANG') ) {
4: define('LEGACY_MAIL_LANG', _LANGCODE);
5: define('LEGACY_MAIL_CHAR', _CHARSET);
6: define('LEGACY_MAIL_ENCO', '7bit');
7: }
8:
9: class My_Mailer extends PHPMailer
10: {
11: public $mConvertLocal = null;
12:
13: public function __construct()
14: {
15: $this->mConvertLocal = new XCube_Delegate();
16: $this->mConvertLocal->register('Legacy_Mailer.ConvertLocal');
17: $this->LE ="\n";
18: $this->prepare();
19: }
20:
21: public function prepare()
22: {
23: $root = XCube_Root::getSingleton();
24: $handler = xoops_gethandler('config');
25: $xoopsMailerConfig = $handler->getConfigsByCat(XOOPS_CONF_MAILER);
26: $this->reset();
27:
28: if ($xoopsMailerConfig['from'] == '') {
29: $this->From = $root->mContext->mXoopsConfig['adminmail'];
30: } else {
31: $this->From = $xoopsMailerConfig['from'];
32: }
33:
34: $this->Sender = $root->mContext->mXoopsConfig['adminmail'];
35: $this->SetLanguage(LEGACY_MAIL_LANG, XOOPS_ROOT_PATH.'/class/mail/phpmailer/language/');
36: $this->CharSet = LEGACY_MAIL_CHAR;
37: $this->Encoding = LEGACY_MAIL_ENCO;
38:
39: switch ($xoopsMailerConfig['mailmethod']) {
40: case 'smtpauth':
41: $this->IsSMTP();
42: $this->SMTPAuth = true;
43: $this->Host = implode(';', $xoopsMailerConfig['smtphost']);
44: $this->Username = $xoopsMailerConfig['smtpuser'];
45: $this->Password = $xoopsMailerConfig['smtppass'];
46: break;
47:
48: case 'smtp':
49: $this->IsSMTP();
50: $this->SMTPAuth = false;
51: $this->Host = implode(';', $xoopsMailerConfig['smtphost']);
52: break;
53:
54: case 'sendmail':
55: $this->IsSendmail();
56: $this->Sendmail = $xoopsMailerConfig['sendmailpath'];
57: break;
58: }
59:
60: return true;
61: }
62:
63: public function setFromEmail($text)
64: {
65: $this->From = $text;
66: }
67:
68: public function setFromName($text)
69: {
70: $this->FromName = $this->convertLocal($this->SecureHeader($text), true);
71: }
72:
73: public function setSubject($text)
74: {
75: $this->Subject = $text;
76: }
77:
78: public function setBody($text)
79: {
80: $search = array("\r\n", "\r", "\n");
81: $replace = array("\n", "\n", $this->LE);
82: $text = str_replace($search, $replace, $text);
83: $this->Body = $this->convertLocal($text);
84: }
85:
86: public function setToEmails($email)
87: {
88: $this->AddAddress($email, "");
89: }
90:
91: public function setTo($add, $name = "")
92: {
93: $this->AddAddress($add, $name);
94: }
95:
96: public function reset()
97: {
98: $this->ClearAllRecipients();
99: $this->Body = "";
100: $this->Subject = "";
101: }
102:
103: public function send()
104: {
105: parent::Send();
106: }
107:
108: public function EncodeHeader($str, $position = 'text')
109: {
110: if ( $position == 'text' ) {
111: return $this->convertLocal($str, true);
112: } else {
113: return parent::EncodeHeader($str, $position);
114: }
115: }
116:
117: private function convertLocal($text, $mime = false)
118: {
119: if ( _LANGCODE == 'ja' ) {
120: $text = $this->_Japanese_convLocal($text, $mime);
121: } else {
122: $this->mConvertLocal->call(new XCube_Ref($text), $mime);
123: }
124: return $text;
125: }
126:
127: private function _Japanese_convLocal($text, $mime)
128: {
129: if ( $mime ) {
130: $text = mb_encode_mimeheader($text, LEGACY_MAIL_CHAR, 'B', $this->LE);
131: } else {
132: $text = mb_convert_encoding($text, 'JIS', _CHARSET);
133: }
134: return $text;
135: }
136: }
137: ?>
138: