| [ Index ] |
|
Code source de PHP NUKE 7.9 |
1 <?php 2 /*************************************************************************** 3 emailer.php 4 ------------------- 5 begin : Sunday Aug. 12, 2001 6 copyright : (C) 2001 The phpBB Group 7 email : support@phpbb.com 8 9 Id: emailer.php,v 1.15.2.34 2003/07/26 11:41:35 acydburn Exp 10 11 ***************************************************************************/ 12 /*************************************************************************** 13 * phpbb2 forums port version 2.0.5 (c) 2003 - Nuke Cops (http://nukecops.com) 14 * 15 * Ported by Nuke Cops to phpbb2 standalone 2.0.5 Test 16 * and debugging completed by the Elite Nukers and site members. 17 * 18 * You run this package at your sole risk. Nuke Cops and affiliates cannot 19 * be held liable if anything goes wrong. You are advised to test this 20 * package on a development system. Backup everything before implementing 21 * in a production environment. If something goes wrong, you can always 22 * backout and restore your backups. 23 * 24 * Installing and running this also means you agree to the terms of the AUP 25 * found at Nuke Cops. 26 * 27 * This is version 2.0.5 of the phpbb2 forum port for PHP-Nuke. Work is based 28 * on Tom Nitzschner's forum port version 2.0.6. Tom's 2.0.6 port was based 29 * on the phpbb2 standalone version 2.0.3. Our version 2.0.5 from Nuke Cops is 30 * now reflecting phpbb2 standalone 2.0.5 that fixes some bugs and the 31 * invalid_session error message. 32 ***************************************************************************/ 33 /*************************************************************************** 34 * This file is part of the phpBB2 port to Nuke 6.0 (c) copyright 2002 35 * by Tom Nitzschner (tom@toms-home.com) 36 * http://bbtonuke.sourceforge.net (or http://www.toms-home.com) 37 * 38 * As always, make a backup before messing with anything. All code 39 * release by me is considered sample code only. It may be fully 40 * functual, but you use it at your own risk, if you break it, 41 * you get to fix it too. No waranty is given or implied. 42 * 43 * Please post all questions/request about this port on http://bbtonuke.sourceforge.net first, 44 * then on my site. All original header code and copyright messages will be maintained 45 * to give credit where credit is due. If you modify this, the only requirement is 46 * that you also maintain all original copyright messages. All my work is released 47 * under the GNU GENERAL PUBLIC LICENSE. Please see the README for more information. 48 * 49 ***************************************************************************/ 50 /*************************************************************************** 51 * 52 * This program is free software; you can redistribute it and/or modify 53 * it under the terms of the GNU General Public License as published by 54 * the Free Software Foundation; either version 2 of the License, or 55 * (at your option) any later version. 56 * 57 ***************************************************************************/ 58 59 // 60 // The emailer class has support for attaching files, that isn't implemented 61 // in the 2.0 release but we can probable find some way of using it in a future 62 // release 63 // 64 65 if (!defined('IN_PHPBB')) { 66 die(); 67 } 68 69 class emailer 70 { 71 var $msg, $subject, $extra_headers; 72 var $addresses, $reply_to, $from; 73 var $use_smtp; 74 75 var $tpl_msg = array(); 76 77 function emailer($use_smtp) 78 { 79 $this->reset(); 80 $this->use_smtp = $use_smtp; 81 $this->reply_to = $this->from = ''; 82 } 83 84 // Resets all the data (address, template file, etc etc to default 85 function reset() 86 { 87 $this->addresses = array(); 88 $this->vars = $this->msg = $this->extra_headers = ''; 89 } 90 91 // Sets an email address to send to 92 function email_address($address) 93 { 94 $this->addresses['to'] = trim($address); 95 } 96 97 function cc($address) 98 { 99 $this->addresses['cc'][] = trim($address); 100 } 101 102 function bcc($address) 103 { 104 $this->addresses['bcc'][] = trim($address); 105 } 106 107 function replyto($address) 108 { 109 $this->reply_to = trim($address); 110 } 111 112 function from($address) 113 { 114 $this->from = trim($address); 115 } 116 117 // set up subject for mail 118 function set_subject($subject = '') 119 { 120 $this->subject = trim(preg_replace('#[\n\r]+#s', '', $subject)); 121 } 122 123 // set up extra mail headers 124 function extra_headers($headers) 125 { 126 $this->extra_headers .= trim($headers) . "\n"; 127 } 128 129 function use_template($template_file, $template_lang = '') 130 { 131 global $board_config, $phpbb_root_path; 132 133 if (trim($template_file) == '') 134 { 135 message_die(GENERAL_ERROR, 'No template file set', '', __LINE__, __FILE__); 136 } 137 138 if (trim($template_lang) == '') 139 { 140 $template_lang = $board_config['default_lang']; 141 } 142 143 if (empty($this->tpl_msg[$template_lang . $template_file])) 144 { 145 $tpl_file = $phpbb_root_path . 'language/lang_' . $template_lang . '/email/' . $template_file . '.tpl'; 146 147 if (!@file_exists(@phpbb_realpath($tpl_file))) 148 { 149 $tpl_file = $phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/email/' . $template_file . '.tpl'; 150 151 if (!@file_exists(@phpbb_realpath($tpl_file))) 152 { 153 message_die(GENERAL_ERROR, 'Could not find email template file :: ' . $template_file, '', __LINE__, __FILE__); 154 } 155 } 156 157 if (!($fd = @fopen($tpl_file, 'r'))) 158 { 159 message_die(GENERAL_ERROR, 'Failed opening template file :: ' . $tpl_file, '', __LINE__, __FILE__); 160 } 161 162 $this->tpl_msg[$template_lang . $template_file] = fread($fd, filesize($tpl_file)); 163 fclose($fd); 164 } 165 166 $this->msg = $this->tpl_msg[$template_lang . $template_file]; 167 168 return true; 169 } 170 171 // assign variables 172 function assign_vars($vars) 173 { 174 $this->vars = (empty($this->vars)) ? $vars : $this->vars . $vars; 175 } 176 177 // Send the mail out to the recipients set previously in var $this->address 178 function send() 179 { 180 global $board_config, $lang, $phpEx, $phpbb_root_path, $db; 181 182 // Escape all quotes, else the eval will fail. 183 $this->msg = str_replace ("'", "\'", $this->msg); 184 $this->msg = preg_replace('#\{([a-z0-9\-_]*?)\}#is', "' . $\\1 . '", $this->msg); 185 186 // Set vars 187 reset ($this->vars); 188 while (list($key, $val) = each($this->vars)) 189 { 190 $$key = $val; 191 } 192 193 eval("\$this->msg = '$this->msg';"); 194 195 // Clear vars 196 reset ($this->vars); 197 while (list($key, $val) = each($this->vars)) 198 { 199 unset($$key); 200 } 201 202 // We now try and pull a subject from the email body ... if it exists, 203 // do this here because the subject may contain a variable 204 $drop_header = ''; 205 $match = array(); 206 if (preg_match('#^(Subject:(.*?))$#m', $this->msg, $match)) 207 { 208 $this->subject = (trim($match[2]) != '') ? trim($match[2]) : (($this->subject != '') ? $this->subject : 'No Subject'); 209 $drop_header .= '[\r\n]*?' . phpbb_preg_quote($match[1], '#'); 210 } 211 else 212 { 213 $this->subject = (($this->subject != '') ? $this->subject : 'No Subject'); 214 } 215 216 if (preg_match('#^(Charset:(.*?))$#m', $this->msg, $match)) 217 { 218 $this->encoding = (trim($match[2]) != '') ? trim($match[2]) : trim($lang['ENCODING']); 219 $drop_header .= '[\r\n]*?' . phpbb_preg_quote($match[1], '#'); 220 } 221 else 222 { 223 $this->encoding = trim($lang['ENCODING']); 224 } 225 226 if ($drop_header != '') 227 { 228 $this->msg = trim(preg_replace('#' . $drop_header . '#s', '', $this->msg)); 229 } 230 231 $to = $this->addresses['to']; 232 233 $cc = (count($this->addresses['cc'])) ? implode(', ', $this->addresses['cc']) : ''; 234 $bcc = (count($this->addresses['bcc'])) ? implode(', ', $this->addresses['bcc']) : ''; 235 236 // Build header 237 $this->extra_headers = (($this->reply_to != '') ? "Reply-to: $this->reply_to\n" : '') . (($this->from != '') ? "From: $this->from\n" : "From: " . $board_config['board_email'] . "\n") . "Return-Path: " . $board_config['board_email'] . "\nMessage-ID: <" . md5(uniqid(time())) . "@" . $board_config['server_name'] . ">\nMIME-Version: 1.0\nContent-type: text/plain; charset=" . $this->encoding . "\nContent-transfer-encoding: 8bit\nDate: " . date('r', time()) . "\nX-Priority: 3\nX-MSMail-Priority: Normal\nX-Mailer: PHP\nX-MimeOLE: Produced By phpBB2\n" . $this->extra_headers . (($cc != '') ? "Cc: $cc\n" : '') . (($bcc != '') ? "Bcc: $bcc\n" : ''); 238 239 // Send message ... removed $this->encode() from subject for time being 240 if ( $this->use_smtp ) 241 { 242 if ( !defined('SMTP_INCLUDED') ) 243 { 244 include ("includes/smtp.php"); 245 } 246 247 $result = smtpmail($to, $this->subject, $this->msg, $this->extra_headers); 248 } 249 else 250 { 251 $empty_to_header = ($to == '') ? TRUE : FALSE; 252 $to = ($to == '') ? (($board_config['sendmail_fix']) ? ' ' : 'Undisclosed-recipients:;') : $to; 253 $result = @mail($to, $this->subject, preg_replace("#(?<!\r)\n#s", "\n", $this->msg), $this->extra_headers); 254 255 if (!$result && !$board_config['sendmail_fix'] && $empty_to_header) 256 { 257 $to = ' '; 258 259 $sql = "UPDATE " . CONFIG_TABLE . " 260 SET config_value = '1' 261 WHERE config_name = 'sendmail_fix'"; 262 if (!$db->sql_query($sql)) 263 { 264 message_die(GENERAL_ERROR, 'Unable to update config table', '', __LINE__, __FILE__, $sql); 265 } 266 267 $board_config['sendmail_fix'] = 1; 268 $result = @mail($to, $this->subject, preg_replace("#(?<!\r)\n#s", "\n", $this->msg), $this->extra_headers); 269 } 270 } 271 272 // Did it work? 273 if (!$result) 274 { 275 message_die(GENERAL_ERROR, 'Failed sending email :: ' . (($this->use_smtp) ? 'SMTP' : 'PHP') . ' :: ' . $result, '', __LINE__, __FILE__); 276 } 277 278 return true; 279 } 280 281 // Encodes the given string for proper display for this encoding ... nabbed 282 // from php.net and modified. There is an alternative encoding method which 283 // may produce lesd output but it's questionable as to its worth in this 284 // scenario IMO 285 function encode($str) 286 { 287 if ($this->encoding == '') 288 { 289 return $str; 290 } 291 292 // define start delimimter, end delimiter and spacer 293 $end = "?="; 294 $start = "=?$this->encoding?B?"; 295 $spacer = "$end\r\n $start"; 296 297 // determine length of encoded text within chunks and ensure length is even 298 $length = 75 - strlen($start) - strlen($end); 299 $length = floor($length / 2) * 2; 300 301 // encode the string and split it into chunks with spacers after each chunk 302 $str = chunk_split(base64_encode($str), $length, $spacer); 303 304 // remove trailing spacer and add start and end delimiters 305 $str = preg_replace('#' . phpbb_preg_quote($spacer, '#') . '$#', '', $str); 306 307 return $start . $str . $end; 308 } 309 310 // 311 // Attach files via MIME. 312 // 313 function attachFile($filename, $mimetype = "application/octet-stream", $szFromAddress, $szFilenameToDisplay) 314 { 315 global $lang; 316 $mime_boundary = "--==================_846811060==_"; 317 318 $this->msg = '--' . $mime_boundary . "\nContent-Type: text/plain;\n\tcharset=\"" . $lang['ENCODING'] . "\"\n\n" . $this->msg; 319 320 if ($mime_filename) 321 { 322 $filename = $mime_filename; 323 $encoded = $this->encode_file($filename); 324 } 325 326 $fd = fopen($filename, "r"); 327 $contents = fread($fd, filesize($filename)); 328 329 $this->mimeOut = "--" . $mime_boundary . "\n"; 330 $this->mimeOut .= "Content-Type: " . $mimetype . ";\n\tname=\"$szFilenameToDisplay\"\n"; 331 $this->mimeOut .= "Content-Transfer-Encoding: quoted-printable\n"; 332 $this->mimeOut .= "Content-Disposition: attachment;\n\tfilename=\"$szFilenameToDisplay\"\n\n"; 333 334 if ( $mimetype == "message/rfc822" ) 335 { 336 $this->mimeOut .= "From: ".$szFromAddress."\n"; 337 $this->mimeOut .= "To: ".$this->emailAddress."\n"; 338 $this->mimeOut .= "Date: ".date("D, d M Y H:i:s") . " UT\n"; 339 $this->mimeOut .= "Reply-To:".$szFromAddress."\n"; 340 $this->mimeOut .= "Subject: ".$this->mailSubject."\n"; 341 $this->mimeOut .= "X-Mailer: PHP/".phpversion()."\n"; 342 $this->mimeOut .= "MIME-Version: 1.0\n"; 343 } 344 345 $this->mimeOut .= $contents."\n"; 346 $this->mimeOut .= "--" . $mime_boundary . "--" . "\n"; 347 348 return $out; 349 // added -- to notify email client attachment is done 350 } 351 352 function getMimeHeaders($filename, $mime_filename="") 353 { 354 $mime_boundary = "--==================_846811060==_"; 355 356 if ($mime_filename) 357 { 358 $filename = $mime_filename; 359 } 360 361 $out = "MIME-Version: 1.0\n"; 362 $out .= "Content-Type: multipart/mixed;\n\tboundary=\"$mime_boundary\"\n\n"; 363 $out .= "This message is in MIME format. Since your mail reader does not understand\n"; 364 $out .= "this format, some or all of this message may not be legible."; 365 366 return $out; 367 } 368 369 // 370 // Split string by RFC 2045 semantics (76 chars per line, end with \r\n). 371 // 372 function myChunkSplit($str) 373 { 374 $stmp = $str; 375 $len = strlen($stmp); 376 $out = ""; 377 378 while ($len > 0) 379 { 380 if ($len >= 76) 381 { 382 $out .= substr($stmp, 0, 76) . "\r\n"; 383 $stmp = substr($stmp, 76); 384 $len = $len - 76; 385 } 386 else 387 { 388 $out .= $stmp . "\r\n"; 389 $stmp = ""; 390 $len = 0; 391 } 392 } 393 return $out; 394 } 395 396 // 397 // Split the specified file up into a string and return it 398 // 399 function encode_file($sourcefile) 400 { 401 if (is_readable(phpbb_realpath($sourcefile))) 402 { 403 $fd = fopen($sourcefile, "r"); 404 $contents = fread($fd, filesize($sourcefile)); 405 $encoded = $this->myChunkSplit(base64_encode($contents)); 406 fclose($fd); 407 } 408 409 return $encoded; 410 } 411 412 } // class emailer 413 414 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Apr 1 11:11:59 2007 | par Balluche grâce à PHPXref 0.7 |