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
This commit is contained in:
sspitzer%netscape.com 2002-09-30 22:13:01 +00:00
Родитель b55366e92c
Коммит 320c8a48d7
7 изменённых файлов: 28 добавлений и 456 удалений

Просмотреть файл

@ -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.
*

Просмотреть файл

@ -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;
*/

Просмотреть файл

@ -1,63 +0,0 @@
<?xml version="1.0"?>
<!-- ***** 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 Corp.
- Portions created by the Initial Developer are Copyright (C) 2002
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
- Peter van der Beken <peterv@netscape.com>
-
- 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 LGPL or the GPL. 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 ***** -->
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:chrome="http://www.mozilla.org/rdf/chrome#">
<!-- list all the packages being supplied by this jar -->
<RDF:Seq about="urn:mozilla:package:root">
<RDF:li resource="urn:mozilla:package:spam"/>
</RDF:Seq>
<!-- package information -->
<RDF:Description about="urn:mozilla:package:spam"
chrome:displayName="Spam plugin"
chrome:author="mozilla.org"
chrome:name="spam">
</RDF:Description>
<!-- overlay information -->
<RDF:Seq about="urn:mozilla:overlays">
<RDF:li resource="chrome://messenger/content/mailWindowOverlay.xul"/>
</RDF:Seq>
<RDF:Seq about="chrome://messenger/content/mailWindowOverlay.xul">
<RDF:li>chrome://spam/content/menuOverlay.xul</RDF:li>
</RDF:Seq>
</RDF:RDF>

Просмотреть файл

@ -1,5 +0,0 @@
messenger.jar:
content/spam/contents.rdf
content/spam/menuOverlay.js
content/spam/menuOverlay.xul
content/spam/primaryToolbar.css

Просмотреть файл

@ -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 <peterv@netscape.com>
* Dan Mosedale <dmose@netscape.com>
*
* 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();
}

Просмотреть файл

@ -1,76 +0,0 @@
<?xml version="1.0"?>
<!-- ***** 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 Corp.
- Portions created by the Initial Developer are Copyright (C) 2002
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
- Peter van der Beken <peterv@netscape.com>
-
- 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 LGPL or the GPL. 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 ***** -->
<?xml-stylesheet href="chrome://spam/content/primaryToolbar.css" type="text/css"?>
<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script src="chrome://spam/content/menuOverlay.js"/>
<broadcasterset id="mailBroadcasters">
<broadcaster id="button_spam_broadcaster"/>
</broadcasterset>
<popup id="folderPaneContext">
<menuseparator id="folderPaneContext-spam-sep"
insertafter="folderPaneContext-properties"/>
<menuitem id="folderPaneContext-spam"
label="Mark as spam"
oncommand="markFolder(true);"
insertafter="folderPaneContext-properties"/>
<menuitem id="folderPaneContext-nonspam"
label="Mark as non-spam"
oncommand="markFolder(false);"
insertafter="folderPaneContext-properties"/>
<menuitem id="folderPaneContext-analyze"
label="Analyze"
oncommand="analyzeFolder();"
insertafter="folderPaneContext-properties"/>
</popup>
<hbox id="toolbar_button_box">
<toolbarbutton id="button-analyze"
class="toolbarbutton-1"
label="Analyze"
oncommand="analyzeMessages();"
insertafter="button-delete"/>
<toolbarbutton id="button-spamdb"
class="toolbarbutton-1"
label="Write DB"
oncommand="writeHash();"/>
</hbox>
</overlay>

Просмотреть файл

@ -1,52 +0,0 @@
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
#button-spam {
-moz-image-region: rect(102px 49px 135px 0px);
}
#button-spam:hover {
-moz-image-region: rect(102px 99px 135px 50px);
}
#button-spam:hover:active {
-moz-image-region: rect(102px 149px 135px 100px);
}
#button-spam[disabled] {
-moz-image-region: rect(102px 199px 135px 150px) !important;
}
#button-analyze {
-moz-image-region: rect(102px 49px 135px 0px);
}
#button-analyze:hover {
-moz-image-region: rect(102px 99px 135px 50px);
}
#button-analyze:hover:active {
-moz-image-region: rect(102px 149px 135px 100px);
}
#button-analyze[disabled] {
-moz-image-region: rect(102px 199px 135px 150px) !important;
}
#button-spamdb {
-moz-image-region: rect(0px 49px 34px 0px);
}
#button-spamdb:hover {
-moz-image-region: rect(0px 99px 34px 50px);
}
#button-spamdb:hover:active {
-moz-image-region: rect(0px 149px 34px 100px);
}
#button-spamdb[disabled] {
-moz-image-region: rect(0px 199px 34px 150px) !important;
}
.spam {
}