[11807] | 1 | <?php |
---|
[11808] | 2 | |
---|
[11807] | 3 | class clj { |
---|
| 4 | static public function send_mail($result, $mailto, $subject, $content, $headers, $args) { |
---|
[11835] | 5 | global $conf, $conf_mail, $lang_info, $page; |
---|
| 6 | global $user; |
---|
| 7 | global $mails_options,$mails_donnees ; |
---|
| 8 | global $template,$erreur_message,$infos_message; |
---|
| 9 | global $errors; |
---|
| 10 | $result=true; |
---|
[11807] | 11 | |
---|
[11835] | 12 | include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); |
---|
| 13 | load_language('plugin.lang', MAIL_SUPERV_PATH); |
---|
[11807] | 14 | |
---|
[11835] | 15 | $infos= clj::pwg_mail($mailto,$args) ; |
---|
| 16 | $mailto=$infos->mailto; |
---|
| 17 | $subject=$infos->subject; |
---|
| 18 | $content=$infos->content; |
---|
| 19 | $headers=$infos->headers; |
---|
| 20 | $result=$infos->result; |
---|
| 21 | $args=$infos->args; |
---|
| 22 | $nb_destinataires=$infos->nb_destinataires; |
---|
[11807] | 23 | |
---|
[11835] | 24 | $ret =clj_send_mail($result, $mailto, $subject, $content, $headers, $args,$nb_destinataires); |
---|
| 25 | return $ret; |
---|
| 26 | |
---|
| 27 | //================================ |
---|
| 28 | // Photographie |
---|
| 29 | //================================ |
---|
| 30 | $ret="false"; |
---|
| 31 | $message =""; |
---|
| 32 | |
---|
| 33 | ob_start(); |
---|
| 34 | $ret = mail($mailto, $subject,$content, $headers); |
---|
| 35 | $message = ob_get_contents(); |
---|
| 36 | ob_end_clean(); |
---|
| 37 | Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto, $subject,$content); |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | return $ret; |
---|
| 41 | return true ; |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | //=========================== |
---|
| 45 | //return false; // envoie |
---|
| 46 | //return true ; // pas d'envoie |
---|
| 47 | //=========================== |
---|
[11807] | 48 | } |
---|
| 49 | /************************************ |
---|
| 50 | * |
---|
| 51 | *************************************/ |
---|
| 52 | static public function send_mail_to( $to){ |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | return $to; |
---|
| 57 | } |
---|
| 58 | /************************************ |
---|
| 59 | * |
---|
| 60 | *************************************/ |
---|
| 61 | static public function send_mail_subject($cvt_subject){ |
---|
| 62 | |
---|
| 63 | return $cvt_subject; |
---|
| 64 | } |
---|
| 65 | /************************************ |
---|
| 66 | * |
---|
| 67 | *************************************/ |
---|
| 68 | static public function send_mail_content($content){ |
---|
| 69 | |
---|
| 70 | return $content; |
---|
| 71 | } |
---|
| 72 | /************************************ |
---|
| 73 | * |
---|
| 74 | *************************************/ |
---|
| 75 | static public function send_mail_headers($headers_init){ |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | return $headers_init; |
---|
| 80 | } |
---|
[11808] | 81 | |
---|
| 82 | /* |
---|
| 83 | * sends an email, using Piwigo specific informations |
---|
| 84 | * |
---|
| 85 | * @param: |
---|
| 86 | * - to: receiver(s) of the mail (list separated by comma). |
---|
| 87 | * - args: function params of mail function: |
---|
| 88 | * o from: sender [default value webmaster email] |
---|
| 89 | * o Cc: array of carbon copy receivers of the mail. [default value empty] |
---|
| 90 | * o Bcc: array of blind carbon copy receivers of the mail. [default value empty] |
---|
| 91 | * o subject [default value 'Piwigo'] |
---|
| 92 | * o content: content of mail [default value ''] |
---|
| 93 | * o content_format: format of mail content [default value 'text/plain'] |
---|
| 94 | * o email_format: global mail format [default value $conf_mail['default_email_format']] |
---|
| 95 | * o theme: template to use [default get_default_theme()] |
---|
| 96 | * |
---|
| 97 | * @return boolean (Ok or not) |
---|
| 98 | * pour mise au point . |
---|
[11835] | 99 | * http://www.faqs.org/rfcs/rfc2822.html |
---|
[11808] | 100 | */ |
---|
[11835] | 101 | function pwg_mail($to, $args = array()){ |
---|
[11808] | 102 | global $conf, $conf_mail, $lang_info, $page; |
---|
[11835] | 103 | global $mails_options ; |
---|
| 104 | remove_event_handler('send_mail', 'pwg_send_mail'); |
---|
| 105 | |
---|
[11808] | 106 | if (empty($to) and empty($args['Cc']) and empty($args['Bcc'])) { |
---|
[11835] | 107 | $retour->mailto= ""; |
---|
| 108 | $retour->subject= ""; |
---|
| 109 | $retour->content= ""; |
---|
| 110 | $retour->headers= ""; |
---|
| 111 | $retour->args= $args ; |
---|
| 112 | $retour->nb_destinataires=0 ; |
---|
| 113 | $retour->$result=true ; |
---|
| 114 | return $retour ; |
---|
[11808] | 115 | } |
---|
[11835] | 116 | |
---|
[11808] | 117 | if (!isset($conf_mail)) { |
---|
| 118 | $conf_mail = get_mail_configuration(); |
---|
| 119 | } |
---|
[11835] | 120 | $args['email_format']="text/html"; |
---|
| 121 | |
---|
[11808] | 122 | if (empty($args['email_format'])) { |
---|
| 123 | $args['email_format'] = $conf_mail['default_email_format']; |
---|
| 124 | } |
---|
| 125 | // Compute root_path in order have complete path |
---|
| 126 | set_make_full_url(); |
---|
| 127 | if (empty($args['from'])) { |
---|
| 128 | $args['from'] = $conf_mail['formated_email_webmaster']; |
---|
| 129 | } else { |
---|
| 130 | $args['from'] = format_email('', $args['from']); |
---|
| 131 | } |
---|
| 132 | if (empty($args['subject'])) { |
---|
| 133 | $args['subject'] = 'Piwigo'; |
---|
| 134 | } |
---|
| 135 | // Spring cleaning |
---|
| 136 | $cvt_subject = trim(preg_replace('#[\n\r]+#s', '', $args['subject'])); |
---|
| 137 | // Ascii convertion |
---|
[11835] | 138 | $cvt_subject = encode_mime_header($cvt_subject); |
---|
[11808] | 139 | |
---|
| 140 | if (!isset($args['content'])) { |
---|
| 141 | $args['content'] = ''; |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | if (empty($args['content_format'])) { |
---|
| 145 | $args['content_format'] = 'text/plain'; |
---|
[11835] | 146 | } |
---|
[11808] | 147 | |
---|
[11835] | 148 | if ($conf_mail['send_bcc_mail_webmaster'] || $mails_options['check_send_webmaster']=="on") { |
---|
| 149 | $args['Bcc'][] = $conf_mail['formated_email_webmaster']; |
---|
| 150 | } |
---|
| 151 | $webmaster = $conf_mail['formated_email_webmaster']; |
---|
| 152 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
---|
| 153 | $Cc="";$Bcc=""; |
---|
| 154 | if (empty($mailto)) $mailto=""; |
---|
| 155 | $nb_destinataires=0; |
---|
| 156 | if( isset($args['Bcc'])){ |
---|
| 157 | $nb_destinataires=count($args['Bcc']); |
---|
| 158 | $Bcc= implode(',', $args['Bcc']) ; |
---|
| 159 | } |
---|
| 160 | if( isset($args['Cc'])){ |
---|
| 161 | $nb_destinataires +=count($args['Cc']); |
---|
| 162 | $Cc= implode(',', $args['Cc']) ; |
---|
| 163 | } |
---|
| 164 | if(!empty($to)) $nb_destinataires +=count(explode(",",$to)); |
---|
| 165 | |
---|
| 166 | |
---|
| 167 | if($nb_destinataires==1 && empty($to)){ |
---|
| 168 | if (isset($args['Bcc']) && count($args['Bcc'])==1) $to = array_pop($args['Bcc']); |
---|
| 169 | if (isset($args['Cc']) && count($args['Cc'])==1){ $to = array_pop($args['Cc']); |
---|
[11808] | 170 | } |
---|
[11835] | 171 | } |
---|
| 172 | $mailto=$to ; |
---|
| 173 | //============================================= |
---|
| 174 | // Test Si Mailto vide |
---|
| 175 | //============================================= |
---|
| 176 | if ($mails_options['check_mailto'] == 'on' && empty($mailto) ) { |
---|
| 177 | //=== suppression webmaster adresse dans les copies . |
---|
| 178 | $match_email = $webmaster; |
---|
| 179 | $new_args=array(); |
---|
| 180 | if( isset($args['Bcc'])) |
---|
| 181 | foreach($args['Bcc'] as $key => $val){ |
---|
| 182 | if (!preg_match('/'. $conf_mail['email_webmaster'] .'/', $val)){ |
---|
| 183 | array_push($new_args, $val); |
---|
| 184 | } |
---|
| 185 | } |
---|
| 186 | $args['Bcc']=$new_args; |
---|
| 187 | //======================================================================= |
---|
| 188 | $new_args=array(); |
---|
| 189 | if( isset($args['Cc'])) |
---|
| 190 | foreach($args['Cc'] as $key => $val){ |
---|
| 191 | if (!preg_match('/'. $conf_mail['email_webmaster'] .'/', $val)){ |
---|
| 192 | array_push($new_args, $val); |
---|
| 193 | } |
---|
| 194 | } |
---|
| 195 | $args['Cc']=$new_args; |
---|
| 196 | $nb_destinataires =count($args['Bcc'])+count($args['Cc']) ; |
---|
| 197 | //======================================================================= |
---|
| 198 | $mailto = $webmaster; |
---|
| 199 | $nb_destinataires++; |
---|
| 200 | } |
---|
| 201 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
---|
[11808] | 202 | |
---|
[11835] | 203 | |
---|
[11808] | 204 | if (empty($args['theme'])) { |
---|
| 205 | $args['theme'] = get_default_theme(); |
---|
| 206 | } |
---|
[11835] | 207 | //============================================ |
---|
| 208 | // TEST EOL |
---|
| 209 | // |
---|
| 210 | //=========================================== |
---|
| 211 | // Note: |
---|
| 212 | // Si le message n'est pas reçu, essayez d'utiliser uniquement un caractère LF (\n). |
---|
| 213 | // Quelques agents de transfert de mail Unix de mauvaise qualité remplacent le caractère LF |
---|
| 214 | // par le caractère CRLF automatiquement |
---|
| 215 | //(ce qui revient à doubler le caractère CR si le caractère CRLF est utilisé). |
---|
| 216 | // Ceci doit être un dernier recours car cela ne correspond pas à la » RFC 2822. |
---|
| 217 | //====================================================== |
---|
| 218 | // drop LF barre |
---|
| 219 | //====================================================== |
---|
| 220 | $Eol="\n"; |
---|
| 221 | $pattern="/free.fr|club/"; |
---|
| 222 | if( preg_match($pattern, $mailto) || preg_match($pattern, $Cc) || preg_match($pattern, $Bcc)){ |
---|
| 223 | $Eol="\r\n"; |
---|
| 224 | } |
---|
| 225 | //==================================================== |
---|
| 226 | // Headers |
---|
| 227 | //==================================================== |
---|
| 228 | $headers = 'From: '.$args['from'].$Eol; |
---|
| 229 | $headers.= 'Reply-To: '.$args['from'].$Eol; |
---|
| 230 | //============================================================================= |
---|
| 231 | // Note: |
---|
| 232 | // L'implémentation de la fonction mail() sous Windows diffère de manière significative avec l'implémentation |
---|
| 233 | // Unix. |
---|
| 234 | // Tout d'abord, il n'utilise pas un programme local pour composer les messages, |
---|
| 235 | // mais opère uniquement et directement sur les sockets, |
---|
| 236 | // ce qui signifie qu'un MTA est nécessairement à l'écoute sur un socket du réseau |
---|
| 237 | // (qui peut être soit sur le réseau local ou sur une machine distante). |
---|
| 238 | // |
---|
| 239 | // Deuxièmement, les en-têtes personnalisés comme From:, Cc:, Bcc: et Date: ne sont pas interprétés |
---|
| 240 | // par le MTA dans un premier temps, mais sont analysés par PHP. |
---|
| 241 | // |
---|
| 242 | // De plus, le paramètre to ne doit pas être une adresse sous la forme |
---|
| 243 | // "Quelque chose <quelqu_un@example.com>". |
---|
| 244 | // La commande mail n'analysera pas correctement ceci lors de la discussion avec le MTA. |
---|
| 245 | //============================================================================= |
---|
| 246 | $Cc="";$Bcc=""; |
---|
| 247 | if (!empty($args['Cc'])) { |
---|
| 248 | $Cc=implode(",",$args['Cc']); |
---|
| 249 | if ($mails_options['check_header_carbon'] == 'on') $Cc= get_strict_email_list( $Cc); |
---|
| 250 | $headers.= 'Cc: '.$Cc.$Eol; |
---|
| 251 | $args['Cc']=explode(", ",$Cc); |
---|
| 252 | } |
---|
| 253 | if (!empty($args['Bcc'])) { |
---|
| 254 | $Bcc=implode(",",$args['Bcc']); |
---|
| 255 | if ($mails_options['check_header_carbon'] == 'on') $Bcc= get_strict_email_list( $Bcc); |
---|
| 256 | $headers.= 'Bcc: '.$Bcc.$Eol; |
---|
| 257 | $args['Bcc']=explode(", ",$Bcc); |
---|
| 258 | } |
---|
| 259 | if (!empty($mailto)) { |
---|
| 260 | if ($mails_options['check_header_carbon'] == 'on') $mailto= get_strict_email_list($mailto); |
---|
| 261 | |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | //===================================== |
---|
| 265 | // List on content-type test si doublé |
---|
| 266 | //===================================== |
---|
[11808] | 267 | $content_type_list[] = $args['email_format']; |
---|
[11835] | 268 | if (!empty($conf_mail['alternative_email_format']) && |
---|
| 269 | $conf_mail['alternative_email_format']!= $args['email_format'] ) { |
---|
| 270 | $content_type_list[] = $conf_mail['alternative_email_format']; |
---|
| 271 | $headers.= 'Content-Type: multipart/alternative;'.$Eol; |
---|
[11808] | 272 | |
---|
[11835] | 273 | }else{ |
---|
| 274 | // $headers.= 'Content-Type: '.$args['email_format'].';'.$Eol; |
---|
| 275 | $headers .= 'Content-type: '.$args['email_format'].'; charset='.get_pwg_charset(). ' ' .$Eol; |
---|
| 276 | } |
---|
| 277 | //===================================== |
---|
| 278 | $headers.= ' boundary="---='.$conf_mail['boundary_key'].'";'.$Eol; |
---|
| 279 | $headers.= ' reply-type=original'.$Eol; |
---|
| 280 | $headers.= 'MIME-Version: 1.0'.$Eol; |
---|
| 281 | $headers.= 'X-Mailer: Piwigo Mailer'.$Eol; |
---|
| 282 | //===================================== |
---|
[11808] | 283 | $content = ''; |
---|
| 284 | foreach (array_unique($content_type_list) as $content_type) { |
---|
| 285 | // key compose of indexes witch allow ti cache mail data |
---|
| 286 | $cache_key = $content_type.'-'.$lang_info['code'].'-'.$args['theme']; |
---|
| 287 | if (!isset($conf_mail[$cache_key])) { |
---|
| 288 | $conf_mail[$cache_key]['theme'] = get_mail_template($content_type, $args['theme']); |
---|
| 289 | |
---|
| 290 | $conf_mail[$cache_key]['theme']->set_filename('mail_header', 'header.tpl'); |
---|
[11835] | 291 | $conf_mail[$cache_key]['theme']->set_filename('mail_footer', 'footer.tpl'); |
---|
| 292 | |
---|
[11808] | 293 | $conf_mail[$cache_key]['theme']->assign( |
---|
| 294 | array( |
---|
| 295 | //Header |
---|
| 296 | 'BOUNDARY_KEY' => $conf_mail['boundary_key'], |
---|
| 297 | 'CONTENT_TYPE' => $content_type, |
---|
| 298 | 'CONTENT_ENCODING' => get_pwg_charset(), |
---|
[11835] | 299 | |
---|
[11808] | 300 | // Footer |
---|
| 301 | 'GALLERY_URL' => get_gallery_home_url(), |
---|
| 302 | 'GALLERY_TITLE' => |
---|
| 303 | isset($page['gallery_title']) ? |
---|
| 304 | $page['gallery_title'] : $conf['gallery_title'], |
---|
| 305 | 'VERSION' => $conf['show_version'] ? PHPWG_VERSION : '', |
---|
| 306 | 'PHPWG_URL' => PHPWG_URL, |
---|
| 307 | |
---|
| 308 | 'TITLE_MAIL' => urlencode(l10n('A comment on your site')), |
---|
| 309 | 'MAIL' => get_webmaster_mail_address() |
---|
| 310 | )); |
---|
| 311 | |
---|
| 312 | if ($content_type == 'text/html') { |
---|
| 313 | if ($conf_mail[$cache_key]['theme']->smarty->template_exists('global-mail-css.tpl')) |
---|
| 314 | { |
---|
| 315 | $conf_mail[$cache_key]['theme']->set_filename('css', 'global-mail-css.tpl'); |
---|
| 316 | $conf_mail[$cache_key]['theme']->assign_var_from_handle('GLOBAL_MAIL_CSS', 'css'); |
---|
| 317 | } |
---|
| 318 | |
---|
| 319 | $file = PHPWG_ROOT_PATH.'themes/'.$args['theme'].'/mail-css.tpl'; |
---|
| 320 | if (is_file($file)) { |
---|
| 321 | $conf_mail[$cache_key]['theme']->set_filename('css', realpath($file)); |
---|
| 322 | $conf_mail[$cache_key]['theme']->assign_var_from_handle('MAIL_CSS', 'css'); |
---|
| 323 | } |
---|
| 324 | } |
---|
| 325 | |
---|
| 326 | // what are displayed on the header of each mail ? |
---|
| 327 | $conf_mail[$cache_key]['header'] = |
---|
| 328 | $conf_mail[$cache_key]['theme']->parse('mail_header', true); |
---|
| 329 | |
---|
| 330 | // what are displayed on the footer of each mail ? |
---|
| 331 | $conf_mail[$cache_key]['footer'] = |
---|
| 332 | $conf_mail[$cache_key]['theme']->parse('mail_footer', true); |
---|
[11835] | 333 | } |
---|
| 334 | |
---|
[11808] | 335 | // Header |
---|
[11835] | 336 | if(count($content_type_list)>1) |
---|
| 337 | $content.= $conf_mail[$cache_key]['header']; |
---|
[11808] | 338 | |
---|
| 339 | // Content |
---|
| 340 | if (($args['content_format'] == 'text/plain') and ($content_type == 'text/html')) { |
---|
| 341 | $content.= '<p>'. |
---|
| 342 | nl2br( |
---|
| 343 | preg_replace("/(http:\/\/)([^\s,]*)/i", |
---|
| 344 | "<a href='$1$2' class='thumblnk'>$1$2</a>", |
---|
| 345 | htmlspecialchars($args['content']))). |
---|
| 346 | '</p>'; |
---|
| 347 | } |
---|
| 348 | else if (($args['content_format'] == 'text/html') and ($content_type == 'text/plain')) |
---|
| 349 | { |
---|
| 350 | // convert html text to plain text |
---|
| 351 | $content.= strip_tags($args['content']); |
---|
| 352 | } else { |
---|
| 353 | $content.= $args['content']; |
---|
| 354 | } |
---|
| 355 | |
---|
| 356 | // Footer |
---|
| 357 | $content.= $conf_mail[$cache_key]['footer']; |
---|
| 358 | |
---|
| 359 | // Close boundary |
---|
[11835] | 360 | if(count($content_type_list)>1) |
---|
| 361 | $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'.$Eol; |
---|
[11808] | 362 | |
---|
[11835] | 363 | }// fin each |
---|
| 364 | //================================================================== |
---|
[11808] | 365 | //~ // Close boundary |
---|
| 366 | //~ $content.= "\n".'-----='.$conf_mail['boundary_key'].'--'."\n"; |
---|
| 367 | |
---|
[11835] | 368 | |
---|
| 369 | //=========================================== |
---|
| 370 | // Note: |
---|
| 371 | //Si le message n'est pas reçu, essayez d'utiliser uniquement un caractère LF (\n). |
---|
| 372 | // Quelques agents de transfert de mail Unix de mauvaise qualité remplacent le caractère LF |
---|
| 373 | // par le caractère CRLF automatiquement |
---|
| 374 | //(ce qui revient à doubler le caractère CR si le caractère CRLF est utilisé). |
---|
| 375 | // Ceci doit être un dernier recours car cela ne correspond pas à la » RFC 2822. |
---|
| 376 | //====================================================== |
---|
| 377 | // drop LF barre |
---|
| 378 | //====================================================== |
---|
| 379 | // $pattern ="/" . preg_quote($pattern, '/')."/" ; |
---|
| 380 | $pattern="/free.fr|club/"; |
---|
| 381 | if( preg_match($pattern, $mailto) || preg_match($pattern, $headers) ){ |
---|
| 382 | $content= preg_replace('#(?<!\r)\n#si', "\r\n", $content); //drop LF barre |
---|
| 383 | } |
---|
| 384 | |
---|
| 385 | //========================================= |
---|
| 386 | // Correction pour windows |
---|
| 387 | //========================================= |
---|
| 388 | $content = str_replace("\n.", "\n..", $content); |
---|
| 389 | //====================================================== |
---|
| 390 | // si adresse avec ip , certaine boite aux lettres traite ces messages |
---|
| 391 | // en spam (orange+windowsmail) |
---|
| 392 | //====================================================== |
---|
| 393 | if ( $mails_options['no_ipaddress'] == 'on' ){ |
---|
| 394 | $pattern ="/(http:\/\/)(((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]{1}[0-9]|[1-9])\.){1}((25[0-5]|2[0-4][0-9]|[1]{1}[0-9]{2}|[1-9]{1}[0-9]|[0-9])\.){2}((25[0-5]|2[0-4][0-9]|[1]{1}[0-9]{2}|[1-9]{1}[0-9]|[0-9]){1}))/" ; |
---|
| 395 | if(preg_match($pattern, $content)){ |
---|
| 396 | $replacement = "http://localhost"; |
---|
| 397 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
| 398 | } |
---|
| 399 | } |
---|
| 400 | |
---|
| 401 | |
---|
| 402 | //=========================================== |
---|
| 403 | |
---|
[11808] | 404 | // Undo Compute root_path in order have complete path |
---|
| 405 | unset_make_full_url(); |
---|
[11835] | 406 | |
---|
| 407 | $retour->mailto= $mailto; |
---|
| 408 | $retour->subject= $cvt_subject; |
---|
| 409 | $retour->content= $content; |
---|
| 410 | $retour->headers= $headers; |
---|
| 411 | $retour->args= $args ; |
---|
| 412 | $retour->nb_destinataires=$nb_destinataires ; |
---|
| 413 | $retour->result=false ; |
---|
| 414 | |
---|
| 415 | return $retour ; |
---|
[11808] | 416 | |
---|
| 417 | } |
---|
[11807] | 418 | |
---|
| 419 | |
---|
| 420 | } |
---|
| 421 | ?> |
---|