-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mail.php
79 lines (63 loc) · 2.54 KB
/
Mail.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/*
Copyright (c) 2009 Robert Johnston
This file is part of Backbox.
Backbox is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Backbox is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Backbox. If not, see http://www.gnu.org/licenses/.
*/
class Bbx_Mail extends Zend_Mail {
protected static $_instance = null;
protected function _encodeHeader($value) {
if (Zend_Mime::isPrintable($value)) {
return $value;
}
else {
$quotedValue = Zend_Mime::encodeQuotedPrintable($value);
$quotedValue = str_replace(array('?', ' '), array('=3F', '=20'), $quotedValue);
$quotedValue = rawurlencode($quotedValue);
$quotedValue = str_replace('%3D%0A','',$quotedValue);
$quotedValue = rawurldecode($quotedValue);
$quotedValue = '=?' . $this->_charset . '?Q?' . $quotedValue . '?=';
}
return $quotedValue;
}
static public function instance() {
$args = func_get_args();
$userOptions = array();
if (count($args) > 0) {
$userOptions = $args[0];
}
if (self::$_instance === null) {
$options = array();
if (isset(Bbx_Config::get()->site->smtp_username)) {
$options = array(
'auth'=>'login',
'username'=>Bbx_Config::get()->site->smtp_username,
'password'=>Bbx_Config::get()->site->smtp_password
);
}
if (isset(Bbx_Config::get()->site->smtp_port)) {
$options['port'] = Bbx_Config::get()->site->smtp_port;
}
if (isset(Bbx_Config::get()->site->smtp_ssl)) {
$options['ssl'] = Bbx_Config::get()->site->smtp_ssl;
}
$port = array_key_exists('port', $options) ? $options['port'] : 25;
$options = array_merge($options, $userOptions);
$transport = new Zend_Mail_Transport_Smtp(Bbx_Config::get()->site->smtp_server, $options);
Zend_Mail::setDefaultTransport($transport);
self::$_instance = new Bbx_Mail();
}
return self::$_instance;
}
public function sendAsync() {
$pid = exec('nice php ' . APPLICATION_PATH . '/../library/Bbx/bin/send-mail.php '
. '"' . $this->getFrom() . '" '
. '"' . $this->getBodyText(true) . '" '
. '"' . implode(',', $this->getRecipients()) . '" '
. '"' . $this->getSubject() . '" '
. '> /dev/null 2>&1 &');
}
}
?>