function inbox(&$pop, $skip = 0, &$ev) { global $conf; global $charset; $user_prefs = $_SESSION['nocc_user_prefs']; $msg_list = array(); $lang = $_SESSION['nocc_lang']; $sort = $_SESSION['nocc_sort']; $sortdir = $_SESSION['nocc_sortdir']; $num_msg = $pop->num_msg(); $per_page = get_per_page(); $start_msg = $skip * $per_page; $end_msg = $start_msg + $per_page; $sorted = $pop->sort($sort, $sortdir, $ev, true); if (NoccException::isException($ev)) { return; } $end_msg = $num_msg > $end_msg ? $end_msg : $num_msg; if ($start_msg > $num_msg) { return $msg_list; } for ($i = $start_msg; $i < $end_msg; $i++) { $subject = $from = $to = ''; $msgnum = $sorted[$i]; $pop_msgno_msgnum = $pop->msgno($msgnum); $ref_contenu_message = $pop->headerinfo($pop_msgno_msgnum, $ev); if (NoccException::isException($ev)) { return; } $struct_msg = $pop->fetchstructure($pop_msgno_msgnum, $ev); if (NoccException::isException($ev)) { return; } // Get message charset $msg_charset = ''; if ($struct_msg->ifparameters) { while ($obj = array_pop($struct_msg->parameters)) { if (strtolower($obj->attribute) == 'charset') { $msg_charset = $obj->value; break; } } } if ($msg_charset == '') { $msg_charset = 'UTF-8'; } // Get subject $subject_header = str_replace('x-unknown', $msg_charset, $ref_contenu_message->subject); $subject_array = nocc_imap::mime_header_decode($subject_header); for ($j = 0; $j < count($subject_array); $j++) { $subject .= $subject_array[$j]->text; } // Get from $from_header = str_replace('x-unknown', $msg_charset, $ref_contenu_message->fromaddress); $from_array = nocc_imap::mime_header_decode($from_header); for ($j = 0; $j < count($from_array); $j++) { $from .= $from_array[$j]->text; } // Get to $to_header = str_replace('x-unknown', $msg_charset, $ref_contenu_message->toaddress); $to_array = nocc_imap::mime_header_decode($to_header); for ($j = 0; $j < count($to_array); $j++) { $to = $to . $to_array[$j]->text . ", "; } $to = substr($to, 0, strlen($to) - 2); $msg_size = 0; if ($pop->is_imap()) { $msg_size = get_mail_size($struct_msg); } else { if (isset($struct_msg->bytes)) { $msg_size = $struct_msg->bytes > 1000 ? ceil($struct_msg->bytes / 1000) : 1; } } if (isset($struct_msg->type) && ($struct_msg->type == 1 || $struct_msg->type == 3)) { if ($struct_msg->subtype == 'ALTERNATIVE' || $struct_msg->subtype == 'RELATED') { $attach = ' '; } else { $attach = '<img src="themes/' . $_SESSION['nocc_theme'] . '/img/attach.png" alt="" />'; } } else { $attach = ' '; } // Check Status Line with UCB POP Server to // see if this is a new message. This is a // non-RFC standard line header. // Set this in conf.php if ($conf->have_ucb_pop_server) { $header_msg = $pop->fetchheader($pop->msgno($msgnum), $ev); if (NoccException::isException($ev)) { return; } $header_lines = explode("\r\n", $header_msg); while (list($k, $v) = each($header_lines)) { list($header_field, $header_value) = explode(':', $v); if ($header_field == 'Status') { $new_mail_from_header = $header_value; } } } else { if ($ref_contenu_message->Unseen == 'U' || $ref_contenu_message->Recent == 'N') { $new_mail_from_header = ''; } else { $new_mail_from_header = ' '; } } if ($new_mail_from_header == '') { $newmail = '<img src="themes/' . $_SESSION['nocc_theme'] . '/img/new.png" alt=""/>'; } else { $newmail = ' '; } $timestamp = chop($ref_contenu_message->udate); $date = format_date($timestamp, $lang); $time = format_time($timestamp, $lang); $msg_list[$i] = array('new' => $newmail, 'number' => $pop->msgno($msgnum), 'attach' => $attach, 'to' => $to, 'from' => $from, 'subject' => $subject, 'date' => $date, 'time' => $time, 'complete_date' => $date, 'size' => $msg_size, 'sort' => $sort, 'sortdir' => $sortdir); } return $msg_list; }
function inbox($servr, $user, $passwd, $folder, $sort, $sortdir, $lang, $theme) { $mailhost = $servr; require 'conf.php'; $pop = @imap_open('{' . $mailhost . '}' . $folder, $user, $passwd); if ($pop == false) { return -1; } else { if (($num_messages = @imap_num_msg($pop)) == 0) { imap_close($pop); return 0; } else { //if ($sort != '' && $sortdir != '') $sorted = imap_sort($pop, $sort, $sortdir, SE_UID); for ($i = 0; $i < $num_messages; $i++) { $subject = $from = ''; $msgnum = $sorted[$i]; $ref_contenu_message = imap_header($pop, imap_msgno($pop, $msgnum)); $struct_msg = imap_fetchstructure($pop, imap_msgno($pop, $msgnum)); $subject_array = imap_mime_header_decode($ref_contenu_message->subject); for ($j = 0; $j < count($subject_array); $j++) { $subject .= $subject_array[$j]->text; } $from_array = imap_mime_header_decode($ref_contenu_message->fromaddress); for ($j = 0; $j < count($from_array); $j++) { $from .= $from_array[$j]->text; } if (is_Imap($mailhost)) { $msg_size = get_mail_size($struct_msg); } else { $msg_size = $struct_msg->bytes > 1000 ? ceil($struct_msg->bytes / 1000) : 1; } if ($struct_msg->type == 1) { if ($struct_msg->subtype == 'ALTERNATIVE' || $struct_msg->subtype == 'RELATED') { $attach = ' '; } else { $attach = '<img src="themes/' . $theme . '/img/attach.gif" height="28" width="27" alt="" />'; } } else { $attach = ' '; } // Check Status Line with UCB POP Server to // see if this is a new message. This is a // non-RFC standard line header. // Set this in conf.php if ($have_ucb_pop_server) { $header_msg = imap_fetchheader($pop, imap_msgno($pop, $msgnum)); $header_lines = explode("\r\n", $header_msg); while (list($k, $v) = each($header_lines)) { list($header_field, $header_value) = explode(':', $v); if ($header_field == 'Status') { $new_mail_from_header = $header_value; } } } else { if ($ref_contenu_message->Unseen == 'U' || $ref_contenu_message->Recent == 'N') { $new_mail_from_header = ''; } else { $new_mail_from_header = ' '; } } if ($new_mail_from_header == '') { $newmail = '<img src="themes/' . $theme . '/img/new.gif" alt="" height="17" width="17" />'; } else { $newmail = ' '; } $msg_list[$i] = array('new' => $newmail, 'number' => imap_msgno($pop, $msgnum), 'next' => imap_msgno($pop, $sorted[$i + 1]), 'prev' => imap_msgno($pop, $sorted[$i - 1]), 'attach' => $attach, 'from' => htmlspecialchars($from), 'subject' => htmlspecialchars($subject), 'date' => change_date(chop($ref_contenu_message->udate), $lang), 'size' => $msg_size, 'sort' => $sort, 'sortdir' => $sortdir); } imap_close($pop); return $msg_list; } } }