Merge pull request #24 from pawel-slowik/master

Sieve plugin - Initial support for enotify/notify (RFC5435, RFC5436)
pull/30/head
Aleksander Machniak 12 years ago
commit 1446775097

@ -403,6 +403,26 @@ class rcube_sieve_script
$action_script .= self::escape_string($action['name']) . ' ' . self::escape_string($action['value']); $action_script .= self::escape_string($action['name']) . ' ' . self::escape_string($action['value']);
break; break;
case 'notify':
array_push($exts, 'enotify');
$action_script .= 'notify';
foreach (array('from', 'importance', 'options', 'message') as $n_tag) {
if (!empty($action[$n_tag])) {
$action_script .= " :$n_tag " . self::escape_string($action[$n_tag]);
}
}
if (!empty($action['address'])) {
$method = 'mailto:' . $action['address'];
if (!empty($action['body'])) {
$method .= '?body=' . rawurlencode($action['body']);
}
}
else {
$method = $action['method'];
}
$action_script .= " " . self::escape_string($method);
break;
case 'vacation': case 'vacation':
array_push($exts, 'vacation'); array_push($exts, 'vacation');
$action_script .= 'vacation'; $action_script .= 'vacation';
@ -840,6 +860,34 @@ class rcube_sieve_script
// $result[] = array('type' => 'require', 'target' => $tokens); // $result[] = array('type' => 'require', 'target' => $tokens);
break; break;
case 'notify':
$notify = array('type' => 'notify', 'method' => array_pop($tokens));
// Parameters: :from, :importance, :options, :message
for ($i=0, $len=count($tokens); $i<$len; $i++) {
$tok = strtolower($tokens[$i]);
if ($tok[0] == ':') {
$notify[substr($tok, 1)] = $tokens[$i+1];
}
}
$method_components = parse_url($notify['method']);
if ($method_components['scheme'] == 'mailto') {
$notify['address'] = $method_components['path'];
$method_params = array();
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'] = (array_key_exists('body', $method_params)) ? $method_params['body'] : '';
}
$result[] = $notify;
break;
} }
if ($separator == $end) if ($separator == $end)

@ -97,6 +97,15 @@ $labels['setvariable'] = 'Set variable';
$labels['setvarname'] = 'Variable name:'; $labels['setvarname'] = 'Variable name:';
$labels['setvarvalue'] = 'Variable value:'; $labels['setvarvalue'] = 'Variable value:';
$labels['setvarmodifiers'] = 'Modifiers:'; $labels['setvarmodifiers'] = 'Modifiers:';
$labels['notify'] = 'Send notification';
$labels['notifyaddress'] = 'To e-mail address:';
$labels['notifybody'] = 'Notification body:';
$labels['notifysubject'] = 'Notification subject:';
$labels['notifyfrom'] = 'Notification sender:';
$labels['notifyimportance'] = 'Importance:';
$labels['notifyimportancelow'] = 'low';
$labels['notifyimportancenormal'] = 'normal';
$labels['notifyimportancehigh'] = 'high';
$labels['filtercreate'] = 'Create filter'; $labels['filtercreate'] = 'Create filter';
$labels['usedata'] = 'Use following data in the filter:'; $labels['usedata'] = 'Use following data in the filter:';
$labels['nextstep'] = 'Next Step'; $labels['nextstep'] = 'Next Step';

@ -88,6 +88,15 @@ $labels['varlowerfirst'] = 'first character lower-case';
$labels['varupperfirst'] = 'first character upper-case'; $labels['varupperfirst'] = 'first character upper-case';
$labels['varquotewildcard'] = 'quote special characters'; $labels['varquotewildcard'] = 'quote special characters';
$labels['varlength'] = 'length'; $labels['varlength'] = 'length';
$labels['notify'] = 'Send notification';
$labels['notifyaddress'] = 'To e-mail address:';
$labels['notifybody'] = 'Notification body:';
$labels['notifysubject'] = 'Notification subject:';
$labels['notifyfrom'] = 'Notification sender:';
$labels['notifyimportance'] = 'Importance:';
$labels['notifyimportancelow'] = 'low';
$labels['notifyimportancenormal'] = 'normal';
$labels['notifyimportancehigh'] = 'high';
$labels['filtercreate'] = 'Create filter'; $labels['filtercreate'] = 'Create filter';
$labels['usedata'] = 'Use following data in the filter:'; $labels['usedata'] = 'Use following data in the filter:';
$labels['nextstep'] = 'Next Step'; $labels['nextstep'] = 'Next Step';

