Skip to content

Commit

Permalink
Allow marking messages as Junk, including manual and automated ways.
Browse files Browse the repository at this point in the history
  • Loading branch information
itemir committed Aug 29, 2015
1 parent 4de01f0 commit 476a847
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 10 deletions.
16 changes: 9 additions & 7 deletions chrome/content/options.xul
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<preference id="custom_dnsbl_enabled" name="extensions.thundersec.custom_dnsbl_enabled" type="bool"/>
<preference id="custom_dnsbl" name="extensions.thundersec.custom_dnsbl" type="string"/>

<preference id="auto_junk_enabled" name="extensions.thundersec.auto_junk_enabled" type="bool"/>
<preference id="api_enabled" name="extensions.thundersec.api_enabled" type="bool"/>
</preferences>
<tabbox id="optionsTabs" selectedIndex="0">
Expand All @@ -39,19 +40,13 @@
<hbox>
<checkbox id="checkbool.custom_dnsbl_enabled" preference="custom_dnsbl_enabled" label="" onclick="enableCustomDNSBL(this);" />
<textbox id="string.custom_dnsbl" preference="custom_dnsbl" onclick="clearInput();"/>
<script>
if ( document.getElementById("checkbool.custom_dnsbl_enabled").checked ) {
document.getElementById("string.custom_dnsbl").removeAttribute("disabled");
} else {
document.getElementById("string.custom_dnsbl").setAttribute("disabled", true);
}
</script>
</hbox>
</vbox>
</hbox>
</tabpanel>
<tabpanel>
<vbox style='width: 100%;'>
<checkbox id="checkbool.auto_junk_enabled" preference="auto_junk_enabled" label="Automatically mark messages as Junk if they fail DNSBL, DKIM or SPF checks." />
<checkbox id="checkbool.api_enabled" preference="api_enabled" label="Send sanitized information to the cloud for improved results." />
<separator/>
<hbox pack='center'>
Expand All @@ -63,4 +58,11 @@
</tabpanels>
</tabbox>
</prefpane>
<script>
if ( document.getElementById("checkbool.custom_dnsbl_enabled").checked ) {
document.getElementById("string.custom_dnsbl").removeAttribute("disabled");
} else {
document.getElementById("string.custom_dnsbl").setAttribute("disabled", true);
}
</script>
</prefwindow>
2 changes: 1 addition & 1 deletion chrome/content/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@

const DB_NAME = 'thundersec.sqlite';
const API_URL = 'https://www.ilkertemir.com/thundersec/api/v1/';
const VERSION = '1.0.4';
const VERSION = '1.1';
// Send generic stats every hour
const STAT_INTERVAL = 1*60*60*1000;
49 changes: 48 additions & 1 deletion chrome/content/thundersec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var stats = { periodStart: Date.now() / 1000,
dkimViolation: 0,
dkimWhitelist: 0 };
var totalDNSlookups = {};
var autoJunked = [];
var currentMailID;
var connection;
var initialized = false;
Expand Down Expand Up @@ -352,6 +353,11 @@ function updateWhiteList(dnsbl, spf, dkim) {
connection.execute("COMMIT TRANSACTION");
}

function markAsJunk(notf, desc) {
// This will mark the message as Junk
gDBView.doCommand(Components.interfaces.nsMsgViewCommandType.junk);
}

function markAsLegitimate(notf, desc) {
var confirm = window.confirm ("Are you sure to mark this e-mail as legitimate?\n\n" +
"This will be remembered and similar messages from " +
Expand Down Expand Up @@ -385,7 +391,34 @@ function optionsBox(notf, desc) {

function updateNotification(mailID) {
if (mailID != currentMailID) {
// User has moved on, don't updae the notificationbox
// User has moved on, don't update the notificationbox
return;
}

// This feels redundant but necessary
let msgHdr = gFolderDisplay.selectedMessage;

if (!msgHdr) {
return
}

var junkScore = msgHdr.getStringProperty("junkscore");
var isJunk = (junkScore == Components.interfaces.nsIJunkMailPlugin.IS_SPAM_SCORE);

// If already marked as Junk, don't display the banner
if (isJunk) {
return
}

var pref = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch("extensions.thundersec.");

// Check if auto-junk feature is enabled
if ( ( pref.getBoolPref('auto_junk_enabled') ) && ( autoJunked.indexOf(mailID) == -1 ) ) {
// We auto-junk a message only once, the rest is for the user
autoJunked.push(mailID);
gDBView.doCommand(Components.interfaces.nsMsgViewCommandType.junk);
return;
}

Expand All @@ -396,6 +429,12 @@ function updateNotification(mailID) {
popup: null,
callback: detailsBox
},
{
label: 'Mark as Junk',
accessKey: 'J',
popup: null,
callback: markAsJunk
},
{
label: 'Mark as Legitimate',
accessKey: 'M',
Expand Down Expand Up @@ -777,6 +816,14 @@ function pluginMain() {
return
}

var junkScore = msgHdr.getStringProperty("junkscore");
var isJunk = (junkScore == Components.interfaces.nsIJunkMailPlugin.IS_SPAM_SCORE);

// If already marked as Junk, don't do any further processing
if (isJunk) {
return
}

MsgHdrToMimeMessage(msgHdr, null, function (aMsgHdr, aMimeMsg) {
// Update counters
stats.inspectTotal++;
Expand Down
1 change: 1 addition & 0 deletions defaults/preferences/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ pref("extensions.thundersec.custom_dnsbl", "dnsbl.example.com");

// Advanced settings
pref("extensions.thundersec.api_enabled", true);
pref("extensions.thundersec.auto_junk__enabled", false);
2 changes: 1 addition & 1 deletion install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Description about="urn:mozilla:install-manifest">
<em:type>2</em:type> <!-- 2 : Extension -->
<em:id>thundersec@community</em:id>
<em:version>1.0.4</em:version>
<em:version>1.1</em:version>
<em:name>ThunderSec</em:name>
<em:description>Provides security features for Mozilla Thunderbird. These include DNSBL and RBL support, DKIM and SPF failure verifications. DNSBL support can be used to leverage Spamhaus, Abuse.ch and other DNSBL/RBL databases, including custom ones.</em:description>
<em:iconURL>chrome://thundersec/content/images/thundersec.png</em:iconURL>
Expand Down

0 comments on commit 476a847

Please sign in to comment.