root/trunk/options/cron.php

Revision 397, 6.5 kB (checked in by bobe, 2 years ago)

Erreur fatale à l’envoi en utilisant options/cron.php et les envois par flot

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php
2 /**
3  * Copyright (c) 2002-2006 Aurélien Maille
4  *
5  * This file is part of Wanewsletter.
6  *
7  * Wanewsletter is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * Wanewsletter is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with Wanewsletter; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  *
21  * @package Wanewsletter
22  * @author  Bobe <wascripts@phpcodeur.net>
23  * @link    http://phpcodeur.net/wascripts/wanewsletter/
24  * @license http://www.gnu.org/copyleft/gpl.html  GNU General Public License
25  * @version $Id$
26  */
27
28 define('IN_NEWSLETTER', true);
29 define('IN_CRON',       true);
30 define('WA_ROOTDIR',    '..');
31
32 require WA_ROOTDIR . '/start.php';
33
34 // FIX temporaire, sinon bug lors des envois par flot
35 function sessid($var)
36 {
37     return $var;
38 }
39
40 load_settings();
41
42 $mode     = ( !empty($_REQUEST['mode']) ) ? trim($_REQUEST['mode']) : '';
43 $liste_id = ( !empty($_REQUEST['liste']) ) ? intval($_REQUEST['liste']) : 0;
44
45 $sql = 'SELECT liste_id, liste_format, sender_email, liste_alias, limitevalidate,
46         liste_name, form_url, return_email, liste_sig, use_cron, confirm_subscribe,
47         pop_host, pop_port, pop_user, pop_pass
48     FROM ' . LISTE_TABLE . '
49     WHERE liste_id = ' . $liste_id;
50 if( !($result = $db->query($sql)) )
51 {
52     trigger_error('Impossible de récupérer les informations sur cette liste', ERROR);
53 }
54
55 if( $listdata = $result->fetch() )
56 {
57     //
58     // On règle le script pour ignorer une déconnexion du client et
59     // poursuivre l'envoi du flot d'emails jusqu'à son terme.
60     //
61     @ignore_user_abort(true);
62     
63     //
64     // On augmente également le temps d'exécution maximal du script.
65     //
66     // Certains hébergeurs désactivent pour des raisons évidentes cette fonction
67     // Si c'est votre cas, vous êtes mal barré
68     //
69     @set_time_limit(1200);
70     
71     if( $mode == 'send' )
72     {
73         require WA_ROOTDIR . '/includes/engine_send.php';
74         
75         $sql = "SELECT log_id, log_subject, log_body_text, log_body_html, log_status
76             FROM " . LOG_TABLE . "
77             WHERE liste_id = $listdata[liste_id]
78                 AND log_status = " . STATUS_STANDBY . "
79             LIMIT 1 OFFSET 0";
80         if( !($result = $db->query($sql)) ) // on récupère le dernier log en statut d'envoi
81         {
82             trigger_error('Impossible d\'obtenir les données sur ce log', ERROR);
83         }
84         
85         if( !($logdata = $result->fetch()) )
86         {
87             $output->message('No_log_to_send');
88         }
89         
90         $sql = "SELECT jf.file_id, jf.file_real_name, jf.file_physical_name, jf.file_size, jf.file_mimetype
91             FROM " . JOINED_FILES_TABLE . " AS jf
92                 INNER JOIN " . LOG_FILES_TABLE . " AS lf ON lf.file_id = jf.file_id
93                 INNER JOIN " . LOG_TABLE . " AS l ON l.log_id = lf.log_id
94                     AND l.liste_id = $listdata[liste_id]
95                     AND l.log_id   = $logdata[log_id]
96             ORDER BY jf.file_real_name ASC";
97         if( !($result = $db->query($sql)) )
98         {
99             trigger_error('Impossible d\'obtenir la liste des fichiers joints', ERROR);
100         }
101         
102         $logdata['joined_files'] = $result->fetchAll();
103         
104         //
105         // On lance l'envoi
106         //
107         $message = launch_sending($listdata, $logdata);
108         
109         $output->message(nl2br($message));
110     }
111     else if( $mode == 'validate' )
112     {
113         require WAMAILER_DIR . '/class.mailer.php';
114         require WAMAILER_DIR . '/class.pop.php';
115         require WA_ROOTDIR . '/includes/class.form.php';
116         require WA_ROOTDIR . '/includes/functions.validate.php';
117         include WA_ROOTDIR . '/includes/functions.stats.php';
118         
119         $limit_security = 100; // nombre maximal d'emails dont le script doit s'occuper à chaque appel
120         
121         //
122         // Initialisation de la classe mailer
123         //
124         $mailer = new Mailer(WA_ROOTDIR . '/language/email_' . $nl_config['language'] . '/');
125         
126         if( $nl_config['use_smtp'] )
127         {
128             $mailer->smtp_path = WAMAILER_DIR . '/';
129             $mailer->use_smtp(
130                 $nl_config['smtp_host'],
131                 $nl_config['smtp_port'],
132                 $nl_config['smtp_user'],
133                 $nl_config['smtp_pass']
134             );
135         }
136         
137         $mailer->set_charset($lang['CHARSET']);
138         $mailer->set_format(FORMAT_TEXTE);
139         $mailer->set_from($listdata['sender_email'], unhtmlspecialchars($listdata['liste_name']));
140         
141         if( $listdata['return_email'] != '' )
142         {
143             $mailer->set_return_path($listdata['return_email']);
144         }
145         
146         $wan =& new Wanewsletter($listdata);
147         $pop =& new Pop();
148         $pop->connect($listdata['pop_host'], $listdata['pop_port'], $listdata['pop_user'], $listdata['pop_pass']);
149         
150         $cpt = 0;
151         $total    = $pop->stat_box();
152         $mail_box = $pop->list_mail();
153         
154         foreach( $mail_box as $mail_id => $mail_size )
155         {
156             $headers = $pop->parse_headers($mail_id);
157             
158             if( !isset($headers['from']) || !preg_match('/^(?:"?([^"]*?)"?)?[ ]*(?:<)?([^> ]+)(?:>)?$/i', $headers['from'], $match) )
159             {
160                 continue;
161             }
162             
163             $pseudo = ( isset($match[1]) ) ? strip_tags(trim($match[1])) : '';
164             $email  = trim($match[2]);
165             
166             if( !isset($headers['to']) || !stristr($headers['to'], $wan->liste_email) )
167             {
168                 continue;
169             }
170             
171             if( !isset($headers['subject']) )
172             {
173                 continue;
174             }
175             
176             $action = strtolower(trim($headers['subject']));
177             
178             switch( $action )
179             {
180                 case 'desinscription':
181                 case 'désinscription':
182                 case 'unsubscribe':
183                     $action = 'desinscription';
184                     break;
185                 
186                 case 'inscription':
187                 case 'subscribe':
188                     $action = 'inscription';
189                     break;
190                 
191                 case 'confirmation':
192                 case 'setformat':
193                     break;
194                 
195                 default:
196                     $pop->delete_mail($mail_id);
197                     continue 2;
198                     break;
199             }
200             
201             $code = $pop->contents[$mail_id]['message'];
202             if( strlen($code) == 32 ) // Compatibilité avec versions < 2.3
203             {
204                 $code = substr($code, 0, 20);
205             }
206             
207             if( $action == 'inscription' || $action == 'setformat' || ($action == 'desinscription' && empty($code)) )
208             {
209                 $wan->do_action($action, $email);
210             }
211             else
212             {
213                 if( empty($headers['date']) || intval($time = strtotime($headers['date'])) > 0 )
214                 {
215                     $time = time();
216                 }
217                 
218                 $wan->check_code($code, $time);
219             }
220             
221             //
222             // On supprime l'email maintenant devenu inutile
223             //
224             $pop->delete_mail($mail_id);
225             
226             $cpt++;
227             
228             if( $cpt > $limit_security )
229             {
230                 break;
231             }
232         }//end for
233         
234         $pop->quit();
235         
236         $output->message('Success_operation');
237     }
238     else
239     {
240         trigger_error('No valid mode specified', ERROR);
241     }
242 }
243 else
244 {
245     trigger_error('Unknown_list', ERROR);
246 }
247
248 ?>
Note: See TracBrowser for help on using the browser.