[ Index ]
 

Code source de IMP H3 (4.1.5)

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/ -> mailbox.php (source)

   1  <?php
   2  /**
   3   * $Horde: imp/mailbox.php,v 2.617.4.67 2007/04/06 22:19:25 slusarz Exp $
   4   *
   5   * Copyright 1999-2007 Charles J. Hagenbuch <chuck@horde.org>
   6   * Copyright 1999-2007 Jon Parise <jon@horde.org>
   7   *
   8   * See the enclosed file COPYING for license information (GPL).  If you
   9   * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
  10   */
  11  
  12  /**
  13   * Delete a list of messages.
  14   */
  15  function _deleteMessages($indices)
  16  {
  17      global $imp, $mailbox_url;
  18  
  19      if (!empty($indices)) {
  20          require_once  IMP_BASE . '/lib/Message.php';
  21          $imp_message = &IMP_Message::singleton();
  22          $imp_message->delete($indices);
  23  
  24          if ($imp['base_protocol'] == 'pop3') {
  25              header('Location: ' . Horde::url($mailbox_url, true));
  26              exit;
  27          }
  28  
  29          return true;
  30      }
  31  
  32      return false;
  33  }
  34  
  35  /**
  36   * Stylize a string.
  37   */
  38  function _stylize($string, $styles)
  39  {
  40      if (!is_array($styles)) {
  41          return $string;
  42      }
  43  
  44      foreach ($styles as $style) {
  45          if (!empty($style)) {
  46              $string = '<' . $style . '>' . $string . '</' . $style . '>';
  47          }
  48      }
  49  
  50      return $string;
  51  }
  52  
  53  /**
  54   * Output the message summaries.
  55   */
  56  function _outputSummaries($search_mbox, $msgs)
  57  {
  58      $template = &new Horde_Template();
  59      $template->set('idx_separator', IMP_IDX_SEP);
  60      $template->set('search_mbox', (bool) $search_mbox, true);
  61      $template->set('messages', $msgs, true);
  62  
  63      // Some browsers have trouble with hidden overflow in table cells
  64      // but not in divs.
  65      if ($GLOBALS['browser']->hasQuirk('no_hidden_overflow_tables')) {
  66          $template->set('overflow_begin', '<div class="ohide">');
  67          $template->set('overflow_end', '</div>');
  68      } else {
  69          $template->set('overflow_begin', '');
  70          $template->set('overflow_end', '');
  71      }
  72      echo $template->fetch(IMP_TEMPLATES . '/mailbox/mailbox.html');
  73  }
  74  
  75  @define('IMP_BASE', dirname(__FILE__));
  76  require_once  IMP_BASE . '/lib/base.php';
  77  require_once  IMP_BASE . '/lib/Mailbox.php';
  78  require_once  IMP_BASE . '/lib/Search.php';
  79  require_once 'Horde/MIME.php';
  80  require_once 'Horde/Identity.php';
  81  require_once 'Horde/Template.php';
  82  require_once 'Horde/Text.php';
  83  
  84  /* Call the mailbox redirection hook, if requested. */
  85  if (!empty($conf['hooks']['mbox_redirect'])) {
  86      require_once HORDE_BASE . '/config/hooks.php';
  87      if (function_exists('_imp_hook_mbox_redirect')) {
  88          $redirect = call_user_func('_imp_hook_mbox_redirect', $imp['mailbox']);
  89          if (!empty($redirect)) {
  90              $redirect = Horde::applicationUrl($redirect, true);
  91              header('Location: ' . $redirect);
  92              exit;
  93          }
  94      }
  95  }
  96  
  97  /* There is a chance that this page is loaded directly via
  98   * message.php. If so, don't re-include config files, and the
  99   * following variables will already be set: $actionID, $start. */
 100  if (isset($from_message_page)) {
 101      $mailbox_url = Util::addParameter(Horde::applicationURL('mailbox.php'), 'mailbox', $imp['mailbox']);
 102  } else {
 103      $mailbox_url = Horde::selfUrl();
 104      $actionID = Util::getFormData('actionID');
 105      $start = Util::getFormData('start');
 106  }
 107  
 108  /* Get form data and make sure it's the type that we're expecting. */
 109  $targetMbox = Util::getFormData('targetMbox');
 110  $newMbox = Util::getFormData('newMbox');
 111  if (!is_array(($indices = Util::getFormData('indices')))) {
 112      $indices = array($indices);
 113  }
 114  $indices_mbox = array($imp['mailbox'] => $indices);
 115  
 116  /* Set the current time zone. */
 117  NLS::setTimeZone();
 118  
 119  /* Cache the charset. */
 120  $charset = NLS::getCharset();
 121  
 122  /* Initialize the user's identities. */
 123  $identity = &Identity::singleton(array('imp', 'imp'));
 124  
 125  $do_filter = $open_compose_window = false;
 126  
 127  /* Run through the action handlers */
 128  switch ($actionID) {
 129  case 'change_sort':
 130      if (($sortby = Util::getFormData('sortby')) !== null) {
 131          $prefs->setValue('sortby', $sortby);
 132      }
 133      if (($sortdir = Util::getFormData('sortdir')) !== null) {
 134          $prefs->setValue('sortdir', $sortdir);
 135      }
 136      $imp_mailbox = &IMP_Mailbox::singleton(null, true);
 137      break;
 138  
 139  case 'blacklist':
 140      require_once  IMP_BASE . '/lib/Filter.php';
 141      $imp_filter = &IMP_Filter::singleton();
 142      $imp_filter->blacklistMessage($indices_mbox);
 143      break;
 144  
 145  case 'whitelist':
 146      require_once  IMP_BASE . '/lib/Filter.php';
 147      $imp_filter = &IMP_Filter::singleton();
 148      $imp_filter->whitelistMessage($indices_mbox);
 149      break;
 150  
 151  case 'spam_report':
 152  case 'notspam_report':
 153      $action = str_replace('_report', '', $actionID);
 154      require_once  IMP_BASE . '/lib/Spam.php';
 155      $imp_spam = &new IMP_Spam();
 156      $imp_spam->reportSpam($indices_mbox, $action);
 157  
 158      /* Delete spam after report. */
 159      $delete_spam = $prefs->getValue('delete_spam_after_report');
 160      if (($action == 'spam') && ($delete_spam == 1)) {
 161          if (_deleteMessages($indices_mbox)) {
 162              if (count($indices) == 1) {
 163                  $notification->push(_("1 message has been deleted."), 'horde.message');
 164              } else {
 165                  $notification->push(sprintf(_("%d messages have been deleted."),
 166                                              count($indices)), 'horde.message');
 167              }
 168          }
 169      } elseif ($delete_spam == 2) {
 170          $targetMbox = ($action == 'spam') ? IMP::folderPref($prefs->getValue('spam_folder'), true) : 'INBOX';
 171          require_once  IMP_BASE . '/lib/Message.php';
 172          $imp_message = &IMP_Message::singleton();
 173          $imp_message->copy($targetMbox, IMP_MESSAGE_MOVE, $indices_mbox, true);
 174      }
 175      break;
 176  
 177  case 'message_missing':
 178      $notification->push(_("Requested message not found."), 'horde.error');
 179      break;
 180  
 181  case 'fwd_digest':
 182      $options = array('fwddigest' => serialize($indices), 'actionID' => 'fwd_digest');
 183      $open_compose_window = IMP::openComposeWin($options);
 184      break;
 185  
 186  case 'delete_messages':
 187      _deleteMessages($indices_mbox);
 188      break;
 189  
 190  case 'undelete_messages':
 191      if (!empty($indices_mbox)) {
 192          require_once  IMP_BASE . '/lib/Message.php';
 193          $imp_message = &IMP_Message::singleton();
 194          $imp_message->undelete($indices_mbox);
 195      }
 196      break;
 197  
 198  case 'move_messages':
 199  case 'copy_messages':
 200      if (!empty($indices) && !empty($targetMbox)) {
 201          require_once  IMP_BASE . '/lib/Message.php';
 202          $imp_message = &IMP_Message::singleton();
 203          $action = ($actionID == 'move_messages') ? IMP_MESSAGE_MOVE : IMP_MESSAGE_COPY;
 204  
 205          if ($conf['tasklist']['use_tasklist'] &&
 206              (strpos($targetMbox, '_tasklist_') === 0)) {
 207              /* If the target is a tasklist, handle the move/copy specially. */
 208              $tasklist = str_replace('_tasklist_', '', $targetMbox);
 209              $imp_message->createTasksOrNotes($tasklist, $action, $indices_mbox, 'task');
 210          } elseif ($conf['notepad']['use_notepad'] &&
 211              (strpos($targetMbox, '_notepad_') === 0)) {
 212              /* If the target is a notepad, handle the move/copy specially. */
 213              $notepad = str_replace('_notepad_', '', $targetMbox);
 214              $imp_message->createTasksOrNotes($notepad, $action, $indices_mbox, 'note');
 215          } else {
 216              /* Otherwise, the target is a standard mailbox. */
 217              if (!empty($newMbox) && ($newMbox == 1)) {
 218                  $new_mailbox = String::convertCharset(IMP::folderPref($targetMbox, true), $charset, 'UTF7-IMAP');
 219  
 220                  require_once  IMP_BASE . '/lib/Folder.php';
 221                  $imp_folder = &IMP_Folder::singleton();
 222                  if ($imp_folder->create($new_mailbox, $prefs->getValue('subscribe'))) {
 223                      $imp_message->copy($new_mailbox, $action, $indices_mbox);
 224                  }
 225              } else {
 226                  $imp_message->copy($targetMbox, $action, $indices_mbox);
 227              }
 228          }
 229      }
 230      break;
 231  
 232  case 'flag_messages':
 233      $flag = Util::getPost('flag');
 234      if (!empty($indices) && !empty($flag)) {
 235          if ($flag{0} == '0') {
 236              $_POST['flag'] = '\\' . substr($flag, 1);
 237              $set = false;
 238          } else {
 239              $_POST['flag'] = '\\' . $flag;
 240              $set = true;
 241          }
 242          require_once  IMP_BASE . '/lib/Message.php';
 243          $imp_message = &IMP_Message::singleton();
 244          $imp_message->flag($_POST['flag'], $indices_mbox, $set);
 245      }
 246      break;
 247  
 248  case 'hide_deleted':
 249      $prefs->setValue('delhide', !$prefs->getValue('delhide'));
 250      break;
 251  
 252  case 'expunge_mailbox':
 253      require_once  IMP_BASE . '/lib/Message.php';
 254      $imp_message = &IMP_Message::singleton();
 255      $imp_message->expungeMailbox(array($imp['mailbox']));
 256      break;
 257  
 258  case 'filter':
 259      $do_filter = true;
 260      break;
 261  
 262  case 'empty_mailbox':
 263      require_once  IMP_BASE . '/lib/Message.php';
 264      $imp_message = &IMP_Message::singleton();
 265      $imp_message->emptyMailbox(array($imp['mailbox']));
 266      break;
 267  
 268  case 'view_messages':
 269      require_once 'Horde/SessionObjects.php';
 270      $cacheSess = &Horde_SessionObjects::singleton();
 271      $redirect = Util::addParameter(Horde::applicationUrl('thread.php', true), array('mode' => 'msgview', 'msglist' => $cacheSess->storeOid($indices_mbox)), null, false);
 272      header("Location: " . $redirect);
 273      exit;
 274      break;
 275  
 276  case 'login_compose':
 277      $open_compose_window = IMP::openComposeWin();
 278      break;
 279  }
 280  
 281  /* Is this a search mailbox? */
 282  $search_mbox = $imp_search->searchMboxID();
 283  
 284  /* Deal with filter options. */
 285  if ($imp['filteravail']) {
 286      /* Only allow filter on display for INBOX. */
 287      if (($imp['mailbox'] == 'INBOX') && $prefs->getValue('filter_on_display')) {
 288          $do_filter = true;
 289      } elseif (($imp['mailbox'] == 'INBOX') ||
 290                ($prefs->getValue('filter_any_mailbox') && !$search_mbox)) {
 291          $filter_url = Util::addParameter($mailbox_url, 'actionID', 'filter');
 292      }
 293  }
 294  
 295  /* Run filters now. */
 296  if ($do_filter) {
 297      require_once  IMP_BASE . '/lib/Filter.php';
 298      $imp_filter = &IMP_Filter::singleton();
 299      $imp_filter->filter($imp['mailbox']);
 300  }
 301  
 302  /* Generate folder options list. */
 303  if ($conf['user']['allow_folders']) {
 304      $folder_options = IMP::flistSelect(_("Messages to"), true, array(), null, true, true, false, true);
 305  }
 306  
 307  /* Build the list of messages in the mailbox. */
 308  if (!isset($imp_mailbox)) {
 309      $imp_mailbox = &IMP_Mailbox::singleton();
 310  }
 311  $imp_mailbox->setNoNewmailPopup(Util::getFormData('no_newmail_popup'));
 312  $pageOb = $imp_mailbox->buildMailboxPage(Util::getFormData('page'), $start);
 313  $mailboxOverview = $imp_mailbox->buildMailboxArray($pageOb->begin, $pageOb->end);
 314  
 315  /* Cache this value since we use it alot on this page. */
 316  $graphicsdir = $registry->getImageDir('horde');
 317  
 318  /* Generate First/Previous page links. */
 319  if ($pageOb->page == 1) {
 320      $pages_first = Horde::img('nav/first-grey.png', null, null, $graphicsdir);
 321      $pages_prev = Horde::img('nav/left-grey.png', null, null, $graphicsdir);
 322  } else {
 323      $first_url = Util::addParameter($mailbox_url, 'page', 1);
 324      $pages_first = Horde::link($first_url, _("First Page")) . Horde::img('nav/first.png', '<<', null, $graphicsdir) . '</a>';
 325      $prev_url = Util::addParameter($mailbox_url, 'page', $pageOb->page - 1);
 326      $pages_prev = Horde::link($prev_url, _("Previous Page"), '', '', '', '', '', array('id' => 'prev')) . Horde::img('nav/left.png', '<', null, $graphicsdir) . '</a>';
 327  }
 328  
 329  /* Generate Next/Last page links. */
 330  if ($pageOb->page == $pageOb->pagecount) {
 331      $pages_last = Horde::img('nav/last-grey.png', null, null, $graphicsdir);
 332      $pages_next = Horde::img('nav/right-grey.png', null, null, $graphicsdir);
 333  } else {
 334      $next_url = Util::addParameter($mailbox_url, 'page', $pageOb->page + 1);
 335      $pages_next = Horde::link($next_url, _("Next Page"), '', '', '', '', '', array('id' => 'next')) . Horde::img('nav/right.png', '>', null, $graphicsdir) . '</a>';
 336      $last_url = Util::addParameter($mailbox_url, 'page', $pageOb->pagecount);
 337      $pages_last = Horde::link($last_url, _("Last Page")) . Horde::img('nav/last.png', '>>', null, $graphicsdir) . '</a>';
 338  }
 339  
 340  /* Determine if we are going to show the Hide/Purge Deleted Message links. */
 341  $sortby = $imp_mailbox->sortby();
 342  if (!$prefs->getValue('use_trash') &&
 343      !$prefs->getValue('use_vtrash') &&
 344      !$GLOBALS['imp_search']->isVINBOXFolder()) {
 345      $showdelete = array('hide' => ($sortby != SORTTHREAD), 'purge' => true);
 346  } else {
 347      $showdelete = array('hide' => false, 'purge' => false);
 348  }
 349  if ($showdelete['hide'] && !$prefs->isLocked('delhide')) {
 350      if ($prefs->getValue('delhide')) {
 351          $deleted_prompt = _("Show Deleted");
 352      } else {
 353          $deleted_prompt = _("Hide Deleted");
 354      }
 355  }
 356  
 357  /* Generate mailbox summary string. */
 358  if (!empty($pageOb->end)) {
 359      $msg_count = sprintf(_("%d to %d of %d Messages"), $pageOb->begin, $pageOb->end, $pageOb->msgcount);
 360  } else {
 361      $msg_count = sprintf(_("No Messages"));
 362  }
 363  
 364  /* If user wants the mailbox to be refreshed, set time here. */
 365  $refresh_time = $prefs->getValue('refresh_time');
 366  $refresh_url = Util::addParameter($mailbox_url, 'page', $pageOb->page);
 367  if (isset($filter_url)) {
 368      $filter_url = Util::addParameter($filter_url, 'page', $pageOb->page);
 369  }
 370  
 371  /* Set the folder for the sort links. */
 372  $sortdir = $prefs->getValue('sortdir');
 373  $sort_url = Util::addParameter($mailbox_url, 'sortdir', ($sortdir) ? 0 : 1);
 374  
 375  /* Determine if we are showing previews. */
 376  $show_preview = $imp_mailbox->showPreviews();
 377  $preview_tooltip = ($show_preview) ? $prefs->getValue('preview_show_tooltip') : false;
 378  if ($preview_tooltip) {
 379      Horde::addScriptFile('tooltip.js', 'horde', true);
 380  } else {
 381      $strip_preview = $prefs->getValue('preview_strip_nl');
 382  }
 383  
 384  $vtrash = null;
 385  if ($search_mbox) {
 386      $unread = 0;
 387      if ($imp_search->isVINBOXFolder()) {
 388          $unread = $imp_mailbox->getMessageCount();
 389      } elseif ($imp_search->isVTrashFolder()) {
 390          $vtrash = $imp_search->createSearchID($search_mbox);
 391     }
 392  } else {
 393      $unread = count($imp_mailbox->unseenMessages());
 394  }
 395  
 396  /* Play audio. */
 397  if ($prefs->getValue('nav_audio') &&
 398      ($newmsgs = $imp_mailbox->newMessageCount()) &&
 399      ($newmsgs > 0) &&
 400      !Util::getFormData('no_newmail_popup')) {
 401      $notification->push($registry->getImageDir() . '/audio/theetone.wav', 'audio');
 402  }
 403  
 404  $title = IMP::getLabel();
 405  $refresh_title = sprintf(_("_Refresh %s"), $title);
 406  $refresh_ak = Horde::getAccessKey($refresh_title);
 407  $refresh_title = Horde::stripAccessKey($refresh_title);
 408  if (!empty($refresh_ak)) {
 409      $refresh_title .= sprintf(_(" (Accesskey %s)"), $refresh_ak);
 410  }
 411  if ($unread) {
 412      $title .= ' (' . $unread . ')';
 413  }
 414  Horde::addScriptFile('keybindings.js', 'horde');
 415  require IMP_TEMPLATES . '/common-header.inc';
 416  require IMP_TEMPLATES . '/menu.inc';
 417  if ($browser->hasFeature('javascript')) {
 418      require IMP_TEMPLATES . '/mailbox/javascript.inc';
 419  }
 420  IMP::status();
 421  
 422  /* Print quota information. */
 423  if (isset($imp['quota']) && is_array($imp['quota'])) {
 424      require_once  IMP_BASE . '/lib/Quota.php';
 425      $quotaDriver = &IMP_Quota::singleton($imp['quota']['driver'], $imp['quota']['params']);
 426      if ($quotaDriver !== false) {
 427          $quota = $quotaDriver->getQuota();
 428          require IMP_TEMPLATES . '/quota/quota.inc';
 429      }
 430  }
 431  
 432  /* Are we currently in the trash mailbox? */
 433  $use_trash = $prefs->getValue('use_trash');
 434  $use_vtrash = $prefs->getValue('use_vtrash');
 435  $trashMbox = ($use_trash && ($imp['mailbox'] == (IMP::folderPref($prefs->getValue('trash_folder'), true)))) ||
 436               ($use_vtrash && !is_null($vtrash));
 437  
 438  /* Show the [black|white]list link if we have functionality enabled. */
 439  $show_blacklist_link = $registry->hasMethod('mail/blacklistFrom');
 440  $show_whitelist_link = $registry->hasMethod('mail/whitelistFrom');
 441  
 442  require IMP_TEMPLATES . '/mailbox/header.inc';
 443  
 444  /* If no messages, exit immediately. */
 445  if (empty($pageOb->end)) {
 446      if ($pageOb->anymsg && isset($deleted_prompt)) {
 447          /* Show 'Show Deleted' prompt if mailbox has no viewable message but
 448             has hidden, deleted messages. */
 449          require IMP_TEMPLATES . '/mailbox/actions_deleted.inc';
 450      }
 451      require IMP_TEMPLATES . '/mailbox/empty_mailbox.inc';
 452      require IMP_TEMPLATES . '/mailbox/footer.inc';
 453      require $registry->get('templates', 'horde') . '/common-footer.inc';
 454      exit;
 455  }
 456  
 457  /* If there are more than 15 messages, cache the actions output. */
 458  if ($pageOb->msgcount != 0) {
 459      $navform = 1;
 460      require IMP_TEMPLATES . '/mailbox/navbar.inc';
 461      if ($pageOb->msgcount > 15) {
 462          ob_start();
 463          require IMP_TEMPLATES . '/mailbox/actions.inc';
 464          $actions_output = ob_get_contents();
 465          ob_end_clean();
 466          echo $actions_output;
 467      } else {
 468          require IMP_TEMPLATES . '/mailbox/actions.inc';
 469      }
 470  }
 471  
 472  /* Define some variables now so we don't have to keep redefining in the
 473     foreach() loop or the templates. */
 474  $curr_time = time();
 475  $curr_time -= $curr_time % 60;
 476  $ltime_val = localtime();
 477  $today_start = mktime(0, 0, 0, $ltime_val[4] + 1, $ltime_val[3], 1900 + $ltime_val[5]);
 478  $today_end = $today_start + 86400;
 479  $drafts_sm_folder = $imp_mailbox->isSpecialFolder();
 480  $lastMbox = '';
 481  $messages = array();
 482  $threadlevel = array();
 483  
 484  /* Determine sorting preferences. */
 485  $thread_sort = ($sortby == SORTTHREAD);
 486  $sortlimit = $imp_mailbox->aboveSortLimit();
 487  
 488  /* Get thread object, if necessary. */
 489  if ($thread_sort) {
 490      $threadob = $imp_mailbox->getThreadOb();
 491      $uid_list = array();
 492      foreach ($mailboxOverview as $val) {
 493          $uid_list[] = $val['header']->uid;
 494      }
 495      $threadtree = $threadob->getThreadImageTree($uid_list, $sortdir);
 496  }
 497  
 498  /* Don't show header row if this is a search mailbox or if no messages in the
 499     current mailbox. */
 500  if (!$search_mbox && ($pageOb->msgcount != 0)) {
 501      require IMP_TEMPLATES . '/mailbox/message_headers.inc';
 502  }
 503  
 504  /* Cache some repetitively used variables. */
 505  $datefmt = $prefs->getValue('date_format');
 506  $timefmt = $prefs->getValue('time_format');
 507  $fromlinkstyle = $prefs->getValue('from_link');
 508  $localeinfo = NLS::getLocaleInfo();
 509  
 510  /* Display message information. */
 511  $msgs = array();
 512  foreach ($mailboxOverview as $msgIndex => $message) {
 513      if ($search_mbox) {
 514          if (empty($lastMbox) || ($message['mbox'] != $lastMbox)) {
 515              if (!empty($lastMbox)) {
 516                  _outputSummaries($search_mbox, $msgs);
 517                  $msgs = array();
 518              }
 519              $folder_link = Horde::url(Util::addParameter('mailbox.php', 'mailbox', $message['mbox']));
 520              $folder_link = Horde::link($folder_link, sprintf(_("View messages in %s"), IMP::displayFolder($message['mbox'])), 'smallheader') . IMP::displayFolder($message['mbox']) . '</a>';
 521              require IMP_TEMPLATES . '/mailbox/searchfolder.inc';
 522              require IMP_TEMPLATES . '/mailbox/message_headers.inc';
 523          }
 524          $lastMbox = $message['mbox'];
 525      }
 526  
 527      /* Initialize the header fields. */
 528      $msg = array(
 529          'color' => (isset($message['color'])) ? htmlspecialchars($message['color']) : '',
 530          'date' => '&nbsp;',
 531          'from' => '&nbsp;',
 532          'mbox' => $message['mbox'],
 533          'preview' => '',
 534          'size' => '?',
 535          'subject' => _("[No Subject]")
 536      );
 537  
 538      /* Initialize some other variables. */
 539      $attachment = false;
 540      $from_adr = null;
 541      $mailto_link = false;
 542      $showfromlink = true;
 543  
 544      /* Now pull the IMAP header values into them, decoding them at
 545         the same time. */
 546      $h = $message['header'];
 547      $messages[] = $h->uid;
 548  
 549      /* Formats the header date string nicely. */
 550      if (empty($h->date)) {
 551          $udate = false;
 552      } else {
 553          $h->date = preg_replace('/\s+\(\w+\)$/', '', $h->date);
 554          $udate = strtotime($h->date, $curr_time);
 555      }
 556      if ($udate === false || $udate === -1) {
 557          $msg['date'] = _("Unknown Date");
 558      } elseif (($udate < $today_start) || ($udate > $today_end)) {
 559          /* Not today, use the date. */
 560          $msg['date'] = strftime($datefmt, $udate);
 561      } else {
 562          /* Else, it's today, use the time. */
 563          $msg['date'] = strftime($timefmt, $udate);
 564      }
 565  
 566      /* Format the from header. */
 567      if (isset($h->from)) {
 568          $from_adr = IMP::bareAddress($h->from);
 569          $from_ob = IMP::parseAddressList($h->from, '');
 570          if (!is_a($from_ob, 'PEAR_Error')) {
 571              $from_ob = array_shift($from_ob);
 572          }
 573          if (is_null($from_adr)) {
 574              $msg['from'] = _("Invalid Address");
 575              $showfromlink = false;
 576          } elseif ($identity->hasAddress($from_adr)) {
 577              if (isset($h->to)) {
 578                  if (strstr($h->to, 'undisclosed-recipients:')) {
 579                      $msg['from'] = _("Undisclosed Recipients");
 580                      $showfromlink = false;
 581                  } else {
 582                      $tmp = IMP::parseAddressList($h->to, '');
 583                      if (!is_a($tmp, 'PEAR_Error')) {
 584                          $tmp = array_shift($tmp);
 585                      }
 586                      if (isset($tmp->personal)) {
 587                          $msg['from'] = stripslashes(MIME::decode($tmp->personal, $charset));
 588                      } else {
 589                          $msg['from'] = IMP::bareAddress($h->to);
 590                      }
 591                      $msg['fullfrom'] = MIME::decode($h->to, $charset);
 592                      if (empty($msg['from'])) {
 593                          $msg['from'] = $msg['fullfrom'];
 594                      }
 595                  }
 596              } else {
 597                  $msg['from'] = _("Undisclosed Recipients");
 598                  $showfromlink = false;
 599              }
 600              if (!$drafts_sm_folder) {
 601                  $msg['from'] = _("To") . ': ' . $msg['from'];
 602              }
 603              $mailto_link = true;
 604          } elseif (isset($from_ob->personal)) {
 605              $msg['from'] = trim(stripslashes(MIME::decode($from_ob->personal, $charset)), '"');
 606              if (!trim($msg['from'], chr(160) . ' ')) {
 607                  $msg['from'] = $from_adr;
 608              }
 609              if ($drafts_sm_folder) {
 610                  $msg['from'] = _("From") . ': ' . $msg['from'];
 611              }
 612              $msg['fullfrom'] = MIME::decode($h->from, $charset);
 613          } else {
 614              if (!isset($from_ob->host) ||
 615                  (strstr($from_ob->host, 'SYNTAX-ERROR') !== false)) {
 616                  $msg['from'] = (!empty($from_adr)) ? $from_adr : _("Unknown Recipient");
 617                  $showfromlink = false;
 618              } else {
 619                  $msg['from'] = $from_adr;
 620                  $msg['fullfrom'] = MIME::decode($h->from, $charset);
 621              }
 622          }
 623      } else {
 624          $msg['from'] = _("Invalid Address");
 625          $showfromlink = false;
 626      }
 627  
 628      if (!empty($h->subject)) {
 629          $subject = MIME::decode($h->subject, $charset);
 630          if (!empty($subject)) {
 631              $msg['subject'] = strtr($subject, "\t", ' ');
 632          }
 633      }
 634      $msg['fullsubject'] = $msg['subject'];
 635  
 636      if (isset($h->size)) {
 637          $msg['size'] = ($h->size > 1024)
 638              ? sprintf(_("%s KB"), number_format($h->size / 1024, 0, $localeinfo['decimal_point'], $localeinfo['thousands_sep']))
 639              : $h->size;
 640      }
 641  
 642      /* Filter the subject text, if requested. */
 643      $msg['subject'] = IMP::filterText($msg['subject']);
 644      $msg['fullsubject'] = IMP::filterText($msg['fullsubject']);
 645  
 646      if (isset($message['structure']) &&
 647          ($message['structure']->getPrimaryType() == 'multipart')) {
 648          switch ($message['structure']->getSubType()) {
 649          case 'signed':
 650              $attachment = 'signed';
 651              $attachment_alt = _("Message is signed");
 652              break;
 653  
 654          case 'encrypted':
 655              $attachment = 'encrypted';
 656              $attachment_alt = _("Message is encrypted");
 657              break;
 658  
 659          case 'alternative':
 660              /* Treat this as no attachments. */
 661              break;
 662  
 663          default:
 664              $attachment = 'attachment';
 665              $attachment_alt = _("Message has attachments");
 666              break;
 667          }
 668      }
 669  
 670      /* Generate the target link. */
 671      $msgMbox = isset($message['mbox']) ? $message['mbox'] : '';
 672      $target = IMP::generateSearchUrl('message.php', $msgMbox);
 673      $target = Util::addParameter($target, 'index', $h->uid);
 674  
 675      /* Get all the flag information. */
 676      $msg['bg'] = 'seen';
 677      $msg['status'] = '';
 678      $flagbits = 0;
 679      $style = array();
 680      $xprio = false;
 681  
 682      /* Check for X-Priority information. */
 683      if ($conf['mailbox']['show_xpriority']) {
 684          require_once  IMP_BASE . '/lib/MIME/Headers.php';
 685          $imp_headers = &new IMP_Headers($h->uid);
 686          $imp_headers->buildHeaders();
 687          if (($priority = $imp_headers->getValue('x-priority'))) {
 688              if (preg_match('/\s*(\d+)\s*/', $priority, $matches)) {
 689                  if (($matches[1] == '1') || ($matches[1] == '2')) {
 690                      $xprio = 'high';
 691                  } elseif (($matches[1] == '4') || ($matches[1] == '5')) {
 692                      $xprio = 'low';
 693                  }
 694              }
 695          }
 696      }
 697  
 698      if ($imp['base_protocol'] != 'pop3') {
 699          if (!empty($h->to) && $identity->hasAddress(IMP::bareAddress($h->to))) {
 700              $msg['status'] .= Horde::img('mail_personal.png', _("Personal"));
 701              $flagbits |= IMP_PERSONAL;
 702          }
 703          if (!$h->seen || $h->recent) {
 704              $flagbits |= IMP_UNSEEN;
 705              $msg['status'] .= Horde::img('mail_unseen.png', _("Unseen"));
 706              $style[] = 'b';
 707              $msg['bg'] = 'unseen';
 708          }
 709          if ($h->answered) {
 710              $flagbits |= IMP_ANSWERED;
 711              $msg['status'] .= Horde::img('mail_answered.png', _("Answered"));
 712              $msg['bg'] = 'answered';
 713          }
 714          if ($h->draft) {
 715              $flagbits |= IMP_DRAFT;
 716              $msg['status'] .= Horde::img('mail_draft.png', _("Draft"));
 717              $target = IMP::composeLink(array(), array('actionID' => 'draft', 'mailbox' => $message['mbox'], 'index' => $h->uid));
 718          }
 719          if ($xprio == 'high') {
 720              $flagbits |= IMP_FLAGGED;
 721              $msg['status'] .= Horde::img('mail_priority_high.png', _("High Priority"));
 722              $msg['bg'] = 'important';
 723          } elseif ($xprio == 'low') {
 724              $msg['status'] .= Horde::img('mail_priority_low.png', _("Low Priority"));
 725              if (isset($style[0]) && $style[0] == 'b') {
 726                  $style = array();
 727              }
 728          }
 729          if ($h->flagged) {
 730              $flagbits |= IMP_FLAGGED;
 731              $msg['status'] .= Horde::img('mail_flagged.png', _("Important"));
 732              $style[] = 'i';
 733              $msg['bg'] = 'important';
 734          }
 735          if ($h->deleted) {
 736              $flagbits |= IMP_DELETED;
 737              $msg['status'] .= Horde::img('mail_deleted.png', _("Deleted"));
 738              $style[] = 'strike';
 739              $msg['bg'] = 'deleted';
 740          }
 741          $flags[] = $flagbits;
 742      } else {
 743          $flags[] = 0;
 744      }
 745  
 746      if ($conf['mailbox']['show_attachments'] && $attachment) {
 747          $msg['status'] .= Horde::img($attachment . '.png', $attachment_alt);
 748      }
 749  
 750      /* Show message preview? */
 751      if ($show_preview) {
 752          $msg['preview'] = $message['preview'];
 753      }
 754  
 755      /* Set the message number. */
 756      $msg['number'] = _stylize($h->msgno, $style);
 757  
 758      /* Format the Date: Header. */
 759      $msg['date'] = _stylize($msg['date'], $style);
 760  
 761      /* Format message size. */
 762      $msg['size'] = _stylize($msg['size'], $style);
 763  
 764      /* Format the From: Header. */
 765      $msg['from'] = _stylize(htmlspecialchars($msg['from']), $style);
 766      switch ($fromlinkstyle) {
 767      case 0:
 768          if ($showfromlink) {
 769              $extra = array('actionID' => 'mailto', 'mailbox' => $imp['mailbox'], 'index' => $h->uid, 'mailto' => $mailto_link);
 770              if ($search_mbox) {
 771                  $extra['thismailbox'] = $message['mbox'];
 772              }
 773              $msg['from'] = Horde::link(IMP::composeLink(array(), $extra), sprintf(_("New Message to %s"), stripslashes($msg['fullfrom']))) . $msg['from'] . '</a>';
 774          }
 775          break;
 776  
 777      case 1:
 778          if (!isset($msg['fullfrom'])) {
 779              $msg['fullfrom'] = $msg['from'];
 780          }
 781          $from_uri = IMP::generateSearchUrl('message.php', $msgMbox);
 782          $from_uri = Util::addParameter($from_uri, 'index', $h->uid);
 783          $msg['from'] = Horde::link($from_uri, $msg['fullfrom']) . $msg['from'] . '</a>';
 784          break;
 785      }
 786  
 787      /* Format the Subject: Header. */
 788      $msg['subject'] = _stylize(Text::htmlSpaces($msg['subject']), $style);
 789      if ($preview_tooltip) {
 790          $msg['subject'] = substr(Horde::linkTooltip($target, $msg['fullsubject'], '', '', '', $msg['preview']), 0, -1) . ' id="subject' . $h->uid . '">' . $msg['subject'] . '</a>';
 791      } else {
 792          $msg['subject'] = substr(Horde::link($target, $msg['fullsubject']), 0, -1) . ' id="subject' . $h->uid . '">' . $msg['subject'] . '</a>' . (!empty($msg['preview']) ? '<br /><small>' . $msg['preview'] . '</small>' : '');
 793      }
 794  
 795      /* Set up threading tree now. */
 796      if ($thread_sort) {
 797          if (!empty($threadtree[$h->uid])) {
 798              $msg['subject'] = $threadtree[$h->uid] . ' ' . $msg['subject'];
 799          }
 800      }
 801  
 802      /* We need the uid so the checkboxes will work. */
 803      $msg['uid'] = $h->uid;
 804  
 805      $msgs[] = $msg;
 806  }
 807  
 808  _outputSummaries($search_mbox, $msgs);
 809  require IMP_TEMPLATES . '/mailbox/message_footers.inc';
 810  
 811  if ($prefs->getValue('show_legend') && ($imp['base_protocol'] != 'pop3')) {
 812      require IMP_TEMPLATES . '/mailbox/legend.inc';
 813  }
 814  
 815  /* If there are 15 messages or less, don't show the actions/navbar
 816   * again. */
 817  if (isset($actions_output)) {
 818      echo $actions_output;
 819      $navform = 2;
 820      require IMP_TEMPLATES . '/mailbox/navbar.inc';
 821  } else {
 822      echo '<tr><td class="control" colspan="6"></td></tr>';
 823  }
 824  
 825  require IMP_TEMPLATES . '/mailbox/footer.inc';
 826  
 827  if ($prefs->getValue('nav_popup') &&
 828      ($newmsgs = $imp_mailbox->newMessageCount())
 829      && ($newmsgs > 0) &&
 830      !Util::getFormData('no_newmail_popup')) {
 831      require IMP_TEMPLATES . '/mailbox/alert.inc';
 832  }
 833  
 834  if (!empty($open_compose_window)) {
 835      $args = 'popup=1';
 836      if (!isset($options)) {
 837          $options = array();
 838      }
 839      foreach (array_merge($options, IMP::getComposeArgs()) as $arg => $value) {
 840          $args .= !empty($value) ? '&' . $arg . '=' . urlencode($value) : '';
 841      }
 842      Horde::addScriptFile('popup.js');
 843      echo "<script type='text/javascript'>popup_imp('" . Horde::applicationUrl('compose.php') . "',700,650,'" . addslashes($args) . "');</script>";
 844  }
 845  
 846  require $registry->get('templates', 'horde') . '/common-footer.inc';


Généré le : Thu Nov 29 12:30:07 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics