Renamed all SQL-related functions to camel-case notation
[mailer.git] / inc / purge / purge-mails.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } // END - if
42
43 // Abort if autopurge is not active or disabled by admin
44 if ((!isExtensionActive('autopurge')) || (!isAutoPurgingActive()) || (getConfig('ap_del_mails') != 'Y')) {
45         // Abort here
46         return FALSE;
47 } // END - if
48
49 // Okay, let's check for deleted mails
50 $result_mails = sqlQuery("SELECT
51         `sender`
52 FROM
53         `{?_MYSQL_PREFIX?}_pool`
54 WHERE
55         `data_type`='DELETED' AND
56         (UNIX_TIMESTAMP() - `timestamp`) >= {?ap_dm_timeout?}
57 ORDER BY
58         `sender` ASC", __FILE__, __LINE__);
59
60 // Init counter...
61 $deletedStats = '0';
62
63 // Is there "purged" mails?
64 if (!ifSqlHasZeroNums($result_mails)) {
65         // Okay, check for their sender's
66         while ($content = sqlFetchArray($result_mails)) {
67                 // Check now...
68                 if (!fetchUserData($content['sender'])) {
69                         // Okay we found some mails!
70                         sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_pool` WHERE `sender`=%s",
71                                 array(bigintval($content['sender'])), __FILE__, __LINE__);
72
73                         // Get all affected (deleted) rows
74                         $deletedStats += sqlAffectedRows();
75                 } // END - if
76         } // END - while
77 } // END - if
78
79 // Free memory
80 sqlFreeResult($result_mails);
81
82 // Now let's check for stats entries as well;
83 $result_mails = sqlQuery("SELECT
84         `userid` AS `sender`
85 FROM
86         `{?_MYSQL_PREFIX?}_user_stats`
87 WHERE
88         (UNIX_TIMESTAMP() - `timestamp_send`) >= {?ap_dm_timeout?}
89 ORDER BY
90         `userid` ASC", __FILE__, __LINE__);
91
92 // Is there "purged" mails?
93 if (!ifSqlHasZeroNums($result_mails)) {
94         // Okay, check for their sender's
95         while ($content = sqlFetchArray($result_mails)) {
96                 // Check now...
97                 if (!fetchUserData($content['sender'])) {
98                         // Okay we found some mails!
99                         sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_stats` WHERE `userid`=%s",
100                                 array(bigintval($content['sender'])), __FILE__, __LINE__);
101
102                         // Get all affected (deleted) rows
103                         $deletedStats += sqlAffectedRows();
104
105                         // Reset query (to prevent possible errors) ...
106                         $result_mails = sqlQuery("SELECT
107         `userid` AS `sender`
108 FROM
109         `{?_MYSQL_PREFIX?}_user_stats`
110 WHERE
111         (UNIX_TIMESTAMP() - `timestamp_send`) >= {?ap_dm_timeout?}
112 ORDER BY
113         `userid` ASC", __FILE__, __LINE__);
114                 } // END - if
115         } // END - while
116 } // END - if
117
118 // Free memory
119 sqlFreeResult($result_mails);
120
121 // Is there deleted mails and the admin want's to receive a notification
122 if (($deletedStats > 0) && (getConfig('ap_dm_notify') == 'Y')) {
123         // Send out email to admin
124         sendAdminNotification('{--ADMIN_AUTOPURGE_DELETE_MAILS_SUBJECT--}', 'admin_purge_del_mails', $deletedStats);
125 } // END - if
126
127 // [EOF]
128 ?>