markasjunk.min.js 2.9 KB
/**
 * Mark-as-Junk plugin script
 *
 * @licstart  The following is the entire license notice for the
 * JavaScript code in this file.
 *
 * Copyright (c) The Roundcube Dev Team
 * Copyright (C) Philip Weir
 *
 * The JavaScript code in this page is free software: you can redistribute it
 * and/or modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.
 *
 * @licend  The above is the entire license notice
 * for the JavaScript code in this file.
 */
rcube_webmail.prototype.markasjunk_mark=function(a){var n,e=this.env.uid?[this.env.uid]:this.message_list.get_selection();e&&(n=this.set_busy(!0,"loading"),this.http_post("plugin.markasjunk."+(a?"junk":"not_junk"),this.selection_post_data({_uid:e}),n))},rcube_webmail.prototype.markasjunk_move=function(a,n){var e=this.env.uid;this.message_list&&1==n.length&&!this.message_list.in_selection(n[0])&&(this.env.uid=n[0]),a?this.move_messages(a):1==this.env.markasjunk_permanently_remove?this.permanently_remove_messages():this.delete_messages(),this.env.uid=e},rcube_webmail.prototype.markasjunk_toggle_button=function(){var m=$("a.junk"),s=$("a.notjunk"),t={spam:!0,ham:!0};this.env.markasjunk_spam_only?t.ham=!1:!this.is_multifolder_listing()&&this.env.markasjunk_spam_mailbox&&(this.env.mailbox!=this.env.markasjunk_spam_mailbox?t.ham=!1:t.spam=!1),$.each(m,function(a){var n=m.eq(a),e=s.eq(a),i=m.eq(a).index();0<n.parent("li").length&&(n=n.parent(),e=e.parent());a=rcmail.triggerEvent("markasjunk-update",{objs:{spamobj:n,hamobj:e},disp:t});a&&a.abort||((t=a?a.disp:t).spam?n.show():n.hide(),t.ham?e.show():e.hide(),t.spam&&!t.ham?i<e.index()&&n.insertAfter(e):i>e.index()&&e.insertAfter(n))})},rcube_webmail.prototype.markasjunk_is_spam_mbox=function(){return!this.is_multifolder_listing()&&this.env.mailbox==this.env.markasjunk_spam_mailbox},window.rcmail&&(rcmail.addEventListener("init",function(){rcmail.register_command("plugin.markasjunk.junk",function(){rcmail.markasjunk_mark(!0)},!rcmail.markasjunk_is_spam_mbox()&&rcmail.env.uid),rcmail.register_command("plugin.markasjunk.not_junk",function(){rcmail.markasjunk_mark(!1)},rcmail.env.uid),rcmail.message_list&&rcmail.message_list.addEventListener("select",function(a){rcmail.enable_command("plugin.markasjunk.junk",!rcmail.markasjunk_is_spam_mbox()&&0<a.get_selection(!1).length),rcmail.enable_command("plugin.markasjunk.not_junk",0<a.get_selection(!1).length)}),rcmail.markasjunk_toggle_button()}),rcmail.addEventListener("listupdate",function(){rcmail.markasjunk_toggle_button()}),rcmail.addEventListener("beforemove",function(a){if(a=a&&"object"==typeof a?a.id:a){var n=null;return rcmail.env.markasjunk_move_spam&&a==rcmail.env.markasjunk_spam_mailbox&&a!=rcmail.env.mailbox?n=!0:rcmail.env.markasjunk_move_ham&&a==rcmail.env.markasjunk_ham_mailbox&&rcmail.env.mailbox==rcmail.env.markasjunk_spam_mailbox&&(n=!1),null!==n?(rcmail.markasjunk_mark(n),!1):void 0}}));