Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Commit

Permalink
Break out spam attribute/subject check into a function for use
Browse files Browse the repository at this point in the history
in the mail and forum pages.

If modopts -> [web] -> forum_no_spam, then filter spam messages
in the forum.  (Maybe make this more advanced in the future so
users can see these messages if they want to.)
  • Loading branch information
echicken committed Jan 8, 2020
1 parent 002a885 commit 1f9a87d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion web/lib/forum.js
Expand Up @@ -312,6 +312,10 @@ function getMailHeaders(sent, ascending) {
return headers;
}

function is_spam(header) {
return (header.attr&MSG_SPAM || (header.subject.search(/^SPAM:/) > -1));
}

function get_mail_headers(filter, ascending) {
const ret = {
headers: [],
Expand All @@ -330,7 +334,7 @@ function get_mail_headers(filter, ascending) {
if (filter == 'sent') ret.headers.push(h);
}
if (h.to_ext == user.number) {
if ((h.attr&MSG_SPAM) || (h.subject.search(/^SPAM:/) > -1)) {
if (is_spam(h)) {
h.attr&MSG_READ ? ret.spam.read++ : (ret.spam.unread++);
if (filter == 'spam') ret.headers.push(h);
} else {
Expand Down Expand Up @@ -998,6 +1002,7 @@ function getMessageThreads(sub, max) {
for (var m = start; m <= msgBase.last_msg; m++) {
var header = msgBase.get_msg_header(m);
if (header === null || header.attr&MSG_DELETE) continue;
if (settings.forum_no_spam && is_spam(header)) continue;
headers[header.number] = header;
c++;
if (c >= count) break;
Expand All @@ -1024,6 +1029,11 @@ function getMessageThreads(sub, max) {
return;
}

if (settings.forum_no_spam && is_spam(header)) {
delete headers[h];
return;
}

if (sub === 'mail' &&
headers[h].to !== user.alias &&
headers[h].to !== user.name &&
Expand Down

0 comments on commit 1f9a87d

Please sign in to comment.