+ // target input (TODO: lists)
+
+ if ($rule['test'] == 'header') {
+ $out .= $select_op->show(($rule['not'] ? 'not' : '').$rule['type']);
+ $target = $rule['arg2'];
+ }
+ else if ($rule['test'] == 'size') {
+ $out .= $select_op->show();
+ if (preg_match('/^([0-9]+)(K|M|G)*$/', $rule['arg'], $matches)) {
+ $sizetarget = $matches[1];
+ $sizeitem = $matches[2];
+ }
+ }
+ else {
+ $out .= $select_op->show(($rule['not'] ? 'not' : '').$rule['test']);
+ $target = '';
+ }
+
+ $out .= '<input type="text" name="_rule_target[]" id="rule_target' .$id. '"
+ value="' .Q($target). '" size="20" ' . $this->error_class($id, 'test', 'target', 'rule_target')
+ . ' style="display:' . ($rule['test']!='size' && $rule['test'] != 'exists' ? 'inline' : 'none') . '" />'."\n";
+
+ $select_size_op = new html_select(array('name' => "_rule_size_op[]", 'id' => 'rule_size_op'.$id));
+ $select_size_op->add(Q($this->gettext('filterunder')), 'under');
+ $select_size_op->add(Q($this->gettext('filterover')), 'over');
+
+ $out .= '<div id="rule_size' .$id. '" style="display:' . ($rule['test']=='size' ? 'inline' : 'none') .'">';
+ $out .= $select_size_op->show($rule['test']=='size' ? $rule['type'] : '');
+ $out .= '<input type="text" name="_rule_size_target[]" id="rule_size_i'.$id.'" value="'.$sizetarget.'" size="10" '
+ . $this->error_class($id, 'test', 'sizetarget', 'rule_size_i') .' />
+ <input type="radio" name="_rule_size_item['.$id.']" value=""'
+ . (!$sizeitem ? ' checked="checked"' : '') .' class="radio" />'.rcube_label('B').'
+ <input type="radio" name="_rule_size_item['.$id.']" value="K"'
+ . ($sizeitem=='K' ? ' checked="checked"' : '') .' class="radio" />'.rcube_label('KB').'
+ <input type="radio" name="_rule_size_item['.$id.']" value="M"'
+ . ($sizeitem=='M' ? ' checked="checked"' : '') .' class="radio" />'.rcube_label('MB').'
+ <input type="radio" name="_rule_size_item['.$id.']" value="G"'
+ . ($sizeitem=='G' ? ' checked="checked"' : '') .' class="radio" />'.rcube_label('GB');
+ $out .= '</div>';
+ $out .= '</td>';
+
+ // add/del buttons
+ $out .= '<td class="rowbuttons">';
+ $out .= '<input type="button" id="ruleadd' . $id .'" value="'. Q($this->gettext('add')). '"
+ onclick="rcmail.managesieve_ruleadd(' . $id .')" class="button" /> ';
+ $out .= '<input type="button" id="ruledel' . $id .'" value="'. Q($this->gettext('del')). '"
+ onclick="rcmail.managesieve_ruledel(' . $id .')" class="button' . ($rows_num<2 ? ' disabled' : '') .'"'
+ . ($rows_num<2 ? ' disabled="disabled"' : '') .' />';
+ $out .= '</td></tr></table>';
+
+ $out .= $div ? "</div>\n" : '';
+
+ return $out;
+ }
+
+ 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' => 'action_type'.$id,
+ 'onchange' => 'action_type_select(' .$id .')'));
+ if (in_array('fileinto', $this->exts))
+ $select_action->add(Q($this->gettext('messagemoveto')), 'fileinto');
+ if (in_array('fileinto', $this->exts) && in_array('copy', $this->exts))
+ $select_action->add(Q($this->gettext('messagecopyto')), 'fileinto_copy');
+ $select_action->add(Q($this->gettext('messageredirect')), 'redirect');
+ if (in_array('copy', $this->exts))
+ $select_action->add(Q($this->gettext('messagesendcopy')), 'redirect_copy');
+ if (in_array('reject', $this->exts))
+ $select_action->add(Q($this->gettext('messagediscard')), 'reject');
+ else if (in_array('ereject', $this->exts))
+ $select_action->add(Q($this->gettext('messagediscard')), 'ereject');
+ if (in_array('vacation', $this->exts))
+ $select_action->add(Q($this->gettext('messagereply')), 'vacation');
+ $select_action->add(Q($this->gettext('messagedelete')), 'discard');
+ $select_action->add(Q($this->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">';
+ // shared targets
+ $out .= '<input type="text" name="_action_target[]" id="action_target' .$id. '" '
+ .'value="' .($action['type']=='redirect' ? Q($action['target'], 'strict', false) : ''). '" size="40" '
+ .'style="display:' .($action['type']=='redirect' ? 'inline' : 'none') .'" '
+ . $this->error_class($id, 'action', 'target', 'action_target') .' />';
+ $out .= '<textarea name="_action_target_area[]" id="action_target_area' .$id. '" '
+ .'rows="3" cols="40" '. $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')) ? Q($action['target'], 'strict', false) : '')
+ . "</textarea>\n";
+
+ // vacation
+ $out .= '<div id="action_vacation' .$id.'" style="display:' .($action['type']=='vacation' ? 'inline' : 'none') .'">';
+ $out .= '<span class="label">'. Q($this->gettext('vacationreason')) .'</span><br />'
+ .'<textarea name="_action_reason[]" id="action_reason' .$id. '" '
+ .'rows="3" cols="40" '. $this->error_class($id, 'action', 'reason', 'action_reason') . '>'
+ . Q($action['reason'], 'strict', false) . "</textarea>\n";
+ $out .= '<br /><span class="label">' .Q($this->gettext('vacationaddresses')) . '</span><br />'
+ .'<input type="text" name="_action_addresses[]" id="action_addr'.$id.'" '
+ .'value="' . (is_array($action['addresses']) ? Q(implode(', ', $action['addresses']), 'strict', false) : $action['addresses']) . '" size="40" '
+ . $this->error_class($id, 'action', 'addresses', 'action_addr') .' />';
+ $out .= '<br /><span class="label">' . Q($this->gettext('vacationdays')) . '</span><br />'
+ .'<input type="text" name="_action_days[]" id="action_days'.$id.'" '
+ .'value="' .Q($action['days'], 'strict', false) . '" size="2" '
+ . $this->error_class($id, 'action', 'days', 'action_days') .' />';
+ $out .= '</div>';
+
+ // mailbox select
+ $out .= '<select id="action_mailbox' .$id. '" name="_action_mailbox[]" style="display:'
+ .(!isset($action) || $action['type']=='fileinto' ? 'inline' : 'none'). '">';
+
+ $this->rc->imap_connect();
+
+ $a_folders = $this->rc->imap->list_mailboxes();
+ $delimiter = $this->rc->imap->get_hierarchy_delimiter();
+
+ // set mbox encoding
+ $mbox_encoding = $this->rc->config->get('managesieve_mbox_encoding', 'UTF7-IMAP');
+
+ if ($action['type'] == 'fileinto')
+ $mailbox = $action['target'];
+ else
+ $mailbox = '';
+
+ foreach ($a_folders as $folder) {
+ $utf7folder = $this->rc->imap->mod_mailbox($folder);
+ $names = explode($delimiter, rcube_charset_convert($folder, 'UTF7-IMAP'));
+ $name = $names[sizeof($names)-1];
+
+ if ($replace_delimiter = $this->rc->config->get('managesieve_replace_delimiter'))
+ $utf7folder = str_replace($delimiter, $replace_delimiter, $utf7folder);
+
+ // convert to Sieve implementation encoding
+ $utf7folder = $this->mbox_encode($utf7folder, $mbox_encoding);
+
+ if ($folder_class = rcmail_folder_classname($name))
+ $foldername = $this->gettext($folder_class);
+ else
+ $foldername = $name;
+
+ $out .= sprintf('<option value="%s"%s>%s%s</option>'."\n",
+ htmlspecialchars($utf7folder),
+ ($mailbox == $utf7folder ? ' selected="selected"' : ''),
+ str_repeat(' ', 4 * (sizeof($names)-1)),
+ Q(abbreviate_string($foldername, 40 - (2 * sizeof($names)-1))));
+ }
+ $out .= '</select>';
+ $out .= '</td>';
+
+ // add/del buttons
+ $out .= '<td class="rowbuttons">';
+ $out .= '<input type="button" id="actionadd' . $id .'" value="'. Q($this->gettext('add')). '"
+ onclick="rcmail.managesieve_actionadd(' . $id .')" class="button" /> ';
+ $out .= '<input type="button" id="actiondel' . $id .'" value="'. Q($this->gettext('del')). '"
+ onclick="rcmail.managesieve_actiondel(' . $id .')" class="button' . ($rows_num<2 ? ' disabled' : '') .'"'
+ . ($rows_num<2 ? ' disabled="disabled"' : '') .' />';
+ $out .= '</td>';
+
+ $out .= '</tr></table>';
+
+ $out .= $div ? "</div>\n" : '';
+
+ return $out;