From 0a581e06e39daafeb0e161f67f2598432a6a8168 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 9 Dec 2007 19:36:03 +0000 Subject: added a space after the -f flag for server compatibility --- system/libraries/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 9c5121179..c0593df0b 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1 +1 @@ - 0) { $this->initialize($config); } log_message('debug', "Email Class Initialized"); } // -------------------------------------------------------------------- /** * Initialize preferences * * @access public * @param array * @return void */ function initialize($config = array()) { $this->clear(); foreach ($config as $key => $val) { if (isset($this->$key)) { $method = 'set_'.$key; if (method_exists($this, $method)) { $this->$method($val); } else { $this->$key = $val; } } } $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE; } // -------------------------------------------------------------------- /** * Initialize the Email Data * * @access public * @return void */ function clear($clear_attachments = FALSE) { $this->_subject = ""; $this->_body = ""; $this->_finalbody = ""; $this->_header_str = ""; $this->_replyto_flag = FALSE; $this->_recipients = array(); $this->_headers = array(); $this->_debug_msg = array(); $this->_set_header('User-Agent', $this->useragent); $this->_set_header('Date', $this->_set_date()); if ($clear_attachments !== FALSE) { $this->_attach_name = array(); $this->_attach_type = array(); $this->_attach_disp = array(); } } // -------------------------------------------------------------------- /** * Set FROM * * @access public * @param string * @param string * @return void */ function from($from, $name = '') { if (preg_match( '/\<(.*)\>/', $from, $match)) $from = $match['1']; if ($this->validate) $this->validate_email($this->_str_to_array($from)); if ($name != '' && substr($name, 0, 1) != '"') { $name = '"'.$name.'"'; } $this->_set_header('From', $name.' <'.$from.'>'); $this->_set_header('Return-Path', '<'.$from.'>'); } // -------------------------------------------------------------------- /** * Set Reply-to * * @access public * @param string * @param string * @return void */ function reply_to($replyto, $name = '') { if (preg_match( '/\<(.*)\>/', $replyto, $match)) $replyto = $match['1']; if ($this->validate) $this->validate_email($this->_str_to_array($replyto)); if ($name == '') { $name = $replyto; } if (substr($name, 0, 1) != '"') { $name = '"'.$name.'"'; } $this->_set_header('Reply-To', $name.' <'.$replyto.'>'); $this->_replyto_flag = TRUE; } // -------------------------------------------------------------------- /** * Set Recipients * * @access public * @param string * @return void */ function to($to) { $to = $this->_str_to_array($to); $to = $this->clean_email($to); if ($this->validate) $this->validate_email($to); if ($this->_get_protocol() != 'mail') $this->_set_header('To', implode(", ", $to)); switch ($this->_get_protocol()) { case 'smtp' : $this->_recipients = $to; break; case 'sendmail' : $this->_recipients = implode(", ", $to); break; case 'mail' : $this->_recipients = implode(", ", $to); break; } } // -------------------------------------------------------------------- /** * Set CC * * @access public * @param string * @return void */ function cc($cc) { $cc = $this->_str_to_array($cc); $cc = $this->clean_email($cc); if ($this->validate) $this->validate_email($cc); $this->_set_header('Cc', implode(", ", $cc)); if ($this->_get_protocol() == "smtp") $this->_cc_array = $cc; } // -------------------------------------------------------------------- /** * Set BCC * * @access public * @param string * @param string * @return void */ function bcc($bcc, $limit = '') { if ($limit != '' && is_numeric($limit)) { $this->bcc_batch_mode = true; $this->bcc_batch_size = $limit; } $bcc = $this->_str_to_array($bcc); $bcc = $this->clean_email($bcc); if ($this->validate) $this->validate_email($bcc); if (($this->_get_protocol() == "smtp") OR ($this->bcc_batch_mode && count($bcc) > $this->bcc_batch_size)) $this->_bcc_array = $bcc; else $this->_set_header('Bcc', implode(", ", $bcc)); } // -------------------------------------------------------------------- /** * Set Email Subject * * @access public * @param string * @return void */ function subject($subject) { $subject = preg_replace("/(\r\n)|(\r)|(\n)/", "", $subject); $subject = preg_replace("/(\t)/", " ", $subject); $this->_set_header('Subject', trim($subject)); } // -------------------------------------------------------------------- /** * Set Body * * @access public * @param string * @return void */ function message($body) { $this->_body = stripslashes(rtrim(str_replace("\r", "", $body))); } // -------------------------------------------------------------------- /** * Assign file attachments * * @access public * @param string * @return string */ function attach($filename, $disposition = 'attachment') { $this->_attach_name[] = $filename; $this->_attach_type[] = $this->_mime_types(next(explode('.', basename($filename)))); $this->_attach_disp[] = $disposition; // Can also be 'inline' Not sure if it matters } // -------------------------------------------------------------------- /** * Add a Header Item * * @access public * @param string * @param string * @return void */ function _set_header($header, $value) { $this->_headers[$header] = $value; } // -------------------------------------------------------------------- /** * Convert a String to an Array * * @access public * @param string * @return array */ function _str_to_array($email) { if ( ! is_array($email)) { if (ereg(',$', $email)) $email = substr($email, 0, -1); if (ereg('^,', $email)) $email = substr($email, 1); if (ereg(',', $email)) { $x = explode(',', $email); $email = array(); for ($i = 0; $i < count($x); $i ++) $email[] = trim($x[$i]); } else { $email = trim($email); settype($email, "array"); } } return $email; } // -------------------------------------------------------------------- /** * Set Multipart Value * * @access public * @param string * @return void */ function set_alt_message($str = '') { $this->alt_message = ($str == '') ? '' : $str; } // -------------------------------------------------------------------- /** * Set Mailtype * * @access public * @param string * @return void */ function set_mailtype($type = 'text') { $this->mailtype = ($type == 'html') ? 'html' : 'text'; } // -------------------------------------------------------------------- /** * Set Wordwrap * * @access public * @param string * @return void */ function set_wordwrap($wordwrap = TRUE) { $this->wordwrap = ($wordwrap === FALSE) ? FALSE : TRUE; } // -------------------------------------------------------------------- /** * Set Protocol * * @access public * @param string * @return void */ function set_protocol($protocol = 'mail') { $this->protocol = ( ! in_array($protocol, $this->_protocols, TRUE)) ? 'mail' : strtolower($protocol); } // -------------------------------------------------------------------- /** * Set Priority * * @access public * @param integer * @return void */ function set_priority($n = 3) { if ( ! is_numeric($n)) { $this->priority = 3; return; } if ($n < 1 OR $n > 5) { $this->priority = 3; return; } $this->priority = $n; } // -------------------------------------------------------------------- /** * Set Newline Character * * @access public * @param string * @return void */ function set_newline($newline = "\n") { if ($newline != "\n" AND $newline != "\r\n" AND $newline != "\r") { $this->newline = "\n"; return; } $this->newline = $newline; } // -------------------------------------------------------------------- /** * Set Message Boundary * * @access private * @return void */ function _set_boundaries() { $this->_alt_boundary = "B_ALT_".uniqid(''); // multipart/alternative $this->_atc_boundary = "B_ATC_".uniqid(''); // attachment boundary } // -------------------------------------------------------------------- /** * Get the Message ID * * @access private * @return string */ function _get_message_id() { $from = $this->_headers['Return-Path']; $from = str_replace(">", "", $from); $from = str_replace("<", "", $from); return "<".uniqid('').strstr($from, '@').">"; } // -------------------------------------------------------------------- /** * Get Mail Protocol * * @access private * @param bool * @return string */ function _get_protocol($return = true) { $this->protocol = strtolower($this->protocol); $this->protocol = ( ! in_array($this->protocol, $this->_protocols, TRUE)) ? 'mail' : $this->protocol; if ($return == true) return $this->protocol; } // -------------------------------------------------------------------- /** * Get Mail Encoding * * @access private * @param bool * @return string */ function _get_encoding($return = true) { $this->_encoding = ( ! in_array($this->_encoding, $this->_bit_depths)) ? '7bit' : $this->_encoding; if ( ! in_array($this->charset, $this->_base_charsets, TRUE)) $this->_encoding = "8bit"; if ($return == true) return $this->_encoding; } // -------------------------------------------------------------------- /** * Get content type (text/html/attachment) * * @access private * @return string */ function _get_content_type() { if ($this->mailtype == 'html' && count($this->_attach_name) == 0) return 'html'; elseif ($this->mailtype == 'html' && count($this->_attach_name) > 0) return 'html-attach'; elseif ($this->mailtype == 'text' && count($this->_attach_name) > 0) return 'plain-attach'; else return 'plain'; } // -------------------------------------------------------------------- /** * Set RFC 822 Date * * @access public * @return string */ function _set_date() { $timezone = date("Z"); $operator = (substr($timezone, 0, 1) == '-') ? '-' : '+'; $timezone = abs($timezone); $timezone = floor($timezone/3600) * 100 + ($timezone % 3600 ) / 60; return sprintf("%s %s%04d", date("D, j M Y H:i:s"), $operator, $timezone); } // -------------------------------------------------------------------- /** * Mime message * * @access private * @return string */ function _get_mime_message() { return "This is a multi-part message in MIME format.".$this->newline."Your email application may not support this format."; } // -------------------------------------------------------------------- /** * Validate Email Address * * @access public * @param string * @return bool */ function validate_email($email) { if ( ! is_array($email)) { $this->_set_error_message('email_must_be_array'); return FALSE; } foreach ($email as $val) { if ( ! $this->valid_email($val)) { $this->_set_error_message('email_invalid_address', $val); return FALSE; } } } // -------------------------------------------------------------------- /** * Email Validation * * @access public * @param string * @return bool */ function valid_email($address) { if ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) return FALSE; else return TRUE; } // -------------------------------------------------------------------- /** * Clean Extended Email Address: Joe Smith * * @access public * @param string * @return string */ function clean_email($email) { if ( ! is_array($email)) { if (preg_match('/\<(.*)\>/', $email, $match)) return $match['1']; else return $email; } $clean_email = array(); for ($i=0; $i < count($email); $i++) { if (preg_match( '/\<(.*)\>/', $email[$i], $match)) $clean_email[] = $match['1']; else $clean_email[] = $email[$i]; } return $clean_email; } // -------------------------------------------------------------------- /** * Build alternative plain text message * * This function provides the raw message for use * in plain-text headers of HTML-formatted emails. * If the user hasn't specified his own alternative message * it creates one by stripping the HTML * * @access private * @return string */ function _get_alt_message() { if ($this->alt_message != "") { return $this->word_wrap($this->alt_message, '76'); } if (eregi( '\', $this->_body, $match)) { $body = $match['1']; $body = substr($body, strpos($body, ">") + 1); } else { $body = $this->_body; } $body = trim(strip_tags($body)); $body = preg_replace( '#