Skip to content

Commit 118f390

Browse files
authored
Merge pull request #963 from bramley/bounce_config
Replace constants in the bounce handling code by config.php settings
2 parents 0612625 + b78dc1c commit 118f390

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed

public_html/lists/admin/init.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,15 @@
216216
if (!isset($bounce_mailbox_purge_unprocessed)) {
217217
$bounce_mailbox_purge_unprocessed = true;
218218
}
219+
if (!isset($bounce_mailbox_maximum)) {
220+
$bounce_mailbox_maximum = 100000;
221+
}
222+
if (!isset($bounce_rules_batch_size)) {
223+
$bounce_rules_batch_size = 500;
224+
}
225+
if (!isset($bounce_mailbox_name)) {
226+
$bounce_mailbox_name = 'INBOX';
227+
}
219228

220229
// set some defaults if they are not specified
221230
if (!defined('REGISTER')) {

public_html/lists/admin/processbounces.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -360,25 +360,36 @@ function processBounceData($bounceid, $msgid, $userid, $bounceDate = null)
360360

361361
function processPop($server, $user, $password)
362362
{
363-
$port = $GLOBALS['bounce_mailbox_port'];
363+
global $bounce_mailbox_port, $bounce_mailbox_name, $bounce_mailbox_maximum;
364+
365+
$port = $bounce_mailbox_port;
364366
if (!$port) {
365367
$port = '110/pop3/notls';
366368
}
367369
set_time_limit(6000);
368370

369-
$link = imap_open('{'.$server.':'.$port.'}INBOX', $user, $password);
371+
$mailboxNames = explode(',', $bounce_mailbox_name);
372+
$report = '';
370373

371-
if (!$link) {
372-
outputProcessBounce($GLOBALS['I18N']->get('Cannot create POP3 connection to')." $server: ".imap_last_error());
374+
foreach ($mailboxNames as $mailboxName) {
375+
$mailbox = sprintf('{%s:%s}%s', $server, $port, $mailboxName);
376+
$link = imap_open($mailbox, $user, $password);
373377

374-
return false;
378+
if (!$link) {
379+
outputProcessBounce($GLOBALS['I18N']->get('Cannot create POP3 connection to')." $mailbox: ".imap_last_error());
380+
381+
return false;
382+
}
383+
$report .= processMessages($link, $bounce_mailbox_maximum);
375384
}
376385

377-
return processMessages($link, 100000);
386+
return $report;
378387
}
379388

380389
function processMbox($file)
381390
{
391+
global $bounce_mailbox_maximum;
392+
382393
set_time_limit(6000);
383394

384395
if (!TEST) {
@@ -392,10 +403,10 @@ function processMbox($file)
392403
return false;
393404
}
394405

395-
return processMessages($link, 100000);
406+
return processMessages($link, $bounce_mailbox_maximum);
396407
}
397408

398-
function processMessages($link, $max = 3000)
409+
function processMessages($link, $max)
399410
{
400411
global $bounce_mailbox_purge_unprocessed, $bounce_mailbox_purge;
401412
$num = imap_num_msg($link);
@@ -554,7 +565,7 @@ function processMessages($link, $max = 3000)
554565
$bounceCount = Sql_Fetch_Row_Query(sprintf('select count(*) from %s', $GLOBALS['tables']['user_message_bounce']));
555566
$total = $bounceCount[0];
556567
$counter = 0;
557-
$batchSize = 500; //# @TODO make a config, to allow tweaking on bigger systems
568+
$batchSize = $bounce_rules_batch_size;
558569
while ($counter < $total) {
559570
$limit = ' limit '.$counter.', '.$batchSize;
560571
$counter += $batchSize;

public_html/lists/config/config_extended.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,18 @@
137137
// Set to 0 to received by mail bounce deletions in the advanced bounce processing report
138138
define('REPORT_DELETED_BOUNCES', 0);
139139

140+
// The name of the POP3 mailbox
141+
// Multiple mailboxes can be specified separated by comma
142+
$bounce_mailbox_name = 'INBOX';
143+
144+
// The maximum number of bounces to retrieve from the mailbox
145+
// This might need to be reduced if the processing times-out
146+
$bounce_mailbox_maximum = 100000;
147+
148+
// When applying bounce rules the number of bounces to process in each batch
149+
// This might need to be reduced when there are a large number of bounces to process
150+
$bounce_rules_batch_size = 500;
151+
140152
/*
141153
142154
=========================================================================

0 commit comments

Comments
 (0)