From d0bf3e60ca5e9f4a1fc1d542c6605ca4dd959b4e Mon Sep 17 00:00:00 2001 From: ketmar Date: Sat, 30 Oct 2021 10:43:15 +0000 Subject: [PATCH] fixed "article_mark_spam" FossilOrigin-Name: 471b0fc93186a482400b71beec0a1ba7bcd524ccd87d61bc0b5f3e6f791880eb --- chibackend/sqbase.d | 14 +++--- chiroptera.d | 127 +++++++++++++++++++++++++++++++++++----------------- 2 files changed, 92 insertions(+), 49 deletions(-) diff --git a/chibackend/sqbase.d b/chibackend/sqbase.d index ea40d51..8d764fb 100644 --- a/chibackend/sqbase.d +++ b/chibackend/sqbase.d @@ -2500,7 +2500,7 @@ public void chiroGetOptionUInts (ref uint v0, ref uint v1, const(char)[] name) { // append tag if necessary, return tagid // tag name must be valid: not empty, and not end with a '/' // returns 0 on invalid tag name -uint chiroAppendTag (const(char)[] tagname, int hidden=0) { +public uint chiroAppendTag (const(char)[] tagname, int hidden=0) { tagname = tagname.xstrip; while (tagname.length && tagname[$-1] == '/') tagname = tagname[0..$-1]; tagname = tagname.xstrip; @@ -2547,7 +2547,7 @@ public bool chiroMessageRemoveTag (uint uid, const(char)[] tagname) { if (tagid == 0) return false; static auto stUpdateStorageTags = LazyStatement!"Store"(` - UPDATE SET tags=:tags WHERE uid=:uid + UPDATE messages SET tags=:tags WHERE uid=:uid ;`); static auto stUidHasTag = LazyStatement!"View"(` @@ -2567,8 +2567,8 @@ public bool chiroMessageRemoveTag (uint uid, const(char)[] tagname) { static auto stGetMsgTags = LazyStatement!"View"(` SELECT DISTINCT(tagid) AS tagid, tt.tag AS name FROM threads - WHERE uid=:uid INNER JOIN tagnames AS tt USING(tagid) + WHERE uid=:uid ;`); @@ -2633,11 +2633,11 @@ public bool chiroMessageAddTag (uint uid, const(char)[] tagname) { if (tagname.indexOf('|') >= 0) return false; static auto stUpdateStorageTags = LazyStatement!"Store"(` - UPDATE SET tags=tags||'|'||:tagname WHERE uid=:uid + UPDATE messages SET tags=tags||'|'||:tagname WHERE uid=:uid ;`); static auto stUidExists = LazyStatement!"View"(` - SELECT uid AS uid FROM threads WHERE uid=:uid LIMIT 1 + SELECT 1 FROM threads WHERE uid=:uid LIMIT 1 ;`); static auto stUidHasTag = LazyStatement!"View"(` @@ -2645,8 +2645,8 @@ public bool chiroMessageAddTag (uint uid, const(char)[] tagname) { ;`); static auto stInsertIntoThreads = LazyStatement!"View"(` - INSERT INTO threads(uid, tagid,appearance,time) - VALUES(:uid, :tagid, :appr, (SELECT time FROM info WHERE uid=:uid LIMIT 1)) + INSERT INTO threads(uid, tagid, appearance, time) + VALUES(:uid, :tagid, :appr, (SELECT time FROM threads WHERE uid=:uid LIMIT 1)) ;`); static auto stUnHobo = LazyStatement!"View"(` diff --git a/chiroptera.d b/chiroptera.d index 88c162e..ff8610a 100644 --- a/chiroptera.d +++ b/chiroptera.d @@ -962,8 +962,36 @@ void initConsole () { if (vbwin is null || vbwin.closed) return; if (mainPane is null) return; if (mainPane.msglistCurrUId) { - messageBogoMarkSpam(mainPane.msglistCurrUId); - if (chiroMessageAddTag(mainPane.msglistCurrUId, "#spam")) { + immutable uint uid = mainPane.msglistCurrUId; + // move to the next message + if (!mainPane.threadListDown()) mainPane.threadListUp(); + conwriteln("calling bogofilter..."); + messageBogoMarkSpam(uid); + conwriteln("adding '#spam' tag"); + immutable bool updatePane = chiroMessageAddTag(uid, "#spam"); + conwriteln("removing other virtual folder tags..."); + DynStr[] tags; + scope(exit) delete tags; + tags.reserve(32); + static auto stGetMsgTags = LazyStatement!"View"(` + SELECT DISTINCT(tagid) AS tagid, tt.tag AS name + FROM threads + INNER JOIN tagnames AS tt USING(tagid) + WHERE uid=:uid + ;`); + foreach (auto row; stGetMsgTags.st.bind(":uid", uid).range) { + auto tag = row.name!SQ3Text; + conwriteln(" tag: ", tag); + if (tag.startsWith("/")) tags ~= DynStr(tag); + } + foreach (ref DynStr tn; tags) { + conwriteln("removing tag '", tn.getData, "'..."); + chiroMessageRemoveTag(uid, tn.getData); + } + conwriteln("done marking as spam."); + if (updatePane) { + mainPane.switchToFolderTid(mainPane.lastDecodedTid, forced:true); + } else { // rescan folder mainPane.updateViewsIfTid(chiroGetTagUid("#spam")); } @@ -974,47 +1002,62 @@ void initConsole () { // //////////////////////////////////////////////////////////////////// // conRegFunc!((ConString fldname) { - /*FIXME - if (auto fld = getActiveFolder) { - Folder destfld = findFolderByPath(fldname); - if (destfld is null) { conwriteln("cannot find folder '", fldname, "'"); } - if (destfld is fld) { conwriteln("cannot move to the same folder"); return; } - Article newart; - uint didx = uint.max; - fld.withBaseReader((abase, cur, top, alist) { - if (cur < alist.length) { - auto aidx = alist.ptr[cur]; - abase.loadContent(aidx); - if (auto art = abase[aidx]) { - assert(art.contentLoaded); - newart = art.clone(); - didx = aidx; - } - } - }); - if (didx == uint.max || newart is null) { conwriteln("article not found!"); return; } - // delete it - assert(didx != uint.max); - assert(newart !is null); - conwriteln("removing ", newart.msgid, " from ", fld.folderPath); - fld.withBaseWriter((abase) { - abase.softDeleted(didx, true); - abase.writeUpdates(); - }); - fld.markForRebuild(); - fld.buildVisibleList(); - // insert into spam - conwriteln("adding ", newart.msgid, " to ", destfld.folderPath); - destfld.withBaseWriter((abase) { - abase.insert(newart); - abase.writeUpdates(); - }); - newart.releaseContent(); - destfld.markForRebuild(); - destfld.buildVisibleList(); - postScreenRebuild(); + if (vbwin is null || vbwin.closed) return; + if (mainPane is null) return; + if (!mainPane.msglistCurrUId) return; + immutable uint uid = mainPane.msglistCurrUId; + + fldname = fldname.xstrip; + while (fldname.length && fldname[$-1] == '/') fldname = fldname[0..$-1].xstrip; + immutable bool isforced = (fldname.length && fldname[0] == '!'); + if (isforced) fldname = fldname[1..$]; + if (fldname.length == 0) { + conwriteln("ERROR: cannot move to empty folder"); + return; } - */ + if (fldname[0].isalnum) { + conwriteln("ERROR: invalid folder name '", fldname, "'"); + return; + } + + uint tagid; + if (!isforced) { + tagid = chiroGetTagUid(fldname); + } else { + tagid = chiroAppendTag(fldname, hidden:(fldname[0] == '#' ? 1 : 0)); + } + if (!tagid) { + conwriteln("ERROR: invalid folder name '", fldname, "'"); + return; + } + + immutable bool updatePane = chiroMessageAddTag(uid, fldname); + DynStr[] tags; + scope(exit) delete tags; + tags.reserve(32); + static auto stGetMsgTags = LazyStatement!"View"(` + SELECT DISTINCT(tagid) AS tagid, tt.tag AS name + FROM threads + INNER JOIN tagnames AS tt USING(tagid) + WHERE uid=:uid + ;`); + foreach (auto row; stGetMsgTags.st.bind(":uid", uid).range) { + auto tag = row.name!SQ3Text; + conwriteln(" tag: ", tag); + if (tag.startsWith("account:")) continue; + if (tag != fldname) tags ~= DynStr(tag); + } + foreach (ref DynStr tn; tags) { + conwriteln("removing tag '", tn.getData, "'..."); + chiroMessageRemoveTag(uid, tn.getData); + } + if (updatePane) { + mainPane.switchToFolderTid(mainPane.lastDecodedTid, forced:true); + } else { + // rescan folder + mainPane.updateViewsIfTid(chiroGetTagUid("#spam")); + } + postScreenRebuild(); })("article_move_to_folder", "move article to existing folder"); -- 2.11.4.GIT