From 749b07c78a29b03c63812c3ec3630b16db4baa8f Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Wed, 14 Dec 2005 18:47:32 -0500
Subject: [PATCH] IMAP bugfixes, better signature handling

---
 index.php                            |    2 
 program/include/main.inc             |   13 ++++--
 program/steps/mail/compose.inc       |    2 
 program/localization/nl/messages.inc |    4 +-
 program/steps/mail/func.inc          |   30 ++++++++++++---
 program/steps/mail/sendmail.inc      |    3 +
 program/js/app.js                    |   18 ++++++---
 program/include/rcube_imap.inc       |    2 
 8 files changed, 51 insertions(+), 23 deletions(-)

diff --git a/index.php b/index.php
index 31d4e75..3141cab 100644
--- a/index.php
+++ b/index.php
@@ -3,7 +3,7 @@
 /*
  +-----------------------------------------------------------------------+
  | RoundCube Webmail IMAP Client                                         |
- | Version 0.1-20051018                                                  |
+ | Version 0.1-20051214                                                  |
  |                                                                       |
  | Copyright (C) 2005, RoundCube Dev. - Switzerland                      |
  | Licensed under the GNU GPL                                            |
diff --git a/program/include/main.inc b/program/include/main.inc
index 40ca1d4..6c4591d 100644
--- a/program/include/main.inc
+++ b/program/include/main.inc
@@ -1098,15 +1098,18 @@
   $now = time();  // local time
   $now -= (int)date('Z'); // make GMT time
   $now += ($CONFIG['timezone'] * 3600); // user's time
+  $now_date = getdate();
 
-  $day_secs = 60*((int)date('H', $now)*60 + (int)date('i', $now));
-  $week_secs = 60 * 60 * 24 * 7;
-  $diff = $now - $timestamp;
+  //$day_secs = 60*((int)date('H', $now)*60 + (int)date('i', $now));
+  //$week_secs = 60 * 60 * 24 * 7;
+  //$diff = $now - $timestamp;
+  $today_limit = mktime(0, 0, 0, $now_date['mon'], $now_date['mday'], $now_date['year']);
+  $week_limit = mktime(0, 0, 0, $now_date['mon'], $now_date['mday']-6, $now_date['year']);
 
   // define date format depending on current time  
-  if ($CONFIG['prettydate'] && !$format && $diff < $day_secs)
+  if ($CONFIG['prettydate'] && !$format && $timestamp > $today_limit)
     return sprintf('%s %s', rcube_label('today'), date('H:i', $timestamp));
-  else if ($CONFIG['prettydate'] && !$format && $diff < $week_secs)
+  else if ($CONFIG['prettydate'] && !$format && $timestamp > $week_limit)
     $format = $CONFIG['date_short'] ? $CONFIG['date_short'] : 'D H:i';
   else if (!$format)
     $format = $CONFIG['date_long'] ? $CONFIG['date_long'] : 'd.m.Y H:i';
diff --git a/program/include/rcube_imap.inc b/program/include/rcube_imap.inc
index cc30b3f..593225d 100644
--- a/program/include/rcube_imap.inc
+++ b/program/include/rcube_imap.inc
@@ -480,7 +480,7 @@
     // cache is OK
     if ($cache_status>0)
       {
-      $a_index = get_message_cache_index($cache_key, FALSE, $this->sort_field);
+      $a_index = $this->get_message_cache_index($cache_key, FALSE, $this->sort_field);
       return array_values($a_index);
       }
 
diff --git a/program/js/app.js b/program/js/app.js
index d65af42..a7445e2 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -6,7 +6,7 @@
  | Copyright (C) 2005, RoundCube Dev, - Switzerland                      |
  | Licensed under the GNU GPL                                            |
  |                                                                       |
- | Modified: 2005/11/13 (roundcube)                                      |
+ | Modified: 2005/12/14 (roundcube)                                      |
  |                                                                       |
  +-----------------------------------------------------------------------+
  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
@@ -1356,24 +1356,30 @@
     var id = obj.options[obj.selectedIndex].value;
     var input_message = rcube_find_object('_message');
     var message = input_message ? input_message.value : '';
+    var sig, p;
 
     // remove the 'old' signature
     if (this.env.identity && this.env.signatures && this.env.signatures[this.env.identity])
       {
-      var sig = this.env.signatures[this.env.identity];
-      
-      if (p = message.lastIndexOf(sig))
+      sig = this.env.signatures[this.env.identity];
+      if (sig.indexOf('-- ')!=0)
+        sig = '-- \n'+sig;
+
+      p = message.lastIndexOf(sig);
+      if (p>=0)
         message = message.substring(0, p-1) + message.substring(p+sig.length, message.length);
       }
 
     // add the new signature string
     if (this.env.signatures && this.env.signatures[id])
       {
-      var sig = this.env.signatures[id];
+      sig = this.env.signatures[id];
+      if (sig.indexOf('-- ')!=0)
+        sig = '-- \n'+sig;
       message += '\n'+sig;
       }
 
-    if (input_message && message)
+    if (input_message)
       input_message.value = message;
       
     this.env.identity = id;
diff --git a/program/localization/nl/messages.inc b/program/localization/nl/messages.inc
index 1c9fba9..39909e9 100644
--- a/program/localization/nl/messages.inc
+++ b/program/localization/nl/messages.inc
@@ -42,9 +42,9 @@
 
 $messages['contactexists'] = 'Een contactpersoon met dit e-mail adres bestaat al';
 
-$messages['blockedimages'] = 'Om je privacy te beschermen zijn externe afbeeldingen zijn geblokkeerd in dit bericht.';
+$messages['blockedimages'] = 'Om je privacy te beschermen zijn externe afbeeldingen geblokkeerd in dit bericht.';
 
-$messages['encryptedmessage'] = 'Dit is een versleuteld bericht en kan niet worden weergegeven. Sorry!';
+$messages['encryptedmessage'] = 'Dit bericht is versleuteld en kan niet worden weergegeven. Sorry!';
 
 $messages['nocontactsfound'] = 'Geen contactpersonen gevonden';
 
diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index 45f1112..6aca28d 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -353,7 +353,7 @@
            
 
   // try to remove the signature
-  if ($sp = strrpos($body, '--'))
+  if ($sp = strrpos($body, '-- '))
     {
     if ($body{$sp+3}==' ' || $body{$sp+3}=="\n" || $body{$sp+3}=="\r")
       $body = substr($body, 0, $sp-1);
diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index 74a9678..c430467 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -161,6 +161,7 @@
   foreach ($arrFolders as $key => $folder)
     {
     $zebra_class = ($nestLevel*$idx)%2 ? 'even' : 'odd';
+    $title = '';
 
     $folder_lc = strtolower($folder['id']);
     if (in_array($folder_lc, $special))
@@ -171,7 +172,12 @@
 
       // shorten the folder name to a given length
       if ($maxlength && $maxlength>1)
-        $foldername = abbrevate_string($foldername, $maxlength);
+        {
+        $fname = abbrevate_string($foldername, $maxlength);
+        if ($fname != $foldername)
+          $title = ' title="'.rep_specialchars_output($foldername, 'html', 'all').'"';
+        $foldername = $fname;
+        }
       }
 
     // add unread message count display
@@ -191,7 +197,7 @@
     else if ($folder['id']==$CONFIG['junk_mbox'])
       $class_name = 'junk';
 
-    $out .= sprintf('<li id="rcmbx%s" class="mailbox %s %s%s%s"><a href="./#%s" onclick="return %s.command(\'list\',\'%s\')" onmouseup="return %s.mbox_mouse_up(\'%s\')">%s</a>',
+    $out .= sprintf('<li id="rcmbx%s" class="mailbox %s %s%s%s"><a href="./#%s" onclick="return %s.command(\'list\',\'%s\')" onmouseup="return %s.mbox_mouse_up(\'%s\')"%s>%s</a>',
                     $folder_css,
                     $class_name,
                     $zebra_class,
@@ -202,6 +208,7 @@
                     $folder['id'],
                     $JS_OBJECT_NAME,
                     $folder['id'],
+                    $title,
                     rep_specialchars_output($foldername, 'html', 'all'));
 
     if (!empty($folder['folders']))
@@ -1008,6 +1015,9 @@
 // modify a HTML message that it can be displayed inside a HTML page
 function rcmail_mod_html_body($body, $container_id)
   {
+  // remove any null-byte characters before parsing
+  $body = preg_replace('/\x00/', '', $body);
+  
   $last_style_pos = 0;
   $body_lc = strtolower($body);
   
@@ -1157,15 +1167,18 @@
   else
     $headers = &$cached;
 
-
-  $message_id = $headers->messageID;
+  // create unique identifier based on message_id
+  if (!empty($headers->messageID))
+    $message_id = md5($headers->messageID);
+  else
+    $message_id = md5($headers->uid.'@'.$_SESSION['imap_host']);
   
   $temp_dir = $CONFIG['temp_dir'].(!eregi('\/$', $CONFIG['temp_dir']) ? '/' : '');
   $cache_dir = $temp_dir.$_SESSION['client_id'];
   $cache_path = $cache_dir.'/'.$message_id;
 
   // message is cached in temp dir
-  if (is_dir($cache_dir) && is_file($cache_path))
+  if ($CONFIG['enable_caching'] && is_dir($cache_dir) && is_file($cache_path))
     {
     if ($fp = fopen($cache_path, 'r'))
       {
@@ -1178,9 +1191,14 @@
 
   // get message from server
   $msg_source = $IMAP->get_raw_body($uid);
+  
+  // return message source without caching
+  if (!$CONFIG['enable_caching'])
+    return $msg_source;
+
 
   // let's cache the message body within the database
-  if ($CONFIG['enable_caching'] && $cached && ($CONFIG['db_max_length'] -300) > $headers->size)
+  if ($cached && ($CONFIG['db_max_length'] -300) > $headers->size)
     {
     $DB->query("UPDATE ".get_table_name('messages')."
                 SET    body=?
diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc
index 6a3b511..3c9f603 100644
--- a/program/steps/mail/sendmail.inc
+++ b/program/steps/mail/sendmail.inc
@@ -277,9 +277,10 @@
 // log mail sending
 if ($CONFIG['smtp_log'])
   {
-  $log_entry = sprintf("[%s] User: %d; Message for %s; Subject: %s\n",
+  $log_entry = sprintf("[%s] User: %d on %s; Message for %s; Subject: %s\n",
                date("d-M-Y H:i:s O", mktime()),
                $_SESSION['user_id'],
+               $_SERVER['REMOTE_ADDR'],
                $mailto,
                $msg_subject);
 

--
Gitblit v1.9.1