2 /************************************************************************
3 * MXChange v0.2.1 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 * -------------------------------------------------------------------- *
14 * $Date:: 2009-03-06 20:24:32 +0100 (Fr, 06. Mär 2009) $ *
15 * $Tag:: 0.2.1-FINAL $ *
16 * $Author:: stelzi $ *
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 - 2008 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
45 // Abort if autopurge is not active or disabled by admin
46 if ((!EXT_IS_ACTIVE("autopurge")) || (getConfig('auto_purge_active') != "Y")) {
51 // Search for mails from deleted members?
52 if (getConfig('ap_del_mails') == "Y") {
53 // Okay, let's check for them...
54 $since = getConfig(('ap_dm_timeout'));
55 $result_mails = SQL_QUERY_ESC("SELECT sender
56 FROM `{!_MYSQL_PREFIX!}_pool`
57 WHERE data_type='DELETED' AND timestamp <= (UNIX_TIMESTAMP() - %s)
59 array($since), __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 $fount = SQL_NUMROWS(SQL_QUERY_ESC("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
70 array(bigintval($content['sender'])), __FILE__, __LINE__));
72 // Okay we found some mails!
73 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_pool` WHERE sender=%s",
74 array(bigintval($content['sender'])), __FILE__, __LINE__);
75 $DELETED += SQL_AFFECTEDROWS();
77 // Reset query (to prevent possible errors) ...
78 $since = getConfig(('ap_dm_timeout'));
79 $result_mails = SQL_QUERY_ESC("SELECT sender
80 FROM `{!_MYSQL_PREFIX!}_pool`
81 WHERE data_type='DELETED' AND timestamp <= (UNIX_TIMESTAMP() - %s)
83 array($since), __FILE__, __LINE__);
89 SQL_FREERESULT($result_mails);
91 // Now let's check for stats entries as well
92 $since = getConfig(('ap_dm_timeout'));
93 $result_mails = SQL_QUERY_ESC("SELECT sender
94 FROM `{!_MYSQL_PREFIX!}_user_stats`
95 WHERE data_type='DELETED' AND timestamp_send <= (UNIX_TIMESTAMP() - %s)
97 array($since), __FILE__, __LINE__);
99 // Do we have "purged" mails?
100 if (SQL_NUMROWS($result_mails) > 0) {
101 // Okay, check for their sender's
102 while ($content = SQL_FETCHARRAY($result_mails)) {
104 $found = SQL_NUMROWS(SQL_QUERY_ESC("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1", array(bigintval($content['sender'])), __FILE__, __LINE__));
106 // Okay we found some mails!
107 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_stats` WHERE sender=%s", array(bigintval($content['sender'])), __FILE__, __LINE__);
108 $DELETED += SQL_AFFECTEDROWS();
110 // Reset query (to prevent possible errors) ...
111 $since = getConfig(('ap_dm_timeout'));
112 $result_mails = SQL_QUERY_ESC("SELECT sender
113 FROM `{!_MYSQL_PREFIX!}_user_stats`
114 WHERE data_type='DELETED' AND timestamp_send <= (UNIX_TIMESTAMP() - %s)
115 ORDER BY sender ASC",
116 array($since), __FILE__, __LINE__);
122 SQL_FREERESULT($result_mails);
124 // Do we have deleted mails and the admin want's to receive a notification
125 if (($DELETED > 0) && (getConfig('ap_dm_notify') == "Y")) {
126 // Send out email to admin
127 SEND_ADMIN_NOTIFICATION(getMessage('AUTOPURGE_ADMIN_DEL_MAILS_SUBJECT'), "admin_autopurge_del_mails", $DELETED, "");