/** * Return mime types and applicable file extensions * * @return array (string mime type => array(string extension)) * @static */ function getMimeTypeMap() { $extensionMap =& MIME_Helper::_getExtensionMap(); return $extensionMap['reverseToArray']; }
/** * @return boolean * @param string $tag * @param int $isMime * @desc Check if a file is indexable by the zOOm toolbox. * @access public */ function isIndexable($tag, $isMime = false) { if ($isMime) { $tag = MIME_Helper::convertMimeToExtension($tag); } return in_array($tag, $this->_indexableList()); }
/** * Figure out the MIME type of this medium * * @param string $user_path * @return string * @access public */ function getMimeType($user_type = null, $user_path = null) { if (empty($this->_mimetype)) { if (empty($user_path)) { global $mosConfig_absolute_path, $zoom; $user_path = $mosConfig_absolute_path . "/" . $zoom->_CONFIG['imagepath'] . $this->getDir() . "/" . $this->_filename; } //$this->_mimetype = MIME_Type::autoDetect($user_path, $user_type, $this->_type); if (!$this->_mimetype | empty($this->_mimetype)) { $ext = ereg_replace(".*\\.([^\\.]*)\$", "\\1", $this->_filename); $this->_mimetype = MIME_Helper::convertExtensionToMime($ext); } return $this->_mimetype; } else { return $this->_mimetype; } }
/** * Returns the full headers for the email properly encoded. * * @access public * @param string $from The sender of the email * @param string $to The recipient of the email * @param string $subject The subject of this email * @return string The full header version of the email */ function getFullHeaders($from, $to, $subject) { // encode the addresses $from = MIME_Helper::encodeAddress($from); $to = MIME_Helper::encodeAddress($to); $subject = MIME_Helper::encode($subject); $body = $this->mime->get(); $this->setHeaders(array('From' => $from, 'To' => $to, 'Subject' => $subject)); $hdrs = $this->mime->headers($this->headers); // RFC 822 formatted date $header = 'Date: ' . gmdate('D, j M Y H:i:s O') . "\r\n"; // return the full dump of the email foreach ($hdrs as $name => $value) { $header .= "{$name}: {$value}\r\n"; } $header .= "\r\n"; return $header . $body; }
/** * Adds an email to the outgoing mail queue. * * @access public * @param string $recipient The recipient of this email * @param array $headers The list of headers that should be sent with this email * @param string $body The body of the message * @param integer $save_email_copy Whether to send a copy of this email to a configurable address or not (eventum_sent@) * @param integer $issue_id The ID of the issue. If false, email will not be associated with issue. * @param string $type The type of message this is. * @param integer $sender_usr_id The id of the user sending this email. * @param integer $type_id The ID of the event that triggered this notification (issue_id, sup_id, not_id, etc) * @return true, or a PEAR_Error object */ function add($recipient, $headers, $body, $save_email_copy = 0, $issue_id = false, $type = '', $sender_usr_id = false, $type_id = false) { // avoid sending emails out to users with inactive status $recipient_email = Mail_API::getEmailAddress($recipient); $usr_id = User::getUserIDByEmail($recipient_email); if (!empty($usr_id)) { $user_status = User::getStatusByEmail($recipient_email); // if user is not set to an active status, then silently ignore if (!User::isActiveStatus($user_status) && !User::isPendingStatus($user_status)) { return false; } } $to_usr_id = User::getUserIDByEmail($recipient_email); $recipient = Mail_API::fixAddressQuoting($recipient); $reminder_addresses = Reminder::_getReminderAlertAddresses(); // add specialized headers if (!empty($issue_id) && (!empty($to_usr_id) && User::getRoleByUser($to_usr_id, Issue::getProjectID($issue_id)) > User::getRoleID("Customer")) || @in_array(Mail_API::getEmailAddress($to), $reminder_addresses)) { $headers += Mail_API::getSpecializedHeaders($issue_id, $type, $headers, $sender_usr_id); } if (empty($issue_id)) { $issue_id = 'null'; } // if the Date: header is missing, add it. if (!in_array('Date', array_keys($headers))) { $headers['Date'] = MIME_Helper::encode(date('D, j M Y H:i:s O')); } if (!empty($headers['To'])) { $headers['To'] = Mail_API::fixAddressQuoting($headers['To']); } list(, $text_headers) = Mail_API::prepareHeaders($headers); $stmt = "INSERT INTO\n " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "mail_queue\n (\n maq_save_copy,\n maq_queued_date,\n maq_sender_ip_address,\n maq_recipient,\n maq_headers,\n maq_body,\n maq_iss_id,\n maq_subject,\n maq_type"; if ($sender_usr_id != false) { $stmt .= ",\nmaq_usr_id"; } if ($type_id != false) { $stmt .= ",\nmaq_type_id"; } $stmt .= ") VALUES (\n {$save_email_copy},\n '" . Date_API::getCurrentDateGMT() . "',\n '" . getenv("REMOTE_ADDR") . "',\n '" . Misc::escapeString($recipient) . "',\n '" . Misc::escapeString($text_headers) . "',\n '" . Misc::escapeString($body) . "',\n " . Misc::escapeInteger($issue_id) . ",\n '" . Misc::escapeString($headers["Subject"]) . "',\n '{$type}'"; if ($sender_usr_id != false) { $stmt .= ",\n" . $sender_usr_id; } if ($type_id != false) { $stmt .= ",\n" . $type_id; } $stmt .= ")"; $res = $GLOBALS["db_api"]->dbh->query($stmt); if (PEAR::isError($res)) { Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); return $res; } else { return true; } }
/** * Method used to get an unique attachment name for a given * filename. This is specially useful for the emails that Microsoft * Outlook sends out with several attachments with the same name * when you embed several inline screenshots in the message * * @access public * @param array $list The nested array of mime parts * @param string $filename The filename to search for * @return string The unique attachment name */ function getAttachmentName(&$list, $filename) { if (@in_array($filename, array_values($list))) { // check if the filename even has an extension... if (!strstr($filename, '.')) { $first_part = $filename; } else { $first_part = substr($filename, 0, strrpos($filename, '.')); } // check if this is already named Outlook-2.bmp (or similar) if (strstr($first_part, "-")) { // if so, gotta get the number and increment it $numeric_portion = substr($first_part, strrpos($first_part, "-") + 1); if (preg_match("/^[0-9]+\$/", $numeric_portion)) { $numeric_portion = intval($numeric_portion) + 1; } $first_part = substr($first_part, 0, strrpos($first_part, "-")); } else { $numeric_portion = 1; } if (!strstr($filename, '.')) { $filename = $first_part . "-" . $numeric_portion; } else { $filename = $first_part . "-" . $numeric_portion . substr($filename, strrpos($filename, '.')); } return MIME_Helper::getAttachmentName($list, $filename); } else { return $filename; } }
/** * Autodetect a file's MIME-type * * This function may be called staticly. * * @param string $file Path to the file to get the type of * @param string $custom_mime An optional custom 'default' value, mostly used for the filetype sent by the users' browser * @param bool $params Append MIME parameters if true * @return string $file's MIME-type on success, false boolean otherwise * @since 1.0.0beta1 * @static */ function autoDetect($file, $custom_mime = null, $custom_ext = null, $params = false) { if (function_exists('mime_content_type')) { $type = mime_content_type($file); if ($type == "application/octet-stream" || $type == "application/unknown") { if (!empty($custom_mime)) { $type = $custom_mime; } elseif (!empty($custom_ext)) { $type = MIME_Helper::convertExtensionToMime($custom_ext); } } } elseif (!empty($custom_mime)) { $type = $custom_mime; } else { $type = MIME_Type::_fileAutoDetect($file); } // _fileAutoDetect() may have returned an error. if ($type === false) { return $type; } //return PEAR::raiseError("Sorry, can't autodetect; you need the mime_magic extension or System_Command and 'file' installed to use this function."); if (!MIME_Helper::convertMimeToExtension($type)) { $type = MIME_Helper::convertExtensionToMime($custom_mime); } // flv (Flash Video format) files need exceptional handling (for now I'll provide a fictional mimetype) if ($custom_ext == "flv") { $type = "video/x-flv"; } // Don't return an empty string if (!$type || !strlen($type)) { //return PEAR::raiseError("Sorry, couldn't determine file type."); return false; } // Strip parameters if present & requested if (MIME_Type::hasParameters($type) && !$params) { $type = MIME_Type::stripParameters($type); } return $type; }
/** * Method used to forward the new email to the list of subscribers. * * @access public * @param integer $user_id The user ID of the person performing this action * @param integer $issue_id The issue ID * @param array $message An array containing the email * @param boolean $internal_only Whether the email should only be redirected to internal users or not * @param boolean $assignee_only Whether the email should only be sent to the assignee * @param boolean $type The type of email this is * @param integer $sup_id the ID of this email * @return void */ function notifyNewEmail($usr_id, $issue_id, $message, $internal_only = FALSE, $assignee_only = FALSE, $type = '', $sup_id = false) { $full_message = $message['full_email']; $sender = $message['from']; $sender_email = strtolower(Mail_API::getEmailAddress($sender)); // get ID of whoever is sending this. $sender_usr_id = User::getUserIDByEmail($sender_email); if (empty($sender_usr_id)) { $sender_usr_id = false; } // automatically subscribe this sender to email notifications on this issue $subscribed_emails = Notification::getSubscribedEmails($issue_id, 'emails'); $subscribed_emails = array_map('strtolower', $subscribed_emails); if (!Notification::isIssueRoutingSender($issue_id, $sender) && !Notification::isBounceMessage($sender_email) && !in_array($sender_email, $subscribed_emails)) { $actions = array('emails'); Notification::subscribeEmail($usr_id, $issue_id, $sender_email, $actions); } // get the subscribers $emails = array(); $users = Notification::getUsersByIssue($issue_id, 'emails'); for ($i = 0; $i < count($users); $i++) { if (empty($users[$i]["sub_usr_id"])) { if ($internal_only == false) { $email = $users[$i]["sub_email"]; } } else { // if we are only supposed to send email to internal users, check if the role is lower than standard user if ($internal_only == true && User::getRoleByUser($users[$i]["sub_usr_id"], Issue::getProjectID($issue_id)) < User::getRoleID('standard user')) { continue; } // check if we are only supposed to send email to the assignees if ($internal_only == true && $assignee_only == true) { $assignee_usr_ids = Issue::getAssignedUserIDs($issue_id); if (!in_array($users[$i]["sub_usr_id"], $assignee_usr_ids)) { continue; } } $email = User::getFromHeader($users[$i]["sub_usr_id"]); } if (!empty($email)) { // don't send the email to the same person who sent it if (strtolower(Mail_API::getEmailAddress($email)) == $sender_email) { continue; } $emails[] = $email; } } if (count($emails) == 0) { return; } $setup = Setup::load(); // change the sender of the message to {prefix}{issue_id}@{host} // - keep everything else in the message, except 'From:', 'Sender:', 'To:', 'Cc:' // make 'Joe Blow <*****@*****.**>' become 'Joe Blow [CSC] <*****@*****.**>' $from = Notification::getFixedFromHeader($issue_id, $sender, 'issue'); list($_headers, $body) = Mime_Helper::splitBodyHeader($full_message); // strip any 'Received:' headers $_headers = Mail_API::stripHeaders($_headers); $header_names = Mime_Helper::getHeaderNames($_headers); // we don't want to keep the (B)Cc list for an eventum-based email $ignore_headers = array('to', 'cc', 'bcc'); $headers = array(); // build the headers array required by the smtp library foreach ($message['headers'] as $header_name => $value) { if (in_array(strtolower($header_name), $ignore_headers) || !in_array($header_name, array_keys($header_names)) || strstr($header_name, ' ')) { continue; } elseif ($header_name == 'from') { $headers['From'] = $from; } else { if (is_array($value)) { $value = implode("; ", $value); } $headers[$header_names[$header_name]] = $value; } } $headers["Subject"] = Mail_API::formatSubject($issue_id, $headers['Subject']); if (empty($type)) { if (User::getRoleByUser($usr_id, Issue::getProjectID($issue_id)) == User::getRoleID("Customer")) { $type = 'customer_email'; } else { $type = 'other_email'; } } @(include_once APP_PEAR_PATH . 'Mail/mime.php'); foreach ($emails as $to) { $recipient_usr_id = User::getUserIDByEmail(Mail_API::getEmailAddress($to)); $to = MIME_Helper::encodeAddress($to); // add the warning message about replies being blocked or not $fixed_body = Mail_API::addWarningMessage($issue_id, $to, $body); $headers['To'] = $to; $mime = new Mail_mime("\r\n"); $hdrs = $mime->headers($headers); Mail_Queue::add($to, $hdrs, $fixed_body, 1, $issue_id, $type, $sender_usr_id, $sup_id); } }