From ff52bee1a2c1b3f6654c8bfe41d1a3d8630e2b55 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Thu, 01 Mar 2007 15:40:00 -0500
Subject: [PATCH] Solved wrong caching of message preview (#1484153, #1484236)

---
 program/steps/mail/show.inc |   21 ++++++++++++---------
 1 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/program/steps/mail/show.inc b/program/steps/mail/show.inc
index 841a41b..19e6e56 100644
--- a/program/steps/mail/show.inc
+++ b/program/steps/mail/show.inc
@@ -23,21 +23,14 @@
 
 $PRINT_MODE = $_action=='print' ? TRUE : FALSE;
 
-// allow caching, unless remote images are present
-if ((bool)get_input_value('_safe', RCUBE_INPUT_GET))
-  send_nocacheing_headers();
-else
-  send_future_expire_header();
-
 // similar code as in program/steps/mail/get.inc
 if ($_GET['_uid'])
   {
   $MESSAGE = array('UID' => get_input_value('_uid', RCUBE_INPUT_GET));
   $MESSAGE['headers'] = $IMAP->get_headers($MESSAGE['UID']);
-  $MESSAGE['structure'] = $IMAP->get_structure($MESSAGE['UID']);
   
   // go back to list if message not found (wrong UID)
-  if (!$MESSAGE['headers'] || !$MESSAGE['structure'])
+  if (!$MESSAGE['headers'])
     {
     show_message('messageopenerror', 'error');
     if ($_action=='preview' && template_exists('messagepreview'))
@@ -49,9 +42,19 @@
       }
     }
 
+  // calculate Etag for this request
+  $etag = md5($MESSAGE['UID'].$IMAP->get_mailbox_name().session_id().($PRINT_MODE?1:0));
+
+  // allow caching, unless remote images are present
+  if ((bool)get_input_value('_safe', RCUBE_INPUT_GET))
+    send_nocacheing_headers();
+  else
+    send_modified_header($_SESSION['login_time'], $etag);
+
+
   $MESSAGE['subject'] = $IMAP->decode_header($MESSAGE['headers']->subject);
   
-  if ($MESSAGE['structure'])
+  if ($MESSAGE['structure'] = $IMAP->get_structure($MESSAGE['UID']))
     list($MESSAGE['parts'], $MESSAGE['attachments']) = rcmail_parse_message(
       $MESSAGE['structure'],
       array('safe' => (bool)$_GET['_safe'],

--
Gitblit v1.9.1