/** * */ function test_multiple_blockquotes() { $html = <<<EOF <br>Begin<br><blockquote>OUTER BEGIN<blockquote>INNER 1<br></blockquote><div><br></div><div>Par 1</div> <blockquote>INNER 2</blockquote><div><br></div><div>Par 2</div> <div><br></div><div>Par 3</div><div><br></div> <blockquote>INNER 3</blockquote>OUTER END</blockquote> EOF; $ht = new rcube_html2text($html, false, false); $res = $ht->get_text(); $this->assertContains('>> INNER 1', $res, 'Quote inner'); $this->assertContains('>> INNER 3', $res, 'Quote inner'); $this->assertContains('> OUTER END', $res, 'Quote outer'); }
function test_links() { $html = '<a href="http://test.com">content</a>'; $expected = 'content [1] Links: ------ [1] http://test.com '; $ht = new rcube_html2text($html, false, true); $res = $ht->get_text(); $this->assertSame($expected, $res, 'Links list'); // href == content (#1490434) $html = '<a href="http://test.com">http://test.com</a>'; $expected = 'http://test.com'; $ht = new rcube_html2text($html, false, true); $res = $ht->get_text(); $this->assertSame($expected, $res, 'Skip link with href == content'); }
function test_broken_blockquotes() { // no end tag $html = <<<EOF Begin<br> <blockquote>QUOTED TEXT <blockquote> NO END TAG FOUND EOF; $ht = new rcube_html2text($html, false, false); $res = $ht->get_text(); $this->assertContains('QUOTED TEXT NO END TAG FOUND', $res, 'No quoating on invalid html'); // with some (nested) end tags $html = <<<EOF Begin<br> <blockquote>QUOTED TEXT <blockquote>INNER 1</blockquote> <blockquote>INNER 2</blockquote> NO END TAG FOUND EOF; $ht = new rcube_html2text($html, false, false); $res = $ht->get_text(); $this->assertContains('QUOTED TEXT INNER 1 INNER 2 NO END', $res, 'No quoating on invalid html'); }
private function html2text($text) { $h2t = new rcube_html2text($text, false, true, 0); return $h2t->get_text(); }
/** * Return the first text part of this message * * @param rcube_message_part $part Reference to the part if found * @return string Plain text message/part content */ function first_text_part(&$part = null) { // no message structure, return complete body if (empty($this->parts)) { return $this->body; } // check all message parts foreach ($this->mime_parts as $mime_id => $part) { if ($part->mimetype == 'text/plain') { return $this->get_part_body($mime_id, true); } else { if ($part->mimetype == 'text/html') { $out = $this->get_part_body($mime_id, true); // create instance of html2text class $txt = new rcube_html2text($out); return $txt->get_text(); } } } $part = null; return null; }
/** * Convert an event object to be used on the client */ private function _client_event($event, $addcss = false) { // compose a human readable strings for alarms_text and recurrence_text if ($event['valarms']) { $event['alarms_text'] = libcalendaring::alarms_text($event['valarms']); $event['valarms'] = libcalendaring::to_client_alarms($event['valarms']); } if ($event['recurrence']) { $event['recurrence_text'] = $this->lib->recurrence_text($event['recurrence']); $event['recurrence'] = $this->lib->to_client_recurrence($event['recurrence'], $event['allday']); unset($event['recurrence_date']); } foreach ((array) $event['attachments'] as $k => $attachment) { $event['attachments'][$k]['classname'] = rcube_utils::file2class($attachment['mimetype'], $attachment['name']); } // convert link URIs references into structs if (array_key_exists('links', $event)) { foreach ((array) $event['links'] as $i => $link) { if (strpos($link, 'imap://') === 0 && ($msgref = $this->driver->get_message_reference($link))) { $event['links'][$i] = $msgref; } } } // check for organizer in attendees list $organizer = null; foreach ((array) $event['attendees'] as $i => $attendee) { if ($attendee['role'] == 'ORGANIZER') { $organizer = $attendee; } if ($attendee['status'] == 'DELEGATED' && $attendee['rsvp'] == false) { $event['attendees'][$i]['noreply'] = true; } else { unset($event['attendees'][$i]['noreply']); } } if ($organizer === null && !empty($event['organizer'])) { $organizer = $event['organizer']; $organizer['role'] = 'ORGANIZER'; if (!is_array($event['attendees'])) { $event['attendees'] = array(); } array_unshift($event['attendees'], $organizer); } // Convert HTML description into plain text if ($this->is_html($event)) { $h2t = new rcube_html2text($event['description'], false, true, 0); $event['description'] = trim($h2t->get_text()); } // mapping url => vurl because of the fullcalendar client script $event['vurl'] = $event['url']; unset($event['url']); return array('_id' => $event['calendar'] . ':' . $event['id'], 'start' => $this->lib->adjust_timezone($event['start'], $event['allday'])->format('c'), 'end' => $this->lib->adjust_timezone($event['end'], $event['allday'])->format('c'), 'changed' => $event['changed'] ? $this->lib->adjust_timezone($event['changed'])->format('c') : null, 'created' => $event['created'] ? $this->lib->adjust_timezone($event['created'])->format('c') : null, 'title' => strval($event['title']), 'description' => strval($event['description']), 'location' => strval($event['location']), 'className' => ($addcss ? 'fc-event-cal-' . asciiwords($event['calendar'], true) . ' ' : '') . 'fc-event-cat-' . asciiwords(strtolower(join('-', (array) $event['categories'])), true) . rtrim(' ' . $event['className']), 'allDay' => $event['allday'] == 1) + $event; }
/** * Return the first text part of this message. * If there's no text/plain part but $strict=true and text/html part * exists, it will be returned in text/plain format. * * @param rcube_message_part &$part Reference to the part if found * @param bool $strict Check only text/plain parts * * @return string Plain text message/part content */ public function first_text_part(&$part = null, $strict = false) { // no message structure, return complete body if (empty($this->parts)) { return $this->body; } if ($this->has_text_part($part)) { return $this->get_part_body($part->mime_id, true); } if (!$strict && ($body = $this->first_html_part($part, true))) { // create instance of html2text class $h2t = new rcube_html2text($body); return $h2t->get_text(); } }
/** * Converts HTML content into plain text * * @param string $html HTML content * @param array $options Conversion parameters (width, links, charset) * * @return string Plain text */ public function html2text($html, $options = array()) { $default_options = array('links' => true, 'width' => 75, 'body' => $html, 'charset' => RCUBE_CHARSET); $options = array_merge($default_options, (array) $options); // Plugins may want to modify HTML in another/additional way $options = $this->plugins->exec_hook('html2text', $options); // Convert to text if (!$options['abort']) { $converter = new rcube_html2text($options['body'], false, $options['links'], $options['width'], $options['charset']); $options['body'] = rtrim($converter->get_text()); } return $options['body']; }
/** * Prepare the given task record before sending it to the client */ private function encode_task(&$rec) { $rec['mask'] = $this->filter_mask($rec); $rec['flagged'] = intval($rec['flagged']); $rec['complete'] = floatval($rec['complete']); if (is_object($rec['created'])) { $rec['created_'] = $this->rc->format_date($rec['created']); $rec['created'] = $rec['created']->format('U'); } if (is_object($rec['changed'])) { $rec['changed_'] = $this->rc->format_date($rec['changed']); $rec['changed'] = $rec['changed']->format('U'); } else { $rec['changed'] = null; } if ($rec['date']) { try { $date = new DateTime($rec['date'] . ' ' . $rec['time'], $this->timezone); $rec['datetime'] = intval($date->format('U')); $rec['date'] = $date->format($this->rc->config->get('date_format', 'Y-m-d')); $rec['_hasdate'] = 1; } catch (Exception $e) { $rec['date'] = $rec['datetime'] = null; } } else { $rec['date'] = $rec['datetime'] = null; $rec['_hasdate'] = 0; } if ($rec['startdate']) { try { $date = new DateTime($rec['startdate'] . ' ' . $rec['starttime'], $this->timezone); $rec['startdatetime'] = intval($date->format('U')); $rec['startdate'] = $date->format($this->rc->config->get('date_format', 'Y-m-d')); } catch (Exception $e) { $rec['startdate'] = $rec['startdatetime'] = null; } } if ($rec['valarms']) { $rec['alarms_text'] = libcalendaring::alarms_text($rec['valarms']); $rec['valarms'] = libcalendaring::to_client_alarms($rec['valarms']); } if ($rec['recurrence']) { $rec['recurrence_text'] = $this->lib->recurrence_text($rec['recurrence']); $rec['recurrence'] = $this->lib->to_client_recurrence($rec['recurrence'], $rec['time'] || $rec['starttime']); } foreach ((array) $rec['attachments'] as $k => $attachment) { $rec['attachments'][$k]['classname'] = rcube_utils::file2class($attachment['mimetype'], $attachment['name']); } // convert link URIs references into structs if (array_key_exists('links', $rec)) { foreach ((array) $rec['links'] as $i => $link) { if (strpos($link, 'imap://') === 0 && ($msgref = $this->driver->get_message_reference($link))) { $rec['links'][$i] = $msgref; } } } // Convert HTML description into plain text if ($this->is_html($rec)) { $h2t = new rcube_html2text($rec['description'], false, true, 0); $rec['description'] = $h2t->get_text(); } if (!is_array($rec['tags'])) { $rec['tags'] = (array) $rec['tags']; } sort($rec['tags'], SORT_LOCALE_STRING); if (in_array($rec['id'], $this->collapsed_tasks)) { $rec['collapsed'] = true; } if (empty($rec['parent_id'])) { $rec['parent_id'] = null; } $this->task_titles[$rec['id']] = $rec['title']; }
private function _action_row($ext, $actions_table, $rowid, $action, $attrib, $example) { $rcmail = rcube::get_instance(); $help_icon = html::img(array('src' => $attrib['helpicon'], 'alt' => $this->gettext('messagehelp'), 'border' => 0)); // set default field display $display = array('vacadv' => $action['type'] == 'vacation' && $this->force_vacto ? '' : 'display: none;', 'vacfrom' => $this->show_vacfrom ? $display['vacadv'] : 'display: none;', 'vachandle' => $this->show_vachandle ? $display['vacadv'] : 'display: none;', 'noteadv' => 'display: none;', 'eheadadv' => 'display: none;'); // setup allowed actions $allowed_actions = array(); $config_actions = $rcmail->config->get('sieverules_allowed_actions', array()); if (in_array('fileinto', $ext) && ($config_actions['fileinto'] || $action['type'] == 'fileinto')) { $allowed_actions['fileinto'] = $this->gettext('messagemoveto'); } if (in_array('fileinto', $ext) && in_array('copy', $ext) && ($config_actions['fileinto'] || $action['type'] == 'fileinto')) { $allowed_actions['fileinto_copy'] = $this->gettext('messagecopyto'); } if (in_array('vacation', $ext) && ($config_actions['vacation'] || $action['type'] == 'vacation')) { $allowed_actions['vacation'] = $this->gettext('messagevacation'); } if (in_array('reject', $ext) && ($config_actions['reject'] || $action['type'] == 'reject')) { $allowed_actions['reject'] = $this->gettext('messagereject'); } elseif (in_array('ereject', $ext) && ($config_actions['reject'] || $action['type'] == 'ereject')) { $allowed_actions['ereject'] = $this->gettext('messagereject'); } if (in_array('imap4flags', $ext) && ($config_actions['imapflags'] || $action['type'] == 'imap4flags')) { $allowed_actions['imap4flags'] = $this->gettext('messageimapflags'); } elseif (in_array('imapflags', $ext) && ($config_actions['imapflags'] || $action['type'] == 'imapflags')) { $allowed_actions['imapflags'] = $this->gettext('messageimapflags'); } if (in_array('notify', $ext) && ($config_actions['notify'] || $action['type'] == 'notify')) { $allowed_actions['notify'] = $this->gettext('messagenotify'); } elseif (in_array('enotify', $ext) && ($config_actions['notify'] || $action['type'] == 'enotify')) { $allowed_actions['enotify'] = $this->gettext('messagenotify'); } if (in_array('editheader', $ext) && ($config_actions['editheaderadd'] || $action['type'] == 'editheaderadd')) { $allowed_actions['editheaderadd'] = $this->gettext('addheader'); } if (in_array('editheader', $ext) && ($config_actions['editheaderrem'] || $action['type'] == 'editheaderrem')) { $allowed_actions['editheaderrem'] = $this->gettext('removeheader'); } if ($config_actions['redirect'] || $action['type'] == 'redirect') { $allowed_actions['redirect'] = $this->gettext('messageredirect'); } if (in_array('copy', $ext) && ($config_actions['redirect'] || $action['type'] == 'redirect_copy')) { $allowed_actions['redirect_copy'] = $this->gettext('messageredirectcopy'); } if ($config_actions['keep'] || $action['type'] == 'keep') { $allowed_actions['keep'] = $this->gettext('messagekeep'); } if ($config_actions['discard'] || $action['type'] == 'discard') { $allowed_actions['discard'] = $this->gettext('messagediscard'); } if ($config_actions['stop'] || $action['type'] == 'stop') { $allowed_actions['stop'] = $this->gettext('messagestop'); } // set the default values reset($allowed_actions); $defaults = array('method' => key($allowed_actions), 'folder' => 'INBOX', 'reject' => '', 'vacto' => null, 'address' => '', 'period' => '', 'periodtype' => '', 'handle' => '', 'subject' => '', 'origsubject' => '', 'msg' => '', 'charset' => RCUBE_CHARSET, 'flags' => '', 'nfrom' => '', 'nimpt' => '', 'nmethod' => '', 'noptions' => '', 'nmsg' => ''); // set default identity for use in vacation action $identity = $rcmail->user->get_identity(); if ($this->show_vacfrom) { $defaults['vacfrom'] = in_array('variables', $ext) ? 'auto' : $identity['email']; } else { $defaults['vacfrom'] = null; } // apply current action values if ($action['type'] == 'fileinto' || $action['type'] == 'fileinto_copy') { $defaults['method'] = $action['type']; $defaults['folder'] = $action['target']; if ($encoding = $rcmail->config->get('sieverules_folder_encoding')) { $defaults['folder'] = rcube_charset::convert($defaults['folder'], $encoding, 'UTF7-IMAP'); } if ($delim = $rcmail->config->get('sieverules_folder_delimiter')) { $defaults['folder'] = str_replace($delim, $rcmail->storage->get_hierarchy_delimiter(), $defaults['folder']); } $defaults['folder'] = $rcmail->config->get('sieverules_include_imap_root', true) ? $defaults['folder'] : $rcmail->storage->mod_folder($defaults['folder'], 'IN'); } elseif ($action['type'] == 'reject' || $action['type'] == 'ereject') { $defaults['method'] = $action['type']; $defaults['reject'] = $action['target']; } elseif ($action['type'] == 'vacation') { $defaults['method'] = 'vacation'; if (isset($action['seconds'])) { $defaults['period'] = $action['seconds']; $defaults['periodtype'] = 'seconds'; } else { $defaults['period'] = $action['days']; $defaults['periodtype'] = 'days'; } $defaults['vacfromdefault'] = $defaults['vacfrom']; $defaults['vacfrom'] = $action['from']; $defaults['vacto'] = $action['addresses']; $defaults['handle'] = $action['handle']; $defaults['subject'] = $action['subject']; $defaults['origsubject'] = $action['origsubject']; $defaults['msg'] = $action['msg']; $defaults['htmlmsg'] = $action['htmlmsg'] ? '1' : ''; $defaults['charset'] = $action['charset']; if ($defaults['htmlmsg'] == '1' && $rcmail->config->get('htmleditor') == '0') { $h2t = new rcube_html2text($defaults['msg'], false, true, 0); $defaults['msg'] = $h2t->get_text(); $defaults['htmlmsg'] = ''; } elseif ($defaults['htmlmsg'] == '' && $rcmail->config->get('htmleditor') == '1') { $defaults['msg'] = $defaults['msg']; $defaults['msg'] = nl2br($defaults['msg']); $defaults['htmlmsg'] = '1'; } if (!$example) { $this->force_vacto = false; } // check advanced enabled if (!empty($defaults['vacfrom']) && $defaults['vacfrom'] != $defaults['vacfromdefault'] || !empty($defaults['vacto']) || !empty($defaults['handle']) || !empty($defaults['period']) || $defaults['charset'] != RCUBE_CHARSET || $this->force_vacto) { $display['vacadv'] = ''; $display['vacfrom'] = $this->show_vacfrom ? '' : 'display: none;'; $display['vachandle'] = $this->show_vachandle ? '' : 'display: none;'; } } elseif ($action['type'] == 'redirect' || $action['type'] == 'redirect_copy') { $defaults['method'] = $action['type']; $defaults['address'] = $action['target']; } elseif ($action['type'] == 'imapflags' || $action['type'] == 'imap4flags') { $defaults['method'] = $action['type']; $defaults['flags'] = $action['target']; } elseif ($action['type'] == 'notify' || $action['type'] == 'enotify') { $defaults['method'] = $action['type']; $defaults['nfrom'] = $action['from']; $defaults['nimpt'] = $action['importance']; $defaults['nmethod'] = $action['method']; $defaults['noptions'] = $action['options']; $defaults['nmsg'] = $action['msg']; // check advanced enabled if (!empty($defaults['nfrom']) || !empty($defaults['nimpt'])) { $display['noteadv'] = ''; } } elseif ($action['type'] == 'editheaderadd' || $action['type'] == 'editheaderrem') { $defaults['method'] = $action['type']; $defaults['headername'] = $action['name']; $defaults['headerval'] = $action['value']; $defaults['headerindex'] = $action['index']; $defaults['headerop'] = $action['operator']; if ($action['type'] == 'editheaderrem' && (!empty($defaults['headerindex']) || !empty($defaults['headerval']))) { $display['eheadadv'] = ''; } } elseif ($action['type'] == 'discard' || $action['type'] == 'keep' || $action['type'] == 'stop') { $defaults['method'] = $action['type']; } // hide the "template" row if (!isset($action)) { $actions_table->set_row_attribs(array('style' => 'display: none;')); } // action type select box $select_action = new html_select(array('name' => "_act[]", 'onchange' => rcmail_output::JS_OBJECT_NAME . '.sieverules_action_select(this)')); foreach ($allowed_actions as $value => $text) { $select_action->add($text, $value); } // add action type to UI $actions_table->add('action', $select_action->show($defaults['method'])); $vacs_table = $this->_vacation_table($ext, $rowid, $defaults, $display, $help_icon); // begin notify action $notify_table = new html_table(array('class' => 'records-table', 'cellspacing' => '0', 'cols' => 3, 'style' => $defaults['method'] == 'notify' || $defaults['method'] == 'enotify' ? '' : 'display: none;')); if (count($this->identities)) { $field_id = 'rcmfd_sievenotifyfrom_' . $rowid; $select_id = new html_select(array('id' => $field_id, 'name' => "_nfrom[]")); $select_id->add($this->gettext('autodetect'), ""); foreach ($this->identities as $sql_arr) { // find currently selected from address if ($defaults['nfrom'] != '' && $defaults['nfrom'] == rcmail::Q($sql_arr['from']['string'])) { $defaults['nfrom'] = $sql_arr['identity_id']; } elseif ($defaults['nfrom'] != '' && $defaults['nfrom'] == $sql_arr['from']['mailto']) { $defaults['nfrom'] = $sql_arr['identity_id']; } $select_id->add($sql_arr['from']['disp_string'], $sql_arr['identity_id']); } $notify_table->set_row_attribs(array('class' => 'advanced', 'style' => $display['noteadv'])); $notify_table->add(null, html::label($field_id, rcmail::Q($this->gettext('sievefrom')))); $notify_table->add(array('colspan' => 2), $select_id->show($defaults['nfrom'])); } $field_id = 'rcmfd_nmethod_' . $rowid; $input_method = new html_inputfield(array('id' => $field_id, 'name' => '_nmethod[]')); $notify_table->add(null, html::label($field_id, rcmail::Q($this->gettext('method')))); $notify_table->add(array('colspan' => 2), $input_method->show($defaults['nmethod'])); $field_id = 'rcmfd_noption_' . $rowid; $input_method = new html_inputfield(array('id' => $field_id, 'name' => '_noption[]')); $notify_table->add(null, html::label($field_id, rcmail::Q($this->gettext('options')))); $notify_table->add(array('colspan' => 2), $input_method->show($defaults['noptions'])); $notify_table->set_row_attribs(array('style' => 'display: none;')); $notify_table->add(array('colspan' => 3, 'class' => 'helpmsg'), $this->gettext('nmethodexp')); $field_id = 'rcmfd_nimpt_' . $rowid; $input_importance = new html_radiobutton(array('id' => $field_id . '_none', 'name' => '_notify_radio_' . $rowid, 'value' => 'none', 'onclick' => rcmail_output::JS_OBJECT_NAME . '.sieverules_notify_impt(this, ' . $rowid . ')', 'class' => 'radio')); $importance_show = $input_importance->show($defaults['nimpt']) . " " . html::label($field_id . '_none', rcmail::Q($this->gettext('importancen'))); $input_importance = new html_radiobutton(array('id' => $field_id . '_1', 'name' => '_notify_radio_' . $rowid, 'value' => '1', 'onclick' => rcmail_output::JS_OBJECT_NAME . '.sieverules_notify_impt(this, ' . $rowid . ')', 'class' => 'radio')); $importance_show .= ' ' . $input_importance->show($defaults['nimpt']) . " " . html::label($field_id . '_1', rcmail::Q($this->gettext('importance1'))); $input_importance = new html_radiobutton(array('id' => $field_id . '_2', 'name' => '_notify_radio_' . $rowid, 'value' => '2', 'onclick' => rcmail_output::JS_OBJECT_NAME . '.sieverules_notify_impt(this, ' . $rowid . ')', 'class' => 'radio')); $importance_show .= ' ' . $input_importance->show($defaults['nimpt']) . " " . html::label($field_id . '_2', rcmail::Q($this->gettext('importance2'))); $input_importance = new html_radiobutton(array('id' => $field_id . '_3', 'name' => '_notify_radio_' . $rowid, 'value' => '3', 'onclick' => rcmail_output::JS_OBJECT_NAME . '.sieverules_notify_impt(this, ' . $rowid . ')', 'class' => 'radio')); $importance_show .= ' ' . $input_importance->show($defaults['nimpt']) . " " . html::label($field_id . '_3', rcmail::Q($this->gettext('importance3'))); $input_importance = new html_hiddenfield(array('id' => 'rcmfd_sievenimpt_' . $rowid, 'name' => '_nimpt[]')); $notify_table->set_row_attribs(array('class' => 'advanced', 'style' => $display['noteadv'])); $notify_table->add(null, rcmail::Q($this->gettext('flag'))); $notify_table->add(array('colspan' => 2), $importance_show . $input_importance->show($defaults['nimpt'])); $field_id = 'rcmfd_nmsg_' . $rowid; $input_msg = new html_inputfield(array('id' => $field_id, 'name' => '_nmsg[]')); $notify_table->add(null, html::label($field_id, rcmail::Q($this->gettext('message')))); $notify_table->add(array('colspan' => 2), $input_msg->show($defaults['nmsg'])); if (in_array('enotify', $ext)) { $input_advopts = new html_checkbox(array('id' => 'nadvopts' . $rowid, 'name' => '_nadv_opts[]', 'onclick' => rcmail_output::JS_OBJECT_NAME . '.sieverules_show_adv(this);', 'value' => '1', 'class' => 'checkbox')); $notify_table->add(array('colspan' => '3', 'style' => 'text-align: right'), html::label('nadvopts' . $rowid, rcmail::Q($this->gettext('advancedoptions'))) . $input_advopts->show($display['noteadv'] == '' ? 1 : 0)); } // begin editheader action $headers_table = new html_table(array('class' => 'records-table', 'cellspacing' => '0', 'cols' => 2, 'style' => $defaults['method'] == 'editheaderadd' || $defaults['method'] == 'editheaderrem' ? '' : 'display: none;')); $field_id = 'rcmfd_eheadname_' . $rowid; $input_header = new html_inputfield(array('id' => $field_id, 'name' => '_eheadname[]')); $headers_table->add(null, html::label($field_id, rcmail::Q($this->gettext('headername')))); $headers_table->add(null, $input_header->show($defaults['headername'])); $field_id = 'rcmfd_eheadindex_' . $rowid; $select_index = new html_select(array('id' => $field_id, 'name' => "_eheadindex[]")); $select_index->add($this->gettext('headerdelall'), ""); $select_index->add("1", "1"); $select_index->add("2", "2"); $select_index->add("3", "3"); $select_index->add("4", "4"); $select_index->add("5", "5"); $select_index->add($this->gettext('last'), "last"); $headers_table->set_row_attribs(array('class' => 'advanced', 'style' => $display['eheadadv'])); $headers_table->add(null, html::label($field_id, rcmail::Q($this->gettext('headerindex')))); $headers_table->add(null, $select_index->show($defaults['headerindex'])); $field_id = 'rcmfd_eheadopp_' . $rowid; $select_match = new html_select(array('id' => $field_id, 'name' => "_eheadopp[]")); $select_match->add($this->gettext('filteris'), ""); $select_match->add($this->gettext('filtercontains'), "contains"); $headers_table->set_row_attribs(array('class' => 'advanced', 'style' => $display['eheadadv'])); $headers_table->add(null, html::label($field_id, rcmail::Q($this->gettext('operator')))); $headers_table->add(null, $select_match->show($defaults['headerop'])); $field_id = 'rcmfd_eheadval_' . $rowid; $input_header = new html_inputfield(array('id' => $field_id, 'name' => '_eheadval[]')); if ($defaults['method'] == 'editheaderrem') { $headers_table->set_row_attribs(array('class' => 'advanced', 'style' => $display['eheadadv'])); } $headers_table->add(null, html::label($field_id, rcmail::Q($this->gettext('headervalue')))); $headers_table->add(null, $input_header->show($defaults['headerval'])); if ($defaults['method'] == 'editheaderrem') { $headers_table->set_row_attribs(array('style' => 'display: none;')); } $field_id = 'rcmfd_eheadaddlast_' . $rowid; $input_index = new html_checkbox(array('id' => $field_id, 'value' => 'last', 'onclick' => rcmail_output::JS_OBJECT_NAME . '.sieverules_toggle_eheadlast(this);', 'name' => '_eheadaddlast[]', 'class' => 'checkbox')); $headers_table->add(null, ' '); $headers_table->add(null, $input_index->show($defaults['headerindex']) . " " . html::label($field_id, rcmail::Q($this->gettext('headerappend')))); if ($defaults['method'] == 'editheaderadd') { $headers_table->set_row_attribs(array('style' => 'display: none;')); } $input_advopts = new html_checkbox(array('id' => 'hadvopts' . $rowid, 'name' => '_hadv_opts[]', 'onclick' => rcmail_output::JS_OBJECT_NAME . '.sieverules_show_adv(this);', 'value' => '1', 'class' => 'checkbox')); $headers_table->add(array('colspan' => '3', 'style' => 'text-align: right'), html::label('nadvopts' . $rowid, rcmail::Q($this->gettext('advancedoptions'))) . $input_advopts->show($display['eheadadv'] == '' ? 1 : 0)); // begin fileinto action $mbox_name = $rcmail->storage->get_folder(); $input_folderlist = new html_select(array('name' => '_folder[]', 'onchange' => rcmail_output::JS_OBJECT_NAME . '.sieverules_select_folder(this);', 'style' => $defaults['method'] == 'fileinto' || $defaults['method'] == 'fileinto_copy' ? '' : 'display: none;', 'is_escaped' => true)); $rcmail->render_folder_tree_select($this->mailboxes, $mbox_name, 100, $input_folderlist, false); $show_customfolder = 'display: none;'; if ($rcmail->config->get('sieverules_fileinto_options', 0) == 2 && !$rcmail->storage->folder_exists($defaults['folder'])) { $customfolder = rcube_charset::convert($rcmail->storage->mod_folder($defaults['folder']), 'UTF7-IMAP'); $defaults['folder'] = '@@newfolder'; $show_customfolder = ''; } $input_customfolder = new html_inputfield(array('name' => '_customfolder[]')); $otherfolders = html::span(array('id' => 'customfolder_rowid', 'style' => $show_customfolder), '<br />' . $input_customfolder->show($customfolder)); // begin redirect action $input_address = new html_inputfield(array('name' => '_redirect[]', 'style' => $defaults['method'] == 'redirect' || $defaults['method'] == 'redirect_copy' ? '' : 'display: none;')); // begin reject action $input_reject = new html_textarea(array('name' => '_reject[]', 'rows' => '5', 'cols' => '40', 'style' => $defaults['method'] == 'reject' || $defaults['method'] == 'ereject' ? '' : 'display: none;')); // begin imapflags action $input_imapflags = new html_select(array('name' => '_imapflags[]', 'style' => $defaults['method'] == 'imapflags' || $defaults['method'] == 'imap4flags' ? '' : 'display: none;')); foreach ($this->flags as $name => $val) { $input_imapflags->add($this->gettext($name), $val); } // add actions to UI $actions_table->add('folder', $input_folderlist->show($defaults['folder']) . $otherfolders . $input_address->show($defaults['address']) . $vacs_table->show() . $notify_table->show() . $input_imapflags->show($defaults['flags']) . $input_reject->show($defaults['reject']) . $headers_table->show()); // add add/delete buttons to UI (if enabled) $add_button = $this->api->output->button(array('command' => 'plugin.sieverules.add_action', 'type' => 'link', 'class' => 'add', 'title' => 'sieverules.addsieveact', 'content' => ' ')); $delete_button = $this->api->output->button(array('command' => 'plugin.sieverules.del_action', 'type' => 'link', 'class' => 'delete', 'classact' => 'delete_act', 'title' => 'sieverules.deletesieveact', 'content' => ' ')); if ($rcmail->config->get('sieverules_multiple_actions')) { $actions_table->add('control', $add_button . $delete_button); } else { $actions_table->add('control', " "); } return $actions_table; }
/** * Convert a HTML string into a text one using html2text * * @param string $html the string to be converted * * @return string the converted string * @access public * @static */ static function htmlToText($html) { require_once 'packages/html2text/rcube_html2text.php'; $token_html = preg_replace('!\\{([a-z_.]+)\\}!i', 'token:{$1}', $html); $converter = new rcube_html2text($token_html); $token_text = $converter->get_text(); $text = preg_replace('!token\\:\\{([a-z_.]+)\\}!i', '{$1}', $token_text); return $text; }
function messageComposeBody($args) { $rcmail = rcmail::get_instance(); $db = $rcmail->get_dbh(); $id = rcube_utils::get_input_value('_id', rcube_utils::INPUT_GPC); $row = $_SESSION['compose_data_' . $id]['param']['mailData']; $type = $_SESSION['compose_data_' . $id]['param']['type']; if (!$row) { return; } $bodyIsHtml = $args['html']; $date = $row['date']; $from = $row['from_email']; $to = $row['to_email']; $body = $row['content']; $subject = $row['subject']; $replyto = $row['reply_to_email']; $prefix = $suffix = ''; if ($type == 'forward') { if (!$bodyIsHtml) { $prefix = "\n\n\n-------- " . $rcmail->gettext('originalmessage') . " --------\n"; $prefix .= $rcmail->gettext('subject') . ': ' . $subject . "\n"; $prefix .= $rcmail->gettext('date') . ': ' . $date . "\n"; $prefix .= $rcmail->gettext('from') . ': ' . $from . "\n"; $prefix .= $rcmail->gettext('to') . ': ' . $to . "\n"; if ($cc = $row['cc_email']) { $prefix .= $rcmail->gettext('cc') . ': ' . $cc . "\n"; } if ($replyto != $from) { $prefix .= $rcmail->gettext('replyto') . ': ' . $replyto . "\n"; } $prefix .= "\n"; global $LINE_LENGTH; $txt = new rcube_html2text($body, false, true, $LINE_LENGTH); $body = $txt->get_text(); $body = preg_replace('/\\r?\\n/', "\n", $body); $body = trim($body, "\n"); } else { $prefix = sprintf("<p>-------- " . $rcmail->gettext('originalmessage') . " --------</p>" . "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tbody>" . "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>" . "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>" . "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>" . "<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>", $rcmail->gettext('subject'), rcube::Q($subject), $rcmail->gettext('date'), rcube::Q($date), $rcmail->gettext('from'), rcube::Q($from, 'replace'), $rcmail->gettext('to'), rcube::Q($to, 'replace')); if ($cc = $row['cc_email']) { $prefix .= sprintf("<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>", $rcmail->gettext('cc'), rcube::Q($cc, 'replace')); } if ($replyto != $from) { $prefix .= sprintf("<tr><th align=\"right\" nowrap=\"nowrap\" valign=\"baseline\">%s: </th><td>%s</td></tr>", $rcmail->gettext('replyto'), rcube::Q($replyto, 'replace')); } $prefix .= "</tbody></table><br>"; } $body = $prefix . $body; } else { $prefix = $rcmail->gettext(array('name' => 'mailreplyintro', 'vars' => array('date' => $rcmail->format_date($date, $rcmail->config->get('date_long')), 'sender' => $from))); if (!$bodyIsHtml) { global $LINE_LENGTH; $txt = new rcube_html2text($body, false, true, $LINE_LENGTH); $body = $txt->get_text(); $body = preg_replace('/\\r?\\n/', "\n", $body); $body = trim($body, "\n"); $body = rcmail_wrap_and_quote($body, $LINE_LENGTH); $prefix .= "\n"; $body = $prefix . $body . $suffix; } else { $body = $prefix . '<blockquote>' . $body . '</blockquote>' . $suffix; $prefix = '<p>' . rcube::Q($prefix) . "</p>\n"; } } $args['body'] = $body; return $args; }
public function as_text() { $script = ''; $variables = ''; $exts = array(); // rules $activeRules = 0; foreach ($this->content as $rule) { $tests = array(); $i = 0; if ($rule['disabled'] == 1) { $script .= '# rule:[' . $rule['name'] . "]" . RCUBE_SIEVE_NEWLINE; $script .= '# disabledRule:[' . $this->_safe_serial(serialize($rule)) . "]" . RCUBE_SIEVE_NEWLINE; } else { // header $script .= '# rule:[' . $rule['name'] . "]" . RCUBE_SIEVE_NEWLINE; // constraints expressions foreach ($rule['tests'] as $test) { $tests[$i] = ''; switch ($test['type']) { case 'size': $tests[$i] .= $test['not'] ? 'not ' : ''; $tests[$i] .= 'size :' . ($test['operator'] == 'under' ? 'under ' : 'over ') . $test['target']; break; case 'virustest': case 'spamtest': array_push($exts, $test['type']); array_push($exts, 'relational'); array_push($exts, 'comparator-i;ascii-numeric'); $tests[$i] .= $test['not'] ? 'not ' : ''; $tests[$i] .= $test['type'] . ' :value ' . ($test['operator'] == 'eq' ? '"eq" ' : ($test['operator'] == 'le' ? '"le" ' : '"ge" ')) . ':comparator "i;ascii-numeric" "' . $test['target'] . '"'; break; case 'true': $tests[$i] .= $test['not'] ? 'not true' : 'true'; break; case 'exists': $tests[$i] .= $test['not'] ? 'not ' : ''; if (is_array($test['header'])) { $tests[$i] .= 'exists ["' . implode('", "', $this->_escape_string($test['header'])) . '"]'; } else { $tests[$i] .= 'exists "' . $this->_escape_string($test['header']) . '"'; } break; case 'envelope': array_push($exts, 'envelope'); case 'header': case 'address': if ($test['operator'] == 'regex') { array_push($exts, 'regex'); } elseif (substr($test['operator'], 0, 5) == 'count' || substr($test['operator'], 0, 5) == 'value') { array_push($exts, 'relational'); } elseif ($test['operator'] == 'user' || $test['operator'] == 'detail' || $test['operator'] == 'domain') { array_push($exts, 'subaddress'); } $tests[$i] .= $test['not'] ? 'not ' : ''; $tests[$i] .= $test['type'] . ' :' . $test['operator']; if ($test['comparator'] != '') { if ($test['comparator'] != 'i;ascii-casemap' && $test['comparator'] != 'i;octet') { array_push($exts, 'comparator-' . $test['comparator']); } $tests[$i] .= ' :comparator "' . $test['comparator'] . '"'; } if (is_array($test['header'])) { $tests[$i] .= ' ["' . implode('", "', $this->_escape_string($test['header'])) . '"]'; } else { $tests[$i] .= ' "' . $this->_escape_string($test['header']) . '"'; } if (is_array($test['target'])) { $tests[$i] .= ' ["' . implode('", "', $this->_escape_string($test['target'])) . '"]'; } else { $tests[$i] .= ' "' . $this->_escape_string($test['target']) . '"'; } break; case 'body': array_push($exts, 'body'); if ($test['operator'] == 'regex') { array_push($exts, 'regex'); } elseif (substr($test['operator'], 0, 5) == 'count' || substr($test['operator'], 0, 5) == 'value') { array_push($exts, 'relational'); } $tests[$i] .= $test['not'] ? 'not ' : ''; $tests[$i] .= $test['type']; if ($test['bodypart'] != '') { $tests[$i] .= ' :' . $test['bodypart']; } if ($test['contentpart'] != '') { $tests[$i] .= ' "' . $test['contentpart'] . '"'; } $tests[$i] .= ' :' . $test['operator']; if ($test['comparator'] != '') { if ($test['comparator'] != 'i;ascii-casemap' && $test['comparator'] != 'i;octet') { array_push($exts, 'comparator-' . $test['comparator']); } $tests[$i] .= ' :comparator "' . $test['comparator'] . '"'; } if (is_array($test['target'])) { $tests[$i] .= ' ["' . implode('", "', $this->_escape_string($test['target'])) . '"]'; } else { $tests[$i] .= ' "' . $this->_escape_string($test['target']) . '"'; } break; case 'date': array_push($exts, 'date'); if ($test['operator'] == 'regex') { array_push($exts, 'regex'); } elseif (substr($test['operator'], 0, 5) == 'count' || substr($test['operator'], 0, 5) == 'value') { array_push($exts, 'relational'); } $tests[$i] .= $test['not'] ? 'not ' : ''; $tests[$i] .= $test['header']; $timezone = rcube::get_instance()->config->get('timezone', 'auto'); if ($timezone != 'auto') { $tz = new DateTimeZone($timezone); $date = new DateTime('now', $tz); $tests[$i] .= ' :zone ' . '"' . $date->format('O') . '"'; } $tests[$i] .= ' :' . $test['operator']; if ($test['comparator'] != '') { if ($test['comparator'] != 'i;ascii-casemap' && $test['comparator'] != 'i;octet') { array_push($exts, 'comparator-' . $test['comparator']); } $tests[$i] .= ' :comparator "' . $test['comparator'] . '"'; } $tests[$i] .= ' "' . $this->_escape_string($test['datepart']) . '"'; $tests[$i] .= ' "' . $this->_escape_string($test['target']) . '"'; break; } $i++; } $script .= ($activeRules > 0 && $this->elsif ? 'els' : '') . ($rule['join'] ? 'if allof (' : 'if anyof ('); $activeRules++; if (sizeof($tests) > 1) { $script .= implode("," . RCUBE_SIEVE_NEWLINE . RCUBE_SIEVE_INDENT, $tests); } elseif (sizeof($tests)) { $script .= $tests[0]; } else { $script .= 'true'; } $script .= ")" . RCUBE_SIEVE_NEWLINE . "{" . RCUBE_SIEVE_NEWLINE; // action(s) $actions = ''; foreach ($rule['actions'] as $action) { switch ($action['type']) { case 'fileinto': case 'fileinto_copy': array_push($exts, 'fileinto'); $args = ''; if ($action['type'] == 'fileinto_copy') { array_push($exts, 'copy'); $args .= ' :copy'; } if ($action['create']) { array_push($exts, 'mailbox'); $args .= ' :create'; } // variables support in fileinto by David Warden if (preg_match('/\\$\\{\\d+\\}/', $action['target'])) { array_push($exts, 'variables'); } $actions .= RCUBE_SIEVE_INDENT . "fileinto" . $args . " \"" . $this->_escape_string($action['target']) . "\";" . RCUBE_SIEVE_NEWLINE; break; case 'redirect': case 'redirect_copy': $args = ''; if ($action['type'] == 'redirect_copy') { array_push($exts, 'copy'); $args .= ' :copy'; } $tokens = preg_split('/[,;\\s]/', $action['target']); foreach ($tokens as $email) { $actions .= RCUBE_SIEVE_INDENT . "redirect" . $args . " \"" . $this->_escape_string($email) . "\";" . RCUBE_SIEVE_NEWLINE; } break; case 'reject': case 'ereject': array_push($exts, $action['type']); if (strpos($action['target'], "\n") !== false) { $actions .= RCUBE_SIEVE_INDENT . $action['type'] . " text:" . RCUBE_SIEVE_NEWLINE . $action['target'] . RCUBE_SIEVE_NEWLINE . "." . RCUBE_SIEVE_NEWLINE . ";" . RCUBE_SIEVE_NEWLINE; } else { $actions .= RCUBE_SIEVE_INDENT . $action['type'] . " \"" . $this->_escape_string($action['target']) . "\";" . RCUBE_SIEVE_NEWLINE; } break; case 'vacation': array_push($exts, 'vacation'); $action['subject'] = $this->_escape_string($action['subject']); // // encoding subject header with mb_encode provides better results with asian characters // if (function_exists("mb_encode_mimeheader")) // { // mb_internal_encoding($action['charset']); // $action['subject'] = mb_encode_mimeheader($action['subject'], $action['charset'], 'Q'); // mb_internal_encoding(RCUBE_CHARSET); // } // detect original recipient if ($action['from'] == 'auto') { if (strpos($variables, 'set "from"') === false) { array_push($exts, 'variables'); $variables .= 'set "from" "";' . RCUBE_SIEVE_NEWLINE; $variables .= 'if header :matches "to" "*" {' . RCUBE_SIEVE_NEWLINE; $variables .= RCUBE_SIEVE_INDENT . 'set "from" "${1}";' . RCUBE_SIEVE_NEWLINE; $variables .= '}' . RCUBE_SIEVE_NEWLINE; } $action['from'] = "\${from}"; } elseif ($action['from'] == 'auto') { $action['from'] = "\${from}"; } // append original subject if ($action['origsubject'] == '1') { if (strpos($variables, 'set "subject"') === false) { array_push($exts, 'variables'); $variables .= 'set "subject" "";' . RCUBE_SIEVE_NEWLINE; $variables .= 'if header :matches "subject" "*" {' . RCUBE_SIEVE_NEWLINE; $variables .= RCUBE_SIEVE_INDENT . 'set "subject" "${1}";' . RCUBE_SIEVE_NEWLINE; $variables .= '}' . RCUBE_SIEVE_NEWLINE; } $action['subject'] = trim($action['subject']); if (substr($action['subject'], -1, 1) != ":") { $action['subject'] .= ":"; } $action['subject'] .= " \${subject}"; } $actions .= RCUBE_SIEVE_INDENT . "vacation" . RCUBE_SIEVE_NEWLINE; if (!empty($action['seconds'])) { array_push($exts, 'vacation-seconds'); $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":seconds " . $action['seconds'] . RCUBE_SIEVE_NEWLINE; } elseif (!empty($action['days'])) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":days " . $action['days'] . RCUBE_SIEVE_NEWLINE; } if (!empty($action['addresses'])) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":addresses [\"" . str_replace(",", "\",\"", $this->_escape_string($action['addresses'])) . "\"]" . RCUBE_SIEVE_NEWLINE; } if (!empty($action['subject'])) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":subject \"" . $action['subject'] . "\"" . RCUBE_SIEVE_NEWLINE; } if (!empty($action['handle'])) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":handle \"" . $this->_escape_string($action['handle']) . "\"" . RCUBE_SIEVE_NEWLINE; } if (!empty($action['from'])) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":from \"" . $this->_escape_string($action['from']) . "\"" . RCUBE_SIEVE_NEWLINE; } if ($action['htmlmsg']) { $MAIL_MIME = new Mail_mime("\r\n"); $action['msg'] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">' . "\r\n<html><body>\r\n" . $action['msg'] . "\r\n</body></html>\r\n"; $MAIL_MIME->setHTMLBody($action['msg']); // add a plain text version of the e-mail as an alternative part. $h2t = new rcube_html2text($action['msg'], false, true, 0); $plainTextPart = $h2t->get_text(); if (!$plainTextPart) { // empty message body breaks attachment handling in drafts $plainTextPart = "\r\n"; } else { // make sure all line endings are CRLF (#1486712) $plainTextPart = preg_replace('/\\r?\\n/', "\r\n", $plainTextPart); } $MAIL_MIME->setTXTBody($plainTextPart); $MAIL_MIME->setParam('html_charset', $action['charset']); $MAIL_MIME->setParam('text_charset', $action['charset']); $action['msg'] = $MAIL_MIME->getMessage(); } // escape lines which start is a . $action['msg'] = preg_replace('/(^|\\r?\\n)\\./', "\$1..", $action['msg']); if ($action['htmlmsg']) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":mime text:" . RCUBE_SIEVE_NEWLINE . $action['msg'] . RCUBE_SIEVE_NEWLINE . "." . RCUBE_SIEVE_NEWLINE . ";" . RCUBE_SIEVE_NEWLINE; } elseif ($action['charset'] != "UTF-8") { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":mime text:" . RCUBE_SIEVE_NEWLINE . "Content-Type: text/plain; charset=" . $action['charset'] . RCUBE_SIEVE_NEWLINE . RCUBE_SIEVE_NEWLINE . $action['msg'] . RCUBE_SIEVE_NEWLINE . "." . RCUBE_SIEVE_NEWLINE . ";" . RCUBE_SIEVE_NEWLINE; } elseif (strpos($action['msg'], "\n") !== false) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . "text:" . RCUBE_SIEVE_NEWLINE . $action['msg'] . RCUBE_SIEVE_NEWLINE . "." . RCUBE_SIEVE_NEWLINE . ";" . RCUBE_SIEVE_NEWLINE; } else { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . "\"" . $this->_escape_string($action['msg']) . "\";" . RCUBE_SIEVE_NEWLINE; } break; case 'imapflags': case 'imap4flags': array_push($exts, $action['type']); if (strpos($actions, "setflag") !== false) { $actions .= RCUBE_SIEVE_INDENT . "addflag \"" . $this->_escape_string($action['target']) . "\";" . RCUBE_SIEVE_NEWLINE; } else { $actions .= RCUBE_SIEVE_INDENT . "setflag \"" . $this->_escape_string($action['target']) . "\";" . RCUBE_SIEVE_NEWLINE; } break; case 'notify': array_push($exts, 'notify'); $actions .= RCUBE_SIEVE_INDENT . "notify" . RCUBE_SIEVE_NEWLINE; $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":method \"" . $this->_escape_string($action['method']) . "\"" . RCUBE_SIEVE_NEWLINE; if (!empty($action['options'])) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":options [\"" . str_replace(",", "\",\"", $this->_escape_string($action['options'])) . "\"]" . RCUBE_SIEVE_NEWLINE; } if (!empty($action['from'])) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":from \"" . $this->_escape_string($action['from']) . "\"" . RCUBE_SIEVE_NEWLINE; } if (!empty($action['importance'])) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":importance \"" . $this->_escape_string($action['importance']) . "\"" . RCUBE_SIEVE_NEWLINE; } $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":message \"" . $this->_escape_string($action['msg']) . "\";" . RCUBE_SIEVE_NEWLINE; break; case 'enotify': array_push($exts, 'enotify'); $actions .= RCUBE_SIEVE_INDENT . "notify" . RCUBE_SIEVE_NEWLINE; if (!empty($action['options'])) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":options [\"" . str_replace(",", "\",\"", $this->_escape_string($action['options'])) . "\"]" . RCUBE_SIEVE_NEWLINE; } if (!empty($action['from'])) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":from \"" . $this->_escape_string($action['from']) . "\"" . RCUBE_SIEVE_NEWLINE; } if (!empty($action['importance'])) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":importance \"" . $this->_escape_string($action['importance']) . "\"" . RCUBE_SIEVE_NEWLINE; } $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":message \"" . $this->_escape_string($action['msg']) . "\"" . RCUBE_SIEVE_NEWLINE; $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . "\"" . $this->_escape_string($action['method']) . "\";" . RCUBE_SIEVE_NEWLINE; break; case 'editheaderadd': array_push($exts, 'editheader'); $actions .= RCUBE_SIEVE_INDENT . "addheader"; if ($action['index'] == 'last') { $actions .= " :last"; } $actions .= " \"" . $this->_escape_string($action['name']) . "\" \"" . $this->_escape_string($action['value']) . "\";" . RCUBE_SIEVE_NEWLINE; break; case 'editheaderrem': array_push($exts, 'editheader'); $actions .= RCUBE_SIEVE_INDENT . "deleteheader"; if (is_numeric($action['index'])) { $actions .= " :index " . $action['index']; } elseif ($action['index'] == 'last') { $actions .= " :last"; } if (strlen($action['operator']) > 0) { $actions .= " :" . $action['operator']; } $actions .= " \"" . $this->_escape_string($action['name']) . "\""; if (strlen($action['value']) > 0) { $actions .= " \"" . $this->_escape_string($action['value']) . "\""; } $actions .= ";" . RCUBE_SIEVE_NEWLINE; break; case 'keep': case 'discard': case 'stop': $actions .= RCUBE_SIEVE_INDENT . $action['type'] . ";" . RCUBE_SIEVE_NEWLINE; break; } } $script .= $actions . "}" . RCUBE_SIEVE_NEWLINE; } } if ($variables) { $variables .= RCUBE_SIEVE_NEWLINE; } // requires $exts = array_unique($exts); if (sizeof($exts)) { $script = 'require ["' . implode('","', $exts) . "\"];" . RCUBE_SIEVE_NEWLINE . RCUBE_SIEVE_NEWLINE . $variables . $script; } // author if ($script && RCUBE_SIEVE_HEADER) { $script = RCUBE_SIEVE_HEADER . RCUBE_SIEVE_NEWLINE . $script; } return $script; }