receiver: better filter processing
[chiroptera.git] / sqbase_experiment / zsq_show_message.d
blobcec7f40cf3b06d610a148ae24ae1404da9440167
1 /* E-Mail Client
2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License ONLY.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // this rebuilds FTS5 tables in SQLite supplementary mail database.
18 module zsq_rebuild_support is aliced;
20 import iv.encoding;
21 import iv.sq3;
22 import iv.strex;
23 import iv.timer;
24 import iv.vfs;
25 import iv.vfs.io;
27 import chibackend;
30 // ////////////////////////////////////////////////////////////////////////// //
31 void main (string[] args) {
32 ChiroTimerEnabled = true;
33 chiroParseCommonCLIArgs(args);
35 // here, i don't have any threads at all
36 if (sqlite3_config(SQLITE_CONFIG_SINGLETHREAD) != SQLITE_OK) throw new Exception("cannot switch SQLite to multi-threaded mode");
38 writeln("opening message support db...");
39 chiroOpenViewDB();
41 if (args.length < 2) {
42 import std.conv : to;
43 uint uid = 0;
44 foreach (auto row; dbView.statement(`SELECT MAX(uid) AS uid FROM info;`).range) uid = row.uid!uint;
45 args ~= uid.to!string;
46 } else {
47 //import std.conv : to;
48 //uid = argv[1].to!uint;
51 auto stSelEmailInfo = dbView.persistentStatement(`
52 SELECT
53 uid AS uid
54 , from_name AS fromName
55 , from_mail AS fromMail
56 , to_name AS toName
57 , to_mail AS toMail
58 , subj AS subj
59 , datetime(threads.time, 'unixepoch') AS time
60 , ChiroUnpack(content_text.content) AS text
61 , ChiroUnpack(content_html.content) AS html
62 FROM info
63 INNER JOIN threads USING(uid)
64 INNER JOIN content_text USING(uid)
65 INNER JOIN content_html USING(uid)
66 WHERE uid=:uid
67 LIMIT 1
68 ;`);
70 auto stSelEmailTags = dbView.persistentStatement(`
71 SELECT
72 DISTINCT(threads.tagid) AS tagid
73 , tagnames.tag AS tagname
74 FROM threads
75 INNER JOIN tagnames
76 USING(tagid)
77 WHERE threads.uid=:uid
78 ;`);
80 foreach (string uidstr; args[1..$]) {
81 uint uid = 0;
82 try {
83 import std.conv : to;
84 uid = uidstr.to!uint;
85 } catch (Exception) {
86 writeln("INVALID UID: ", uidstr);
88 if (!uid) continue;
89 foreach (auto mrow; stSelEmailInfo.bind(":uid", uid).range) {
90 writeln("================ UID: ", uid, " ================");
91 writeln("From: ", mrow.fromName!SQ3Text.recodeToKOI8, " <", mrow.fromMail!SQ3Text.recodeToKOI8, ">");
92 writeln(" To: ", mrow.toName!SQ3Text.recodeToKOI8, " <", mrow.toMail!SQ3Text.recodeToKOI8, ">");
93 writeln("Subj: ", mrow.subj!SQ3Text.recodeToKOI8);
94 writeln("Date: ", mrow.time!SQ3Text);
96 write("Tags:");
97 bool wasTag = false;
98 foreach (auto trow; stSelEmailTags.bind(":uid", uid).range) {
99 if (wasTag) write(","); else wasTag = true;
100 write(" ", trow.tagname!SQ3Text);
102 writeln;
104 if (mrow.text!SQ3Text.length) {
105 writeln("----------------------------------------------- (text)");
106 writeln(mrow.text!SQ3Text.recodeToKOI8);
109 if (mrow.html!SQ3Text.length) {
110 writeln("----------------------------------------------- (html)");
111 writeln(mrow.html!SQ3Text.recodeToKOI8);
116 dbView.close();