]> git.mxchange.org Git - mailer.git/blob - inc/autopurge/purge-mails.php
Huge rewrite:
[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 - 2008 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         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 } // END - if
44
45 // Abort if autopurge is not active or disabled by admin
46 if ((!EXT_IS_ACTIVE('autopurge')) || (getConfig('auto_purge_active') != 'Y')) {
47         // Abort here
48         return false;
49 } // END - if
50
51 // Search for mails from deleted members?
52 if (getConfig('ap_del_mails') == 'Y') {
53         // Okay, let's check for them...
54         $result_mails = SQL_QUERY_ESC("SELECT `sender`
55 FROM `{!_MYSQL_PREFIX!}_pool`
56 WHERE `data_type`='DELETED' AND `timestamp` <= (UNIX_TIMESTAMP() - %s)
57 ORDER BY `sender` ASC",
58                 array(getConfig('ap_dm_timeout')), __FILE__, __LINE__);
59
60         // Reset counter...
61         $DELETED = 0;
62
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)) {
67                         // Check now...
68                         $fount = SQL_NUMROWS(SQL_QUERY_ESC("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s LIMIT 1",
69                         array(bigintval($content['sender'])), __FILE__, __LINE__));
70                         if ($found == 0) {
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__);
74                                 $DELETED += SQL_AFFECTEDROWS();
75
76                                 // Reset query (to prevent possible errors) ...;
77                                 $result_mails = SQL_QUERY_ESC("SELECT `sender`
78 FROM `{!_MYSQL_PREFIX!}_pool`
79 WHERE `data_type`='DELETED' AND timestamp <= (UNIX_TIMESTAMP() - %s)
80 ORDER BY `sender` ASC",
81                                         array(getConfig('ap_dm_timeout')), __FILE__, __LINE__);
82                         }
83                 }
84         }
85
86         // Free memory
87         SQL_FREERESULT($result_mails);
88
89         // Now let's check for stats entries as well;
90         $result_mails = SQL_QUERY_ESC("SELECT `sender`
91 FROM `{!_MYSQL_PREFIX!}_user_stats`
92 WHERE `data_type`='DELETED' AND `timestamp_send` <= (UNIX_TIMESTAMP() - %s)
93 ORDER BY `sender` ASC",
94                 array(getConfig('ap_dm_timeout')), __FILE__, __LINE__);
95
96         // Do we have "purged" mails?
97         if (SQL_NUMROWS($result_mails) > 0) {
98                 // Okay, check for their sender's
99                 while ($content = SQL_FETCHARRAY($result_mails)) {
100                         // Check now...
101                         $found = SQL_NUMROWS(SQL_QUERY_ESC("SELECT `userid` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s LIMIT 1",
102                                 array(bigintval($content['sender'])), __FILE__, __LINE__));
103                         if ($found == 0) {
104                                 // Okay we found some mails!
105                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_stats` WHERE `sender`=%s",
106                                         array(bigintval($content['sender'])), __FILE__, __LINE__);
107                                 $DELETED += SQL_AFFECTEDROWS();
108
109                                 // Reset query (to prevent possible errors) ...
110                                 $result_mails = SQL_QUERY_ESC("SELECT `sender`
111 FROM `{!_MYSQL_PREFIX!}_user_stats`
112 WHERE `data_type`='DELETED' AND timestamp_send <= (UNIX_TIMESTAMP() - %s)
113 ORDER BY `sender` ASC",
114                                         array(getConfig('ap_dm_timeout')), __FILE__, __LINE__);
115                         }
116                 }
117         }
118
119         // Free memory
120         SQL_FREERESULT($result_mails);
121
122         // Do we have deleted mails and the admin want's to receive a notification
123         if (($DELETED > 0) && (getConfig('ap_dm_notify') == 'Y')) {
124                 // Send out email to admin
125                 sendAdminNotification(getMessage('AUTOPURGE_ADMIN_DEL_MAILS_SUBJECT'), 'admin_autopurge_del_mails', $DELETED, '');
126         } // END - if
127 }
128
129 //
130 ?>