source: extensions/free_mail/main.inc.php @ 3912

Last change on this file since 3912 was 3912, checked in by cljosse, 15 years ago
File size: 5.7 KB
Line 
1<?php
2/*
3Plugin Name: Plugin Mail
4Version: 1.03
5Description: Plugin modifie l entete des mails en cas de SPAM
6Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=309
7Author: cljosse
8Author URI:http://cljosse.e3b.org
9*/
10 
11if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
12define('Free_Mail_DIR' , basename(dirname(__FILE__)));
13define('Free_Mail_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
14include_once (Free_Mail_PATH.'include/constants.php'); 
15
16
17/*
18 add_event_handler('send_mail_headers','clj_send_mail_headers' ) ;
19function clj_send_mail_headers($headers)
20{
21echo '<pre>';
22print_r($headers) ;
23echo '</pre>' ;
24}
25
26add_event_handler('send_mail_to', 'clj_send_mail_to');
27function clj_send_mail_to($mailto)
28{
29echo '<pre>';
30//print_r($mailto) ;
31echo '</pre>' ;
32}
33
34add_event_handler('send_mail_content', 'clj_send_mail_content');
35function clj_send_mail_content($content)
36{
37echo '<pre>';
38//print_r($content) ;
39echo '</pre>' ;
40}
41
42*/
43//  trigger_event('send_mail_to', get_strict_email_list($to)),
44// add_event_handler('send_mail_to', 'clj_send_mail_to');
45/*function clj_send_mail_to($mailto)
46{
47
48$to=get_strict_email_list($mailto);
49echo '<pre>';
50 print_r($mailto) ;
51 print_r( $to);
52echo '</pre>' ;
53
54 
55}
56  */
57 
58add_event_handler('send_mail', 'clj_send_mail', EVENT_HANDLER_PRIORITY_NEUTRAL, 6);
59
60function clj_send_mail($result, $mailto, $subject, $content, $headers, $args)
61{
62    global $conf, $user, $lang_info,  $conf_mail;
63      $query = "
64                SELECT COUNT(*)
65                FROM ".FREE_MAIL_TABLE."
66                ;";
67  list($count) = mysql_fetch_row(pwg_query($query));
68  if ($count == 0)
69  {
70         $next_day = time()  ;
71         $date_check='';
72           $q = '
73    INSERT INTO '.FREE_MAIL_TABLE.' (id, date_check)
74    VALUES (1,"'. $next_day.'")
75         ;';
76        pwg_query($q);
77        } 
78         $query = "
79    SELECT *
80    FROM ".FREE_MAIL_TABLE."
81        ;";
82    $data = mysql_fetch_array(pwg_query($query));
83    $next_day = $data['date_check'];
84    $next_day =(float) ($next_day -time())/3600 ;
85 
86$ret="Attente de déblocage SPAMS " ;
87$t1='5.0';
88 
89   //================= réécriture de l'entête ===============================
90
91if (!isset( $mailto)){ echo 'erreur maito absent'; exit(); }
92if (empty( $mailto))  { echo 'erreur maito vide'; 
93 /*
94echo '<pre>
95-------------------------------------------------------------------
96CONF_MAIL
97';
98 print_r($conf_mail) ;
99 echo '<pre>
100-------------------------------------------------------------------
101ARGS
102';
103 print_r($args) ;
104echo '</pre>' ;
105*/
106//$mailto=$conf_mail['email_webmaster'];
107 
108 
109  $headers = 'From: '.$args['from']."\n";
110  $headers.= 'Reply-To: '.$args['from']."\n";
111
112    if (empty($mailto))
113  {
114    // Add only when to is empty
115    // else mail() add 'To:' on header
116  //  $headers.= 'To: undisclosed-recipients: ;'."\n";
117  }
118 
119 
120   if (!empty($args['Cc']))
121  {
122   // $headers.= 'Cc: '.implode(',', $args['Cc'])." \n";
123           $headers.=  'Cc: '.$conf_mail['email_webmaster']." \n";
124  }
125 
126 
127
128  if (!empty($args['Bcc']))
129  {
130    $temp= ' '.implode(',', $args['Bcc'])." \n";
131        //echo $temp;
132        //$headers.=  'Bcc: '.$temp." \n";
133        $temp='Bcc: '.$conf_mail['email_webmaster']." \n";
134   $headers.=  'Bcc: '.$conf_mail['email_webmaster']." \n";
135  }
136
137  $headers.= 'Content-Type: multipart/alternative;'."\n";
138  $headers.= '  boundary="---='.$conf_mail['boundary_key'].'";'."\n";
139  $headers.= '  reply-type=original'."\n";
140  $headers.= 'MIME-Version: 1.0'."\n";
141  $headers.= 'X-Mailer: Piwigo Mailer'."\n";
142 
143
144;
145 }
146 
147 
148        $texte = "This is a multi-part message in MIME format.\n"; 
149       
150        $texte .= "-----=".$conf_mail['boundary_key']."\n"; 
151        $texte .= "Ceci est un message est au format MIME.\n"; 
152        $texte .= 'Content-Type: text/plain; charset="UTF-8"'."\n"; 
153        $texte .= 'Content-Transfer-Encoding: 8bit'."\n\n"; 
154        $texte .= $args['content']; // A voir texte brut...
155           
156                $texte .= "\n\n"; 
157       
158                $content =$texte .$content ;
159
160                $ret=false;
161                // $t1 =$next_day ;
162 if ( $t1 >=$next_day) {
163   ob_start();
164   $ret = mail($mailto, $subject, $content, $headers);
165   $message = ob_get_contents();
166        //ob_flush();
167   ob_end_clean();
168//Trop de spam
169$pos = strpos($message, 'spam');
170 
171if ($pos === false) {
172if ($ret) {
173    return $ret;
174        }
175       
176                echo '<pre>';
177echo            'mailto:   '.$mailto.'
178';
179                print_r($headers) ;
180                echo '--------------------------------------------
181                ';
182                print_r($message) ;
183               
184                        print_r($content) ;
185                echo '</pre>' ;
186                exit();
187               
188} else 
189{ 
190 echo $message;
191$ret=false;
192
193   }
194 
195       
196
197 if ($ret) {
198     return $ret;
199 }else{
200        $next_day = time() + (2 * 24 * 60 * 60);
201        echo "Attention defaut d'envoie de mails " .$ret. "\n" ;
202       $query = '
203        UPDATE '.FREE_MAIL_TABLE.'
204        SET date_check="'. $next_day.'"
205      ;';
206      pwg_query($query);
207          $next_day=($next_day-time()) /3600 ;
208            exit();
209 }
210 
211
212
213}else{
214
215        /*      echo '<pre>';
216print_r ($headers);
217print_r($content );
218echo '</pre>'; 
219*/
220
221                echo '<pre>';
222                print "Attention il ya eu un d&eacute;faut d'envoie de mails encore
223                ". (int)$next_day . "H
224                avant le déblocage."   ;
225                echo '</pre>';
226                echo '
227          <a href="admin.php">RETOUR vers admin.php </a>
228          ';
229                echo '<pre>';
230                echo 'ARGS:             ';
231                print_r($args) ;
232                        echo '
233                        ----------------------------------------------------
234                        MAIL TO:
235                        ' ;
236                        print_r($mailto) ;
237
238                        echo '
239                        ----------------------------------------------------
240                        HEADER
241                        ' ;
242                        print_r($headers) ;
243                                        echo '
244                                        ----------------------------------------------------
245                                        content
246                        ' ;
247                       
248                        print_r($content) ;
249                echo '</pre>' ;
250       
251     exit();
252 }
253 
254
255}
256
257
258
259?>
Note: See TracBrowser for help on using the repository browser.