egui: style lookup optimisations
[chiroptera.git] / sqbase_experiment / zsq_00_create_accounts.d
blob182eb8d9444d3b1145c5f3c0dd91eef98ed602bb
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 // WARNING! this doesn't perform any sanity checks on "accounts.rc"!
18 module zsq_create_accounts is aliced;
20 import chibackend;
22 import iv.sq3;
23 import iv.strex;
24 import iv.vfs;
25 import iv.vfs.io;
26 import iv.vfs.util;
29 // ////////////////////////////////////////////////////////////////////////// //
30 void setMonthLimits () {
31 auto st = dbConf.persistentStatement(`
32 INSERT INTO options
33 ( name, value)
34 VALUES(:name,:value)
35 ON CONFLICT(name)
36 DO UPDATE SET value=:value
37 `);
40 .bindConstText(":name", "/mainpane/msgview/monthlimit")
41 .bind(":value", 6)
42 .doAll();
45 .bindConstText(":name", "/mainpane/msgview/monthlimit/accounts")
46 .bind(":value", -1)
47 .doAll();
50 .bindConstText(":name", "/mainpane/msgview/monthlimit/dmars_ng")
51 .bind(":value", 4)
52 .doAll();
55 .bindConstText(":name", "/mainpane/msgview/monthlimit/lj_and_ljr")
56 .bind(":value", 2)
57 .doAll();
61 // ////////////////////////////////////////////////////////////////////////// //
62 void main (string[] args) {
63 ChiroTimerEnabled = true;
64 chiroParseCommonCLIArgs(args);
66 // here, i don't have any threads at all
67 if (sqlite3_config(SQLITE_CONFIG_SINGLETHREAD) != SQLITE_OK) throw new Exception("cannot switch SQLite to multi-threaded mode");
69 bool allowed = false;
70 foreach (string s; args[1..$]) {
71 if (s == "force") allowed = true;
73 if (!allowed) throw new Exception("use \"force\" to rebuild");
75 try {
76 chiroOpenConfDB();
77 } catch (Exception) {
78 chiroRecreateConfDB();
81 auto stInsAcc = dbConf.persistentStatement(`
82 INSERT INTO accounts
83 ( checktime, nosendauth, debuglog, name, recvserver, sendserver, user, pass, realname, email, inbox, nntpgroup)
84 VALUES(:checktime,:nosendauth,:debuglog,:name,:recvserver,:sendserver,:user,:pass,:realname,:email,:inbox,:nntpgroup)
85 ;`);
87 dbConf.execute("BEGIN TRANSACTION;");
88 scope(failure) dbConf.execute("ROLLBACK TRANSACTION;");
89 uint count = 0;
90 foreach (string[] argv; loadRCFile("accounts.rc")) {
91 string accname = argv[1];
92 if (!isValidUTFNick(accname)) throw new Exception("invalid account name \""~accname~"\"");
93 string inbox = "/accounts/"~accname~"/inbox";
95 stInsAcc
96 .bind(":checktime", 15)
97 .bind(":nosendauth", 0)
98 .bind(":debuglog", 0)
99 .bindConstText(":name", accname)
100 .bindConstText(":recvserver", "")
101 .bindConstText(":sendserver", "")
102 .bindConstText(":user", "")
103 .bindConstText(":pass", "")
104 .bindConstText(":realname", "")
105 .bindConstText(":email", "")
106 .bindConstText(":inbox", inbox)
107 .bindConstText(":nntpgroup", "");
109 for (usize aidx = 2; aidx < argv.length; ) {
110 string aname = argv[aidx++];
111 switch (aname) {
112 case "debuglog": case "debug_log":
113 stInsAcc.bind(":debuglog", 1);
114 break;
115 case "no_debuglog": case "no_debug_log":
116 stInsAcc.bind(":debuglog", 0);
117 break;
118 case "smtp_no_auth": case "smtp_noauth":
119 stInsAcc.bind(":nosendauth", 1);
120 break;
121 case "default":
122 break;
123 case "user":
124 stInsAcc.bindConstText(":user", argv[aidx++]);
125 break;
126 case "pass":
127 case "password":
128 stInsAcc.bindConstText(":pass", argv[aidx++]);
129 break;
130 case "name":
131 case "realname":
132 case "real_name":
133 stInsAcc.bindConstText(":realname", argv[aidx++]);
134 break;
135 case "server":
136 stInsAcc.bindConstText(":recvserver", argv[aidx++]);
137 break;
138 case "smtpserver":
139 case "smtp_server":
140 stInsAcc.bindConstText(":sendserver", argv[aidx++]);
141 break;
142 case "mail":
143 case "email":
144 case "e-mail":
145 stInsAcc.bindConstText(":email", argv[aidx++]);
146 break;
147 case "folder":
149 string s = argv[aidx++];
150 while (s.length && s[0] == '/') s = s[1..$];
151 while (s.length && s[$-1] == '/') s = s[0..$-1];
152 s = "/"~s;
153 assert(s != "/");
154 stInsAcc.bindText(":inbox", s);
156 break;
157 case "group":
158 stInsAcc.bindConstText(":nntpgroup", argv[aidx++]);
159 break;
160 case "checktime":
161 case "check_time":
163 import std.conv : to;
164 stInsAcc.bind(":checktime", argv[aidx++].to!uint);
166 break;
167 default:
168 throw new Exception("unknown option \""~aname~"\"");
172 switch (argv[0]) {
173 case "popbox":
174 case "nntpbox":
175 break;
176 default:
177 throw new Exception("unknown account type \""~argv[0]~"\"");
180 stInsAcc.doAll();
181 ++count;
183 setMonthLimits();
184 dbConf.execute("COMMIT TRANSACTION;");
186 writeln(count, " accounts added.");
188 writeln("closing the db");
189 dbConf.close();