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 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2009 by Roland Haeder *
21 * Copyright (c) 2009, 2010 by Mailer Developer Team *
22 * For more information visit: http://www.mxchange.org *
24 * This program is free software; you can redistribute it and/or modify *
25 * it under the terms of the GNU General Public License as published by *
26 * the Free Software Foundation; either version 2 of the License, or *
27 * (at your option) any later version. *
29 * This program is distributed in the hope that it will be useful, *
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32 * GNU General Public License for more details. *
34 * You should have received a copy of the GNU General Public License *
35 * along with this program; if not, write to the Free Software *
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
38 ************************************************************************/
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
45 // Abort if autopurge is not active or disabled by admin
46 if ((!isExtensionActive('autopurge')) || (getConfig('auto_purge_active') != 'Y') || (getConfig('ap_del_mails') != 'Y')) {
51 // Okay, let's check for deleted mails
52 $result_mails = SQL_QUERY("SELECT
55 `{?_MYSQL_PREFIX?}_pool`
57 `data_type`='DELETED' AND `timestamp` <= (UNIX_TIMESTAMP() - {?ap_dm_timeout?})
59 `sender` ASC", __FILE__, __LINE__);
64 // Do we have "purged" mails?
65 if (SQL_NUMROWS($result_mails) > 0) {
66 // Okay, check for their sender's
67 while ($content = SQL_FETCHARRAY($result_mails)) {
69 if (!fetchUserData($content['sender'])) {
70 // Okay we found some mails!
71 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_pool` WHERE `sender`=%s",
72 array(bigintval($content['sender'])), __FILE__, __LINE__);
74 // Get all affected (deleted) rows
75 $deletedStats += SQL_AFFECTEDROWS();
77 // Reset query (to prevent possible errors) ...;
78 $result_mails = SQL_QUERY("SELECT
81 `{?_MYSQL_PREFIX?}_pool`
83 `data_type`='DELETED' AND timestamp <= (UNIX_TIMESTAMP() - {?ap_dm_timeout?})
85 `sender` ASC", __FILE__, __LINE__);
91 SQL_FREERESULT($result_mails);
93 // Now let's check for stats entries as well;
94 $result_mails = SQL_QUERY("SELECT
97 `{?_MYSQL_PREFIX?}_user_stats`
99 `timestamp_send` <= (UNIX_TIMESTAMP() - {?ap_dm_timeout?})
101 `userid` ASC", __FILE__, __LINE__);
103 // Do we have "purged" mails?
104 if (SQL_NUMROWS($result_mails) > 0) {
105 // Okay, check for their sender's
106 while ($content = SQL_FETCHARRAY($result_mails)) {
108 if (!fetchUserData($content['sender'])) {
109 // Okay we found some mails!
110 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `userid`=%s",
111 array(bigintval($content['userid'])), __FILE__, __LINE__);
113 // Get all affected (deleted) rows
114 $deletedStats += SQL_AFFECTEDROWS();
116 // Reset query (to prevent possible errors) ...
117 $result_mails = SQL_QUERY("SELECT
120 `{?_MYSQL_PREFIX?}_user_stats`
122 `timestamp_send` <= (UNIX_TIMESTAMP() - {?ap_dm_timeout?})
124 `userid` ASC", __FILE__, __LINE__);
130 SQL_FREERESULT($result_mails);
132 // Do we have deleted mails and the admin want's to receive a notification
133 if (($deletedStats > 0) && (getConfig('ap_dm_notify') == 'Y')) {
134 // Send out email to admin
135 sendAdminNotification(getMessage('AUTOPURGE_ADMIN_DEL_MAILS_SUBJECT'), 'admin_autopurge_del_mails', $deletedStats);