Viewing File: /usr/local/cpanel/base/frontend/jupiter/mail/spam/services/spamAssassin.min.js
define(["angular","lodash","cjt/util/locale","cjt/io/uapi-request","cjt/io/uapi","cjt/services/APICatcher","cjt/services/alertService"],(function(e,s,t,a){"use strict";var n=e.module("cpanel.apacheSpamAssassin.spamAssassin.service",[]);n.value("PAGE",PAGE),n.factory("spamAssassin",["$q","$filter","APICatcher","PAGE","alertService",function(n,i,r,o,p){var u=function(){},m="INBOX.spam",l=["rewrites_subjects","spam_as_acl","spam_auto_delete","spam_box_enabled","spam_enabled","spam_status_changeable"];function c(e){p.add({message:e,type:"success",replace:!1})}function d(){return o.user}function f(e){return"spamBox"===e?"1"===o.feature_spam_box.toString():"spamAutoDelete"!==e||"1"===o.feature_spam_assassin.toString()}return u.prototype=r,e.extend(u.prototype,{symbolicTestNames:[],spamAssassinSettings:{},userPreferences:{},_parseUserPreferences:function(s){var t=this;return s?(e.forEach(s,(function(e,s){"required_score"===s?(t.userPreferences[s]=Number(e.shift(),10)||5,t.userPreferences[s]=isNaN(t.userPreferences[s])?5:t.userPreferences[s]):t.userPreferences[s]="score"===s?e.filter((function(e){var s=e.trim().split(/\s+/);return 2===s.length||5===s.length})).map((function(e){var s=e.trim().split(/\s+/);return s.shift()+" "+s.pop()})):e})),t.userPreferences):t.userPreferences},hasFeature:f,getValidRoutes:function(e){return s.filter(e,(function(e){return f(e.id)}))}.bind(u.prototype),getSpamAssassinSettings:function(){var s=this,t=new a.Class;return t.initialize("Email","get_spam_settings"),s.promise(t).then((function(t){var a=t.data;return e.forEach(a,(function(e,t){"spam_auto_delete_score"===t?(s.spamAssassinSettings[t]=parseInt(e,10),s.spamAssassinSettings[t]=isNaN(s.spamAssassinSettings[t])?5:s.spamAssassinSettings[t]):-1!==l.indexOf(t)?s.spamAssassinSettings[t]="1"===e.toString():s.spamAssassinSettings[t]=a[t]})),s.spamAssassinSettings}))}.bind(u.prototype),enableSpamAssassin:function(){var e=this,s=new a.Class;return s.initialize("Email","enable_spam_assassin"),e.promise(s).then((function(s){return e.spamAssassinSettings.spam_enabled=!0,c(t.maketext("[asis,Apache SpamAssassin] has been enabled.")),s}))}.bind(u.prototype),disableSpamAssassin:function(){var e=this,s=new a.Class;return s.initialize("Email","disable_spam_assassin"),e.promise(s).then((function(s){return e.spamAssassinSettings.spam_enabled=!1,c(t.maketext("[asis,Apache SpamAssassin] has been disabled.")),e.spamAssassinSettings.spam_box_enabled&&e.disableSpamBox(),e.spamAssassinSettings.spam_auto_delete&&e.disableAutoDelete(),s}))}.bind(u.prototype),enableAutoDelete:function(e){var s=this,n=new a.Class;function i(a){return s.spamAssassinSettings.spam_auto_delete?c(t.maketext("The Auto-Delete Threshold Score has been updated to [_1].",e)):c(t.maketext("Spam Auto-Delete has been enabled.")),s.spamAssassinSettings.spam_auto_delete=!0,s.spamAssassinSettings.spam_auto_delete_score=e,a}return n.initialize("Email","add_spam_filter",{required_score:e}),s.spamAssassinSettings.spam_enabled?this.promise(n).then(i):s.enableSpamAssassin().then((function(){return s.promise(n).then(i)}))}.bind(u.prototype),disableAutoDelete:function(){var e=this,s=new a.Class;return s.initialize("Email","disable_spam_autodelete"),this.promise(s).then((function(s){return e.spamAssassinSettings.spam_auto_delete=!1,c(t.maketext("Spam Auto-Delete has been disabled.")),s}))}.bind(u.prototype),enableSpamBox:function(){var e=this,s=new a.Class;function n(s){return e.spamAssassinSettings.spam_box_enabled=!0,c(t.maketext("Spam Box has been enabled.")),s}return s.initialize("Email","enable_spam_box"),e.spamAssassinSettings.spam_enabled?this.promise(s).then(n):e.enableSpamAssassin().then((function(){return e.promise(s).then(n)}))}.bind(u.prototype),disableSpamBox:function(){var e=this,s=new a.Class;return s.initialize("Email","disable_spam_box"),this.promise(s).then((function(s){return e.spamAssassinSettings.spam_box_enabled=!1,c(t.maketext("Spam Box has been disabled.")),s}))}.bind(u.prototype),getSpamBoxSize:function(){var e=new a.Class;return e.initialize("Mailboxes","get_mailbox_status_list",{account:d()}),e.addFilter("mailbox","eq",m),this.promise(e).then((function(e){var s=e.data.shift();if(!s)return 0;var t=parseInt(s.vsize,10);return isNaN(t)?0:t}))}.bind(u.prototype),clearSpamBoxFolder:function(){var e=new a.Class;return e.initialize("Mailboxes","expunge_mailbox_messages",{account:d(),query:"all",mailbox:m}),this.promise(e).then((function(e){return c(t.maketext("Expunged the Spam Box folder for “[_1]”.",d())),e}))}.bind(u.prototype),getUserPreferences:function(){var e=this,s=new a.Class;return s.initialize("SpamAssassin","get_user_preferences"),this.promise(s).then((function(s){return e.userPreferences.whitelist_from=[],e.userPreferences.blacklist_from=[],e.userPreferences.required_score=5,e.userPreferences.score=[],e._parseUserPreferences(s.data)}))}.bind(u.prototype),updateUserPreference:function(e,s){var n=this,i=new a.Class;return i.initialize("SpamAssassin","update_user_preference",{preference:e}),i.addArgument("value",s),this.promise(i).then((function(e){return c(t.maketext("The [asis,Apache SpamAssassin] user preferences have been updated.")),n._parseUserPreferences(e.data)}))}.bind(u.prototype),getSymbolicTestNames:function(){var e=this;if(e.symbolicTestNames.length)return n.resolve(e.symbolicTestNames);var s=new a.Class;return s.initialize("SpamAssassin","get_symbolic_test_names"),e.promise(s).then((function(s){return e.symbolicTestNames=s.data.map((function(e){return{key:e.key,rule_type:e.rule_type,score:e.score}})),e.symbolicTestNames}))}.bind(u.prototype),clearAllSpamBoxFolders:function(){var e=new a.Class;return e.initialize("SpamAssassin","clear_spam_box"),this.promise(e).then((function(e){return c(t.maketext("All Spam Box folders expunged.")),e}))}.bind(u.prototype)}),new u}])}));
Back to Directory
File Manager