Several fixes for broken actions (sorry for lame text)
[mailer.git] / inc / autopurge / purge-mails.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 05/29/2004 *
4  * ===============                              Last change: 11/26/2004 *
5  *                                                                      *
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  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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                  *
22  *                                                                      *
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.                                  *
27  *                                                                      *
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.                         *
32  *                                                                      *
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,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         die();
42 } // END - if
43
44 // Abort if autopurge is not active or disabled by admin
45 if ((!isExtensionActive('autopurge')) || (getConfig('auto_purge_active') != 'Y')) {
46         // Abort here
47         return false;
48 } // END - if
49
50 // Search for mails from deleted members?
51 if (getConfig('ap_del_mails') == 'Y') {
52         // Okay, let's check for them...
53         $result_mails = SQL_QUERY("SELECT
54         `sender`
55 FROM
56         `{?_MYSQL_PREFIX?}_pool`
57 WHERE
58         `data_type`='DELETED' AND `timestamp` <= (UNIX_TIMESTAMP() - {?ap_dm_timeout?})
59 ORDER BY
60         `sender` ASC", __FILE__, __LINE__);
61
62         // Reset counter...
63         $DELETED = 0;
64
65         // Do we have "purged" mails?
66         if (SQL_NUMROWS($result_mails) > 0) {
67                 // Okay, check for their sender's
68                 while ($content = SQL_FETCHARRAY($result_mails)) {
69                         // Check now...
70                         $fount = SQL_NUMROWS(SQL_QUERY_ESC("SELECT userid FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1",
71                         array(bigintval($content['sender'])), __FILE__, __LINE__));
72                         if ($found == 0) {
73                                 // Okay we found some mails!
74                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_pool` WHERE `sender`=%s",
75                                         array(bigintval($content['sender'])), __FILE__, __LINE__);
76                                 $DELETED += SQL_AFFECTEDROWS();
77
78                                 // Reset query (to prevent possible errors) ...;
79                                 $result_mails = SQL_QUERY("SELECT
80         `sender`
81 FROM
82         `{?_MYSQL_PREFIX?}_pool`
83 WHERE
84         `data_type`='DELETED' AND timestamp <= (UNIX_TIMESTAMP() - {?ap_dm_timeout?})
85 ORDER BY
86         `sender` ASC", __FILE__, __LINE__);
87                         }
88                 }
89         }
90
91         // Free memory
92         SQL_FREERESULT($result_mails);
93
94         // Now let's check for stats entries as well;
95         $result_mails = SQL_QUERY("SELECT
96         `userid` AS sender
97 FROM
98         `{?_MYSQL_PREFIX?}_user_stats`
99 WHERE
100         `data_type`='DELETED' AND `timestamp_send` <= (UNIX_TIMESTAMP() - {?ap_dm_timeout?})
101 ORDER BY
102         `sender` ASC", __FILE__, __LINE__);
103
104         // Do we have "purged" mails?
105         if (SQL_NUMROWS($result_mails) > 0) {
106                 // Okay, check for their sender's
107                 while ($content = SQL_FETCHARRAY($result_mails)) {
108                         // Check now...
109                         $found = SQL_NUMROWS(SQL_QUERY_ESC("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1",
110                                 array(bigintval($content['sender'])), __FILE__, __LINE__));
111                         if ($found == 0) {
112                                 // Okay we found some mails!
113                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `sender`=%s",
114                                         array(bigintval($content['sender'])), __FILE__, __LINE__);
115                                 $DELETED += SQL_AFFECTEDROWS();
116
117                                 // Reset query (to prevent possible errors) ...
118                                 $result_mails = SQL_QUERY("SELECT
119         `userid` AS sender
120 FROM
121         `{?_MYSQL_PREFIX?}_user_stats`
122 WHERE
123         `data_type`='DELETED' AND timestamp_send <= (UNIX_TIMESTAMP() - {?ap_dm_timeout?})
124 ORDER BY
125         `sender` ASC", __FILE__, __LINE__);
126                         }
127                 }
128         }
129
130         // Free memory
131         SQL_FREERESULT($result_mails);
132
133         // Do we have deleted mails and the admin want's to receive a notification
134         if (($DELETED > 0) && (getConfig('ap_dm_notify') == 'Y')) {
135                 // Send out email to admin
136                 sendAdminNotification(getMessage('AUTOPURGE_ADMIN_DEL_MAILS_SUBJECT'), 'admin_autopurge_del_mails', $DELETED, '');
137         } // END - if
138 }
139
140 //
141 ?>