From 320c8a48d7d8f9938a25ac0d13f4ea6d633a5f65 Mon Sep 17 00:00:00 2001 From: "sspitzer%netscape.com" Date: Mon, 30 Sep 2002 22:13:01 +0000 Subject: [PATCH] adding consts to the nsIMsgFilterPlugin interface, and using it. removing UI added to extension, since there is core UI For this already (but off by default). part of bug #169638. r/sr=bienvenu --- .../base/search/public/nsIMsgFilterPlugin.idl | 5 + .../bayesianSpamFilter.js | 56 ++--- .../bayesian-spam-filter/contents.rdf | 63 ----- .../extensions/bayesian-spam-filter/jar.mn | 5 - .../bayesian-spam-filter/menuOverlay.js | 227 ------------------ .../bayesian-spam-filter/menuOverlay.xul | 76 ------ .../bayesian-spam-filter/primaryToolbar.css | 52 ---- 7 files changed, 28 insertions(+), 456 deletions(-) delete mode 100644 mailnews/extensions/bayesian-spam-filter/contents.rdf delete mode 100644 mailnews/extensions/bayesian-spam-filter/jar.mn delete mode 100644 mailnews/extensions/bayesian-spam-filter/menuOverlay.js delete mode 100644 mailnews/extensions/bayesian-spam-filter/menuOverlay.xul delete mode 100644 mailnews/extensions/bayesian-spam-filter/primaryToolbar.css diff --git a/mailnews/base/search/public/nsIMsgFilterPlugin.idl b/mailnews/base/search/public/nsIMsgFilterPlugin.idl index c72e86e9d028..5d759b3e21ad 100644 --- a/mailnews/base/search/public/nsIMsgFilterPlugin.idl +++ b/mailnews/base/search/public/nsIMsgFilterPlugin.idl @@ -47,6 +47,11 @@ interface nsIStreamListener; [scriptable, uuid(e2e56690-a676-11d6-80c9-00008646b737)] interface nsIMsgFilterPlugin : nsISupports { + const long unknownToSpam = 0; + const long unknownToHam = 1; + const long hamToSpam = 2; + const long spamToHam = 3; + /** * Initialize the plugin object. * diff --git a/mailnews/extensions/bayesian-spam-filter/bayesianSpamFilter.js b/mailnews/extensions/bayesian-spam-filter/bayesianSpamFilter.js index 459fa4f811b0..68c643a65a45 100644 --- a/mailnews/extensions/bayesian-spam-filter/bayesianSpamFilter.js +++ b/mailnews/extensions/bayesian-spam-filter/bayesianSpamFilter.js @@ -89,11 +89,6 @@ function do_CreateInstance(aContractID, aInterface) return Components.classes[aContractID].createInstance(aInterface); } -const kUnknownToSpam = 0; -const kUnknownToHam = 1; -const kHamToSpam = 2; -const kSpamToHam = 3; - const kHamCount = 0; const kSpamCount = 1; const kSpamProb = 2; @@ -130,23 +125,15 @@ const kDebugAll = kDebugTokenize | kDebugTokenCount | kDebugCalculateProbabilities | kDebugCalculateToken kDebugCalculateSpam | kDebugClassify; -var gDebugLevel = kDebugCalculateToken | kDebugCalculateSpam | kDebugClassify; -var gDebugStream = null; +var gDebugLevel = kDebugAll; + function debugOutput(aOutput) { - if (!gDebugStream) { - var profileMgr = do_GetService(PROFILEMGR_CTRID, nsIProfileInternal); - var outFile = profileMgr.getProfileDir(profileMgr.currentProfile); - outFile.append("bayesianspam.log"); - var fileTransportService = do_GetService(FILETPTSVC_CTRID, nsIFileTransportService); - var trans = fileTransportService.createTransport(outFile, NS_RDWR | - NS_CREATE_FILE | - NS_APPEND, 420, false); - gDebugStream = trans.openOutputStream(0, -1, 0); - } - gDebugStream.write(aOutput, aOutput.length); - gDebugStream.flush(); + dump(aOutput + "\n"); + + // XXX todo, use the nsISpamSettings logging stuff } + // XXX DEBUG_END /** @@ -408,16 +395,16 @@ nsBaseStatsTable.prototype = if (gDebugLevel & kDebugTokenCount) { var output = "Changing " + aToken; switch (aAction) { - case kSpamToHam: + case nsIMsgFilterPlugin.spamToHam: output += " from spam to ham\n" break; - case kUnknownToHam: + case nsIMsgFilterPlugin.unknownToSpam: output += " from unknown to ham\n" break; - case kHamToSpam: + case nsIMsgFilterPlugin.hamToSpam: output += " from ham to spam\n" break; - case kUnknownToSpam: + case nsIMsgFilterPlugin.unknownToSpam: output += " from unknown to spam\n" break; } @@ -426,14 +413,14 @@ nsBaseStatsTable.prototype = // XXX DEBUG_END switch (aAction) { - case kSpamToHam: + case nsIMsgFilterPlugin.spamToHam: --value[kSpamCount]; - case kUnknownToHam: + case nsIMsgFilterPlugin.unknownToHam: ++value[kHamCount]; break; - case kHamToSpam: + case nsIMsgFilterPlugin.hamToSpam: --value[kHamCount]; - case kUnknownToSpam: + case nsIMsgFilterPlugin.unknownToSpam: ++value[kSpamCount]; break; } @@ -741,6 +728,7 @@ nsJunkmail.prototype = //nsIMimeConverter); //} + // XXX TODO fix me, don't use raw prefs for this this.dummyFilterObj = new nsDummyFilter( gPrefs.getCharPref("mail.server." + aServerKey + ".type") + "://" + @@ -752,6 +740,8 @@ nsJunkmail.prototype = // this.threshhold = gPrefs.getIntPref("mail.server." + aServerKey // + ".junkmail.threshhold"); + // XXX TODO fix me, use the nsISpamSettings logStream for this + // // the logfile is called "junklog.txt" in the server directory // var logFile = gPrefs.getComplexValue("mail.server." @@ -1048,14 +1038,14 @@ nsJunkmail.prototype = function endData() { switch (aAction) { - case kSpamToHam: + case nsIMsgFilterPlugin.spamToHam: --caller.mTable.mSpamCount; - case kUnknownToHam: + case nsIMsgFilterPlugin.unknownToHam: ++caller.mTable.mHamCount; break; - case kHamToSpam: + case nsIMsgFilterPlugin.hamToSpam: --caller.mTable.mHamCount; - case kUnknownToSpam: + case nsIMsgFilterPlugin.unknownToSpam: ++caller.mTable.mSpamCount; break; } @@ -1098,7 +1088,7 @@ nsJunkmail.prototype = score = caller.mTable.calculate(extrema); if (score <= 0.5) { /* for (counter = 0; counter < words.length; ++counter) { - caller.mTable.addTokenToHash(words[counter], kUnknownToHam); + caller.mTable.addTokenToHash(words[counter], nsIMsgFilterPlugin.unknownToHam); } ++caller.mTable.mHamCount; */ @@ -1106,7 +1096,7 @@ nsJunkmail.prototype = } else { /* for (counter = 0; counter < words.length; ++counter) { - caller.mTable.addTokenToHash(words[counter], kUnknownToSpam); + caller.mTable.addTokenToHash(words[counter], nsIMsgFilterPlugin.unknownToSpam); } ++caller.mTable.mSpamCount; */ diff --git a/mailnews/extensions/bayesian-spam-filter/contents.rdf b/mailnews/extensions/bayesian-spam-filter/contents.rdf deleted file mode 100644 index 81f10574a229..000000000000 --- a/mailnews/extensions/bayesian-spam-filter/contents.rdf +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - chrome://spam/content/menuOverlay.xul - - diff --git a/mailnews/extensions/bayesian-spam-filter/jar.mn b/mailnews/extensions/bayesian-spam-filter/jar.mn deleted file mode 100644 index 6afe91b23c00..000000000000 --- a/mailnews/extensions/bayesian-spam-filter/jar.mn +++ /dev/null @@ -1,5 +0,0 @@ -messenger.jar: - content/spam/contents.rdf - content/spam/menuOverlay.js - content/spam/menuOverlay.xul - content/spam/primaryToolbar.css diff --git a/mailnews/extensions/bayesian-spam-filter/menuOverlay.js b/mailnews/extensions/bayesian-spam-filter/menuOverlay.js deleted file mode 100644 index b15fce6adf53..000000000000 --- a/mailnews/extensions/bayesian-spam-filter/menuOverlay.js +++ /dev/null @@ -1,227 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter van der Beken - * Dan Mosedale - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -const nsIMsgDBHdr = Components.interfaces.nsIMsgDBHdr; - -var gJunkmailComponent; -function getJunkmailComponent() -{ - if (!gJunkmailComponent) { - gJunkmailComponent = Components.classes['@mozilla.org/messenger/filter-plugin;1?name=junkmail'] - .getService(Components.interfaces.nsISupports).wrappedJSObject; - gJunkmailComponent.initComponent(); - } -} - -function analyze(aMessage, aNextFunction) -{ - function callback(aScore) { - } - - callback.prototype = - { - onMessageScored: function processNext(aScore) - { - if (aMessage) { - //if (aScore == -1) debugger; - if (aScore == 0) { - aMessage.setStringProperty("score", "0"); - } - else if (aScore == 1) { - aMessage.setStringProperty("score", "100"); - } - } - aNextFunction(); - } - }; - - - // Pffft, jumping through hoops here. - var messageURI = aMessage.folder.generateMessageURI(aMessage.messageKey) + "?fetchCompleteMessage=true"; - var messageURL = mailSession.ConvertMsgURIToMsgURL(messageURI, msgWindow); - gJunkmailComponent.calculate(messageURL, new callback); -} - -function analyzeFolder() -{ - function processNext() - { - if (messages.hasMoreElements()) { - // Pffft, jumping through hoops here. - var message = messages.getNext().QueryInterface(nsIMsgDBHdr); - while (!message.isRead) { - if (!messages.hasMoreElements()) { - gJunkmailComponent.batchUpdate = false; - return; - } - message = messages.getNext().QueryInterface(nsIMsgDBHdr); - } - analyze(message, processNext); - } - else { - gJunkmailComponent.batchUpdate = false; - } - } - - getJunkmailComponent(); - var folder = GetFirstSelectedMsgFolder(); - var messages = folder.getMessages(msgWindow); - gJunkmailComponent.batchUpdate = true; - processNext(); -} - -function analyzeMessages() -{ - function processNext() - { - if (counter < messages.length) { - // Pffft, jumping through hoops here. - var messageUri = messages[counter]; - var message = messenger.messageServiceFromURI(messageUri).messageURIToMsgHdr(messageUri); - - ++counter; - while (!message.isRead) { - if (counter == messages.length) { - gJunkmailComponent.mBatchUpdate = false; - return; - } - messageUri = messages[counter]; - message = messenger.messageServiceFromURI(messageUri).messageURIToMsgHdr(messageUri); - ++counter; - } - analyze(message, processNext); - } - else { - gJunkmailComponent.batchUpdate = false; - } - } - - getJunkmailComponent(); - var messages = GetSelectedMessages(); - var counter = 0; - gJunkmailComponent.batchUpdate = true; - processNext(); -} - -function markMessage(aMessage, aSpam, aNextFunction) -{ - // Pffft, jumping through hoops here. - var messageURI = aMessage.folder.generateMessageURI(aMessage.messageKey) + "?fetchCompleteMessage=true"; - var messageURL = mailSession.ConvertMsgURIToMsgURL(messageURI, msgWindow); - var action; - if (aSpam) { - action = kUnknownToSpam; - if (aMessage.getStringProperty("score") == "100") { - // Marking a spam message as spam does nothing - aNextFunction(); - return; - } - if (aMessage.getStringProperty("score") == "0") { - // Marking a non-spam message as spam - action = kNoSpamToSpam; - } - aMessage.setStringProperty("score","100"); - } - else { - action = kUnknownToNoSpam; - if (aMessage.getStringProperty("score") == "0") { - // Marking a non-spam message as non-spam does nothing - aNextFunction(); - return; - } - if (aMessage.getStringProperty("score") == "100") { - // Marking a spam message as non-spam - action = kSpamToNoSpam; - } - aMessage.setStringProperty("score", "0"); - } - gJunkmailComponent.mark(messageURL, action, aNextFunction); -} - -function markFolder(aSpam) -{ - function processNext() - { - if (messages.hasMoreElements()) { - // Pffft, jumping through hoops here. - var message = messages.getNext().QueryInterface(nsIMsgDBHdr); - markMessage(message, aSpam, processNext); - } - else { - gJunkmailComponent.batchUpdate = false; - } - } - - getJunkmailComponent(); - var folder = GetFirstSelectedMsgFolder(); - var messages = folder.getMessages(msgWindow); - gJunkmailComponent.batchUpdate = true; - processNext(); -} - -function markMessages(aSpam) -{ - function processNext() - { - if (counter < messages.length) { - // Pffft, jumping through hoops here. - var messageUri = messages[counter]; - var message = messenger.messageServiceFromURI(messageUri).messageURIToMsgHdr(messageUri); - - ++counter; - markMessage(message, aSpam, processNext); - } - else { - gJunkmailComponent.batchUpdate = false; - } - } - - getJunkmailComponent(); - var messages = GetSelectedMessages(); - var counter = 0; - gJunkmailComponent.batchUpdate = true; - processNext(); -} - -function writeHash() -{ - getJunkmailComponent(); - gJunkmailComponent.mTable.writeHash(); -} diff --git a/mailnews/extensions/bayesian-spam-filter/menuOverlay.xul b/mailnews/extensions/bayesian-spam-filter/menuOverlay.xul deleted file mode 100644 index 06ca9d326a43..000000000000 --- a/mailnews/extensions/bayesian-spam-filter/menuOverlay.xul +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - -