1: <?php
2: // $Id: xoopsmultimailer.php,v 1.4 2008/09/21 06:45:39 minahito Exp $
3: // ------------------------------------------------------------------------ //
4: // XOOPS - PHP Content Management System //
5: // Copyright (c) 2000 XOOPS.org //
6: // <http://www.xoops.org/> //
7: // ------------------------------------------------------------------------ //
8: // This program is free software; you can redistribute it and/or modify //
9: // it under the terms of the GNU General Public License as published by //
10: // the Free Software Foundation; either version 2 of the License, or //
11: // (at your option) any later version. //
12: // //
13: // You may not change or alter any portion of this comment or credits //
14: // of supporting developers from this source code or any supporting //
15: // source code which is considered copyrighted (c) material of the //
16: // original comment or credit authors. //
17: // //
18: // This program is distributed in the hope that it will be useful, //
19: // but WITHOUT ANY WARRANTY; without even the implied warranty of //
20: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
21: // GNU General Public License for more details. //
22: // //
23: // You should have received a copy of the GNU General Public License //
24: // along with this program; if not, write to the Free Software //
25: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
26: // ------------------------------------------------------------------------ //
27: //
28: // URL: http://www.xoops.org //
29: // Project: The XOOPS Project //
30: // ------------------------------------------------------------------------- //
31: /**
32: * @package class
33: * @subpackage mail
34: *
35: * @filesource
36: *
37:
38: * @copyright copyright (c) 2000-2003 The XOOPS Project (http://www.xoops.org)
39: *
40: * @version $Revision: 1.4 $ - $Date: 2008/09/21 06:45:39 $
41: */
42:
43: if (!defined('XOOPS_ROOT_PATH')) exit();
44:
45: /**
46: * load the base class
47: */
48: require_once(XOOPS_ROOT_PATH.'/class/mail/phpmailer/class.phpmailer.php');
49:
50: /**
51: * Mailer Class.
52: *
53: * At the moment, this does nothing but send email through PHP's "mail()" function,
54: * but it has the abiltiy to do much more.
55: *
56: * If you have problems sending mail with "mail()", you can edit the member variables
57: * to suit your setting. Later this will be possible through the admin panel.
58: *
59: * @todo Make a page in the admin panel for setting mailer preferences.
60: *
61: * @package class
62: * @subpackage mail
63: *
64: * @author Jochen Buennagel <job@buennagel.com>
65: * @copyright (c) 2000-2003 The Xoops Project - www.xoops.org
66: * @version $Revision: 1.4 $ - changed by $Author: minahito $ on $Date: 2008/09/21 06:45:39 $
67: */
68: class XoopsMultiMailer extends PHPMailer {
69:
70: /**
71: * "from" address
72: * @var string
73: * @access private
74: */
75: var $From = "";
76:
77: /**
78: * "from" name
79: * @var string
80: * @access private
81: */
82: var $FromName = "";
83:
84: // can be "smtp", "sendmail", or "mail"
85: /**
86: * Method to be used when sending the mail.
87: *
88: * This can be:
89: * <li>mail (standard PHP function "mail()") (default)
90: * <li>smtp (send through any SMTP server, SMTPAuth is supported.
91: * You must set {@link $Host}, for SMTPAuth also {@link $SMTPAuth},
92: * {@link $Username}, and {@link $Password}.)
93: * <li>sendmail (manually set the path to your sendmail program
94: * to something different than "mail()" uses in {@link $Sendmail})
95: *
96: * @var string
97: * @access private
98: */
99: var $Mailer = "mail";
100:
101: /**
102: * set if $Mailer is "sendmail"
103: *
104: * Only used if {@link $Mailer} is set to "sendmail".
105: * Contains the full path to your sendmail program or replacement.
106: * @var string
107: * @access private
108: */
109: var $Sendmail = "/usr/sbin/sendmail";
110:
111: /**
112: * SMTP Host.
113: *
114: * Only used if {@link $Mailer} is set to "smtp"
115: * @var string
116: * @access private
117: */
118: var $Host = "";
119:
120: /**
121: * Does your SMTP host require SMTPAuth authentication?
122: * @var boolean
123: * @access private
124: */
125: var $SMTPAuth = FALSE;
126:
127: /**
128: * Username for authentication with your SMTP host.
129: *
130: * Only used if {@link $Mailer} is "smtp" and {@link $SMTPAuth} is TRUE
131: * @var string
132: * @access private
133: */
134: var $Username = "";
135:
136: /**
137: * Password for SMTPAuth.
138: *
139: * Only used if {@link $Mailer} is "smtp" and {@link $SMTPAuth} is TRUE
140: * @var string
141: * @access private
142: */
143: var $Password = "";
144:
145: /**
146: * Constuctor
147: *
148: * @access public
149: * @return void
150: *
151: * @global $xoopsConfig
152: */
153: function XoopsMultiMailer(){
154: global $xoopsConfig;
155: $this->ClearAllRecipients();
156: $config_handler =& xoops_gethandler('config');
157: $xoopsMailerConfig =& $config_handler->getConfigsByCat(XOOPS_CONF_MAILER);
158: $this->From = $xoopsMailerConfig['from'];
159: if ($this->From == '') {
160: $this->From = $xoopsConfig['adminmail'];
161: }
162: $this->Sender = $xoopsConfig['adminmail'];
163: if ($xoopsMailerConfig["mailmethod"] == "smtpauth") {
164: $this->Mailer = "smtp";
165: $this->SMTPAuth = TRUE;
166: $this->Host = implode(';',$xoopsMailerConfig['smtphost']);
167: $this->Username = $xoopsMailerConfig['smtpuser'];
168: $this->Password = $xoopsMailerConfig['smtppass'];
169: } else {
170: $this->Mailer = $xoopsMailerConfig['mailmethod'];
171: $this->SMTPAuth = FALSE;
172: $this->Sendmail = $xoopsMailerConfig['sendmailpath'];
173: $this->Host = implode(';',$xoopsMailerConfig['smtphost']);
174: }
175: }
176:
177: /**
178: * Formats an address correctly. This overrides the default AddrFormat method
179: * which does not seem to encode $FromName correctly
180: * This method name is renamed from "addr_format", because method name in parent class is renamed.
181: * @access private
182: * @return string
183: */
184: //TODO: We must verify,whether we should prepare this method even now.(phpmailer is upgraded from 1.65 to 1.73)
185: function AddrFormat($addr) {
186: if(empty($addr[1]))
187: $formatted = $addr[0];
188: else
189: $formatted = sprintf('%s <%s>', '=?'.$this->CharSet.'?B?'.base64_encode($addr[1]).'?=', $addr[0]);
190:
191: return $formatted;
192: }
193:
194: /**
195: * Override PHPMailer Send()
196: * Add verification whether Sender property contains correct mail format.
197: */
198:
199: function Send() {
200: if (empty($this->Sender)
201: || preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i",$this->Sender)) {
202: return parent::Send();
203: }
204: return false;
205: }
206:
207: /**
208: * Sets the language for all class error messages. Returns false
209: * if it cannot load the language file. The default language type
210: * is English.
211: * @param string $lang_type Type of language (e.g. Portuguese: "br")
212: * @param string $lang_path Path to the language file directory
213: * @access public
214: * @return bool
215: */
216: function SetLanguage($lang_type, $lang_path = 'language/') {
217: // Patch for XOOPS Cube Legacy 2008/09/21
218: $ext = substr($lang_path, -1, 1);
219: if ($ext != '/' && file_exists($lang_path)) {
220: include($lang_path);
221: $this->language = $PHPMAILER_LANG;
222: return true;
223: }
224:
225: return parent::SetLanguage($lang_type, $lang_path);
226: }
227: }
228: ?>
229: