From 92a030d928246cfc5f3c0b1f2538dc1bfb4777e3 Mon Sep 17 00:00:00 2001
From: Paweł Słowik <pawel.slowik@iq.pl>
Date: Tue, 04 Sep 2012 08:59:15 -0400
Subject: [PATCH] Added tests, fixed PHP warnings

---
 plugins/managesieve/lib/rcube_sieve_script.php |    6 ++++--
 plugins/managesieve/tests/src/parser_notify_a  |   16 ++++++++++++++++
 plugins/managesieve/tests/src/parser_notify_b  |   15 +++++++++++++++
 3 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/plugins/managesieve/lib/rcube_sieve_script.php b/plugins/managesieve/lib/rcube_sieve_script.php
index 66bedb5..3e418ed 100644
--- a/plugins/managesieve/lib/rcube_sieve_script.php
+++ b/plugins/managesieve/lib/rcube_sieve_script.php
@@ -868,13 +868,15 @@
                 if ($method_components['scheme'] == 'mailto') {
                     $notify['address'] = $method_components['path'];
                     $method_params = array();
-                    parse_str($method_components['query'], $method_params);
+                    if (array_key_exists('query', $method_components)) {
+                        parse_str($method_components['query'], $method_params);
+                    }
                     $method_params = array_change_key_case($method_params, CASE_LOWER);
                     /* magic_quotes_gpc and magic_quotes_sybase affect the output of parse_str */
                     if (ini_get('magic_quotes_gpc') || ini_get('magic_quotes_sybase')) {
                         array_map('stripslashes', $method_params);
                     }
-                    $notify['body'] = $method_params['body'];
+                    $notify['body'] = (array_key_exists('body', $method_params)) ? $method_params['body'] : '';
                 }
 
                 $result[] = $notify;
diff --git a/plugins/managesieve/tests/src/parser_notify_a b/plugins/managesieve/tests/src/parser_notify_a
new file mode 100644
index 0000000..324805a
--- /dev/null
+++ b/plugins/managesieve/tests/src/parser_notify_a
@@ -0,0 +1,16 @@
+require ["enotify","variables"];
+if header :contains "from" "boss@example.org"
+{
+	notify :importance "1" :message "This is probably very important" "mailto:alm@example.com";
+	stop;
+}
+if header :matches "Subject" "*"
+{
+	set "subject" "${1}";
+}
+if header :matches "From" "*"
+{
+	set "from" "${1}";
+}
+notify :importance "3" :message "${from}: ${subject}" "mailto:alm@example.com";
+
diff --git a/plugins/managesieve/tests/src/parser_notify_b b/plugins/managesieve/tests/src/parser_notify_b
new file mode 100644
index 0000000..5378985
--- /dev/null
+++ b/plugins/managesieve/tests/src/parser_notify_b
@@ -0,0 +1,15 @@
+require ["envelope","variables","enotify"];
+if envelope :all :matches "from" "*"
+{
+	set "env_from" " [really: ${1}]";
+}
+if header :matches "Subject" "*"
+{
+	set "subject" "${1}";
+}
+if address :all :matches "from" "*"
+{
+	set "from_addr" "${1}";
+}
+notify :message "${from_addr}${env_from}: ${subject}" "mailto:alm@example.com";
+

--
Gitblit v1.9.1