From 74d7841c2643434fbd3e8759f160bda05f82ab0d Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Tue, 21 Aug 2012 05:23:17 -0400
Subject: [PATCH] Merge branch 'master' of github.com:roundcube/roundcubemail

---
 CHANGELOG                             |    2 
 program/js/common.js                  |    1 
 skins/classic/splitter.js             |    4 
 program/include/rcube_utils.php       |    5 +
 tests/Utils.php                       |   74 ++++++++++++++++++++++++
 config/main.inc.php.dist              |    7 +
 program/include/rcube.php             |    5 +
 program/include/rcube_output_html.php |    5 +
 program/steps/mail/func.inc           |    4 +
 tests/phpunit.xml                     |    1 
 program/localization/en_US/labels.inc |    5 -
 program/js/googiespell.js             |    4 
 program/localization/pl_PL/labels.inc |    1 
 program/js/app.js                     |    8 ++
 skins/larry/ui.js                     |    6 +-
 15 files changed, 118 insertions(+), 14 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 6a7b214..784bbc8 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,8 @@
 ===========================
 
 - Fix so subscribed non-existing/non-accessible shared folder can be unsubscribed
+- Added session_path config option and unified cookies settings in javascript
+- Added "Undeleted" option to messages list filter
 - Rewritten test scripts for PHPUnit
 - Add new DB abstraction layer based on PHP PDO, supporting SQLite3 (#1488332)
 - Removed PEAR::MDB2 package
diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index 1e9c1fd..8d615f3 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -241,12 +241,15 @@
 // must be greater than 'keep_alive'/60
 $rcmail_config['session_lifetime'] = 10;
 
-// session domain: .example.org
+// Session domain: .example.org
 $rcmail_config['session_domain'] = '';
 
-// session name. Default: 'roundcube_sessid'
+// Session name. Default: 'roundcube_sessid'
 $rcmail_config['session_name'] = null;
 
+// Session path. Defaults to PHP session.cookie_path setting.
+$rcmail_config['session_path'] = null;
+
 // Backend to use for session storage. Can either be 'db' (default) or 'memcache'
 // If set to memcache, a list of servers need to be specified in 'memcache_hosts'
 // Make sure the Memcache extension (http://pecl.php.net/package/memcache) version >= 2.0.0 is installed
diff --git a/program/include/rcube.php b/program/include/rcube.php
index 84014ef..0e40b3c 100644
--- a/program/include/rcube.php
+++ b/program/include/rcube.php
@@ -405,12 +405,17 @@
 
         $sess_name   = $this->config->get('session_name');
         $sess_domain = $this->config->get('session_domain');
+        $sess_path   = $this->config->get('session_path');
         $lifetime    = $this->config->get('session_lifetime', 0) * 60;
 
         // set session domain
         if ($sess_domain) {
             ini_set('session.cookie_domain', $sess_domain);
         }
+        // set session path
+        if ($sess_path) {
+            ini_set('session.cookie_path', $sess_path);
+        }
         // set session garbage collecting time according to session_lifetime
         if ($lifetime) {
             ini_set('session.gc_maxlifetime', $lifetime * 2);
diff --git a/program/include/rcube_output_html.php b/program/include/rcube_output_html.php
index 0a8f0e3..a071ee3 100644
--- a/program/include/rcube_output_html.php
+++ b/program/include/rcube_output_html.php
@@ -67,6 +67,11 @@
         $this->set_env('task', $task);
         $this->set_env('x_frame_options', $this->config->get('x_frame_options', 'sameorigin'));
 
+        // add cookie info
+        $this->set_env('cookie_domain', ini_get('session.cookie_domain'));
+        $this->set_env('cookie_path', ini_get('session.cookie_path'));
+        $this->set_env('cookie_secure', ini_get('session.cookie_secure'));
+
         // load the correct skin (in case user-defined)
         $skin = $this->config->get('skin');
         $this->set_skin($skin);
diff --git a/program/include/rcube_utils.php b/program/include/rcube_utils.php
index d1a8315..9f18b79 100644
--- a/program/include/rcube_utils.php
+++ b/program/include/rcube_utils.php
@@ -110,6 +110,11 @@
                 }
             }
 
+            // last domain part
+            if (preg_match('/[^a-zA-Z]/', array_pop($domain_array))) {
+                return false;
+            }
+
             $rcube = rcube::get_instance();
 
             if (!$dns_check || !$rcube->config->get('email_dns_check')) {
diff --git a/program/js/app.js b/program/js/app.js
index e8bb6c1..9ca16b3 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -6585,6 +6585,12 @@
     return 0;
   };
 
+  // Cookie setter
+  this.set_cookie = function(name, value, expires)
+  {
+    setCookie(name, value, expires, this.env.cookie_path, this.env.cookie_domain, this.env.cookie_secure);
+  }
+
 }  // end object rcube_webmail
 
 
@@ -6615,6 +6621,8 @@
   }
 };
 
