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 * 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')) {
44 // Abort if autopurge is not active or disabled by admin
45 if ((!isExtensionActive('autopurge')) || (getConfig('auto_purge_active') != 'Y') || (getConfig('ap_del_mails') != 'Y')) {
50 // Okay, let's check for deleted mails
51 $result_mails = SQL_QUERY("SELECT
54 `{?_MYSQL_PREFIX?}_pool`
56 `data_type`='DELETED' AND `timestamp` <= (UNIX_TIMESTAMP() - {?ap_dm_timeout?})
58 `sender` ASC", __FILE__, __LINE__);
63 // Do we have "purged" mails?
64 if (SQL_NUMROWS($result_mails) > 0) {
65 // Okay, check for their sender's
66 while ($content = SQL_FETCHARRAY($result_mails)) {
68 if (!fetchUserData($content['sender'])) {
69 // Okay we found some mails!
70 SQL_QUERY_ESC("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 += SQL_AFFECTEDROWS();
76 // Reset query (to prevent possible errors) ...;
77 $result_mails = SQL_QUERY("SELECT
80 `{?_MYSQL_PREFIX?}_pool`
82 `data_type`='DELETED' AND timestamp <= (UNIX_TIMESTAMP() - {?ap_dm_timeout?})
84 `sender` ASC", __FILE__, __LINE__);
90 SQL_FREERESULT($result_mails);
92 // Now let's check for stats entries as well;
93 $result_mails = SQL_QUERY("SELECT
96 `{?_MYSQL_PREFIX?}_user_stats`
98 `timestamp_send` <= (UNIX_TIMESTAMP() - {?ap_dm_timeout?})
100 `sender` ASC", __FILE__, __LINE__);
102 // Do we have "purged" mails?
103 if (SQL_NUMROWS($result_mails) > 0) {
104 // Okay, check for their sender's
105 while ($content = SQL_FETCHARRAY($result_mails)) {
107 if (!fetchUserData($content['sender'])) {
108 // Okay we found some mails!
109 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `sender`=%s",
110 array(bigintval($content['sender'])), __FILE__, __LINE__);
112 // Get all affected (deleted) rows
113 $deletedStats += SQL_AFFECTEDROWS();
115 // Reset query (to prevent possible errors) ...
116 $result_mails = SQL_QUERY("SELECT
119 `{?_MYSQL_PREFIX?}_user_stats`
121 `timestamp_send` <= (UNIX_TIMESTAMP() - {?ap_dm_timeout?})
123 `sender` ASC", __FILE__, __LINE__);
129 SQL_FREERESULT($result_mails);
131 // Do we have deleted mails and the admin want's to receive a notification
132 if (($deletedStats > 0) && (getConfig('ap_dm_notify') == 'Y')) {
133 // Send out email to admin
134 sendAdminNotification(getMessage('AUTOPURGE_ADMIN_DEL_MAILS_SUBJECT'), 'admin_autopurge_del_mails', $deletedStats);