utilize the advantages of bcc... we have a hard limit of 50 recipients here, if the same language and notify method is used (if the case of only one recipient is given the bcc method will be not used).

git-svn-id: file:///svn/phpbb/trunk@4776 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen 2004-01-31 19:09:17 +00:00
parent d170696d68
commit ca729d6ac1

View file

@ -61,13 +61,17 @@ if (isset($_POST['submit']))
$usernames = implode(', ', preg_replace('#^[\s]*?(.*?)[\s]*?$#e', "\"'\" . \$db->sql_escape('\\1') . \"'\"", explode("\n", $usernames))); $usernames = implode(', ', preg_replace('#^[\s]*?(.*?)[\s]*?$#e', "\"'\" . \$db->sql_escape('\\1') . \"'\"", explode("\n", $usernames)));
$sql = 'SELECT username, user_email, user_jabber, user_notify_type, user_lang $sql = 'SELECT username, user_email, user_jabber, user_notify_type, user_lang
FROM ' . USERS_TABLE . ' FROM ' . USERS_TABLE . "
WHERE username IN (' . $usernames . ') WHERE username IN ($usernames)
AND user_allow_massemail = 1'; AND user_allow_massemail = 1
ORDER BY user_lang, user_notify_type, SUBSTRING(user_email FROM INSTR(user_email,'@'))";
} }
else else
{ {
$sql = ($group_id) ? 'SELECT u.user_email, u.username, u.user_lang, u.user_jabber, u.user_notify_type FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug WHERE ug.group_id = $group_id AND ug.user_pending <> 1 AND u.user_id = ug.user_id AND u.user_allow_massemail = 1" : 'SELECT username, user_email, user_jabber, user_notify_type, user_lang FROM ' . USERS_TABLE . ' WHERE user_allow_massemail = 1'; $sql = ($group_id) ? 'SELECT u.user_email, u.username, u.user_lang, u.user_jabber, u.user_notify_type FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug WHERE ug.group_id = $group_id AND ug.user_pending <> 1 AND u.user_id = ug.user_id AND u.user_allow_massemail = 1" : 'SELECT u.username, u.user_email, u.user_jabber, u.user_notify_type, u.user_lang FROM ' . USERS_TABLE . ' u WHERE u.user_allow_massemail = 1';
// TODO: different for other db servers?
$sql .= " ORDER BY u.user_lang, u.user_notify_type, SUBSTRING(u.user_email FROM INSTR(u.user_email,'@'))";
} }
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
@ -77,18 +81,32 @@ if (isset($_POST['submit']))
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
$i = 0; $i = $j = 0;
// Send with BCC, no more than 50 recipients for one mail (to not exceed the limit)
$max_chunk_size = 50;
$email_list = array(); $email_list = array();
$old_lang = $row['user_lang'];
$old_notify_type = $row['user_notify_type'];
do do
{ {
if (($row['user_notify'] == NOTIFY_EMAIL && $row['user_email']) || if (($row['user_notify'] == NOTIFY_EMAIL && $row['user_email']) ||
($row['user_notify'] == NOTIFY_IM && $row['user_jabber']) || ($row['user_notify'] == NOTIFY_IM && $row['user_jabber']) ||
($row['user_notify'] == NOTIFY_BOTH && $row['user_email'] && $row['user_jabber'])) ($row['user_notify'] == NOTIFY_BOTH && $row['user_email'] && $row['user_jabber']))
{ {
$email_list[$row['user_lang']][$i]['method'] = $row['user_notify_type']; if ($i == $max_chunk_size || $row['user_lang'] != $old_lang || $row['user_notify_type'] != $old_notify_type)
$email_list[$row['user_lang']][$i]['email'] = $row['user_email']; {
$email_list[$row['user_lang']][$i]['name'] = $row['username']; $i = 0;
$email_list[$row['user_lang']][$i]['jabber'] = $row['user_jabber']; $j++;
$old_lang = $row['user_lang'];
$old_notify_type = $row['user_notify_type'];
}
$email_list[$j][$i]['lang'] = $row['user_lang'];
$email_list[$j][$i]['method'] = $row['user_notify_type'];
$email_list[$j][$i]['email'] = $row['user_email'];
$email_list[$j][$i]['name'] = $row['username'];
$email_list[$j][$i]['jabber'] = $row['user_jabber'];
$i++; $i++;
} }
} }
@ -100,11 +118,28 @@ if (isset($_POST['submit']))
$messenger = new messenger(); $messenger = new messenger();
foreach ($email_list as $lang => $to_ary) for ($i = 0; $i < sizeof($email_list); $i++)
{ {
foreach ($to_ary as $to) $used_lang = $email_list[$i][0]['lang'];
$used_method = $email_list[$i][0]['method'];
if (sizeof($email_list[$i]) == 1)
{ {
$messenger->template('admin_send_email', $lang); $messenger->to($email_list[$i][0]['email'], $email_list[$i][0]['name']);
$messenger->im($email_list[$i][0]['jabber'], $email_list[$i][0]['name']);
}
else
{
for ($j = 0; $j < sizeof($email_list[$i]); $j++)
{
$email_row = $email_list[$i][$j];
$messenger->bcc($email_row['email'], $email_row['name']);
$messenger->im($email_row['jabber'], $email_row['name']);
}
}
$messenger->template('admin_send_email', $used_lang);
$messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']); $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
$messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']); $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
@ -112,11 +147,7 @@ if (isset($_POST['submit']))
$messenger->headers('X-AntiAbuse: User IP - ' . $user->ip); $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
$messenger->subject($subject); $messenger->subject($subject);
$messenger->headers($extra_headers);
$messenger->replyto($config['board_email']); $messenger->replyto($config['board_email']);
$messenger->to($to['email'], $to['name']);
$messenger->im($to['jabber'], $to['name']);
$messenger->assign_vars(array( $messenger->assign_vars(array(
'SITENAME' => $config['sitename'], 'SITENAME' => $config['sitename'],
@ -124,11 +155,9 @@ if (isset($_POST['submit']))
'MESSAGE' => $message) 'MESSAGE' => $message)
); );
$messenger->send($to['method']); $messenger->send($used_method);
}
}
$messenger->queue->save(); $messenger->queue->save();
}
unset($email_list); unset($email_list);
if ($group_id) if ($group_id)