diff -Nuar trunk/roundcubemail/index.php roundcubemail/index.php --- trunk/roundcubemail/index.php 2008-05-02 07:29:12.000000000 +0500 +++ roundcubemail/index.php 2008-05-03 18:05:50.000000000 +0500 @@ -296,6 +296,18 @@ if ($RCMAIL->action=='folders' || $RCMAIL->action=='subscribe' || $RCMAIL->action=='unsubscribe' || $RCMAIL->action=='create-folder' || $RCMAIL->action=='rename-folder' || $RCMAIL->action=='delete-folder') include('program/steps/settings/manage_folders.inc'); + + if ($RCMAIL->action=='save-mailrule') + include('program/steps/settings/save_mailrule.inc'); + + if ($RCMAIL->action=='edit-mailrule' || $RCMAIL->action=='add-mailrule') + include('program/steps/settings/edit_mailrule.inc'); + + if ($RCMAIL->action=='delete-mailrule') + include('program/steps/settings/delete_mailrule.inc'); + + if ($RCMAIL->action=='mailrules') + include('program/steps/settings/mailrules.inc'); } diff -Nuar trunk/roundcubemail/program/include/rcube_user.php roundcubemail/program/include/rcube_user.php --- trunk/roundcubemail/program/include/rcube_user.php 2008-04-30 08:21:42.000000000 +0500 +++ roundcubemail/program/include/rcube_user.php 2008-05-03 15:53:04.000000000 +0500 @@ -129,6 +129,128 @@ return false; } + /** + * Get default mailrule of this user + * + * @param int Mailrule ID. If empty, the default mailrule is returned + * @return array Hash array with all cols of the + */ + function get_mailrule() + { + $sql_result = $this->db->query( + "SELECT * FROM ".get_table_name('mailrules')." + WHERE mailrule_id=? + AND user_id=? + AND del<>1", + get_input_value('_iid', RCUBE_INPUT_GPC), + $this->ID); + + return $this->db->fetch_assoc($sql_result); + } + + /** + * Return a list of all mailrules linked with this user + * + * @return array List of mailrules + */ + function list_mailrules() + { + // get contacts from DB + $sql_result = $this->db->query( + "SELECT * FROM ".get_table_name('mailrules')." + WHERE del<>1 + AND user_id=?", + $this->ID); + + return $sql_result; + } + + /** + * Create a new mailrule record linked with this user + * + * @param array Hash array with col->value pairs to save + * @return int The inserted mailrule ID or false on error + */ + function insert_mailrule($data) + { + if (!$this->ID) + return false; + + $insert_cols = $insert_values = array(); + foreach ((array)$data as $col => $value) + { + $insert_cols[] = $this->db->quoteIdentifier($col); + $insert_values[] = $this->db->quote($value); + } + + $this->db->query( + "INSERT INTO ".get_table_name('mailrules')." + (user_id, ".join(', ', $insert_cols).") + VALUES (?, ".join(', ', $insert_values).")", + $this->ID); + + return $this->db->insert_id(get_sequence_name('mailrules')); + } + + /** + * Update a specific mailrule record + * + * @param int Mailrule ID + * @param array Hash array with col->value pairs to save + * @return boolean True if saved successfully, false if nothing changed + */ + function update_mailrule($iid, $data) + { + if (!$this->ID) + return false; + + $write_sql = array(); + + foreach ((array)$data as $col => $value) + { + $write_sql[] = sprintf("%s=%s", + $this->db->quoteIdentifier($col), + $this->db->quote($value)); + } + + $this->db->query( + "UPDATE ".get_table_name('mailrules')." + SET ".join(', ', $write_sql)." + WHERE mailrule_id=? + AND user_id=? + AND del<>1", + $iid, + $this->ID); + + return $this->db->affected_rows(); + } + + /** + * Mark the given mailrule as deleted + * + * @param int Mailrule ID + * @return boolean True if deleted successfully, false if nothing changed + */ + function delete_mailrule($iid) + { + if (!$this->ID) + return false; + + if (!$this->ID || $this->ID == '') + return false; + + $this->db->query( + "UPDATE ".get_table_name('mailrules')." + SET del=1 + WHERE user_id=? + AND mailrule_id=?", + $this->ID, + $iid); + + return $this->db->affected_rows(); + } + + /** * Get default identity of this user diff -Nuar trunk/roundcubemail/program/js/app.js roundcubemail/program/js/app.js --- trunk/roundcubemail/program/js/app.js 2008-04-28 11:43:14.000000000 +0500 +++ roundcubemail/program/js/app.js 2008-05-03 18:14:17.000000000 +0500 @@ -282,7 +282,7 @@ case 'settings': - this.enable_command('preferences', 'identities', 'save', 'folders', true); + this.enable_command('preferences', 'identities', 'save', 'folders', 'mailrules', true); if (this.env.action=='identities' || this.env.action=='edit-identity' || this.env.action=='add-identity') this.enable_command('edit', 'add', 'delete', true); @@ -293,6 +293,12 @@ if (this.env.action=='folders') this.enable_command('subscribe', 'unsubscribe', 'create-folder', 'rename-folder', 'delete-folder', true); + if (this.env.action=='mailrules' || this.env.action=='edit-mailrule' || this.env.action=='add-mailrule') + this.enable_command('edit', 'add', 'delete', true); + + if (this.env.action=='edit-mailrule' || this.env.action=='add-mailrule') + this.enable_command('save', true); + if (this.gui_objects.identitieslist) { this.identity_list = new rcube_list_widget(this.gui_objects.identitieslist, {multiselect:false, draggable:false, keyboard:false}); @@ -304,6 +310,17 @@ this.identity_list.highlight_row(this.env.iid); } + if (this.gui_objects.mailruleslist) + { + this.mailrule_list = new rcube_list_widget(this.gui_objects.mailruleslist, {multiselect:false, draggable:false, keyboard:false}); + this.mailrule_list.addEventListener('select', function(o){ p.mailrule_select(o); }); + this.mailrule_list.init(); + this.mailrule_list.focus(); + + if (this.env.iid) + this.mailrule_list.highlight_row(this.env.iid); + } + if (this.gui_objects.subscriptionlist) this.init_subscription_list(); @@ -608,8 +625,16 @@ this.load_contact(0, 'add'); else if (this.task=='settings') { - this.identity_list.clear_selection(); - this.load_identity(0, 'add-identity'); + if(this.env.action=='mailrules') + { + this.mailrule_list.clear_selection(); + this.load_mailrule(0, 'add-mailrule'); + } + else + { + this.identity_list.clear_selection(); + this.load_identity(0, 'add-identity'); + } } break; @@ -618,7 +643,10 @@ if (this.task=='addressbook' && (cid = this.get_single_cid())) this.load_contact(cid, 'edit'); else if (this.task=='settings' && props) - this.load_identity(props, 'edit-identity'); + if (this.env.action=='mailrules') + this.load_mailrule(props, 'edit-mailrule'); + else + this.load_identity(props, 'edit-identity'); break; case 'save-identity': @@ -666,7 +694,10 @@ this.delete_contacts(); // user settings task else if (this.task=='settings') - this.delete_identity(); + if(this.env.action=='edit-mailrule') + this.delete_mailrule(); + else + this.delete_identity(); break; @@ -936,7 +967,11 @@ case 'preferences': this.goto_url(''); break; - + + case 'mailrules': + this.goto_url('mailrules'); + break; + case 'identities': this.goto_url('identities'); break; @@ -968,6 +1003,10 @@ this.delete_folder(props); break; + + case 'delete-mailrule': + this.delete_mailrule(); + } return obj ? false : true; @@ -2522,6 +2561,67 @@ this.subscription_list.init(); } + this.mailrule_select = function(list) + { + var id; + if (id = list.get_single_selection()) + this.load_mailrule(id, 'edit-mailrule'); + }; + + // load rule record + this.load_mailrule = function(id, action) + { + if (action=='edit-mailrule' && (!id || id==this.env.iid)) + return false; + + var add_url = ''; + var target = window; + if (this.env.contentframe && window.frames && window.frames[this.env.contentframe]) + { + add_url = '&_framed=1'; + target = window.frames[this.env.contentframe]; + document.getElementById(this.env.contentframe).style.visibility = 'inherit'; + } + + if (action && (id || action=='add-mailrule')) + { + this.set_busy(true); + target.location.href = this.env.comm_path+'&_action='+action+'&_iid='+id+add_url; + } + return true; + }; + + // delete rule record + this.delete_mailrule = function(id) + { + // exit if no mailbox specified or if selection is empty + var selection = this.mailrule_list.get_selection(); + if (!(selection.length || this.env.iid)) + return; + + if (!id) + id = this.env.iid ? this.env.iid : selection[0]; + + // if (this.env.framed && id) + this.goto_url('delete-mailrule', '_iid='+id, true); + return true; + }; + + this.delete_identity = function(id) + { + // exit if no mailbox specified or if selection is empty + var selection = this.identity_list.get_selection(); + if (!(selection.length || this.env.iid)) + return; + + if (!id) + id = this.env.iid ? this.env.iid : selection[0]; + + // if (this.env.framed && id) + this.goto_url('delete-identity', '_iid='+id, true); + return true; + }; + this.identity_select = function(list) { var id; diff -Nuar trunk/roundcubemail/program/localization/ru/labels.inc roundcubemail/program/localization/ru/labels.inc --- trunk/roundcubemail/program/localization/ru/labels.inc 2008-02-22 15:05:18.000000000 +0400 +++ roundcubemail/program/localization/ru/labels.inc 2008-05-03 15:55:04.000000000 +0500 @@ -190,5 +190,14 @@ $labels['sortby'] = 'Сортировать по'; $labels['sortasc'] = 'Возрастанию'; $labels['sortdesc'] = 'Убыванию'; +$labels['mailrules'] = 'Правила'; +$labels['managemailrules'] = 'Управление правилами'; +$labels['newmailrule'] = 'Создать правило'; +$labels['location'] = 'Назначение'; +$labels['logoutclear'] = 'Очищать корзину при выходе'; +$labels['logoutcompact'] = 'Сжимать Входящие при выходе'; +$labels['uisettings'] = 'Интерфейс Пользователя'; +$labels['serversettings'] = 'Настройки Сервера'; +$labels['count'] = 'Кол-во Правил'; -?> \ No newline at end of file +?> diff -Nuar trunk/roundcubemail/program/steps/mail/func.inc roundcubemail/program/steps/mail/func.inc --- trunk/roundcubemail/program/steps/mail/func.inc 2008-05-01 14:27:48.000000000 +0500 +++ roundcubemail/program/steps/mail/func.inc 2008-05-03 15:07:10.000000000 +0500 @@ -79,6 +79,90 @@ +function rcmail_sort_mail($header) + { + global $IMAP, $CONFIG, $COMM_PATH, $OUTPUT, $DB; + + $SQL_RESULT = $DB->query("SELECT * FROM ".get_table_name('mailrules')." + WHERE del<>1 + AND user_id=?", + $_SESSION['user_id']); + while ($sql_arr = $DB->fetch_assoc($SQL_RESULT)) + { + $SQL_ARRA[] = $sql_arr; + } + + $from_parts = $IMAP->decode_address_list($header->from); + $to_parts = $IMAP->decode_address_list($header->to); + $cc_parts = $IMAP->decode_address_list($header->cc); + $bcc_parts = $IMAP->decode_address_list($header->bcc); + $replyto_parts = $IMAP->decode_address_list($header->replyto); + + $moved_message = 0; + if ($SQL_ARRA) + { + foreach($SQL_ARRA as $sql_arr) + { + $need_to_be_moved = 0; + + foreach($from_parts as $from_part) + { + if(empty($sql_arr['from']) || stristr($from_part['name'],$sql_arr['from']) || stristr($from_part['address'],$sql_arr['from'])) + { + $need_to_be_moved++; + } + } + + foreach($to_parts as $to_part) + { + if(empty($sql_arr['to']) || stristr($to_part['name'],$sql_arr['to']) || stristr($to_part['address'],$sql_arr['to'])) + { + $need_to_be_moved++; + } + } + + foreach($cc_parts as $cc_part) + { + if(empty($sql_arr['cc']) || stristr($cc_part['name'],$sql_arr['cc']) || stristr($cc_part['address'],$sql_arr['cc'])) + { + $need_to_be_moved++; + } + } + + foreach($bcc_parts as $bcc_part) + { + if(empty($sql_arr['bcc']) || stristr($bcc_part['name'],$sql_arr['bcc']) || stristr($bcc_part['address'],$sql_arr['bcc'])) + { + $need_to_be_moved++; + } + } + + foreach($replyto_parts as $replyto_part) + { + if(empty($sql_arr['replyto']) || stristr($replyto_part['name'],$sql_arr['replyto']) || stristr($replyto_part['address'],$sql_arr['replyto'])) + { + $need_to_be_moved++; + } + } + + if(empty($sql_arr['subject']) || stristr(rep_specialchars_output($IMAP->decode_header($header->subject), 'html', 'all'),$sql_arr['subject'])) + { + $need_to_be_moved++; + } + + if($need_to_be_moved == 6) + { + $IMAP->move_message($header->uid, $sql_arr['location'], $_SESSION['mbox']); + $moved_message = 1; + break; + } + } + } + + return $moved_message; + } + + // return the message list as HTML table function rcmail_message_list($attrib) { @@ -199,65 +283,67 @@ // create row for each message foreach ($a_headers as $i => $header) //while (list($i, $header) = each($a_headers)) { - $message_icon = $attach_icon = ''; - $js_row_arr = array(); - $zebra_class = $i%2 ? 'even' : 'odd'; - - // set messag attributes to javascript array - if ($header->deleted) - $js_row_arr['deleted'] = true; - if (!$header->seen) - $js_row_arr['unread'] = true; - if ($header->answered) - $js_row_arr['replied'] = true; - // set message icon - if ($attrib['deletedicon'] && $header->deleted) - $message_icon = $attrib['deletedicon']; - else if ($attrib['unreadicon'] && !$header->seen) - $message_icon = $attrib['unreadicon']; - else if ($attrib['repliedicon'] && $header->answered) - $message_icon = $attrib['repliedicon']; - else if ($attrib['messageicon']) - $message_icon = $attrib['messageicon']; - - // set attachment icon - if ($attrib['attachmenticon'] && preg_match("/multipart\/[mr]/i", $header->ctype)) - $attach_icon = $attrib['attachmenticon']; + if(rcmail_sort_mail($header) == 0) + { + $message_icon = $attach_icon = ''; + $js_row_arr = array(); + $zebra_class = $i%2 ? 'even' : 'odd'; + + // set messag attributes to javascript array + if ($header->deleted) + $js_row_arr['deleted'] = true; + if (!$header->seen) + $js_row_arr['unread'] = true; + if ($header->answered) + $js_row_arr['replied'] = true; + // set message icon + if ($attrib['deletedicon'] && $header->deleted) + $message_icon = $attrib['deletedicon']; + else if ($attrib['unreadicon'] && !$header->seen) + $message_icon = $attrib['unreadicon']; + else if ($attrib['repliedicon'] && $header->answered) + $message_icon = $attrib['repliedicon']; + else if ($attrib['messageicon']) + $message_icon = $attrib['messageicon']; + + // set attachment icon + if ($attrib['attachmenticon'] && preg_match("/multipart\/[mr]/i", $header->ctype)) + $attach_icon = $attrib['attachmenticon']; - $out .= sprintf(''."\n", - $header->uid, - $header->seen ? '' : ' unread', - $header->deleted ? ' deleted' : '', - $zebra_class); + $out .= sprintf(''."\n", + $header->uid, + $header->seen ? '' : ' unread', + $header->deleted ? ' deleted' : '', + $zebra_class); - $out .= sprintf("%s\n", $message_icon ? sprintf($image_tag, $skin_path, $message_icon, '') : ''); + $out .= sprintf("%s\n", $message_icon ? sprintf($image_tag, $skin_path, $message_icon, '') : ''); - // format each col - foreach ($a_show_cols as $col) - { - if ($col=='from' || $col=='to') - $cont = Q(rcmail_address_string($header->$col, 3, $attrib['addicon']), 'show'); - else if ($col=='subject') + // format each col + foreach ($a_show_cols as $col) { - $action = $mbox==$CONFIG['drafts_mbox'] ? 'compose' : 'show'; - $uid_param = $mbox==$CONFIG['drafts_mbox'] ? '_draf_uid' : '_uid'; - $cont = Q(rcube_imap::decode_mime_string($header->$col, $header->charset)); - if (empty($cont)) $cont = Q(rcube_label('nosubject')); - $cont = sprintf('%s', Q(rcmail_url($action, array($uid_param=>$header->uid, '_mbox'=>$mbox))), $cont); - } - else if ($col=='size') - $cont = show_bytes($header->$col); - else if ($col=='date') - $cont = format_date($header->date); - else - $cont = Q($header->$col); + if ($col=='from' || $col=='to') + $cont = Q(rcmail_address_string($header->$col, 3, $attrib['addicon']), 'show'); + else if ($col=='subject') + { + $action = $mbox==$CONFIG['drafts_mbox'] ? 'compose' : 'show'; + $uid_param = $mbox==$CONFIG['drafts_mbox'] ? '_draf_uid' : '_uid'; + $cont = Q(rcube_imap::decode_mime_string($header->$col, $header->charset)); + if (empty($cont)) $cont = Q(rcube_label('nosubject')); + $cont = sprintf('%s', Q(rcmail_url($action, array($uid_param=>$header->uid, '_mbox'=>$mbox))), $cont); + } + else if ($col=='size') + $cont = show_bytes($header->$col); + else if ($col=='date') + $cont = format_date($header->date); + else + $cont = Q($header->$col); - $out .= '' . $cont . "\n"; - } + $out .= '' . $cont . "\n"; + } - $out .= sprintf("%s\n", $attach_icon ? sprintf($image_tag, $skin_path, $attach_icon, '') : ''); - $out .= "\n"; - + $out .= sprintf("%s\n", $attach_icon ? sprintf($image_tag, $skin_path, $attach_icon, '') : ''); + $out .= "\n"; + } if (sizeof($js_row_arr)) $a_js_message_arr[$header->uid] = $js_row_arr; } diff -Nuar trunk/roundcubemail/program/steps/settings/delete_mailrule.inc roundcubemail/program/steps/settings/delete_mailrule.inc --- trunk/roundcubemail/program/steps/settings/delete_mailrule.inc 1970-01-01 04:00:00.000000000 +0400 +++ roundcubemail/program/steps/settings/delete_mailrule.inc 2008-05-03 15:55:50.000000000 +0500 @@ -0,0 +1,40 @@ + | + +-----------------------------------------------------------------------+ + + $Id: delete_mailrule.inc + +*/ +if (($ids = get_input_value('_iid', RCUBE_INPUT_GET)) && preg_match('/^[0-9]+(,[0-9]+)*$/', $ids)) +{ + + if ($USER->delete_mailrule($ids)) + { + $OUTPUT->show_message('deletedsuccessfully', 'confirmation'); + } + + // send response + if ($OUTPUT->ajax_call) + $OUTPUT->send(); +} + +if ($OUTPUT->ajax_call) +exit; + +// go to mailrules page +rcmail_overwrite_action('mailrules'); + +?> \ No newline at end of file diff -Nuar trunk/roundcubemail/program/steps/settings/edit_mailrule.inc roundcubemail/program/steps/settings/edit_mailrule.inc --- trunk/roundcubemail/program/steps/settings/edit_mailrule.inc 1970-01-01 04:00:00.000000000 +0400 +++ roundcubemail/program/steps/settings/edit_mailrule.inc 2008-05-03 17:33:14.000000000 +0500 @@ -0,0 +1,163 @@ + | + +-----------------------------------------------------------------------+ + + $Id: edit_mailrule.inc 392 2006-12-03 22:32:16Z mangoose $ + +*/ + + +$RCMAIL->imap_init(true); + +if (($_GET['_iid'] || $_POST['_iid']) && $RCMAIL->action=='edit-mailrule') + { + + $MAILRULE_RECORD = $USER->get_mailrule(); + if (is_array($MAILRULE_RECORD)) + $OUTPUT->set_env('iid', $MAILRULE_RECORD['mailrule_id']); + + $PAGE_TITLE = rcube_label('edititem'); + } +else + $PAGE_TITLE = rcube_label('newitem'); + + +$OUTPUT->include_script('list.js'); + + +function rcube_mailrule_form($attrib) + { + + global $MAILRULE_RECORD, $OUTPUT, $IMAP, $RCMAIL, $CONFIG; + + $tinylang = substr($_SESSION['language'], 0, 2); + if (!file_exists('program/js/tiny_mce/langs/'.$tinylang.'.js')) + { + $tinylang = 'en'; + } + + $OUTPUT->include_script('tiny_mce/tiny_mce_src.js'); + $OUTPUT->add_script("tinyMCE.init({ mode : 'specific_textareas'," . + "apply_source_formatting : true," . + "content_css : '\$__skin_path' + '/editor_content.css'," . + "editor_css : '\$__skin_path' + '/editor_ui.css'," . + "theme : 'advanced'," . + "theme_advanced_toolbar_location : 'top'," . + "theme_advanced_toolbar_align : 'left'," . + "theme_advanced_buttons1 : 'bold,italic,underline,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,separator,outdent,indent,charmap,hr'," . + "theme_advanced_buttons2 : 'link,unlink,code,forecolor,fontselect,fontsizeselect'," . + "theme_advanced_buttons3 : '' });"); + + if (!$MAILRULE_RECORD && $RCMAIL->action != 'add-mailrule') + return rcube_label('notfound'); + + // add some labels to client + rcube_add_label('noemailwarning', 'nonamewarning'); + + + list($form_start, $form_end) = get_form_tags($attrib, 'save-mailrule', array('name' => '_iid', 'value' => $MAILRULE_RECORD['mailrule_id'])); + unset($attrib['form']); + + + // list of available cols + $a_show_cols = array('name' => array('type' => 'text'), + 'from' => array('type' => 'text'), + 'to' => array('type' => 'text'), + 'subject' => array('type' => 'text'), + 'cc' => array('type' => 'text'), + 'bcc' => array('type' => 'text'), + 'replyto' => array('type' => 'text')); + + $field_attrib = array('name' => '_location'); + $select_from = new html_select($field_attrib); + $mailbox_arr = $IMAP->list_mailboxes(); + + foreach ($mailbox_arr as $mbox_str ) + { + $delimiter = $IMAP->get_hierarchy_delimiter(); + $foldersplit = explode($delimiter, $mbox_str); + $level = count($foldersplit) - 1; + $display_folder = str_repeat('    ', $level) . rcube_charset_convert($foldersplit[$level], 'UTF-7'); + $folder_html = in_array($mbox_str, $CONFIG['default_imap_folders']) ? rcmail_localize_foldername($mbox_str) : $display_folder; + $select_from->add($folder_html, $mbox_str); + } + + + // a specific part is requested + if ($attrib['part']) + { + $colprop = $a_show_cols[$attrib['part']]; + if (is_array($colprop)) + { + $out = $form_start; + $out .= rcmail_get_edit_field($attrib['part'], $MAILRULE_RECORD[$attrib['part']], $attrib, $colprop['type']); + + return $out; + } + else + return ''; + } + + + // return the complete edit form as table + $out = "$form_start\n\n"; + + foreach ($a_show_cols as $col => $colprop) + { + $attrib['id'] = 'rcmfd_'.$col; + + if (strlen($colprop['onclick'])) + $attrib['onclick'] = $colprop['onclick']; + else + unset($attrib['onclick']); + + + if ($col == 'signature') + { + $attrib['size'] = $colprop['size']; + $attrib['rows'] = $colprop['rows']; + $attrib['mce_editable'] = $MAILRULE_RECORD['html_signature'] ? "true" : "false"; + } + else + { + unset($attrib['size']); + unset($attrib['rows']); + unset($attrib['mce_editable']); + } + + $label = strlen($colprop['label']) ? $colprop['label'] : $col; + $value = rcmail_get_edit_field($col, $MAILRULE_RECORD[$col], $attrib, $colprop['type']); + $out .= sprintf("\n", + $attrib['id'], + Q(rcube_label($label)), + $value); + } + $out .= sprintf("\n"); + $out .= "\n
%s
",rcube_label('location')); + $out .= $select_from->show($MAILRULE_RECORD['location']); + $out .= sprintf("
$form_end"; + return $out; + + } + + +$OUTPUT->add_handler('mailrulesform', 'rcube_mailrule_form'); +if ($RCMAIL->action=='add-mailrule' && template_exists('addmailrule')) + $OUTPUT->send('addmailrule'); + + $OUTPUT->send('editmailrule'); + +?> diff -Nuar trunk/roundcubemail/program/steps/settings/func.inc roundcubemail/program/steps/settings/func.inc --- trunk/roundcubemail/program/steps/settings/func.inc 2008-05-01 12:59:38.000000000 +0500 +++ roundcubemail/program/steps/settings/func.inc 2008-05-03 17:44:04.000000000 +0500 @@ -247,7 +247,105 @@ return $out; } +function rcmail_mailrules_list($attrib) +{ + global $OUTPUT, $USER; + + // add id to message list table if not specified + if (!strlen($attrib['id'])) + $attrib['id'] = 'rcmMailruleslist'; + // define list of cols to be displayed + $a_show_cols = array('name', 'count', 'location'); + // create XHTML table + $out = mailrule_table_output($attrib, $USER->list_mailrules(), $a_show_cols, 'mailrule_id'); + + // set client env + $OUTPUT->add_gui_object('mailruleslist', $attrib['id']); + return $out; +} +/** + * Create a HTML table based on the given data + * + * @param array Named table attributes + * @param mixed Table row data. Either a two-dimensional array or a valid SQL result set + * @param array List of cols to show + * @param string Name of the identifier col + * @return string HTML table code + */ +function mailrule_table_output($attrib, $table_data, $a_show_cols, $id_col) + { + + global $DB, $IMAP, $RCMAIL; + $RCMAIL->imap_init(true); + $CONFIG = $RCMAIL->config->all();; + $orig_col = $a_show_cols; + // allow the following attributes to be added to the tag + $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id', 'cellpadding', 'cellspacing', 'border', 'summary')); + + $table = '\n"; + + // add table title + $table .= "\n"; + + foreach ($a_show_cols as $col) + $table .= '\n"; + + $table .= "\n\n"; + + $c = 0; + if (!is_array($table_data)) + { + while ($table_data && ($sql_arr = $DB->fetch_assoc($table_data))) + { + $delimiter = $IMAP->get_hierarchy_delimiter(); + $foldersplit = explode($delimiter, $sql_arr['location']); + $level = count($foldersplit) - 1; + $display_folder = str_repeat('    ', $level) . rcube_charset_convert($foldersplit[$level], 'UTF-7'); + $sql_arr['location'] = in_array($sql_arr['location'], $CONFIG['default_imap_folders']) ? rcmail_localize_foldername($sql_arr['location']) : $display_folder; + + $zebra_class = $c%2 ? 'even' : 'odd'; + + $table .= sprintf(''."\n", $sql_arr[$id_col]); + + // format each col + foreach ($a_show_cols as $col) + { + $cont = Q($sql_arr[$col]); + + $table .= '\n"; + } + + $table .= "\n"; + $c++; + } + } + else + { + foreach ($table_data as $row_data) + { + $zebra_class = $c%2 ? 'even' : 'odd'; + + $table .= sprintf(''."\n", $row_data[$id_col]); + + // format each col + foreach ($a_show_cols as $col) + { + $cont = Q($row_data[$col]); + + $table .= '\n"; + } + + $table .= "\n"; + $c++; + } + } + + // complete message table + $table .= "
' . Q(rcube_label($col)) . "
' . $cont . "
' . $cont . "
\n"; + + return $table; + } // similar function as in /steps/addressbook/edit.inc function get_form_tags($attrib, $action, $add_hidden=array()) @@ -282,6 +380,7 @@ // register UI objects $OUTPUT->add_handlers(array( 'userprefs' => 'rcmail_user_prefs_form', + 'mailruleslist' => 'rcmail_mailrules_list', 'identitieslist' => 'rcmail_identities_list', 'itentitieslist' => 'rcmail_identities_list' // keep this for backward compatibility )); diff -Nuar trunk/roundcubemail/program/steps/settings/mailrules.inc roundcubemail/program/steps/settings/mailrules.inc --- trunk/roundcubemail/program/steps/settings/mailrules.inc 1970-01-01 04:00:00.000000000 +0400 +++ roundcubemail/program/steps/settings/mailrules.inc 2008-05-03 16:00:52.000000000 +0500 @@ -0,0 +1,48 @@ + | + +-----------------------------------------------------------------------+ + + $Id: manage_mailrules.inc N/A 2006-12-11 mangoose $ + +*/ + +if ($USER_DATA = $DB->fetch_assoc($sql_result)) + $OUTPUT->set_pagetitle(sprintf('%s (%s@%s)', rcube_label('mailrules'), $USER_DATA['username'], $USER_DATA['mail_host'])); + +$OUTPUT->include_script('list.js'); + +// similar function as /steps/addressbook/func.inc::rcmail_contact_frame() +function rcmail_mailrule_frame($attrib) + { + global $OUTPUT; + + if (!$attrib['id']) + $attrib['id'] = 'rcmMailRuleFrame'; + + $attrib['name'] = $attrib['id']; + + $OUTPUT->set_env('contentframe', $attrib['name']); + + $attrib_str = create_attrib_string($attrib, array('name', 'id', 'class', 'style', 'src', 'width', 'height', 'frameborder')); + $out = ''; + + return $out; + } + +$OUTPUT->add_handler('mailrulesframe', 'rcmail_mailrule_frame'); +$OUTPUT->send('mailrules'); + +?> diff -Nuar trunk/roundcubemail/program/steps/settings/save_mailrule.inc roundcubemail/program/steps/settings/save_mailrule.inc --- trunk/roundcubemail/program/steps/settings/save_mailrule.inc 1970-01-01 04:00:00.000000000 +0400 +++ roundcubemail/program/steps/settings/save_mailrule.inc 2008-05-03 16:08:09.000000000 +0500 @@ -0,0 +1,96 @@ + | + +-----------------------------------------------------------------------+ + + + +*/ + +$a_save_cols = array('name','from', 'to', 'subject', 'cc', 'bcc', 'replyto', 'location','count'); +$a_html_cols = array('signature'); +$a_boolean_cols = array('standard', 'html_signature'); +$updated = $default_id = false; + +// check input +if (empty($_POST['_from']) && empty($_POST['_to']) && empty($_POST['_subject']) && empty($_POST['_cc']) && empty($_POST['_bcc']) && empty($_POST['_replyto'])) + { + show_message('formincomplete', 'warning'); + rcmail_overwrite_action('mailrules'); + return; + } + + +$save_data = array(); +foreach ($a_save_cols as $col) +{ + $fname = '_'.$col; + if (isset($_POST[$fname])) + $save_data[$col] = get_input_value($fname, RCUBE_INPUT_POST, in_array($col, $a_html_cols)); + + if (!empty($_POST[$fname]) && $col !== 'location' && $col !== 'name') + $save_data['count'] += 1; +} + +// update an existing contact +if ($_POST['_iid']) + { + if ($updated = $USER->update_mailrule(get_input_value('_iid', RCUBE_INPUT_POST), $save_data)) + { + $OUTPUT->show_message('successfullysaved', 'confirmation'); + + if ($_POST['_framed']) + { + // update the changed col in list + // ... + } + } + else if ($DB->is_error()) + { + // show error message + $OUTPUT->show_message('errorsaving', 'error'); + rcmail_overwrite_action('mailrules'); + return; + } + + } + +// insert a new contact +else + { + if ($insert_id = $USER->insert_mailrule($save_data)) + { + $_GET['_iid'] = $insert_id; + + if ($_POST['_framed']) + { + // add contact row or jump to the page where it should appear + // .... + } + } + else + { + // show error message + $OUTPUT->show_message('errorsaving', 'error'); + rcmail_overwrite_action('mailrules'); + return; + } + } + + +// go to next step +rcmail_overwrite_action($OUTPUT->action ? 'edit-mailrule' : 'mailrules'); + +?> diff -Nuar trunk/roundcubemail/skins/default/includes/settingscripts.html roundcubemail/skins/default/includes/settingscripts.html --- trunk/roundcubemail/skins/default/includes/settingscripts.html 2005-10-13 22:13:10.000000000 +0500 +++ roundcubemail/skins/default/includes/settingscripts.html 2008-05-03 16:14:35.000000000 +0500 @@ -2,7 +2,18 @@ if (window.rcmail && rcmail.env.action) { - var action = rcmail.env.action=='preferences' ? 'default' : (rcmail.env.action.indexOf('identity')>0 ? 'identities' : rcmail.env.action); + if (rcmail.env.action=='preferences') + var action = 'default'; + else + { + if ((rcmail.env.action.indexOf('identity')>0)) + var action = 'identities'; + else if ((rcmail.env.action.indexOf('mailrule')>0)) + var action = 'mailrules'; + else + var action = rcmail.env.action; + } + var tab = document.getElementById('settingstab'+action); } else @@ -11,4 +22,4 @@ if (tab) tab.className = 'tablink-selected'; - \ No newline at end of file + diff -Nuar trunk/roundcubemail/skins/default/includes/settingstabs.html roundcubemail/skins/default/includes/settingstabs.html --- trunk/roundcubemail/skins/default/includes/settingstabs.html 2005-09-25 14:18:02.000000000 +0500 +++ roundcubemail/skins/default/includes/settingstabs.html 2008-05-03 16:12:17.000000000 +0500 @@ -1,3 +1,3 @@
- +
diff -Nuar trunk/roundcubemail/skins/default/mailrule.css roundcubemail/skins/default/mailrule.css --- trunk/roundcubemail/skins/default/mailrule.css 1970-01-01 04:00:00.000000000 +0400 +++ roundcubemail/skins/default/mailrule.css 2008-05-03 16:21:26.000000000 +0500 @@ -0,0 +1,60 @@ +#mailrules-list +{ + position: absolute; + top: 95px; + left: 20px; +} + +#mailrules-div +{ + height: 120px; + width: 600px; + overflow: auto; + border: 1px solid #999999; +} + +#mailrules-table tbody td +{ + cursor: pointer; +} + +#mailrule-frame +{ + position: relative; + margin-top: 20px; + border: 1px solid #999999; +} + +#mailrule-details +{ + margin-top: 30px; + width: 600px; + border: 1px solid #999999; +} + +#mailrule-details table td.title +{ + color: #666666; + font-weight: bold; + text-align: right; + padding-right: 10px; +} + +#mailrule-title +{ + height: 12px !important; + padding: 4px 20px 3px 6px; + border-bottom: 1px solid #999999; + color: #333333; + font-size: 11px; + font-weight: bold; + background-color: #EBEBEB; + background-image: url(images/listheader_aqua.gif); +} + +#mailrules-table +{ + width: 100%; + white-space: nowrap; + background-color: #F9F9F9; +} diff -Nuar trunk/roundcubemail/skins/default/templates/addmailrule.html roundcubemail/skins/default/templates/addmailrule.html --- trunk/roundcubemail/skins/default/templates/addmailrule.html 1970-01-01 04:00:00.000000000 +0400 +++ roundcubemail/skins/default/templates/addmailrule.html 2008-05-04 08:45:50.000000000 +0500 @@ -0,0 +1,40 @@ + + + +<roundcube:object name="pagetitle" /> + + + + + + + + + + + + +
+
+ +
+

+ +
+
+ +
+ + +


+ +

+
+
+
+ + + + + + \ No newline at end of file diff -Nuar trunk/roundcubemail/skins/default/templates/editmailrule.html roundcubemail/skins/default/templates/editmailrule.html --- trunk/roundcubemail/skins/default/templates/editmailrule.html 1970-01-01 04:00:00.000000000 +0400 +++ roundcubemail/skins/default/templates/editmailrule.html 2008-05-04 08:45:28.000000000 +0500 @@ -0,0 +1,40 @@ + + + +<roundcube:object name="pagetitle" /> + + + + + + + + + + + +
+
+ +
+

+ +
+
+ +
+ + +


+  + +

+
+
+
+ + + + + + diff -Nuar trunk/roundcubemail/skins/default/templates/mailrules.html roundcubemail/skins/default/templates/mailrules.html --- trunk/roundcubemail/skins/default/templates/mailrules.html 1970-01-01 04:00:00.000000000 +0400 +++ roundcubemail/skins/default/templates/mailrules.html 2008-05-04 08:45:01.000000000 +0500 @@ -0,0 +1,27 @@ + + + +<roundcube:object name="pagetitle" /> + + + + + + + + + + +
+
+ +
+

+
+ +
+ + + + + diff -Nuar trunk/roundcubemail/SQL/mysql5.initial.sql roundcubemail/SQL/mysql5.initial.sql --- trunk/roundcubemail/SQL/mysql5.initial.sql 2008-04-03 11:03:54.000000000 +0500 +++ roundcubemail/SQL/mysql5.initial.sql 2008-05-03 16:23:50.000000000 +0500 @@ -122,4 +122,22 @@ ) TYPE=INNODB CHARACTER SET utf8 COLLATE utf8_general_ci; +-- Table structure for table `mailrules` + +CREATE TABLE `mailrules` ( + `mailrule_id` int(11) NOT NULL auto_increment, + `name` varchar(128) default NULL, + `from` varchar(128) default NULL, + `to` varchar(128) default NULL, + `subject` varchar(128) default NULL, + `cc` varchar(128) default NULL, + `bcc` varchar(128) default NULL, + `replyto` varchar(128) default NULL, + 'count' int(10) unsigned NOT NULL default '0', + `user_id` int(10) unsigned NOT NULL default '0', + `del` tinyint(1) NOT NULL default '0', + `location` varchar(128) default NULL, + PRIMARY KEY (`mailrule_id`) +) TYPE=INNODB CHARACTER SET utf8 COLLATE utf8_general_ci; + SET FOREIGN_KEY_CHECKS=1;