@ -103,6 +103,15 @@ $labels['varlowerfirst'] = 'pierwsza litera mała (:lowerfirst)';
$labels['varupperfirst'] = 'pierwsza litera duża (:upperfirst)'; $labels['varupperfirst'] = 'pierwsza litera duża (:upperfirst)';
$labels['varquotewildcard'] = 'anulowane znaki specjalne (:quotewildcard)'; $labels['varquotewildcard'] = 'anulowane znaki specjalne (:quotewildcard)';
$labels['varlength'] = 'długość (:length)'; $labels['varlength'] = 'długość (:length)';
$labels['notify'] = 'Wyślij powiadomienie';
$labels['notifyaddress'] = 'Na adres e-mail:';
$labels['notifybody'] = 'Treść powiadomienia:';
$labels['notifysubject'] = 'Temat powiadomienia:';
$labels['notifyfrom'] = 'Nadawca powiadomienia:';
$labels['notifyimportance'] = 'Priorytet:';
$labels['notifyimportancelow'] = 'niski';
$labels['notifyimportancenormal'] = 'normalny';
$labels['notifyimportancehigh'] = 'wysoki';
$labels['filtercreate'] = 'Utwórz filtr'; $labels['filtercreate'] = 'Utwórz filtr';
$labels['usedata'] = 'Użyj następujących danych do utworzenia filtra:'; $labels['usedata'] = 'Użyj następujących danych do utworzenia filtra:';
$labels['nextstep'] = 'Następny krok'; $labels['nextstep'] = 'Następny krok';

