From fb5255e2f0bcd69b7fd45889bcda0fd4ad332ca1 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Wed, 26 Feb 2014 20:23:46 +0100 Subject: Fix filter creation from an email when preview frame is disabled (#1489647) --- plugins/managesieve/Changelog | 1 + plugins/managesieve/managesieve.js | 16 +++++++--- plugins/managesieve/managesieve.php | 62 ++++++++++++++++++++++++------------- 3 files changed, 54 insertions(+), 25 deletions(-) diff --git a/plugins/managesieve/Changelog b/plugins/managesieve/Changelog index 974495acd..559390f34 100644 --- a/plugins/managesieve/Changelog +++ b/plugins/managesieve/Changelog @@ -7,6 +7,7 @@ - Fix issue in displaying filter form when managesieve_kolab_master=true and sieve variables extension is supported by the server (#1489599) - Fix wrong action folder selection if managesieve_domains is not empty (#1489617) +- Fix filter creation from an email when preview frame is disabled (#1489647) * version 7.1 [2013-11-22] ----------------------------------------------------------- diff --git a/plugins/managesieve/managesieve.js b/plugins/managesieve/managesieve.js index 8e344ad54..6b36127d3 100644 --- a/plugins/managesieve/managesieve.js +++ b/plugins/managesieve/managesieve.js @@ -801,9 +801,17 @@ rcube_webmail.prototype.managesieve_tip_register = function(tips) /********* Mail UI methods *********/ /*********************************************************/ -rcube_webmail.prototype.managesieve_create = function() +rcube_webmail.prototype.managesieve_create = function(force) { - if (!rcmail.env.sieve_headers || !rcmail.env.sieve_headers.length) + if (!force && this.env.action != 'show' && !$('#'+this.env.contentframe).is(':visible')) { + var uid = this.message_list.get_single_selection(), + lock = this.set_busy(true, 'loading'); + + this.http_post('plugin.managesieve-action', {_uid: uid}, lock); + return; + } + + if (!this.env.sieve_headers || !this.env.sieve_headers.length) return; var i, html, buttons = {}, dialog = $("#sievefilterform"); @@ -816,9 +824,9 @@ rcube_webmail.prototype.managesieve_create = function() // build dialog window content html = '
'+this.gettext('managesieve.usedata')+'
'; dialog.html(html); diff --git a/plugins/managesieve/managesieve.php b/plugins/managesieve/managesieve.php index 7a7faee4c..aa74c52b0 100644 --- a/plugins/managesieve/managesieve.php +++ b/plugins/managesieve/managesieve.php @@ -137,30 +137,12 @@ class managesieve extends rcube_plugin $this->mail_headers_done = true; - $headers = $args['headers']; - $ret = array(); - - if ($headers->subject) - $ret[] = array('Subject', rcube_mime::decode_header($headers->subject)); - - // @TODO: List-Id, others? - foreach (array('From', 'To') as $h) { - $hl = strtolower($h); - if ($headers->$hl) { - $list = rcube_mime::decode_address_list($headers->$hl); - foreach ($list as $item) { - if ($item['mailto']) { - $ret[] = array($h, $item['mailto']); - } - } - } - } + $headers = $this->parse_headers($args['headers']); if ($this->rc->action == 'preview') - $this->rc->output->command('parent.set_env', array('sieve_headers' => $ret)); + $this->rc->output->command('parent.set_env', array('sieve_headers' => $headers)); else - $this->rc->output->set_env('sieve_headers', $ret); - + $this->rc->output->set_env('sieve_headers', $headers); return $args; } @@ -170,6 +152,18 @@ class managesieve extends rcube_plugin */ function managesieve_actions() { + // handle fetching email headers for the new filter form + if ($uid = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_GPC)) { + $mailbox = $this->rc->get_storage()->get_folder(); + $message = new rcube_message($uid, $mailbox); + $headers = $this->parse_headers($message->headers); + + $this->rc->output->set_env('sieve_headers', $headers); + $this->rc->output->command('managesieve_create', true); + $this->rc->output->send(); + } + + // handle other action $this->init_ui(); $engine = $this->get_engine(); $engine->actions(); @@ -210,4 +204,30 @@ class managesieve extends rcube_plugin return $this->engine; } + + /** + * Extract mail headers for new filter form + */ + private function parse_headers($headers) + { + $result = array(); + + if ($headers->subject) + $result[] = array('Subject', rcube_mime::decode_header($headers->subject)); + + // @TODO: List-Id, others? + foreach (array('From', 'To') as $h) { + $hl = strtolower($h); + if ($headers->$hl) { + $list = rcube_mime::decode_address_list($headers->$hl); + foreach ($list as $item) { + if ($item['mailto']) { + $result[] = array($h, $item['mailto']); + } + } + } + } + + return $result; + } } -- cgit v1.2.3