forked from ccraig/cpoMMo
/
mailings_send4.php
182 lines (146 loc) · 5.71 KB
/
mailings_send4.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
<?php
/**
* Copyright (C) 2005, 2006, 2007, 2008 Brice Burgess <bhb@iceburg.net>
*
* This file is part of poMMo (http://www.pommo.org)
*
* poMMo 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 2, or any later version.
*
* poMMo 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 program; see the file docs/LICENSE. If not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/**********************************
INITIALIZATION METHODS
*********************************/
$serial = (empty($_GET['serial'])) ? time() : addslashes($_GET['serial']);
require ('../bootstrap.php');
require_once(Pommo::$_baseDir.'classes/Pommo_Mta.php');
Pommo::init(array('sessionID' => $serial, 'keep' => TRUE, 'authLevel' => 0));
$logger = & Pommo::$_logger;
$dbo = & Pommo::$_dbo;
// don't die on query so we can capture logs'
// NOTE: Be extra careful to check the success of queries/methods!
$dbo->dieOnQuery(FALSE);
// turn logging off unless verbosity is 1
if(Pommo::$_verbosity > 1)
$dbo->debug(FALSE);
// start error logging
Pommo::logErrors();
/**********************************
STARTUP ROUTINES
*********************************/
$config = Pommo_Api::configGet(array(
'list_exchanger',
'maxRuntime',
'smtp_1',
'smtp_2',
'smtp_3',
'smtp_4',
'throttle_SMTP',
'throttle_MPS',
'throttle_BPS',
'throttle_DP',
'throttle_DMPP',
'throttle_DBPP'));
$p = array(
'queueSize' => 100,
'maxRunTime' => $config['maxRuntime'],
'serial' => $serial
);
// NOTE: PR15 removed multimode (simultaneous SMTP relays) variables + functionality!
// we will be migrating to swiftmailer, and its multi-SMTP support/balancing in PR16-ish.
/**********************************
* MAILING INITIALIZATION
*********************************/
// calculate spawn # (number of times this MTA has spawned under this serial)
Pommo::$_session['spawn'] = (isset(Pommo::$_session['spawn'])) ? Pommo::$_session['spawn']+1 : 1;
$p['spawn'] = Pommo::$_session['spawn'];
// initialize MTA
$mailing = new Pommo_Mta($p);
$logger->addMsg(sprintf(Pommo::_T('Started Mailing MTA. Spawn #%s.'),$p['spawn']),3,TRUE);
// poll mailing status
$mailing->poll();
// check if message body contains personalizations
// personalizations are cached in session
require_once(Pommo::$_baseDir.'classes/Pommo_Helper_Personalize.php'); // require once here so that mailer can use
if(!isset(Pommo::$_session['personalization'])) {
Pommo::$_session['personalization'] = FALSE;
$matches = array();
preg_match('/\[\[[^\]]+]]/', $mailing->_mailing['body'], $matches);
if (!empty($matches))
Pommo::$_session['personalization'] = TRUE;
preg_match('/\[\[[^\]]+]]/', $mailing->_mailing['altbody'], $matches);
if (!empty($matches))
Pommo::$_session['personalization'] = TRUE;
// cache personalizations in session
if (Pommo::$_session['personalization']) {
Pommo::$_session['personalization_body'] = Pommo_Helper_Personalize::search($mailing->_mailing['body']);
Pommo::$_session['personalization_altbody'] = Pommo_Helper_Personalize::search($mailing->_mailing['altbody']);
}
}
/**********************************
* PREPARE THE MAILER
*********************************/
$html = ($mailing->_mailing['ishtml'] == 'on') ? TRUE : FALSE;
$mailer = new PommoMailer($mailing->_mailing['fromname'],$mailing->_mailing['fromemail'],$mailing->_mailing['frombounce'], $config['list_exchanger'],NULL,$mailing->_mailing['charset'], Pommo::$_session['personalization']);
if (!$mailer->prepareMail($mailing->_mailing['subject'], $mailing->_mailing['body'], $html, $mailing->_mailing['altbody']))
$mailer->shutdown('*** ERROR *** prepareMail() returned errors.');
// Set appropriate SMTP relay
if ($config['list_exchanger'] == 'smtp') {
$mailer->setRelay(unserialize($config['smtp_1']));
//$mailer->setRelay($config['smtp_' . $relayID]); /* PR15: depricated */
$mailer->SMTPKeepAlive = TRUE;
}
// necessary? (better method!)
$mailing->attach('_mailer',$mailer);
/**********************************
* INITIALIZE Throttler
*********************************/
$tid = 1; // forced shared throttler, until swiftmailer implementation
//$tid = ($config['throttle_SMTP'] == 'shared') ? 1 : $relayID; /* old shared throttle support */
if(empty(Pommo::$_session['throttler'][$tid]))
Pommo::$_session['throttler'] = array (
$tid => array(
'base' => array(
'MPS' => $config['throttle_MPS'],
'BPS' => $config['throttle_BPS'],
'DP' => $config['throttle_DP'],
'DMPP' => $config['throttle_DMPP'],
'DBPP' => $config['throttle_DBPP'],
'genesis' => time()
),
'domainHistory' => array(),
'sent' => floatval(0),
'sentBytes' => floatval(0)
)
);
$throttler =& new Pommo_Throttler(
Pommo::$_session['throttler'][$tid]['base'],
Pommo::$_session['throttler'][$tid]['domainHistory'],
Pommo::$_session['throttler'][$tid]['sent'],
Pommo::$_session['throttler'][$tid]['sentBytes']
);
$byteMask = $throttler->byteTracking();
if ($byteMask > 1) // byte tracking/throttling enabled
$mailer->trackMessageSize();
$mailing->attach('_byteMask',$byteMask);
// necessary? (better method!)
$mailing->attach('_throttler',$throttler);
/**********************************
* INITIALIZE Queue
*********************************/
$mailing->pullQueue();
$mailing->pushThrottler();
/**********************************
PROCESS QUEUE
*********************************/
$mailing->processQueue();
?>