@ -639,7 +639,8 @@ function action_type_select(id)
target_area: document.getElementById('action_target_area' + id), target_area: document.getElementById('action_target_area' + id),
flags: document.getElementById('action_flags' + id), flags: document.getElementById('action_flags' + id),
vacation: document.getElementById('action_vacation' + id), vacation: document.getElementById('action_vacation' + id),
set: document.getElementById('action_set' + id) set: document.getElementById('action_set' + id),
notify: document.getElementById('action_notify' + id)
}; };
if (obj.value == 'fileinto' || obj.value == 'fileinto_copy') { if (obj.value == 'fileinto' || obj.value == 'fileinto_copy') {
@ -660,6 +661,9 @@ function action_type_select(id)
else if (obj.value == 'set') { else if (obj.value == 'set') {
enabled.set = 1; enabled.set = 1;
} }
else if (obj.value == 'notify') {
enabled.notify = 1;
}
for (var x in elems) { for (var x in elems) {
elems[x].style.display = !enabled[x] ? 'none' : 'inline'; elems[x].style.display = !enabled[x] ? 'none' : 'inline';

@ -625,6 +625,11 @@ class managesieve extends rcube_plugin
$varnames = get_input_value('_action_varname', RCUBE_INPUT_POST); $varnames = get_input_value('_action_varname', RCUBE_INPUT_POST);
$varvalues = get_input_value('_action_varvalue', RCUBE_INPUT_POST); $varvalues = get_input_value('_action_varvalue', RCUBE_INPUT_POST);
$varmods = get_input_value('_action_varmods', RCUBE_INPUT_POST); $varmods = get_input_value('_action_varmods', RCUBE_INPUT_POST);
$notifyaddrs = get_input_value('_action_notifyaddress', RCUBE_INPUT_POST);
$notifybodies = get_input_value('_action_notifybody', RCUBE_INPUT_POST);
$notifymessages = get_input_value('_action_notifymessage', RCUBE_INPUT_POST);
$notifyfrom = get_input_value('_action_notifyfrom', RCUBE_INPUT_POST);
$notifyimp = get_input_value('_action_notifyimportance', RCUBE_INPUT_POST);
// we need a "hack" for radiobuttons // we need a "hack" for radiobuttons
foreach ($sizeitems as $item) foreach ($sizeitems as $item)
@ -878,6 +883,23 @@ class managesieve extends rcube_plugin
$this->errors['actions'][$i]['value'] = $this->gettext('cannotbeempty'); $this->errors['actions'][$i]['value'] = $this->gettext('cannotbeempty');
} }
break; break;
case 'notify':
if (empty($notifyaddrs[$idx])) {
$this->errors['actions'][$i]['address'] = $this->gettext('cannotbeempty');
}
else if (!check_email($notifyaddrs[$idx])) {
$this->errors['actions'][$i]['address'] = $this->gettext('noemailwarning');
}
if (!empty($notifyfrom[$idx]) && !check_email($notifyfrom[$idx])) {
$this->errors['actions'][$i]['from'] = $this->gettext('noemailwarning');
}
$this->form['actions'][$i]['address'] = $notifyaddrs[$idx];
$this->form['actions'][$i]['body'] = $notifybodies[$idx];
$this->form['actions'][$i]['message'] = $notifymessages[$idx];
$this->form['actions'][$i]['from'] = $notifyfrom[$idx];
$this->form['actions'][$i]['importance'] = $notifyimp[$idx];
break;
} }
$this->form['actions'][$i]['type'] = $type; $this->form['actions'][$i]['type'] = $type;
@ -1479,6 +1501,9 @@ class managesieve extends rcube_plugin
if (in_array('variables', $this->exts)) { if (in_array('variables', $this->exts)) {
$select_action->add(Q($this->gettext('setvariable')), 'set'); $select_action->add(Q($this->gettext('setvariable')), 'set');
} }
if (in_array('enotify', $this->exts)) {
$select_action->add(Q($this->gettext('notify')), 'notify');
}
$select_action->add(Q($this->gettext('rulestop')), 'stop'); $select_action->add(Q($this->gettext('rulestop')), 'stop');
$select_type = $action['type']; $select_type = $action['type'];
@ -1571,6 +1596,41 @@ class managesieve extends rcube_plugin
} }
$out .= '</div>'; $out .= '</div>';
// notify
// skip :options tag - not used by the mailto method
$out .= '<div id="action_notify' .$id.'" style="display:' .($action['type']=='notify' ? 'inline' : 'none') .'">';
$out .= '<span class="label">' .Q($this->gettext('notifyaddress')) . '</span><br />'
.'<input type="text" name="_action_notifyaddress['.$id.']" id="action_notifyaddress'.$id.'" '
.'value="' . Q($action['address']) . '" size="35" '
. $this->error_class($id, 'action', 'address', 'action_notifyaddress') .' />';
$out .= '<br /><span class="label">'. Q($this->gettext('notifybody')) .'</span><br />'
.'<textarea name="_action_notifybody['.$id.']" id="action_notifybody' .$id. '" '
.'rows="3" cols="35" '. $this->error_class($id, 'action', 'method', 'action_notifybody') . '>'
. Q($action['body'], 'strict', false) . "</textarea>\n";
$out .= '<br /><span class="label">' .Q($this->gettext('notifysubject')) . '</span><br />'
.'<input type="text" name="_action_notifymessage['.$id.']" id="action_notifymessage'.$id.'" '
.'value="' . Q($action['message']) . '" size="35" '
. $this->error_class($id, 'action', 'message', 'action_notifymessage') .' />';
$out .= '<br /><span class="label">' .Q($this->gettext('notifyfrom')) . '</span><br />'
.'<input type="text" name="_action_notifyfrom['.$id.']" id="action_notifyfrom'.$id.'" '
.'value="' . Q($action['from']) . '" size="35" '
. $this->error_class($id, 'action', 'from', 'action_notifyfrom') .' />';
$importance_options = array(
3 => 'notifyimportancelow',
2 => 'notifyimportancenormal',
1 => 'notifyimportancehigh'
);
$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(Q($this->gettext($io_n)), $io_v);
}
$out .= '<br /><span class="label">' . Q($this->gettext('notifyimportance')) . '</span><br />';
$out .= $select_importance->show(array(intval($action['importance'])));
$out .= '</div>';
// mailbox select // mailbox select
if ($action['type'] == 'fileinto') if ($action['type'] == 'fileinto')
$mailbox = $this->mod_mailbox($action['target'], 'out'); $mailbox = $this->mod_mailbox($action['target'], 'out');

@ -0,0 +1,19 @@
require ["enotify","variables"];
# rule:[notify1]
if header :contains "from" "boss@example.org"
{
notify :importance "1" :message "This is probably very important" "mailto:alm@example.com";
stop;
}
# rule:[subject]
if header :matches "Subject" "*"
{
set "subject" "${1}";
}
# rule:[from notify2]
if header :matches "From" "*"
{
set "from" "${1}";
notify :importance "3" :message "${from}: ${subject}" "mailto:alm@example.com";
}

@ -0,0 +1,18 @@
require ["envelope","variables","enotify"];
# rule:[from]
if envelope :all :matches "from" "*"
{
set "env_from" " [really: ${1}]";
}
# rule:[subject]
if header :matches "Subject" "*"
{
set "subject" "${1}";
}
# rule:[from notify]
if address :all :matches "from" "*"
{
set "from_addr" "${1}";
notify :message "${from_addr}${env_from}: ${subject}" "mailto:alm@example.com";
}
Loading…
Cancel
Save