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')) || (!isAutoPurgingActive()) || (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
58 `timestamp` <= (UNIX_TIMESTAMP() - {?ap_dm_timeout?})
60 `sender` ASC", __FILE__, __LINE__);
65 // Do we have "purged" mails?
66 if (!SQL_HASZERONUMS($result_mails)) {
67 // Okay, check for their sender's
68 while ($content = SQL_FETCHARRAY($result_mails)) {
70 if (!fetchUserData($content['sender'])) {
71 // Okay we found some mails!
72 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_pool` WHERE `sender`=%s",
73 array(bigintval($content['sender'])), __FILE__, __LINE__);
75 // Get all affected (deleted) rows
76 $deletedStats += SQL_AFFECTEDROWS();
78 // Reset query (to prevent possible errors) ...;
79 $result_mails = SQL_QUERY("SELECT
82 `{?_MYSQL_PREFIX?}_pool`
84 `data_type`='DELETED' AND
85 `timestamp` <= (UNIX_TIMESTAMP() - {?ap_dm_timeout?})
87 `sender` ASC", __FILE__, __LINE__);
93 SQL_FREERESULT($result_mails);
95 // Now let's check for stats entries as well;
96 $result_mails = SQL_QUERY("SELECT
99 `{?_MYSQL_PREFIX?}_user_stats`
101 `timestamp_send` <= (UNIX_TIMESTAMP() - {?ap_dm_timeout?})
103 `userid` ASC", __FILE__, __LINE__);
105 // Do we have "purged" mails?
106 if (!SQL_HASZERONUMS($result_mails)) {
107 // Okay, check for their sender's
108 while ($content = SQL_FETCHARRAY($result_mails)) {
110 if (!fetchUserData($content['sender'])) {
111 // Okay we found some mails!
112 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `userid`=%s",
113 array(bigintval($content['userid'])), __FILE__, __LINE__);
115 // Get all affected (deleted) rows
116 $deletedStats += SQL_AFFECTEDROWS();
118 // Reset query (to prevent possible errors) ...
119 $result_mails = SQL_QUERY("SELECT
122 `{?_MYSQL_PREFIX?}_user_stats`
124 `timestamp_send` <= (UNIX_TIMESTAMP() - {?ap_dm_timeout?})
126 `userid` ASC", __FILE__, __LINE__);
132 SQL_FREERESULT($result_mails);
134 // Do we have deleted mails and the admin want's to receive a notification
135 if (($deletedStats > 0) && (getConfig('ap_dm_notify') == 'Y')) {
136 // Send out email to admin
137 sendAdminNotification('{--ADMIN_AUTOPURGE_DELETE_MAILS_SUBJECT--}', 'admin_autopurge_del_mails', $deletedStats);