Skip to content

Commit

Permalink
Keep current folder context when fetching message parts,
Browse files Browse the repository at this point in the history
to make sure that proper folder is used in case when
current folder has been changed in meantime.
  • Loading branch information
alecpl committed Aug 29, 2012
1 parent 764641d commit 10562d8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
26 changes: 19 additions & 7 deletions program/include/rcube_message.php
Expand Up @@ -52,7 +52,8 @@ class rcube_message
private $opt = array();
private $parse_alternative = false;

public $uid = null;
public $uid;
public $folder;
public $headers;
public $parts = array();
public $mime_parts = array();
Expand All @@ -68,17 +69,22 @@ class rcube_message
*
* Provide a uid, and parse message structure.
*
* @param string $uid The message UID.
* @param string $uid The message UID.
* @param string $folder Folder name
*
* @see self::$app, self::$storage, self::$opt, self::$parts
*/
function __construct($uid)
function __construct($uid, $folder = null)
{
$this->uid = $uid;
$this->app = rcube::get_instance();
$this->storage = $this->app->get_storage();
$this->folder = strlen($folder) ? $folder : $this->storage->get_folder();
$this->storage->set_options(array('all_headers' => true));

// Set current folder
$this->storage->set_folder($this->folder);

$this->headers = $this->storage->get_message($uid);

if (!$this->headers)
Expand Down Expand Up @@ -179,10 +185,12 @@ public function get_part_content($mime_id, $fp = null, $skip_charset_conv = fals
}
return $fp ? true : $part->body;
}

// get from IMAP
$this->storage->set_folder($this->folder);

return $this->storage->get_message_part($this->uid, $mime_id, $part, NULL, $fp, $skip_charset_conv);
} else
return null;
}
}


Expand Down Expand Up @@ -637,8 +645,10 @@ private function get_mime_numbers(&$part)
function tnef_decode(&$part)
{
// @TODO: attachment may be huge, hadle it via file
if (!isset($part->body))
if (!isset($part->body)) {
$this->storage->set_folder($this->folder);
$part->body = $this->storage->get_message_part($this->uid, $part->mime_id, $part);
}

$parts = array();
$tnef = new tnef_decoder;
Expand Down Expand Up @@ -673,8 +683,10 @@ function tnef_decode(&$part)
function uu_decode(&$part)
{
// @TODO: messages may be huge, hadle body via file
if (!isset($part->body))
if (!isset($part->body)) {
$this->storage->set_folder($this->folder);
$part->body = $this->storage->get_message_part($this->uid, $part->mime_id, $part);
}

$parts = array();
// FIXME: line length is max.65?
Expand Down
2 changes: 1 addition & 1 deletion program/include/rcube_storage.php
Expand Up @@ -195,7 +195,7 @@ public function set_default_folders($arr)
*/
public function set_folder($folder)
{
if ($this->folder == $folder) {
if ($this->folder === $folder) {
return;
}

Expand Down

0 comments on commit 10562d8

Please sign in to comment.