+rcube_webmail.prototype.get_cookie = getCookie;
+
 // copy event engine prototype
 rcube_webmail.prototype.addEventListener = rcube_event_engine.prototype.addEventListener;
 rcube_webmail.prototype.removeEventListener = rcube_event_engine.prototype.removeEventListener;
diff --git a/program/js/common.js b/program/js/common.js
index fdef345..a08387e 100644
--- a/program/js/common.js
+++ b/program/js/common.js
@@ -635,6 +635,7 @@
   return unescape(dc.substring(begin + prefix.length, end));
 };
 
+// deprecated aliases, to be removed, use rcmail.set_cookie/rcmail.get_cookie
 roundcube_browser.prototype.set_cookie = setCookie;
 roundcube_browser.prototype.get_cookie = getCookie;
 
diff --git a/program/js/googiespell.js b/program/js/googiespell.js
index 9f1b41b..478858b 100644
--- a/program/js/googiespell.js
+++ b/program/js/googiespell.js
@@ -25,7 +25,7 @@
 function GoogieSpell(img_dir, server_url, has_dict)
 {
     var ref = this,
-        cookie_value = getCookie('language');
+        cookie_value = rcmail.get_cookie('language');
 
     GOOGIE_CUR_LANG = cookie_value != null ? cookie_value : GOOGIE_DEFAULT_LANG;
 
@@ -150,7 +150,7 @@
     //Set cookie
     var now = new Date();
     now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
-    setCookie('language', lan_code, now);
+    rcmail.set_cookie('language', lan_code, now);
 };
 
 this.setForceWidthHeight = function(width, height)
diff --git a/program/localization/en_US/labels.inc b/program/localization/en_US/labels.inc
index 94bae19..6085b38 100644
--- a/program/localization/en_US/labels.inc
+++ b/program/localization/en_US/labels.inc
@@ -1,7 +1,6 @@
 <?php
 
 /*
-
  +-----------------------------------------------------------------------+
  | language/en_US/labels.inc                                             |
  |                                                                       |
@@ -15,9 +14,6 @@
  +-----------------------------------------------------------------------+
  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
  +-----------------------------------------------------------------------+
-
- @version $Id$
-
 */
 
 $labels = array();
@@ -163,6 +159,7 @@
 $labels['flagged'] = 'Flagged';
 $labels['unanswered'] = 'Unanswered';
 $labels['deleted'] = 'Deleted';
+$labels['undeleted'] = 'Not deleted';
 $labels['invert'] = 'Invert';
 $labels['filter'] = 'Filter';
 $labels['list'] = 'List';
diff --git a/program/localization/pl_PL/labels.inc b/program/localization/pl_PL/labels.inc
index 92da1f6..d5ffcaa 100644
--- a/program/localization/pl_PL/labels.inc
+++ b/program/localization/pl_PL/labels.inc
@@ -134,6 +134,7 @@
 $labels['flagged'] = 'Oznaczone';
 $labels['unanswered'] = 'Bez odpowiedzi';
 $labels['deleted'] = 'Usunięte';
+$labels['undeleted'] = 'Nieusunięte';
 $labels['invert'] = 'Odwróć';
 $labels['filter'] = 'Filtr';
 $labels['list'] = 'Lista';
diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index 3d65eac..7f0b4db 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -1712,8 +1712,10 @@
   $select_filter->add(rcube_label('unread'), 'UNSEEN');
   $select_filter->add(rcube_label('flagged'), 'FLAGGED');
   $select_filter->add(rcube_label('unanswered'), 'UNANSWERED');
-  if (!$CONFIG['skip_deleted'])
+  if (!$CONFIG['skip_deleted']) {
     $select_filter->add(rcube_label('deleted'), 'DELETED');
+    $select_filter->add(rcube_label('undeleted'), 'UNDELETED');
+  }
   $select_filter->add(rcube_label('priority').': '.rcube_label('highest'), 'HEADER X-PRIORITY 1');
   $select_filter->add(rcube_label('priority').': '.rcube_label('high'), 'HEADER X-PRIORITY 2');
   $select_filter->add(rcube_label('priority').': '.rcube_label('normal'), 'NOT HEADER X-PRIORITY 1 NOT HEADER X-PRIORITY 2 NOT HEADER X-PRIORITY 4 NOT HEADER X-PRIORITY 5');
diff --git a/skins/classic/splitter.js b/skins/classic/splitter.js
index 59ebb51..3f1c973 100644
--- a/skins/classic/splitter.js
+++ b/skins/classic/splitter.js
@@ -47,7 +47,7 @@
       rcube_event.add_listener({element: window, event:'resize', object:this, method:'onResize'});
 
     // read saved position from cookie
-    var cookie = bw.get_cookie(this.id);
+    var cookie = rcmail.get_cookie(this.id);
     if (cookie && !isNaN(cookie)) {
       this.pos = parseFloat(cookie);
       this.resize();
@@ -197,7 +197,7 @@
   {
     var exp = new Date();
     exp.setYear(exp.getFullYear() + 1);
-    bw.set_cookie(this.id, this.pos, exp);
+    rcmail.set_cookie(this.id, this.pos, exp);
   };
 
 } // end class rcube_splitter
