2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 05/29/2004 *
4 * =================== Last change: 11/26/2004 *
6 * -------------------------------------------------------------------- *
7 * File : autopurge.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Automatical purging of outdated mail links *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Auto-Loeschung von veralteten Mail-Links *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2013 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
43 // Abort if autopurge is not active or disabled by admin
44 if ((!isExtensionActive('autopurge')) || (!isAutoPurgingActive()) || (getConfig('ap_del_mails') != 'Y')) {
49 // Okay, let's check for deleted mails
50 $result_mails = sqlQuery("SELECT
53 `{?_MYSQL_PREFIX?}_pool`
55 `data_type`='DELETED' AND
56 (UNIX_TIMESTAMP() - `timestamp`) >= {?ap_dm_timeout?}
58 `sender` ASC", __FILE__, __LINE__);
63 // Is there "purged" mails?
64 if (!ifSqlHasZeroNums($result_mails)) {
65 // Okay, check for their sender's
66 while ($content = sqlFetchArray($result_mails)) {
68 if (!fetchUserData($content['sender'])) {
69 // Okay we found some mails!
70 sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_pool` WHERE `sender`=%s",
71 array(bigintval($content['sender'])), __FILE__, __LINE__);
73 // Get all affected (deleted) rows
74 $deletedStats += sqlAffectedRows();
80 sqlFreeResult($result_mails);
82 // Now let's check for stats entries as well;
83 $result_mails = sqlQuery("SELECT
86 `{?_MYSQL_PREFIX?}_user_stats`
88 (UNIX_TIMESTAMP() - `timestamp_send`) >= {?ap_dm_timeout?}
90 `userid` ASC", __FILE__, __LINE__);
92 // Is there "purged" mails?
93 if (!ifSqlHasZeroNums($result_mails)) {
94 // Okay, check for their sender's
95 while ($content = sqlFetchArray($result_mails)) {
97 if (!fetchUserData($content['sender'])) {
98 // Okay we found some mails!
99 sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `userid`=%s",
100 array(bigintval($content['sender'])), __FILE__, __LINE__);
102 // Get all affected (deleted) rows
103 $deletedStats += sqlAffectedRows();
105 // Reset query (to prevent possible errors) ...
106 $result_mails = sqlQuery("SELECT
109 `{?_MYSQL_PREFIX?}_user_stats`
111 (UNIX_TIMESTAMP() - `timestamp_send`) >= {?ap_dm_timeout?}
113 `userid` ASC", __FILE__, __LINE__);
119 sqlFreeResult($result_mails);
121 // Is there deleted mails and the admin want's to receive a notification
122 if (($deletedStats > 0) && (getConfig('ap_dm_notify') == 'Y')) {
123 // Send out email to admin
124 sendAdminNotification('{--ADMIN_AUTOPURGE_DELETE_MAILS_SUBJECT--}', 'admin_purge_del_mails', $deletedStats);