You should have received a copy of the GNU Public License along with this package; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* array of months for faster/cleaner code */ $Months = array('jan' => '01', 'feb' => '02', 'mar' => '03', 'apr' => '04', 'may' => '05', 'jun' => '06', 'jul' => '07', 'aug' => '08', 'sep' => '09', 'oct' => '10', 'nov' => '11', 'dec' => '12'); /* display_toaddress: check the user's address and list of addresses that To: should be displayed for */ function display_toaddress ($user, $server, $from, $to) { $myemail = get_barefrom($user, $server); if (is_int(strpos($from, $myemail))) { if (!is_int(strpos($to, $myemail))) { return true; // if both from and to this user, display the from instead to save confusion } else return false; } else return false; } function messageRange ($arr, $index, &$offset, &$beginIndex) { $count = 200; // maybe make this configurable later $half = $count/2; if ($index < $half) $start = 0; else if (($index + $count) >= count($arr)) $start = max(0, count($arr) - $count); else $start = $index - $half; $end = min($start + $count, count($arr)); $new = array(); for ($i = $start; $i < $end; $i++) { $new[] = $arr[$i]; } $offset = $start; $beginIndex = $index - $start - 1; return $new; } $need_horde_db = 1; require '../lib/horde.lib'; require './lib/imp.lib'; require './config/defaults.php3'; require './lib/mimetypes.lib'; require './lib/postconf.php3'; /* Html styles configuration */ require './config/html.php3'; /* Mailbox configuration */ require './config/mailbox.php3'; /* include mime and language configuration */ require './config/mime.php3'; require './config/lang.php3'; /* if this is a login, check for a language preference */ if (isset($actionID) && $actionID == IMP_LOGIN) { if (isset($IMAPServer)) { include './config/servers.php3'; $my_server = @$IMAPServers[$IMAPServer]; $tmp_server = $my_server->server; } else { $tmp_server = $server; } $tmp_lang = imp_get_lang($imapuser, $tmp_server); if ($tmp_lang != '' && valid_lang($tmp_lang, '')) $new_lang = $tmp_lang; } $set = false; if (isset($new_lang)) { $language = $new_lang; $set = true; } $language = select_lang('', $set); require './lib/postconf.php3'; require "./locale/$language/mailbox.lang"; require './locale/local/mailbox.lang'; require './config/lang.php3'; $this_client = new WebClient; error_reporting($default->error_level); /* Set or read session */ page_open(array('sess' => 'HordeSession')); if (isset($actionID) && $actionID == IMP_LOGIN) { $imp = new ImpSession(); $imp->construct(); $sess->register('imp'); } else if (!isset($imp) || !is_object($imp)) { page_close(); header('Location: ' . $sess->url('login.php3')); exit; } else { $imp->unpickle(); } /* only proceed on a valid login */ $imp->authenticate(); /* indicates invalid login or expired login so skip all the crap below */ if (isset($imp->stream) && (!$imp->stream)) exit; if (!isset($plural)) $plural = false; $delnum = 0; /* Run through the action handlers */ $status_string = ''; $status_color = 'green'; if (isset($actionID)) { if (isset($indices) && !is_array($indices)) { $indices = array($indices); } switch ($actionID) { case NO_ACTION: $status_string = $lang->mailbox . $imp->label; break; case DELETE_MESSAGES: if (isset($indices) && $indices && $imp->mailbox) { for ($i = 0; $i < count($indices); $i++) { if (!(imap_delete($imp->stream, imap_msgno($imp->stream, $indices[$i])))) { $status_string = $lang->error($imp->label, 'deletion'); $status_color = 'red'; } } if ($imp->servtype == 'pop3') { imap_expunge($imp->stream); imap_close($imp->stream); $imp->authenticate(); } if (!$status_string) { if ($i != 1) $plural = true; $status_string = $lang->success1($imp->label, 'deleted', $i, $plural); } } break; case UNDELETE_MESSAGES: if (isset($indices) && $imp->mailbox && $indices) { for ($i = 0; $i < count($indices); $i++) { if (!(imap_undelete($imp->stream, imap_msgno($imp->stream, $indices[$i])))) { $status_string = $lang->error($imp->label, 'undeletion'); $status_color = 'red'; } } if (!$status_string) { if ($i != 1) $plural = true; $status_string = $lang->success1($imp->label, 'undeleted', $i, $plural); } } break; case MOVE_MESSAGES: if (isset($indices) && isset($targetMbox) && $targetMbox && $indices) { $targetMbox = imap_utf7_encode($targetMbox); $msg_list = implode($indices, ','); if (!(imap_mail_copy($imp->stream, $msg_list, $targetMbox, CP_UID|CP_MOVE)) ) { $status_string = $lang->error($imp->label, 'move'); $status_color = 'red'; } else { if ($imp->servtype == 'pop3') { imap_expunge($imp->stream); imap_close($imp->stream); $imp->authenticate(); } if (count($indices) != 1) $plural = true; $status_string = $lang->success2($imp->label, imap_utf7_decode($targetMbox), 'moved', count($indices), $plural); } } break; case COPY_MESSAGES: if (isset($targetMbox) && isset($indices) && $targetMbox && $indices) { $targetMbox = imap_utf7_encode($targetMbox); $msg_list = implode($indices, ','); if (!(imap_mail_copy($imp->stream, $msg_list, $targetMbox, CP_UID)) ) { $status_string = $lang->error($imp->label, 'copy'); $status_color = 'red'; } else { if (count($indices) != 1) $plural = true; $status_string = $lang->success2($imp->label, imap_utf7_decode($targetMbox), 'copied', count($indices), $plural); } } break; case HIDE_DELETED: $imp->delhide = (!$imp->delhide); if ($imp->delhide) { $status_string = $lang->hiding_deleted; } else { $status_string = $lang->showing_deleted; } break; case EXPUNGE_MAILBOX: if ($imp->mailbox) { if (!(imap_expunge($imp->stream))) { $status_string = $lang->error($imp->label, 'expunge'); $status_color = 'red'; } else { $status_string = $lang->mailbox . ': ' . $imp->label . ': ' . $lang->expunged; } } break; case IMP_LOGIN: $status_string = $lang->mailbox . ': ' . $imp->label; if (isset($new_lang)) { $imp->setLang($new_lang); $language = $new_lang; } if ($default->log_stats || $default->log_auth) { openlog($default->log_ident, LOG_PID, $default->log_stats_facil); if ($default->log_stats) syslog($default->log_prio, "mailbox.php3 $REMOTE_ADDR login SUCCESS $imp->server:$imp->port as $imp->user $language"); if ($default->log_auth) syslog($default->log_prio | $default->log_auth_facil, "Login $REMOTE_ADDR to $imp->server:$imp->port as $imp->user"); closelog(); } break; } } if (empty($status_string)) { $status_string = $lang->mailbox . ': ' . $imp->label; } if ($default->user_use_folders) { $options = mailbox_list(true); } $sidebar = false; require "$default->include_dir/doctype.inc"; require "$default->include_dir/generic-header.inc"; $check = imap_check($imp->stream); $nummsgs = (is_object($check) && isset($check->Nmsgs)) ? $check->Nmsgs : 0; /* removed call to imap_num_msgs - cbj */ if ($nummsgs > $default->max_messages_page) { $page_count = ceil($nummsgs/$default->max_messages_page); /* Figure out which page to display */ if (isset($page) && $page) { if ($page > $page_count) $page = $page_count; /* make sure we're not past the end */ if ($page < 1) $page = 1; /* ... or before the beginning! */ } else if (isset($start) && $start) { /* messages set this when returning to a mailbox */ $page = ceil($start/$default->max_messages_page); } else if (function_exists('imap_search')) { /* try and use imap_search to find the first unread message */ $new = imap_search($imp->stream, 'UNSEEN'); if ($new) { if ($imp->sortdir) $page = $page_count - ceil((max($new) + 1)/$default->max_messages_page) + 1; else $page = ceil(min($new)/$default->max_messages_page); } else { if ($imp->sortdir) $page = 1; else $page = $page_count; } } else { if ($imp->sortdir) $page = 1; else $page = $page_count; } /* sanity checks */ if ($page > $page_count) $page = $page_count; if ($page < 1) $page = 1; $begin = ($page - 1) * $default->max_messages_page + 1; $end = $begin + $default->max_messages_page - 1; if ($end > $nummsgs) { $end = $nummsgs; } if ($page == 1) { if (!$this_client->lynx) { $pages_first = "graphics_url/first-grey.gif\" border=\"0\" alt=\"\">"; $pages_prev = "graphics_url/prev-grey.gif\" border=\"0\" alt=\"\">"; } else { $pages_first = ''; $pages_prev = ''; } } else { $prev = $page - 1; $target_first_url = $sess->url("$default->root_url/mailbox.php3?page=1"); $target_prev_url = $sess->url("$default->root_url/mailbox.php3?page=$prev"); if (!$this_client->lynx) { $pages_first = "graphics_url/first.gif\" border=\"0\" alt=\"$lang->first_page\">"; $pages_prev = "graphics_url/prev.gif\" border=\"0\" alt=\"$lang->prev_page\">"; } else { $pages_first = "<< [ $lang->first_page ]"; $pages_prev = "< [ $lang->prev_page ]"; } } if ($page == $page_count) { if (!$this_client->lynx) { $pages_last = "graphics_url/last-grey.gif\" border=\"0\" alt=\"\">"; $pages_next = "graphics_url/next-grey.gif\" border=\"0\" alt=\"\">"; } else { $pages_last = ''; $pages_next = ''; } } else { $next = $page + 1; $target_last_url = $sess->url("$default->root_url/mailbox.php3?page=$page_count"); $target_next_url = $sess->url("$default->root_url/mailbox.php3?page=$next"); if (!$this_client->lynx) { $pages_last = "graphics_url/last.gif\" border=\"0\" alt=\"$lang->last_page\">"; $pages_next = "graphics_url/next.gif\" border=\"0\" alt=\"$lang->next_page\">"; } else { $pages_last = "[ $lang->last_page ] >>"; $pages_next = "[ $lang->next_page ] >"; } } } else { $begin = 1; $end = $nummsgs; $page = 1; } if ($nummsgs != 0) $sorted = imap_sort($imp->stream, $imp->sortby, $imp->sortdir, SE_UID); else $sorted = array(); $imp->msgl = implode(':', messageRange($sorted, $begin, $offset, $beginIndex)); $imp->offset = $offset; $imp->pickle(); page_close(); $title = "Index of $imp->label"; if ($imp->delhide) { $deleted_prompt = $lang->show_deleted;; } else { $deleted_prompt = $lang->hide_deleted; } if ($this_client->lynx) { include_lynx_menu(IMPMENU_MAIN); include "$default->include_dir/mailbox/lynx_header.inc"; include "$default->include_dir/mailbox/lynx_navbar_top.inc"; include "$default->include_dir/mailbox/lynx_actions.inc"; include "$default->include_dir/mailbox/lynx_message_headers.inc"; } else { include "$default->include_dir/mailbox/header.inc"; include "$default->include_dir/mailbox/navbar_top.inc"; include "$default->include_dir/mailbox/actions.inc"; include "$default->include_dir/mailbox/message_headers.inc"; } // now step through each message for ($i = $begin, $j = $beginIndex; $i <= $end; $i++, $j++) { $msgnum = $sorted[$i-1]; $h = @imap_header($imp->stream, imap_msgno($imp->stream, $msgnum)); /* Start of deleted message hiding code ... */ if (($imp->delhide) && ($h->Deleted == 'D')) { $delnum++; } /* Display the message ... */ else { /* initialize the header fields */ $dat = ''; $frm = ''; $sub = ''; $msg_size = '?'; /* now pull the IMAP header values into them, decoding and chopping them at the same time */ /* formats the header date string nicely */ if (empty($h->date)) { $dat = ''; } else { /* Make the message date shown in the message listing the value from the RFC822 Date: field instead of the GMT equivalent as obtained from $h->udate. */ $msgdate = strtotime($h->date); if ((date('Y', $msgdate) != date('Y')) || (date('M') != date('M', $msgdate)) || (date('d') != date('d', $msgdate))) { // not today, use the date $dat = strftime($default->date_format, $msgdate); } else { // else it's today, use the time $dat = strftime($default->time_format, $msgdate); } } if (isset($h->from[0])) { $from = $h->from[0]; if (isset($from->personal)) { $frm = trim(decode_mime_string($from->personal)); } else if (isset($from->mailbox) && isset($from->host)) { $frm = $from->mailbox . '@' . $from->host; } else if (isset($h->fromaddress)) $from = trim(decode_mime_string($h->fromaddress)); } else if (isset($h->fromaddress)) $frm = trim(decode_mime_string($h->fromaddress)); if (isset($h->fromaddress) && display_toaddress($imp->user, $imp->server, $h->fromaddress, (isset($h->toaddress) ? $h->toaddress : ''))) { if (isset($h->toaddress)) { $to = chop(decode_mime_string($h->toaddress)); } else { $to = $lang->undisclosed_recipients; } $frm = $lang->to_label . ': ' . $to; } if (isset($h->subject)) $sub = trim(decode_mime_string($h->subject)); if (isset($h->Size)) $msg_size = ($h->Size > 1024) ? sprintf('%.0f kb', $h->Size / 1024) : $h->Size; if (strlen($frm) > $default->max_frm_chars) $frm = substr($frm, 0, $default->max_frm_chars) . '...'; if (strlen($sub) > $default->max_sub_chars) $sub = substr($sub, 0, $default->max_sub_chars) . '...'; /* make sure that they get put into an HTML readable format */ $frm = htmlspecialchars($frm); $sub = htmlspecialchars($sub); /* set them to useful things for IMP if they ended up being empty */ if ($dat == '') { $dat = ' '; } if ($frm == '') { $frm = ' '; } if ($sub == '') { $sub = $lang->no_subject; } // make sure to have something here for the link text // strikethru text if message deleted if ($h->Deleted == 'D') { $dat = '' . $dat . ''; $frm = '' . $frm . ''; $sub = '' . $sub . ''; $msg_size = '' . $msg_size . ''; } $attachment_icon = ''; $flag = array(); $structure = @imap_fetchstructure($imp->stream, $msgnum, FT_UID); $num_parts = @count($structure->parts); $bodypart = 1; if (isset($structure->parts) && is_array($structure->parts) && $num_parts > 0 && (isset($structure->type) && $structure->type == TYPEMULTIPART)) { if (strtolower($structure->subtype) == 'alternative') $attachment_icon = $default->multipart_alternative_icon; else $attachment_icon = $default->attachment_icon; } else { /* Only one part in message, check for an attachment */ $mime = new mime_part_data; $mime->set_imap_data($msgnum, 0, $imp->mailbox); $mime->parse($structure); if ($mime->type_text != 'text' || $mime->subtype != 'plain' ) $attachment_icon = $default->attachment_icon; } // decide what to do in the from column if ($default->from_link == 'message') $from_link = '' . $frm . ''; else if ($default->from_link == 'compose') { if ($default->minimum_popups) $from_link = '$frm"; else $from_link = '$frm"; } else $from_link = $frm; include "$default->include_dir/mailbox/message_summaries.inc"; } // for deleted message hiding } // end message display loop if ($delnum > 0) { include "$default->include_dir/mailbox/deleted_summary.inc"; } if ($end == 0) { include "$default->include_dir/mailbox/empty_mailbox.inc"; } require "$default->include_dir/mailbox/message_footers.inc"; require "$default->include_dir/mailbox/actions.inc"; require "$default->include_dir/mailbox/navbar_bottom.inc"; require "$default->include_dir/mailbox/footer.inc"; if (!$default->minimum_popups && !$this_client->rather_not_popup) { include './lib/js/open_compose_win.js'; } require "$default->include_dir/mailbox/javascript.inc"; require './lib/js/open_contacts.js'; if ((isset($actionID) && ($actionID == IMP_LOGIN)) || (isset($horde_frames))) { include "$default->include_dir/mailbox/refresh_toolbar-javascript.inc"; } if (!$this_client->lynx) { status ($status_string, $status_color); } ?>