diff --git a/skins/larry/ui.js b/skins/larry/ui.js
index b6056b6..ca16807 100644
--- a/skins/larry/ui.js
+++ b/skins/larry/ui.js
@@ -461,7 +461,7 @@
     var button = $(e.target),
       frame = $('#mailpreviewframe'),
       visible = !frame.is(':visible'),
-      splitter = mailviewsplit.pos || parseInt(bw.get_cookie('mailviewsplitter') || 320),
+      splitter = mailviewsplit.pos || parseInt(rcmail.get_cookie('mailviewsplitter') || 320),
       topstyles, bottomstyles, uid;
 
     frame.toggle();
@@ -974,7 +974,7 @@
       $(window).resize(onResize);
 
     // read saved position from cookie
-    var cookie = bw.get_cookie(this.id);
+    var cookie = rcmail.get_cookie(this.id);
     if (cookie && !isNaN(cookie)) {
       this.pos = parseFloat(cookie);
       this.resize();
@@ -1135,7 +1135,7 @@
   {
     var exp = new Date();
     exp.setYear(exp.getFullYear() + 1);
-    bw.set_cookie(this.id, this.pos, exp);
+    rcmail.set_cookie(this.id, this.pos, exp);
   };
 
 } // end class rcube_splitter
diff --git a/tests/Utils.php b/tests/Utils.php
new file mode 100644
index 0000000..648b399
--- /dev/null
+++ b/tests/Utils.php
@@ -0,0 +1,74 @@
+<?php
+
+/**
+ * Test class to test rcube_utils class
+ *
+ * @package Tests
+ */
+class Utils extends PHPUnit_Framework_TestCase
+{
+
+    /**
+     * Valid email addresses for test_valid_email()
+     */
+    function data_valid_email()
+    {
+        return array(
+            array('email@domain.com', 'Valid email'),
+            array('firstname.lastname@domain.com', 'Email contains dot in the address field'),
+            array('email@subdomain.domain.com', 'Email contains dot with subdomain'),
+            array('firstname+lastname@domain.com', 'Plus sign is considered valid character'),
+            array('email@123.123.123.123', 'Domain is valid IP address'),
+            array('email@[123.123.123.123]', 'Square bracket around IP address is considered valid'),
+            array('"email"@domain.com', 'Quotes around email is considered valid'),
+            array('1234567890@domain.com', 'Digits in address are valid'),
+            array('email@domain-one.com', 'Dash in domain name is valid'),
+            array('_______@domain.com', 'Underscore in the address field is valid'),
+            array('email@domain.name', '.name is valid Top Level Domain name'),
+            array('email@domain.co.jp', 'Dot in Top Level Domain name also considered valid (use co.jp as example here)'),
+            array('firstname-lastname@domain.com', 'Dash in address field is valid'),
+        );
+    }
+
+    /**
+     * Invalid email addresses for test_invalid_email()
+     */
+    function data_invalid_email()
+    {
+        return array(
+            array('plainaddress', 'Missing @ sign and domain'),
+            array('#@%^%#$@#$@#.com', 'Garbage'),
+            array('@domain.com', 'Missing username'),
+            array('Joe Smith <email@domain.com>', 'Encoded html within email is invalid'),
+            array('email.domain.com', 'Missing @'),
+            array('email@domain@domain.com', 'Two @ sign'),
+            array('.email@domain.com', 'Leading dot in address is not allowed'),
+            array('email.@domain.com', 'Trailing dot in address is not allowed'),
+            array('email..email@domain.com', 'Multiple dots'),
+            array('あいうえお@domain.com', 'Unicode char as address'),
+            array('email@domain.com (Joe Smith)', 'Text followed email is not allowed'),
+            array('email@domain', 'Missing top level domain (.com/.net/.org/etc)'),
+            array('email@-domain.com', 'Leading dash in front of domain is invalid'),
+//            array('email@domain.web', '.web is not a valid top level domain'),
+            array('email@111.222.333.44444', 'Invalid IP format'),
+            array('email@domain..com', 'Multiple dot in the domain portion is invalid'),
+        );
+    }
+
+    /**
+     * @dataProvider data_valid_email
+     */
+    function test_valid_email($email, $title)
+    {
+        $this->assertTrue(rcube_utils::check_email($email, false), $title);
+    }
+
+    /**
+     * @dataProvider data_invalid_email
+     */
+    function test_invalid_email($email, $title)
+    {
+        $this->assertFalse(rcube_utils::check_email($email, false), $title);
+    }
+
+}
diff --git a/tests/phpunit.xml b/tests/phpunit.xml
index 4a3b883..cfd066e 100644
--- a/tests/phpunit.xml
+++ b/tests/phpunit.xml
@@ -7,6 +7,7 @@
             <file>MailDecode.php</file>
             <file>MailFunc.php</file>
             <file>ModCss.php</file>
+            <file>Utils.php</file>
             <file>VCards.php</file>
         </testsuite>
     </testsuites>

--
Gitblit v1.9.1