X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=program%2Fjs%2Fapp.js.src;h=15d8884a2443faccdec647b0c6b64d2569de4730;hb=76507f7c63a660742e76889ad6e3919f3dde3bb0;hp=411aa2ba4e31ca563063254d1634dc915474c076;hpb=81942a239bba3e46191211a3231ecfadd91ac038;p=roundcube.git diff --git a/program/js/app.js.src b/program/js/app.js.src index 411aa2b..15d8884 100644 --- a/program/js/app.js.src +++ b/program/js/app.js.src @@ -3,7 +3,8 @@ | Roundcube Webmail Client Script | | | | This file is part of the Roundcube Webmail client | - | Copyright (C) 2005-2010, Roundcube Dev, - Switzerland | + | Copyright (C) 2005-2011, The Roundcube Dev Team | + | Copyright (C) 2011, Kolab Systems AG | | Licensed under the GNU GPL | | | +-----------------------------------------------------------------------+ @@ -14,13 +15,12 @@ | Requires: jquery.js, common.js, list.js | +-----------------------------------------------------------------------+ - $Id: app.js 4763 2011-05-13 17:31:09Z alec $ + $Id: app.js 5554 2011-12-07 07:50:00Z alec $ */ - function rcube_webmail() { - this.env = {}; + this.env = { recipients_separator:',', recipients_delimiter:', ' }; this.labels = {}; this.buttons = {}; this.buttons_sel = {}; @@ -37,15 +37,10 @@ function rcube_webmail() // webmail client settings this.dblclick_time = 500; - this.message_time = 2000; + this.message_time = 4000; this.identifier_expr = new RegExp('[^0-9a-z\-_]', 'gi'); - // mimetypes supported by the browser (default settings) - this.mimetypes = new Array('text/plain', 'text/html', 'text/xml', - 'image/jpeg', 'image/gif', 'image/png', - 'application/x-javascript', 'application/pdf', 'application/x-shockwave-flash'); - // default environment vars this.env.keep_alive = 60; // seconds this.env.request_timeout = 180; // seconds @@ -63,7 +58,7 @@ function rcube_webmail() // set environment variable(s) this.set_env = function(p, value) { - if (p != null && typeof(p) == 'object' && !value) + if (p != null && typeof p === 'object' && !value) for (var n in p) this.env[n] = p[n]; else @@ -71,9 +66,12 @@ function rcube_webmail() }; // add a localized label to the client environment - this.add_label = function(key, value) + this.add_label = function(p, value) { - this.labels[key] = value; + if (typeof p == 'string') + this.labels[p] = value; + else if (typeof p == 'object') + $.extend(this.labels, p); }; // add a button to the button list @@ -88,12 +86,15 @@ function rcube_webmail() if (over) button_prop.over = over; this.buttons[command].push(button_prop); + + if (this.loaded) + init_button(command, button_prop); }; // register a specific gui object this.gui_object = function(name, id) { - this.gui_objects[name] = id; + this.gui_objects[name] = this.loaded ? rcube_find_object(id) : id; }; // register a container object @@ -127,7 +128,7 @@ function rcube_webmail() // initialize webmail client this.init = function() { - var p = this; + var n, p = this; this.task = this.env.task; // check browser @@ -137,13 +138,29 @@ function rcube_webmail() } // find all registered gui containers - for (var n in this.gui_containers) + for (n in this.gui_containers) this.gui_containers[n] = $('#'+this.gui_containers[n]); // find all registered gui objects - for (var n in this.gui_objects) + for (n in this.gui_objects) this.gui_objects[n] = rcube_find_object(this.gui_objects[n]); + // clickjacking protection + if (this.env.x_frame_options) { + try { + // bust frame if not allowed + if (this.env.x_frame_options == 'deny' && top.location.href != self.location.href) + top.location.href = self.location.href; + else if (top.location.hostname != self.location.hostname) + throw 1; + } catch (e) { + // possible clickjacking attack: disable all form elements + $('form').each(function(){ ref.lock_form(this, true); }); + this.display_message("Blocked: possible clickjacking attack!", 'error'); + return; + } + } + // init registered buttons this.init_buttons(); @@ -154,7 +171,7 @@ function rcube_webmail() } // enable general commands - this.enable_command('logout', 'mail', 'addressbook', 'settings', true); + this.enable_command('logout', 'mail', 'addressbook', 'settings', 'save-pref', 'compose', 'undo', true); if (this.env.permaurl) this.enable_command('permaurl', true); @@ -163,7 +180,7 @@ function rcube_webmail() case 'mail': // enable mail commands - this.enable_command('list', 'checkmail', 'compose', 'add-contact', 'search', 'reset-search', 'collapse-folder', true); + this.enable_command('list', 'checkmail', 'add-contact', 'search', 'reset-search', 'collapse-folder', true); if (this.gui_objects.messagelist) { @@ -199,19 +216,20 @@ function rcube_webmail() $(this.gui_objects.qsearchbox).focusin(function() { rcmail.message_list.blur(); }); } - if (this.env.trash_mailbox && this.env.mailbox != this.env.trash_mailbox) + if (!this.env.flag_for_deletion && this.env.trash_mailbox && this.env.mailbox != this.env.trash_mailbox) this.set_alttext('delete', 'movemessagetotrash'); this.env.message_commands = ['show', 'reply', 'reply-all', 'reply-list', 'forward', 'moveto', 'copy', 'delete', 'open', 'mark', 'edit', 'viewsource', 'download', - 'print', 'load-attachment', 'load-headers']; + 'print', 'load-attachment', 'load-headers', 'forward-attachment']; - if (this.env.action=='show' || this.env.action=='preview') { + if (this.env.action == 'show' || this.env.action == 'preview') { this.enable_command(this.env.message_commands, this.env.uid); this.enable_command('reply-list', this.env.list_post); if (this.env.action == 'show') { - this.http_request('pagenav', '_uid='+this.env.uid+'&_mbox='+urlencode(this.env.mailbox), + this.http_request('pagenav', '_uid='+this.env.uid+'&_mbox='+urlencode(this.env.mailbox) + + (this.env.search_request ? '&_search='+this.env.search_request : ''), this.display_message('', 'loading')); } @@ -228,7 +246,7 @@ function rcube_webmail() } } else if (this.env.action == 'compose') { - this.env.compose_commands = ['send-attachment', 'remove-attachment', 'send', 'toggle-editor']; + this.env.compose_commands = ['send-attachment', 'remove-attachment', 'send', 'cancel', 'toggle-editor']; if (this.env.drafts_mailbox) this.env.compose_commands.push('savedraft') @@ -250,7 +268,10 @@ function rcube_webmail() } // show printing dialog else if (this.env.action == 'print' && this.env.uid) - window.print(); + if (bw.safari) + window.setTimeout('window.print()', 10); + else + window.print(); // get unread count for each mailbox if (this.gui_objects.mailboxlist) { @@ -270,11 +291,13 @@ function rcube_webmail() break; - case 'addressbook': if (this.gui_objects.folderlist) this.env.contactfolders = $.extend($.extend({}, this.env.address_sources), this.env.contactgroups); + this.enable_command('add', 'import', this.env.writable_source); + this.enable_command('list', 'listgroup', 'listsearch', 'advanced-search', true); + if (this.gui_objects.contactslist) { this.contact_list = new rcube_list_widget(this.gui_objects.contactslist, @@ -295,55 +318,46 @@ function rcube_webmail() if (this.gui_objects.qsearchbox) { $(this.gui_objects.qsearchbox).focusin(function() { rcmail.contact_list.blur(); }); } + + this.update_group_commands(); + this.command('list'); } this.set_page_buttons(); - if (this.env.address_sources && this.env.address_sources[this.env.source] && !this.env.address_sources[this.env.source].readonly) { - this.enable_command('add', 'import', true); - this.enable_command('group-create', this.env.address_sources[this.env.source].groups); - } - if (this.env.cid) { this.enable_command('show', 'edit', true); // register handlers for group assignment via checkboxes if (this.gui_objects.editform) { - $('input.groupmember').change(function(){ - var cmd = this.checked ? 'group-addmembers' : 'group-delmembers'; - ref.http_post(cmd, '_cid='+urlencode(ref.env.cid) - + '&_source='+urlencode(ref.env.source) - + '&_gid='+urlencode(this.value)); + $('input.groupmember').change(function() { + ref.group_member_change(this.checked ? 'add' : 'del', ref.env.cid, ref.env.source, this.value); }); } } - if ((this.env.action=='add' || this.env.action=='edit') && this.gui_objects.editform) { + if (this.gui_objects.editform) { this.enable_command('save', true); - $("input[type='text']").first().select(); + if (this.env.action == 'add' || this.env.action == 'edit') + this.init_contact_form(); } - else if (this.gui_objects.qsearchbox) { + + if (this.gui_objects.qsearchbox) { this.enable_command('search', 'reset-search', 'moveto', true); - $(this.gui_objects.qsearchbox).select(); } - if (this.contact_list && this.contact_list.rowcount > 0) - this.enable_command('export', true); - - this.enable_command('list', 'listgroup', true); break; - case 'settings': this.enable_command('preferences', 'identities', 'save', 'folders', true); - if (this.env.action=='identities') { + if (this.env.action == 'identities') { this.enable_command('add', this.env.identities_level < 2); } - else if (this.env.action=='edit-identity' || this.env.action=='add-identity') { + else if (this.env.action == 'edit-identity' || this.env.action == 'add-identity') { this.enable_command('add', this.env.identities_level < 2); this.enable_command('save', 'delete', 'edit', 'toggle-editor', true); } - else if (this.env.action=='folders') { + else if (this.env.action == 'folders') { this.enable_command('subscribe', 'unsubscribe', 'create-folder', 'rename-folder', true); } else if (this.env.action == 'edit-folder' && this.gui_objects.editform) { @@ -383,11 +397,16 @@ function rcube_webmail() $('#rcmloginpwd').focus(); // detect client timezone - $('#rcmlogintz').val(new Date().getTimezoneOffset() / -60); + var dt = new Date(), + tz = dt.getTimezoneOffset() / -60, + stdtz = dt.getStdTimezoneOffset() / -60; + + $('#rcmlogintz').val(stdtz); + $('#rcmlogindst').val(tz > stdtz ? 1 : 0); // display 'loading' message on form submit, lock submit button $('form').submit(function () { - $('input[type=submit]', this).attr('disabled', true); + $('input[type=submit]', this).prop('disabled', true); rcmail.display_message('', 'loading'); }); @@ -398,12 +417,16 @@ function rcube_webmail() break; } + // prevent from form submit with Enter key in file input fields + if (bw.ie) + $('input[type=file]').keydown(function(e) { if (e.keyCode == '13') e.preventDefault(); }); + // flag object as complete this.loaded = true; // show message if (this.pending_message) - this.display_message(this.pending_message[0], this.pending_message[1]); + this.display_message(this.pending_message[0], this.pending_message[1], this.pending_message[2]); // map implicit containers if (this.gui_objects.folderlist) @@ -415,9 +438,9 @@ function rcube_webmail() // execute all foreign onload scripts // @deprecated for (var i in this.onloads) { - if (typeof(this.onloads[i]) == 'string') + if (typeof this.onloads[i] === 'string') eval(this.onloads[i]); - else if (typeof(this.onloads[i]) == 'function') + else if (typeof this.onloads[i] === 'function') this.onloads[i](); } @@ -425,6 +448,11 @@ function rcube_webmail() this.start_keepalive(); }; + this.log = function(msg) + { + if (window.console && console.log) + console.log(msg); + }; /*********************************************************/ /********* client command interface *********/ @@ -433,6 +461,8 @@ function rcube_webmail() // execute a specific command on the web client this.command = function(command, props, obj) { + var ret, uid, cid, url, flag; + if (obj && obj.blur) obj.blur(); @@ -449,32 +479,34 @@ function rcube_webmail() } // check input before leaving compose step - if (this.task=='mail' && this.env.action=='compose' && $.inArray(command, this.env.compose_commands)<0) { + if (this.task == 'mail' && this.env.action == 'compose' && $.inArray(command, this.env.compose_commands)<0) { if (this.cmp_hash != this.compose_field_hash() && !confirm(this.get_label('notsentwarning'))) return false; } // process external commands - if (typeof this.command_handlers[command] == 'function') { - var ret = this.command_handlers[command](props, obj); - return ret !== null ? ret : (obj ? false : true); + if (typeof this.command_handlers[command] === 'function') { + ret = this.command_handlers[command](props, obj); + return ret !== undefined ? ret : (obj ? false : true); } - else if (typeof this.command_handlers[command] == 'string') { - var ret = window[this.command_handlers[command]](props, obj); - return ret !== null ? ret : (obj ? false : true); + else if (typeof this.command_handlers[command] === 'string') { + ret = window[this.command_handlers[command]](props, obj); + return ret !== undefined ? ret : (obj ? false : true); } // trigger plugin hooks this.triggerEvent('actionbefore', {props:props, action:command}); - var event_ret = this.triggerEvent('before'+command, props); - if (typeof event_ret != 'undefined') { - // abort if one the handlers returned false - if (event_ret === false) + ret = this.triggerEvent('before'+command, props); + if (ret !== undefined) { + // abort if one of the handlers returned false + if (ret === false) return false; else - props = event_ret; + props = ret; } + ret = undefined; + // process internal command switch (command) { @@ -504,7 +536,6 @@ function rcube_webmail() return false; case 'open': - var uid; if (uid = this.get_single_uid()) { obj.href = '?_task='+this.env.task+'&_action=show&_mbox='+urlencode(this.env.mailbox)+'&_uid='+uid; return true; @@ -512,21 +543,15 @@ function rcube_webmail() break; case 'list': - if (this.task=='mail') { - if (!this.env.search_request || (props && props != this.env.mailbox)) - this.reset_qsearch(); - + this.reset_qsearch(); + if (this.task == 'mail') { this.list_mailbox(props); - if (this.env.trash_mailbox) + if (this.env.trash_mailbox && !this.env.flag_for_deletion) this.set_alttext('delete', this.env.mailbox != this.env.trash_mailbox ? 'movemessagetotrash' : 'deletemessage'); } - else if (this.task=='addressbook') { - if (!this.env.search_request || (props != this.env.source)) - this.reset_qsearch(); - + else if (this.task == 'addressbook') { this.list_contacts(props); - this.enable_command('add', 'import', (this.env.address_sources && !this.env.address_sources[this.env.source].readonly)); } break; @@ -578,8 +603,8 @@ function rcube_webmail() // common commands used in multiple tasks case 'show': - if (this.task=='mail') { - var uid = this.get_single_uid(); + if (this.task == 'mail') { + uid = this.get_single_uid(); if (uid && (!this.env.uid || uid != this.env.uid)) { if (this.env.mailbox == this.env.drafts_mailbox) this.goto_url('compose', '_draft_uid='+uid+'&_mbox='+urlencode(this.env.mailbox), true); @@ -587,61 +612,68 @@ function rcube_webmail() this.show_message(uid); } } - else if (this.task=='addressbook') { - var cid = props ? props : this.get_single_cid(); - if (cid && !(this.env.action=='show' && cid==this.env.cid)) + else if (this.task == 'addressbook') { + cid = props ? props : this.get_single_cid(); + if (cid && !(this.env.action == 'show' && cid == this.env.cid)) this.load_contact(cid, 'show'); } break; case 'add': - if (this.task=='addressbook') + if (this.task == 'addressbook') this.load_contact(0, 'add'); - else if (this.task=='settings') { + else if (this.task == 'settings') { this.identity_list.clear_selection(); this.load_identity(0, 'add-identity'); } break; case 'edit': - var cid; 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'); else if (this.task=='mail' && (cid = this.get_single_uid())) { - var url = (this.env.mailbox == this.env.drafts_mailbox) ? '_draft_uid=' : '_uid='; + url = (this.env.mailbox == this.env.drafts_mailbox) ? '_draft_uid=' : '_uid='; this.goto_url('compose', url+cid+'&_mbox='+urlencode(this.env.mailbox), true); } break; case 'save': - if (this.gui_objects.editform) { - var input_pagesize = $("input[name='_pagesize']"); - var input_name = $("input[name='_name']"); - var input_email = $("input[name='_email']"); - + var input, form = this.gui_objects.editform; + if (form) { + // adv. search + if (this.env.action == 'search') { + } // user prefs - if (input_pagesize.length && isNaN(parseInt(input_pagesize.val()))) { + else if ((input = $("input[name='_pagesize']", form)) && input.length && isNaN(parseInt(input.val()))) { alert(this.get_label('nopagesizewarning')); - input_pagesize.focus(); + input.focus(); break; } // contacts/identities else { - if (input_name.length && input_name.val() == '') { - alert(this.get_label('nonamewarning')); - input_name.focus(); - break; + // reload form + if (props == 'reload') { + form.action += '?_reload=1'; } - else if (input_email.length && !rcube_check_email(input_email.val())) { + else if (this.task == 'settings' && (this.env.identities_level % 2) == 0 && + (input = $("input[name='_email']", form)) && input.length && !rcube_check_email(input.val()) + ) { alert(this.get_label('noemailwarning')); - input_email.focus(); + input.focus(); break; } + + // clear empty input fields + $('input.placeholder').each(function(){ if (this.value == this._placeholder) this.value = ''; }); } - this.gui_objects.editform.submit(); + // add selected source (on the list) + if (parent.rcmail && parent.rcmail.env.source) + form.action = this.add_url(form.action, '_orig_source', parent.rcmail.env.source); + + form.submit(); } break; @@ -680,7 +712,7 @@ function rcube_webmail() if (props && !props._row) break; - var uid, flag = 'read'; + flag = 'read'; if (props._row.uid) { uid = props._row.uid; @@ -700,7 +732,7 @@ function rcube_webmail() if (props && !props._row) break; - var uid, flag = 'flagged'; + flag = 'flagged'; if (props._row.uid) { uid = props._row.uid; @@ -727,7 +759,7 @@ function rcube_webmail() var qstring = '_mbox='+urlencode(this.env.mailbox)+'&_uid='+this.env.uid+'&_part='+props.part; // open attachment in frame if it's of a supported mimetype - if (this.env.uid && props.mimetype && $.inArray(props.mimetype, this.mimetypes)>=0) { + if (this.env.uid && props.mimetype && this.env.mimetypes && $.inArray(props.mimetype, this.env.mimetypes)>=0) { if (props.mimetype == 'text/html') qstring += '&_safe=1'; this.attachment_win = window.open(this.env.comm_path+'&_action=get&'+qstring+'&_frame=1', 'rcubemailattachment'); @@ -796,21 +828,15 @@ function rcube_webmail() break; case 'compose': - var url = this.env.comm_path+'&_action=compose'; + url = this.url('mail/compose'); - if (this.task=='mail') { + if (this.task == 'mail') { url += '&_mbox='+urlencode(this.env.mailbox); - - if (this.env.mailbox==this.env.drafts_mailbox) { - var uid; - if (uid = this.get_single_uid()) - url += '&_draft_uid='+uid; - } - else if (props) + if (props) url += '&_to='+urlencode(props); } // modify url if we're in addressbook - else if (this.task=='addressbook') { + else if (this.task == 'addressbook') { // switch to mail compose step directly if (props && props.indexOf('@') > 0) { url = this.get_task_url('mail', url); @@ -819,24 +845,25 @@ function rcube_webmail() } // use contact_id passed as command parameter - var a_cids = []; + var n, len, a_cids = []; if (props) a_cids.push(props); // get selected contacts else if (this.contact_list) { var selection = this.contact_list.get_selection(); - for (var n=0; n 0) { - var add_url = (this.env.source ? '_source='+urlencode(this.env.source)+'&' : ''); - if (this.env.search_request) - add_url += '_search='+this.env.search_request; - - this.goto_url('export', add_url); + this.goto_url('export', { _source:this.env.source, _gid:this.env.group, _search:this.env.search_request }); } break; + case 'upload-photo': + this.upload_contact_photo(props); + break; + + case 'delete-photo': + this.replace_contact_photo('-del-'); + break; + // user settings commands case 'preferences': case 'identities': @@ -1011,27 +1053,33 @@ function rcube_webmail() this.goto_url('settings/' + command); break; + case 'undo': + this.http_request('undo', '', this.display_message('', 'loading')); + break; + // unified command call (command name == function name) default: var func = command.replace(/-/g, '_'); - if (this[func] && typeof this[func] == 'function') - this[func](props); + if (this[func] && typeof this[func] === 'function') { + ret = this[func](props); + } break; } - this.triggerEvent('after'+command, props); + if (this.triggerEvent('after'+command, props) === false) + ret = false; this.triggerEvent('actionafter', {props:props, action:command}); - return obj ? false : true; + return ret === false ? false : obj ? false : true; }; // set command(s) enabled or disabled this.enable_command = function() { - var args = Array.prototype.slice.call(arguments), + var i, n, args = Array.prototype.slice.call(arguments), enable = args.pop(), cmd; - for (var n=0; n= pos.x2 || mouse.y < pos.y1 || mouse.y >= pos.y2) { @@ -1270,10 +1348,10 @@ function rcube_webmail() } // over the folders - for (var k in this.env.folder_coords) { + for (k in this.env.folder_coords) { pos = this.env.folder_coords[k]; if (mouse.x >= pos.x1 && mouse.x < pos.x2 && mouse.y >= pos.y1 && mouse.y < pos.y2){ - if ((check = this.check_droptarget(k))) { + if ((check = this.check_droptarget(k))) { li = this.get_folder_li(k); div = $(li.getElementsByTagName('div')[0]); @@ -1284,9 +1362,9 @@ function rcube_webmail() this.folder_auto_expand = k; this.folder_auto_timer = window.setTimeout(function() { - rcmail.command('collapse-folder', rcmail.folder_auto_expand); - rcmail.drag_start(null); - }, 1000); + rcmail.command('collapse-folder', rcmail.folder_auto_expand); + rcmail.drag_start(null); + }, 1000); } else if (this.folder_auto_timer) { window.clearTimeout(this.folder_auto_timer); this.folder_auto_timer = null; @@ -1312,31 +1390,29 @@ function rcube_webmail() } }; - this.collapse_folder = function(id) + this.collapse_folder = function(name) { - var li = this.get_folder_li(id), - div = $(li.getElementsByTagName('div')[0]); - - if (!div || (!div.hasClass('collapsed') && !div.hasClass('expanded'))) - return; - - var ul = $(li.getElementsByTagName('ul')[0]); + var li = this.get_folder_li(name, '', true), + div = $('div:first', li), + ul = $('ul:first', li); if (div.hasClass('collapsed')) { ul.show(); div.removeClass('collapsed').addClass('expanded'); - var reg = new RegExp('&'+urlencode(id)+'&'); - this.set_env('collapsed_folders', this.env.collapsed_folders.replace(reg, '')); + var reg = new RegExp('&'+urlencode(name)+'&'); + this.env.collapsed_folders = this.env.collapsed_folders.replace(reg, ''); } - else { + else if (div.hasClass('expanded')) { ul.hide(); div.removeClass('expanded').addClass('collapsed'); - this.set_env('collapsed_folders', this.env.collapsed_folders+'&'+urlencode(id)+'&'); + this.env.collapsed_folders = this.env.collapsed_folders+'&'+urlencode(name)+'&'; // select parent folder if one of its childs is currently selected - if (this.env.mailbox.indexOf(id + this.env.delimiter) == 0) - this.command('list', id); + if (this.env.mailbox.indexOf(name + this.env.delimiter) == 0) + this.command('list', name); } + else + return; // Work around a bug in IE6 and IE7, see #1485309 if (bw.ie6 || bw.ie7) { @@ -1347,14 +1423,18 @@ function rcube_webmail() } } - this.http_post('save-pref', '_name=collapsed_folders&_value='+urlencode(this.env.collapsed_folders)); - this.set_unread_count_display(id, false); + this.command('save-pref', { name: 'collapsed_folders', value: this.env.collapsed_folders }); + this.set_unread_count_display(name, false); }; this.doc_mouse_up = function(e) { var model, list, li, id; + // ignore event if jquery UI dialog is open + if ($(rcube_event.get_target(e)).closest('.ui-dialog, .ui-widget-overlay').length) + return; + if (list = this.message_list) { if (!rcube_mouse_is_over(e, list.list.parentNode)) list.blur(); @@ -1388,7 +1468,7 @@ function rcube_webmail() // reset 'pressed' buttons if (this.buttons_sel) { for (id in this.buttons_sel) - if (typeof id != 'function') + if (typeof id !== 'function') this.button_out(this.buttons_sel[id], id); this.buttons_sel = {}; } @@ -1420,7 +1500,7 @@ function rcube_webmail() if (selected) { // Hide certain command buttons when Drafts folder is selected if (this.env.mailbox == this.env.drafts_mailbox) - this.enable_command('reply', 'reply-all', 'reply-list', 'forward', false); + this.enable_command('reply', 'reply-all', 'reply-list', 'forward', 'forward-attachment', false); // Disable reply-list when List-Post header is not set else { var msg = this.env.messages[list.get_single_selection()]; @@ -1476,11 +1556,12 @@ function rcube_webmail() this.msglist_keypress = function(list) { + if (list.modkey == CONTROL_KEY) + return; + if (list.key_pressed == list.ENTER_KEY) this.command('show'); - else if (list.key_pressed == list.DELETE_KEY) - this.command('delete'); - else if (list.key_pressed == list.BACKSPACE_KEY) + else if (list.key_pressed == list.DELETE_KEY || list.key_pressed == list.BACKSPACE_KEY) this.command('delete'); else if (list.key_pressed == 33) this.command('previouspage'); @@ -1516,12 +1597,12 @@ function rcube_webmail() } if ((found = $.inArray('flag', this.env.coltypes)) >= 0) - this.set_env('flagged_col', found); + this.env.flagged_col = found; if ((found = $.inArray('subject', this.env.coltypes)) >= 0) - this.set_env('subject_col', found); + this.env.subject_col = found; - this.http_post('save-pref', { '_name':'list_cols', '_value':this.env.coltypes, '_session':'list_attrib/columns' }); + this.command('save-pref', { name: 'list_cols', value: this.env.coltypes, session: 'list_attrib/columns' }); }; this.check_droptarget = function(id) @@ -1594,14 +1675,18 @@ function rcube_webmail() if (!this.gui_objects.messagelist || !this.message_list) return false; + // Prevent from adding messages from different folder (#1487752) + if (flags.mbox != this.env.mailbox && !flags.skip_mbox_check) + return false; + if (!this.env.messages[uid]) this.env.messages[uid] = {}; // merge flags over local message object $.extend(this.env.messages[uid], { deleted: flags.deleted?1:0, - replied: flags.replied?1:0, - unread: flags.unread?1:0, + replied: flags.answered?1:0, + unread: !flags.seen?1:0, forwarded: flags.forwarded?1:0, flagged: flags.flagged?1:0, has_children: flags.has_children?1:0, @@ -1615,23 +1700,18 @@ function rcube_webmail() flags: flags.extra_flags }); - var c, html, tree = expando = '', + var c, n, col, html, tree = '', expando = '', list = this.message_list, rows = list.rows, - tbody = this.gui_objects.messagelist.tBodies[0], - rowcount = tbody.rows.length, - even = rowcount%2, message = this.env.messages[uid], css_class = 'message' - + (even ? ' even' : ' odd') - + (flags.unread ? ' unread' : '') + + (!flags.seen ? ' unread' : '') + (flags.deleted ? ' deleted' : '') + (flags.flagged ? ' flagged' : '') - + (flags.unread_children && !flags.unread && !this.env.autoexpand_threads ? ' unroot' : '') + + (flags.unread_children && flags.seen && !this.env.autoexpand_threads ? ' unroot' : '') + (message.selected ? ' selected' : ''), // for performance use DOM instead of jQuery here - row = document.createElement('tr'), - col = document.createElement('td'); + row = document.createElement('tr'); row.id = 'rcmrow'+uid; row.className = css_class; @@ -1642,12 +1722,12 @@ function rcube_webmail() css_class += ' status'; if (flags.deleted) css_class += ' deleted'; - else if (flags.unread) + else if (!flags.seen) css_class += ' unread'; else if (flags.unread_children > 0) css_class += ' unreadchildren'; } - if (flags.replied) + if (flags.answered) css_class += ' replied'; if (flags.forwarded) css_class += ' forwarded'; @@ -1658,9 +1738,10 @@ function rcube_webmail() // threads if (this.env.threading) { - // This assumes that div width is hardcoded to 15px, - var width = message.depth * 15; if (message.depth) { + // This assumes that div width is hardcoded to 15px, + tree += '  '; + if ((rows[message.parent_uid] && rows[message.parent_uid].expanded === false) || ((this.env.autoexpand_threads == 0 || this.env.autoexpand_threads == 2) && (!rows[message.parent_uid] || !rows[message.parent_uid].expanded)) @@ -1672,16 +1753,12 @@ function rcube_webmail() message.expanded = true; } else if (message.has_children) { - if (typeof(message.expanded) == 'undefined' && (this.env.autoexpand_threads == 1 || (this.env.autoexpand_threads == 2 && message.unread_children))) { + if (message.expanded === undefined && (this.env.autoexpand_threads == 1 || (this.env.autoexpand_threads == 2 && message.unread_children))) { message.expanded = true; } - } - - if (width) - tree += '  '; - if (message.has_children && !message.depth) expando = '
  
'; + } } tree += ' '; @@ -1695,7 +1772,7 @@ function rcube_webmail() } // add each submitted col - for (var n in this.env.coltypes) { + for (n in this.env.coltypes) { c = this.env.coltypes[n]; col = document.createElement('td'); col.className = String(c).toLowerCase(); @@ -1715,7 +1792,7 @@ function rcube_webmail() else if (c == 'status') { if (flags.deleted) css_class = 'deleted'; - else if (flags.unread) + else if (!flags.seen) css_class = 'unread'; else if (flags.unread_children > 0) css_class = 'unreadchildren'; @@ -1725,8 +1802,17 @@ function rcube_webmail() } else if (c == 'threads') html = expando; - else if (c == 'subject') + else if (c == 'subject') { + if (bw.ie) + col.onmouseover = function() { rcube_webmail.long_subject_title_ie(this, message.depth+1); }; html = tree + cols[c]; + } + else if (c == 'priority') { + if (flags.prio > 0 && flags.prio < 6) + html = ' '; + else + html = ' '; + } else html = cols[c]; @@ -1760,7 +1846,7 @@ function rcube_webmail() { var update, add_url = ''; - if (typeof sort_col == 'undefined') + if (sort_col === undefined) sort_col = this.env.sort_col; if (!sort_order) sort_order = this.env.sort_order; @@ -1825,10 +1911,7 @@ function rcube_webmail() if (action == 'preview' && String(target.location.href).indexOf(url) >= 0) this.show_contentframe(true); else { - if (!this.env.frame_lock) { - (this.is_framed() ? parent.rcmail : this).env.frame_lock = this.set_busy(true, 'loading'); - } - target.location.href = this.env.comm_path+url; + this.location_href(this.env.comm_path+url, target, true); // mark as read and change mbox unread counter if (action == 'preview' && this.message_list && this.message_list.rows[id] && this.message_list.rows[id].unread && this.env.preview_pane_mark_read >= 0) { @@ -1862,6 +1945,12 @@ function rcube_webmail() this.set_busy(false, null, this.env.frame_lock); }; + this.lock_frame = function() + { + if (!this.env.frame_lock) + (this.is_framed() ? parent.rcmail : this).env.frame_lock = this.set_busy(true, 'loading'); + }; + // list a specific page this.list_page = function(page) { @@ -1887,18 +1976,13 @@ function rcube_webmail() // list messages of a specific mailbox using filter this.filter_mailbox = function(filter) { - var search, lock = this.set_busy(true, 'searching'); - - if (this.gui_objects.qsearchbox) - search = this.gui_objects.qsearchbox.value; + var lock = this.set_busy(true, 'searching'); this.clear_message_list(); // reset vars this.env.current_page = 1; - this.http_request('search', '_filter='+filter - + (search ? '&_q='+urlencode(search) : '') - + (this.env.mailbox ? '&_mbox='+urlencode(this.env.mailbox) : ''), lock); + this.http_request('search', this.search_params(false, filter), lock); }; // list messages of a specific mailbox @@ -1933,7 +2017,7 @@ function rcube_webmail() if (mbox != this.env.mailbox || (mbox == this.env.mailbox && !page && !sort)) url += '&_refresh=1'; - this.select_folder(mbox, this.env.mailbox); + this.select_folder(mbox, '', true); this.env.mailbox = mbox; // load message list remotely @@ -1950,7 +2034,7 @@ function rcube_webmail() // load message list to target frame/window if (mbox) { this.set_busy(true, 'loading'); - target.location.href = this.env.comm_path+'&_mbox='+urlencode(mbox)+(page ? '&_page='+page : '')+url; + this.location_href(this.env.comm_path+'&_mbox='+urlencode(mbox)+(page ? '&_page='+page : '')+url, target); } }; @@ -1997,8 +2081,7 @@ function rcube_webmail() new_row = tbody.firstChild; while (new_row) { - if (new_row.nodeType == 1 && (r = this.message_list.rows[new_row.uid]) - && r.unread_children) { + if (new_row.nodeType == 1 && (r = this.message_list.rows[new_row.uid]) && r.unread_children) { this.message_list.expand_all(r); this.set_unread_children(r.uid); } @@ -2033,8 +2116,12 @@ function rcube_webmail() }; // Initializes threads indicators/expanders after list update - this.init_threads = function(roots) + this.init_threads = function(roots, mbox) { + // #1487752 + if (mbox && mbox != this.env.mailbox) + return false; + for (var n=0, len=roots.length; n 0) { + ac_props = { + threads: this.env.autocomplete_threads, + sources: this.env.autocomplete_sources + }; + } // init live search events - this.init_address_input_events(input_to); + this.init_address_input_events(input_to, ac_props); for (var i in ac_fields) { - this.init_address_input_events($("[name='_"+ac_fields[i]+"']")); + this.init_address_input_events($("[name='_"+ac_fields[i]+"']"), ac_props); } if (!html_mode) { this.set_caret_pos(input_message, this.env.top_posting ? 0 : $(input_message).val().length); // add signature according to selected identity // if we have HTML editor, signature is added in callback - if (input_from.attr('type') == 'select-one' && $("input[name='_draft_saveid']").val() == '') { + if (input_from.prop('type') == 'select-one' && $("input[name='_draft_saveid']").val() == '') { this.change_identity(input_from[0]); } } @@ -2845,14 +2946,16 @@ function rcube_webmail() this.auto_save_start(); }; - this.init_address_input_events = function(obj) + this.init_address_input_events = function(obj, props) { - obj[bw.ie || bw.safari || bw.chrome ? 'keydown' : 'keypress'](function(e){ return ref.ksearch_keydown(e, this); }) + this.env.recipients_delimiter = this.env.recipients_separator + ' '; + + obj[bw.ie || bw.safari || bw.chrome ? 'keydown' : 'keypress'](function(e) { return ref.ksearch_keydown(e, this, props); }) .attr('autocomplete', 'off'); }; // checks the input fields before sending a message - this.check_compose_input = function() + this.check_compose_input = function(cmd) { // check input fields var ed, input_to = $("[name='_to']"), @@ -2863,7 +2966,7 @@ function rcube_webmail() input_message = $("[name='_message']"); // check sender (if have no identities) - if (input_from.attr('type') == 'text' && !rcube_check_email(input_from.val(), true)) { + if (input_from.prop('type') == 'text' && !rcube_check_email(input_from.val(), true)) { alert(this.get_label('nosenderwarning')); input_from.focus(); return false; @@ -2879,7 +2982,7 @@ function rcube_webmail() // check if all files has been uploaded for (var key in this.env.attachments) { - if (typeof this.env.attachments[key] == 'object' && !this.env.attachments[key].complete) { + if (typeof this.env.attachments[key] === 'object' && !this.env.attachments[key].complete) { alert(this.get_label('notuploadedwarning')); return false; } @@ -2887,15 +2990,28 @@ function rcube_webmail() // display localized warning for missing subject if (input_subject.val() == '') { - var subject = prompt(this.get_label('nosubjectwarning'), this.get_label('nosubject')); + var myprompt = $('
').html('
' + this.get_label('nosubjectwarning') + '
').appendTo(document.body); + var prompt_value = $('').attr('type', 'text').attr('size', 30).appendTo(myprompt).val(this.get_label('nosubject')); - // user hit cancel, so don't send - if (!subject && subject !== '') { + var buttons = {}; + buttons[this.get_label('cancel')] = function(){ input_subject.focus(); - return false; - } - else - input_subject.val((subject ? subject : this.get_label('nosubject'))); + $(this).dialog('close'); + }; + buttons[this.get_label('sendmessage')] = function(){ + input_subject.val(prompt_value.val()); + $(this).dialog('close'); + ref.command(cmd, { nocheck:true }); // repeat command which triggered this + }; + + myprompt.dialog({ + modal: true, + resizable: false, + buttons: buttons, + close: function(event, ui) { $(this).remove() } + }); + prompt_value.select(); + return false; } // Apply spellcheck changes if spell checker is active @@ -2976,6 +3092,36 @@ function rcube_webmail() this.enable_command('spellcheck', this.spellcheck_ready); }; + // get selected language + this.spellcheck_lang = function() + { + var ed; + if (window.tinyMCE && (ed = tinyMCE.get(this.env.composebody)) && ed.plugins.spellchecker) { + return ed.plugins.spellchecker.selectedLang; + } + else if (this.env.spellcheck) { + return GOOGIE_CUR_LANG; + } + }; + + // resume spellchecking, highlight provided mispellings without new ajax request + this.spellcheck_resume = function(ishtml, data) + { + if (ishtml) { + var ed = tinyMCE.get(this.env.composebody); + sp = ed.plugins.spellchecker; + + sp.active = 1; + sp._markWords(data); + ed.nodeChanged(); + } + else { + var sp = this.env.spellcheck; + sp.prepare(false, true); + sp.processData(data); + } + } + this.set_draft_id = function(id) { $("input[name='_draft_saveid']").val(id); @@ -3054,7 +3200,7 @@ function rcube_webmail() sig = this.env.signatures[sig].is_html ? this.env.signatures[sig].plain_text : this.env.signatures[sig].text; sig = sig.replace(/\r\n/g, '\n'); - if (!sig.match(/^--[ -]\n/)) + if (!sig.match(/^--[ -]\n/m)) sig = sig_separator + '\n' + sig; p = this.env.sig_above ? message.indexOf(sig) : message.lastIndexOf(sig); @@ -3066,7 +3212,7 @@ function rcube_webmail() sig = this.env.signatures[id]['is_html'] ? this.env.signatures[id]['plain_text'] : this.env.signatures[id]['text']; sig = sig.replace(/\r\n/g, '\n'); - if (!sig.match(/^--[ -]\n/)) + if (!sig.match(/^--[ -]\n/m)) sig = sig_separator + '\n' + sig; if (this.env.sig_above) { @@ -3135,12 +3281,12 @@ function rcube_webmail() if (this.env.signatures[id]) { if (this.env.signatures[id].is_html) { sig = this.env.signatures[id].text; - if (!this.env.signatures[id].plain_text.match(/^--[ -]\r?\n/)) + if (!this.env.signatures[id].plain_text.match(/^--[ -]\r?\n/m)) sig = sig_separator + '
' + sig; } else { sig = this.env.signatures[id].text; - if (!sig.match(/^--[ -]\r?\n/)) + if (!sig.match(/^--[ -]\r?\n/m)) sig = sig_separator + '\n' + sig; sig = '
' + sig + '
'; } @@ -3159,37 +3305,23 @@ function rcube_webmail() if (!form) return false; - // get file input fields - var send = false; - for (var n=0; n