-
Notifications
You must be signed in to change notification settings - Fork 0
/
advanced_mailer.class.php
228 lines (206 loc) · 5.13 KB
/
advanced_mailer.class.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php
/**
* @file advanced_mailer.class.php
* @author Kijin Sung <[email protected]>
* @license GPLv2 or Later <https://www.gnu.org/licenses/gpl-2.0.html>
* @brief Advanced Mailer Main Class
*/
class Advanced_Mailer extends ModuleObject
{
/**
* Definition of sending methods and related settings.
*/
public $sending_methods = array(
'dummy' => array(
'conf' => array(),
'spf' => '',
'dkim' => '',
),
'mail' => array(
'conf' => array(),
'spf' => '',
'dkim' => '',
),
'smtp' => array(
'conf' => array('host', 'port', 'security', 'username', 'password'),
'spf' => '',
'dkim' => '',
),
'ses' => array(
'conf' => array('region', 'access_key', 'secret_key'),
'spf' => '',
'dkim' => '********._domainkey',
),
'mailgun' => array(
'conf' => array('domain', 'api_key'),
'spf' => 'include:mailgun.org',
'dkim' => 'mailo._domainkey',
),
'mandrill' => array(
'conf' => array('api_key'),
'spf' => 'include:spf.mandrillapp.com',
'dkim' => 'mandrill._domainkey',
),
'postmark' => array(
'conf' => array('api_key'),
'spf' => 'include:spf.mtasv.net',
'dkim' => '********.pm._domainkey',
),
'sendgrid' => array(
'conf' => array('username', 'password'),
'spf' => 'include:sendgrid.net',
'dkim' => 'smtpapi._domainkey',
),
'sparkpost' => array(
'conf' => array('api_key'),
'spf' => 'include:sparkpostmail.com',
'dkim' => '********._domainkey',
),
'woorimail' => array(
'conf' => array('domain', 'api_key', 'account_type'),
'spf' => 'include:woorimail.com',
'dkim' => '',
),
);
/**
* Definition of sending methods available in PHP 5.3.
*/
public $sending_methods_php53 = array('dummy', 'mail', 'smtp', 'woorimail');
/**
* Get the configuration of the current module.
*/
public function getConfig()
{
$config = getModel('module')->getModuleConfig('advanced_mailer');
if(!is_object($config))
{
$config = new stdClass();
$config->is_enabled = 'N';
$config->sending_method = 'mail';
}
if(!$config->sending_method)
{
$config->sending_method = 'mail';
}
if(isset($config->send_type) || isset($config->api_key))
{
$config = $this->migrateConfig($config);
}
return $config;
}
/**
* Migrate from previous configuration format.
*/
public function migrateConfig($config)
{
if(isset($config->send_type))
{
$config->sending_method = $config->send_type;
unset($config->send_type);
}
if(isset($config->username))
{
if(in_array('username', $this->sending_methods[$config->sending_method]['conf']))
{
$config->{$config->sending_method . '_username'} = $config->username;
}
unset($config->username);
}
if(isset($config->password))
{
if(in_array('password', $this->sending_methods[$config->sending_method]['conf']))
{
$config->{$config->sending_method . '_password'} = $config->password;
}
unset($config->password);
}
if(isset($config->domain))
{
if(in_array('domain', $this->sending_methods[$config->sending_method]['conf']))
{
$config->{$config->sending_method . '_domain'} = $config->domain;
}
unset($config->domain);
}
if(isset($config->api_key))
{
if(in_array('api_key', $this->sending_methods[$config->sending_method]['conf']))
{
$config->{$config->sending_method . '_api_key'} = $config->api_key;
}
unset($config->api_key);
}
if(isset($config->account_type))
{
if(in_array('account_type', $this->sending_methods[$config->sending_method]['conf']))
{
$config->{$config->sending_method . '_account_type'} = $config->account_type;
}
unset($config->account_type);
}
if(isset($config->aws_region))
{
$config->ses_region = $config->aws_region;
unset($config->aws_region);
}
if(isset($config->aws_access_key))
{
$config->ses_access_key = $config->aws_access_key;
unset($config->aws_access_key);
}
if(isset($config->aws_secret_key))
{
$config->ses_secret_key = $config->aws_secret_key;
unset($config->aws_secret_key);
}
return $config;
}
/**
* Check triggers.
*/
public function checkTriggers()
{
$oModuleModel = getModel('module');
if($oModuleModel->getTrigger('moduleHandler.init', 'advanced_mailer', 'model', 'triggerReplaceMailClass', 'before'))
{
return true;
}
return false;
}
/**
* Register triggers.
*/
public function registerTriggers()
{
$oModuleModel = getModel('module');
if(!$this->checkTriggers())
{
$oModuleController = getController('module');
$oModuleController->insertTrigger('moduleHandler.init', 'advanced_mailer', 'model', 'triggerReplaceMailClass', 'before');
return true;
}
return false;
}
public function createObject($error = 0, $message = 'success')
{
return class_exists('BaseObject') ? new BaseObject($error, $message) : new Object($error, $message);
}
public function moduleInstall()
{
$this->registerTriggers();
return $this->createObject();
}
public function checkUpdate()
{
return !$this->checkTriggers();
}
public function moduleUpdate()
{
$this->registerTriggers();
return $this->createObject(0, 'success_updated');
}
public function recompileCache()
{
// no-op
}
}