This blob has been accessed 375 times via Git panel.
- <?php
- header('Content-Type: text/html; charset=UTF-8');
- header('Cache-Control: private');
- ini_set("session.use_trans_sid","0");
- ini_set("mbstring.language","Neutral");
- ini_set("mbstring.internal_encoding","UTF-8");
- ini_set("mbstring.encoding_translation","On");
- ini_set("mbstring.http_input","auto");
- ini_set("mbstring.http_output","UTF-8");
- ini_set("mbstring.detect_order","auto");
- ini_set("mbstring.substitute_character","none");
- ini_set("default_charset","UTF-8");
- error_reporting(E_ERROR);
- session_start();
- if ($_SESSION['logged_lvl'] == "subscriber") {
- $fileUsr = sha1($_SESSION['logged_uid']);
- }
- if (isset($_POST['mbox_min']) and !empty($_POST['mbox_min']) and is_numeric($_POST['mbox_min'])) {
- $mbox_min = $_POST['mbox_min'];
- }
- else {
- $mbox_min = "0";
- }
- if (isset($_POST['mbox_ppg']) and !empty($_POST['mbox_ppg']) and is_numeric($_POST['mbox_ppg'])) {
- $mbox_ppg = $_POST['mbox_ppg'];
- }
- else {
- $mbox_ppg = "14";
- }
- $mbox_max = $mbox_min + $mbox_ppg;
- function time_elapsed_string($ptime) {
- if ($etime < 1) {
- return '0 seconds';
- }
- $a = array( 12 * 30 * 24 * 60 * 60 => 'year',
- 30 * 24 * 60 * 60 => 'month',
- 7 * 24 * 60 * 60 => 'week',
- 24 * 60 * 60 => 'day',
- 60 * 60 => 'hour',
- 60 => 'minute',
- 1 => 'second'
- );
- foreach ($a as $secs => $str) {
- $d = $etime / $secs;
- if ($d >= 1) {
- $r = round($d);
- return $r . ' ' . $str . ($r > 1 ? 's' : '');
- }
- }
- }
- function HumanReadableFilesize($size) {
- $mod = 1024;
- $units = explode(' ','B KB MB GB TB PB');
- for ($i = 0; $size > $mod; $i++) {
- $size /= $mod;
- }
- return round($size, 2) . ' ' . $units[$i];
- }
- // cleong@organic.com
- function get_mime_type(&$struct) {
- $primary_mime_type = array("TEXT", "MULTIPART","MESSAGE", "APPLICATION", "AUDIO", "IMAGE", "VIDEO", "OTHER");
- if($struct->subtype) {
- return $primary_mime_type[(int) $struct->type] . '/' .$struct->subtype;
- }
- return "TEXT/PLAIN";
- }
- function get_part($stream, $msg_number, $mime_type, $structure = false, $part_number = false) {
- if (!$structure) {
- $structure = imap_fetchstructure($stream, $msg_number, FT_UID);
- }
- if ($structure) {
- if ($mime_type == get_mime_type($structure)) {
- if (!$part_number) {
- $part_number = "1";
- }
- $text = imap_fetchbody($stream, $msg_number, $part_number, FT_UID);
- if ($structure->encoding == 3) {
- return imap_base64($text);
- }
- else if ($structure->encoding == 4) {
- return imap_qprint($text);
- }
- else {
- return $text;
- }
- }
- if ($structure->type == 1) /* multipart */ {
- while (list($index, $sub_structure) = each($structure->parts)) {
- if ($part_number) {
- $prefix = $part_number . '.';
- }
- $data = get_part($stream, $msg_number, $mime_type, $sub_structure,$prefix . ($index + 1));
- if ($data) {
- return $data;
- }
- }
- }
- }
- return false;
- }
- function extract_emails_from($string){
- preg_match_all("/[\+\=\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $string, $matches);
- return $matches[0];
- }
- function return_bytes($val) {
- $val = trim($val);
- switch ($last) {
- case 'k':
- case 'K':
- return(int)$val * 1024;
- break;
- case 'm':
- case 'M':
- return(int)$val * 1048576;
- break;
- default:
- return $val;
- }
- }
- $server_upload_max_filesize = return_bytes(ini_get('upload_max_filesize'));
- $server_post_max_size = return_bytes(ini_get('post_max_size'));
- $server_memory_limit = return_bytes(ini_get('memory_limit'));
- $max_file_size = $server_upload_max_filesize;
- if ($server_upload_max_filesize > $server_post_max_size) {
- $max_file_size = $server_post_max_size;
- }
- if ($server_post_max_size > $server_memory_limit) {
- $max_file_size = $server_memory_limit;
- }
- function header_mime2text ($header) {
- $header_decode = imap_mime_header_decode(str_replace(array('\r\n', '\r', '\n'), ' ', $header));
- foreach ($header_decode as $header_decoded) {
- $header_text = $header_text . $header_decoded->text;
- }
- $header_text = mb_convert_encoding($header_text,"UTF-8","auto");
- $header_text = mb_convert_encoding($header_text,"UTF-8","UTF-8");
- return ($header_text);
- }
- function is_image($path) {
- $a = getimagesize($path);
- $image_type = $a[2];
- if (in_array($image_type, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG , IMAGETYPE_BMP))) {
- return true;
- }
- return false;
- }
- // chris@isavvy.co.nz
- class EmailMessage {
- protected $connection;
- protected $messageNumber;
- public $attachments;
- public $getAttachments = true;
- public function __construct($connection, $messageNumber) {
- $this->connection = $connection;
- $this->messageNumber = $messageNumber;
- }
- public function fetch() {
- $structure = @imap_fetchstructure($this->connection, $this->messageNumber);
- if (!$structure) {
- return false;
- }
- else {
- $this->recurse($structure->parts);
- return true;
- }
- }
- public function recurse($messageParts, $prefix = '', $index = 1, $fullPrefix = true) {
- foreach ($messageParts as $part) {
- $partNumber = $prefix . $index;
- if ($part->type == 2) {
- $msg = new EmailMessage($this->connection, $this->messageNumber);
- $msg->getAttachments = $this->getAttachments;
- $msg->recurse($part->parts, $partNumber.'.', 0, false);
- $this->attachments[] = array(
- 'type' => $part->type,
- 'subtype' => $part->subtype,
- 'filename' => '',
- 'data' => $msg,
- 'inline' => false,
- );
- }
- elseif (isset($part->parts)) {
- if ($fullPrefix) {
- $this->recurse($part->parts, $prefix.$index.'.');
- }
- else {
- $this->recurse($part->parts, $prefix);
- }
- }
- elseif ($part->type > 2) {
- if (isset($part->id)) {
- $id = str_replace(array('<', '>'), '', $part->id);
- $this->attachments[$id] = array(
- 'type' => $part->type,
- 'subtype' => $part->subtype,
- 'filename' => $this->getFilenameFromPart($part),
- 'data' => $this->getAttachments ? $this->getPart($partNumber, $part->encoding) : '',
- 'inline' => true,
- );
- }
- else {
- $this->attachments[] = array(
- 'type' => $part->type,
- 'subtype' => $part->subtype,
- 'filename' => $this->getFilenameFromPart($part),
- 'data' => $this->getAttachments ? $this->getPart($partNumber, $part->encoding) : '',
- 'inline' => false,
- );
- }
- }
- $index++;
- }
- }
- function getPart($partNumber, $encoding) {
- $data = imap_fetchbody($this->connection, $this->messageNumber, $partNumber);
- switch($encoding) {
- case 0: return $data; // 7BIT
- case 1: return $data; // 8BIT
- case 2: return $data; // BINARY
- case 3: return base64_decode($data); // BASE64
- case 4: return quoted_printable_decode($data); // QUOTED_PRINTABLE
- case 5: return $data; // OTHER
- }
- }
- function getFilenameFromPart($part) {
- $filename = '';
- if ($part->ifdparameters) {
- foreach ($part->dparameters as $object) {
- if (strtolower($object->attribute) == 'filename') {
- $filename = $object->value;
- }
- }
- }
- if (!$filename && $part->ifparameters) {
- foreach ($part->parameters as $object) {
- if (strtolower($object->attribute) == 'name') {
- $filename = $object->value;
- }
- }
- }
- return $filename;
- }
- }
- function kartero_sort_folders($host,$array) {
- if (is_array($array)) {
- if (in_array("{$host}INBOX",$array)) {
- $inbox = array_search("{$host}INBOX",$array);
- unset($array[$inbox]);
- unset($inbox);
- }
- if (in_array("{$host}Sent",$array)) {
- $sent = array_search("{$host}Sent",$array);
- unset($array[$sent]);
- }
- else {
- if ($sent) {
- unset($sent);
- }
- }
- if (in_array("{$host}Trash",$array)) {
- $trash = array_search("{$host}Trash",$array);
- unset($array[$trash]);
- }
- else {
- if ($trash) {
- unset($trash);
- }
- }
- sort($array);
- if ($trash) {
- array_unshift($array,"{$host}Trash");
- unset($trash);
- }
- if ($sent) {
- array_unshift($array,"{$host}Sent");
- unset($sent);
- }
- array_unshift($array,"{$host}INBOX");
- reset($array);
- return $array;
- }
- }
- ?>