Exemplo n.º 1
0
 /**
  * Returns message data.
  *
  * @param string $mailbox  Folder name
  * @param int    $uid      Message UID
  * @param bool   $update   If message doesn't exists in cache it will be fetched
  *                         from IMAP server
  * @param bool   $no_cache Enables internal cache usage
  *
  * @return rcube_mail_header Message data
  */
 function get_message($mailbox, $uid, $update = true, $cache = true)
 {
     // Check internal cache
     if (($message = $this->icache['message']) && $message['mailbox'] == $mailbox && $message['object']->uid == $uid) {
         return $this->icache['message']['object'];
     }
     $sql_result = $this->db->query("SELECT flags, data" . " FROM " . get_table_name('cache_messages') . " WHERE user_id = ?" . " AND mailbox = ?" . " AND uid = ?", $this->userid, $mailbox, (int) $uid);
     if ($sql_arr = $this->db->fetch_assoc($sql_result)) {
         $message = $this->build_message($sql_arr);
         $found = true;
         // update message ID according to index data
         $index = $this->get_index($mailbox, 'ANY');
         if (!empty($index) && ($id = array_search($uid, $index))) {
             $message->id = $id;
         }
     }
     // Get the message from IMAP server
     if (empty($message) && $update) {
         $message = $this->imap->get_headers($uid, $mailbox, true);
         // cache will be updated in close(), see below
     }
     // Save the message in internal cache, will be written to DB in close()
     // Common scenario: user opens unseen message
     // - get message (SELECT)
     // - set message headers/structure (INSERT or UPDATE)
     // - set \Seen flag (UPDATE)
     // This way we can skip one UPDATE
     if (!empty($message) && $cache) {
         // Save current message from internal cache
         $this->save_icache();
         $this->icache['message'] = array('object' => $message, 'mailbox' => $mailbox, 'exists' => $found, 'md5sum' => md5(serialize($message)));
     }
     return $message;
 }
Exemplo n.º 2
0
 /**
  * __construct
  *
  * Provide a uid, and parse message structure.
  *
  * @param string $uid The message UID.
  *
  * @uses rcmail::get_instance()
  * @uses rcube_imap::decode_mime_string()
  * @uses self::set_safe()
  *
  * @see self::$app, self::$imap, self::$opt, self::$structure
  */
 function __construct($uid)
 {
     $this->app = rcmail::get_instance();
     $this->imap = $this->app->imap;
     $this->imap->get_all_headers = true;
     $this->uid = $uid;
     $this->headers = $this->imap->get_headers($uid, NULL, true, true);
     if (!$this->headers) {
         return;
     }
     $this->subject = rcube_imap::decode_mime_string($this->headers->subject, $this->headers->charset);
     list(, $this->sender) = each($this->imap->decode_address_list($this->headers->from));
     $this->set_safe(intval($_GET['_safe']) || $_SESSION['safe_messages'][$uid]);
     $this->opt = array('safe' => $this->is_safe, 'prefer_html' => $this->app->config->get('prefer_html'), 'get_url' => rcmail_url('get', array('_mbox' => $this->imap->get_mailbox_name(), '_uid' => $uid)));
     if ($this->structure = $this->imap->get_structure($uid, $this->headers->body_structure)) {
         $this->get_mime_numbers($this->structure);
         $this->parse_structure($this->structure);
     } else {
         $this->body = $this->imap->get_body($uid);
     }
     // notify plugins and let them analyze this structured message object
     $this->app->plugins->exec_hook('message_load', array('object' => $this));
 }