Example #1
0
 function test_parse_regexp_tests()
 {
     $tests = array(array('test' => 'header', 'type' => 'regex', 'arg1' => 'received', 'arg2' => '(20|21|22|23|24|25|26|27|28) Feb 2014'), array('test' => 'header', 'type' => 'regex', 'arg1' => 'received', 'arg2' => '([ 0]1|[ 0]2|[ 0]3|[ 0]4|[ 0]5) Mar 2014'));
     $result = rcube_sieve_vacation::parse_regexp_tests($tests);
     $this->assertCount(2, $result);
     $this->assertSame('20 Feb 2014', $result['from']);
     $this->assertSame('05 Mar 2014', $result['to']);
 }
 function action_div($fid, $id, $div = true)
 {
     $action = isset($this->form) ? $this->form['actions'][$id] : $this->script[$fid]['actions'][$id];
     $rows_num = isset($this->form) ? sizeof($this->form['actions']) : sizeof($this->script[$fid]['actions']);
     $out = $div ? '<div class="actionrow" id="actionrow' . $id . '">' . "\n" : '';
     $out .= '<table><tr><td class="rowactions">';
     // action select
     $select_action = new html_select(array('name' => "_action_type[{$id}]", 'id' => 'action_type' . $id, 'onchange' => 'action_type_select(' . $id . ')'));
     if (in_array('fileinto', $this->exts)) {
         $select_action->add(rcube::Q($this->plugin->gettext('messagemoveto')), 'fileinto');
     }
     if (in_array('fileinto', $this->exts) && in_array('copy', $this->exts)) {
         $select_action->add(rcube::Q($this->plugin->gettext('messagecopyto')), 'fileinto_copy');
     }
     $select_action->add(rcube::Q($this->plugin->gettext('messageredirect')), 'redirect');
     if (in_array('copy', $this->exts)) {
         $select_action->add(rcube::Q($this->plugin->gettext('messagesendcopy')), 'redirect_copy');
     }
     if (in_array('reject', $this->exts)) {
         $select_action->add(rcube::Q($this->plugin->gettext('messagediscard')), 'reject');
     } else {
         if (in_array('ereject', $this->exts)) {
             $select_action->add(rcube::Q($this->plugin->gettext('messagediscard')), 'ereject');
         }
     }
     if (in_array('vacation', $this->exts)) {
         $select_action->add(rcube::Q($this->plugin->gettext('messagereply')), 'vacation');
     }
     $select_action->add(rcube::Q($this->plugin->gettext('messagedelete')), 'discard');
     if (in_array('imapflags', $this->exts) || in_array('imap4flags', $this->exts)) {
         $select_action->add(rcube::Q($this->plugin->gettext('setflags')), 'setflag');
         $select_action->add(rcube::Q($this->plugin->gettext('addflags')), 'addflag');
         $select_action->add(rcube::Q($this->plugin->gettext('removeflags')), 'removeflag');
     }
     if (in_array('variables', $this->exts)) {
         $select_action->add(rcube::Q($this->plugin->gettext('setvariable')), 'set');
     }
     if (in_array('enotify', $this->exts) || in_array('notify', $this->exts)) {
         $select_action->add(rcube::Q($this->plugin->gettext('notify')), 'notify');
     }
     $select_action->add(rcube::Q($this->plugin->gettext('messagekeep')), 'keep');
     $select_action->add(rcube::Q($this->plugin->gettext('rulestop')), 'stop');
     $select_type = $action['type'];
     if (in_array($action['type'], array('fileinto', 'redirect')) && $action['copy']) {
         $select_type .= '_copy';
     }
     $out .= $select_action->show($select_type);
     $out .= '</td>';
     // actions target inputs
     $out .= '<td class="rowtargets">';
     // force domain selection in redirect email input
     $domains = (array) $this->rc->config->get('managesieve_domains');
     if (!empty($domains)) {
         sort($domains);
         $domain_select = new html_select(array('name' => "_action_target_domain[{$id}]", 'id' => 'action_target_domain' . $id));
         $domain_select->add(array_combine($domains, $domains));
         if ($action['type'] == 'redirect') {
             $parts = explode('@', $action['target']);
             if (!empty($parts)) {
                 $action['domain'] = array_pop($parts);
                 $action['target'] = implode('@', $parts);
             }
         }
     }
     // redirect target
     $out .= '<span id="redirect_target' . $id . '" style="white-space:nowrap;' . ' display:' . ($action['type'] == 'redirect' ? 'inline' : 'none') . '">' . '<input type="text" name="_action_target[' . $id . ']" id="action_target' . $id . '"' . ' value="' . ($action['type'] == 'redirect' ? rcube::Q($action['target'], 'strict', false) : '') . '"' . (!empty($domains) ? ' size="20"' : ' size="35"') . $this->error_class($id, 'action', 'target', 'action_target') . ' />' . (!empty($domains) ? ' @ ' . $domain_select->show($action['domain']) : '') . '</span>';
     // (e)reject target
     $out .= '<textarea name="_action_target_area[' . $id . ']" id="action_target_area' . $id . '" ' . 'rows="3" cols="35" ' . $this->error_class($id, 'action', 'targetarea', 'action_target_area') . 'style="display:' . (in_array($action['type'], array('reject', 'ereject')) ? 'inline' : 'none') . '">' . (in_array($action['type'], array('reject', 'ereject')) ? rcube::Q($action['target'], 'strict', false) : '') . "</textarea>\n";
     // vacation
     $vsec = in_array('vacation-seconds', $this->exts);
     $auto_addr = $this->rc->config->get('managesieve_vacation_addresses_init');
     $addresses = isset($action['addresses']) || !$auto_addr ? (array) $action['addresses'] : $this->user_emails();
     $out .= '<div id="action_vacation' . $id . '" style="display:' . ($action['type'] == 'vacation' ? 'inline' : 'none') . '">';
     $out .= '<span class="label">' . rcube::Q($this->plugin->gettext('vacationreason')) . '</span><br />' . '<textarea name="_action_reason[' . $id . ']" id="action_reason' . $id . '" ' . 'rows="3" cols="35" ' . $this->error_class($id, 'action', 'reason', 'action_reason') . '>' . Q($action['reason'], 'strict', false) . "</textarea>\n";
     $out .= '<br /><span class="label">' . rcube::Q($this->plugin->gettext('vacationsubject')) . '</span><br />' . '<input type="text" name="_action_subject[' . $id . ']" id="action_subject' . $id . '" ' . 'value="' . (is_array($action['subject']) ? rcube::Q(implode(', ', $action['subject']), 'strict', false) : $action['subject']) . '" size="35" ' . $this->error_class($id, 'action', 'subject', 'action_subject') . ' />';
     $out .= '<br /><span class="label">' . rcube::Q($this->plugin->gettext('vacationaddr')) . '</span><br />' . $this->list_input($id, 'action_addresses', $addresses, true, $this->error_class($id, 'action', 'addresses', 'action_addresses'), 30) . html::a(array('href' => '#', 'onclick' => rcmail_output::JS_OBJECT_NAME . ".managesieve_vacation_addresses({$id})"), rcube::Q($this->plugin->gettext('filladdresses')));
     $out .= '<br /><span class="label">' . rcube::Q($this->plugin->gettext($vsec ? 'vacationinterval' : 'vacationdays')) . '</span><br />' . '<input type="text" name="_action_interval[' . $id . ']" id="action_interval' . $id . '" ' . 'value="' . rcube::Q(rcube_sieve_vacation::vacation_interval($action), 'strict', false) . '" size="2" ' . $this->error_class($id, 'action', 'interval', 'action_interval') . ' />';
     if ($vsec) {
         $out .= '&nbsp;<label><input type="radio" name="_action_interval_type[' . $id . ']" value="days"' . (!isset($action['seconds']) ? ' checked="checked"' : '') . ' class="radio" />' . $this->plugin->gettext('days') . '</label>' . '&nbsp;<label><input type="radio" name="_action_interval_type[' . $id . ']" value="seconds"' . (isset($action['seconds']) ? ' checked="checked"' : '') . ' class="radio" />' . $this->plugin->gettext('seconds') . '</label>';
     }
     $out .= '</div>';
     // flags
     $flags = array('read' => '\\Seen', 'answered' => '\\Answered', 'flagged' => '\\Flagged', 'deleted' => '\\Deleted', 'draft' => '\\Draft');
     $flags_target = (array) $action['target'];
     $out .= '<div id="action_flags' . $id . '" style="display:' . (preg_match('/^(set|add|remove)flag$/', $action['type']) ? 'inline' : 'none') . '"' . $this->error_class($id, 'action', 'flags', 'action_flags') . '>';
     foreach ($flags as $fidx => $flag) {
         $out .= '<input type="checkbox" name="_action_flags[' . $id . '][]" value="' . $flag . '"' . (in_array_nocase($flag, $flags_target) ? 'checked="checked"' : '') . ' />' . rcube::Q($this->plugin->gettext('flag' . $fidx)) . '<br>';
     }
     $out .= '</div>';
     // set variable
     $set_modifiers = array('lower', 'upper', 'lowerfirst', 'upperfirst', 'quotewildcard', 'length');
     $out .= '<div id="action_set' . $id . '" style="display:' . ($action['type'] == 'set' ? 'inline' : 'none') . '">';
     $out .= '<span class="label">' . rcube::Q($this->plugin->gettext('setvarname')) . '</span><br />' . '<input type="text" name="_action_varname[' . $id . ']" id="action_varname' . $id . '" ' . 'value="' . rcube::Q($action['name']) . '" size="35" ' . $this->error_class($id, 'action', 'name', 'action_varname') . ' />';
     $out .= '<br /><span class="label">' . rcube::Q($this->plugin->gettext('setvarvalue')) . '</span><br />' . '<input type="text" name="_action_varvalue[' . $id . ']" id="action_varvalue' . $id . '" ' . 'value="' . rcube::Q($action['value']) . '" size="35" ' . $this->error_class($id, 'action', 'value', 'action_varvalue') . ' />';
     $out .= '<br /><span class="label">' . rcube::Q($this->plugin->gettext('setvarmodifiers')) . '</span><br />';
     foreach ($set_modifiers as $s_m) {
         $s_m_id = 'action_varmods' . $id . $s_m;
         $out .= sprintf('<input type="checkbox" name="_action_varmods[%s][]" value="%s" id="%s"%s />%s<br>', $id, $s_m, $s_m_id, array_key_exists($s_m, (array) $action) && $action[$s_m] ? ' checked="checked"' : '', rcube::Q($this->plugin->gettext('var' . $s_m)));
     }
     $out .= '</div>';
     // notify
     $notify_methods = (array) $this->rc->config->get('managesieve_notify_methods');
     $importance_options = $this->notify_importance_options;
     if (empty($notify_methods)) {
         $notify_methods = $this->notify_methods;
     }
     list($method, $target) = explode(':', $action['method'], 2);
     $method = strtolower($method);
     if ($method && !in_array($method, $notify_methods)) {
         $notify_methods[] = $method;
     }
     $select_method = new html_select(array('name' => "_action_notifymethod[{$id}]", 'id' => "_action_notifymethod{$id}", 'class' => $this->error_class($id, 'action', 'method', 'action_notifymethod')));
     foreach ($notify_methods as $m_n) {
         $select_method->add(rcube::Q($this->rc->text_exists('managesieve.notifymethod' . $m_n) ? $this->plugin->gettext('managesieve.notifymethod' . $m_n) : $m_n), $m_n);
     }
     $select_importance = new html_select(array('name' => "_action_notifyimportance[{$id}]", 'id' => "_action_notifyimportance{$id}", 'class' => $this->error_class($id, 'action', 'importance', 'action_notifyimportance')));
     foreach ($importance_options as $io_v => $io_n) {
         $select_importance->add(rcube::Q($this->plugin->gettext($io_n)), $io_v);
     }
     // @TODO: nice UI for mailto: (other methods too) URI parameters
     $out .= '<div id="action_notify' . $id . '" style="display:' . ($action['type'] == 'notify' ? 'inline' : 'none') . '">';
     $out .= '<span class="label">' . rcube::Q($this->plugin->gettext('notifytarget')) . '</span><br />' . $select_method->show($method) . '<input type="text" name="_action_notifytarget[' . $id . ']" id="action_notifytarget' . $id . '" ' . 'value="' . rcube::Q($target) . '" size="25" ' . $this->error_class($id, 'action', 'target', 'action_notifytarget') . ' />';
     $out .= '<br /><span class="label">' . rcube::Q($this->plugin->gettext('notifymessage')) . '</span><br />' . '<textarea name="_action_notifymessage[' . $id . ']" id="action_notifymessage' . $id . '" ' . 'rows="3" cols="35" ' . $this->error_class($id, 'action', 'message', 'action_notifymessage') . '>' . rcube::Q($action['message'], 'strict', false) . "</textarea>\n";
     if (in_array('enotify', $this->exts)) {
         $out .= '<br /><span class="label">' . rcube::Q($this->plugin->gettext('notifyfrom')) . '</span><br />' . '<input type="text" name="_action_notifyfrom[' . $id . ']" id="action_notifyfrom' . $id . '" ' . 'value="' . rcube::Q($action['from']) . '" size="35" ' . $this->error_class($id, 'action', 'from', 'action_notifyfrom') . ' />';
     }
     $out .= '<br /><span class="label">' . rcube::Q($this->plugin->gettext('notifyimportance')) . '</span><br />';
     $out .= $select_importance->show($action['importance'] ? (int) $action['importance'] : 2);
     $out .= '<div id="action_notifyoption_div' . $id . '">' . '<span class="label">' . rcube::Q($this->plugin->gettext('notifyoptions')) . '</span><br />' . $this->list_input($id, 'action_notifyoption', (array) $action['options'], true, $this->error_class($id, 'action', 'options', 'action_notifyoption'), 30) . '</div>';
     $out .= '</div>';
     // mailbox select
     if ($action['type'] == 'fileinto') {
         $mailbox = $this->mod_mailbox($action['target'], 'out');
         // make sure non-existing (or unsubscribed) mailbox is listed (#1489956)
         $additional = array($mailbox);
     } else {
         $mailbox = '';
     }
     $select = $this->rc->folder_selector(array('realnames' => false, 'maxlength' => 100, 'id' => 'action_mailbox' . $id, 'name' => "_action_mailbox[{$id}]", 'style' => 'display:' . (empty($action['type']) || $action['type'] == 'fileinto' ? 'inline' : 'none'), 'additional' => $additional));
     $out .= $select->show($mailbox);
     $out .= '</td>';
     // add/del buttons
     $out .= '<td class="rowbuttons">';
     $out .= '<a href="#" id="actionadd' . $id . '" title="' . rcube::Q($this->plugin->gettext('add')) . '"
         onclick="rcmail.managesieve_actionadd(' . $id . ')" class="button add"></a>';
     $out .= '<a href="#" id="actiondel' . $id . '" title="' . rcube::Q($this->plugin->gettext('del')) . '"
         onclick="rcmail.managesieve_actiondel(' . $id . ')" class="button del' . ($rows_num < 2 ? ' disabled' : '') . '"></a>';
     $out .= '</td>';
     $out .= '</tr></table>';
     $out .= $div ? "</div>\n" : '';
     return $out;
 }