NeoMutt  2024-12-12-14-g7b49f7
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
db.c
Go to the documentation of this file.
1
32#include "config.h"
33#include <sqlite3.h>
34#include <stdbool.h>
35#include <stddef.h>
36#include <sys/stat.h>
37#include "private.h"
38#include "mutt/lib.h"
39#include "address/lib.h"
40#include "config/lib.h"
41#include "core/lib.h"
42#include "lib.h"
43
44// Prepared SQL statements
45static sqlite3_stmt *AccountGetStmt = NULL;
46static sqlite3_stmt *AccountInsertStmt = NULL;
47static sqlite3_stmt *AccountUpdateStmt = NULL;
48static sqlite3_stmt *AccountDeleteStmt = NULL;
49static sqlite3_stmt *PeerGetStmt = NULL;
50static sqlite3_stmt *PeerInsertStmt = NULL;
51static sqlite3_stmt *PeerUpdateStmt = NULL;
52static sqlite3_stmt *PeerHistoryInsertStmt = NULL;
53static sqlite3_stmt *GossipHistoryInsertStmt = NULL;
54
56sqlite3 *AutocryptDB = NULL;
57
64static int autocrypt_db_create(const char *db_path)
65{
66 if (sqlite3_open_v2(db_path, &AutocryptDB,
67 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL) != SQLITE_OK)
68 {
69 /* L10N: autocrypt couldn't open the SQLite database.
70 The %s is the full path of the database file. */
71 mutt_error(_("Unable to open autocrypt database %s"), db_path);
72 return -1;
73 }
75}
76
83int mutt_autocrypt_db_init(bool can_create)
84{
85 int rc = -1;
86
87 if (AutocryptDB)
88 return 0;
89
90 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
91 const char *const c_autocrypt_dir = cs_subset_path(NeoMutt->sub, "autocrypt_dir");
92 if (!c_autocrypt || !c_autocrypt_dir)
93 return -1;
94
95 struct Buffer *db_path = buf_pool_get();
96 buf_concat_path(db_path, c_autocrypt_dir, "autocrypt.db");
97
98 struct stat st = { 0 };
99 if (stat(buf_string(db_path), &st) == 0)
100 {
101 if (sqlite3_open_v2(buf_string(db_path), &AutocryptDB, SQLITE_OPEN_READWRITE, NULL) != SQLITE_OK)
102 {
103 /* L10N: autocrypt couldn't open the SQLite database.
104 The %s is the full path of the database file. */
105 mutt_error(_("Unable to open autocrypt database %s"), buf_string(db_path));
106 goto cleanup;
107 }
108
110 goto cleanup;
111 }
112 else
113 {
114 if (!can_create)
115 goto cleanup;
116 if (autocrypt_db_create(buf_string(db_path)))
117 goto cleanup;
118 /* Don't abort the whole init process because account creation failed */
121 }
122
123 rc = 0;
124
125cleanup:
126 buf_pool_release(&db_path);
127 return rc;
128}
129
134{
135 if (!AutocryptDB)
136 return;
137
138 sqlite3_finalize(AccountGetStmt);
139 AccountGetStmt = NULL;
140 sqlite3_finalize(AccountInsertStmt);
141 AccountInsertStmt = NULL;
142 sqlite3_finalize(AccountUpdateStmt);
143 AccountUpdateStmt = NULL;
144 sqlite3_finalize(AccountDeleteStmt);
145 AccountDeleteStmt = NULL;
146
147 sqlite3_finalize(PeerGetStmt);
148 PeerGetStmt = NULL;
149 sqlite3_finalize(PeerInsertStmt);
150 PeerInsertStmt = NULL;
151 sqlite3_finalize(PeerUpdateStmt);
152 PeerUpdateStmt = NULL;
153
154 sqlite3_finalize(PeerHistoryInsertStmt);
156
157 sqlite3_finalize(GossipHistoryInsertStmt);
159
160 sqlite3_close_v2(AutocryptDB);
161 AutocryptDB = NULL;
162}
163
169{
171 buf_lower(a->mailbox);
173}
174
179void mutt_autocrypt_db_normalize_addrlist(struct AddressList *al)
180{
182
183 struct Address *np = NULL;
184 TAILQ_FOREACH(np, al, entries)
185 {
186 buf_lower(np->mailbox);
187 }
188
189 mutt_addrlist_to_intl(al, NULL);
190}
191
205static struct Address *copy_normalize_addr(struct Address *addr)
206{
207 /* NOTE: the db functions expect a single address, so in
208 * this function we copy only the address passed in.
209 *
210 * The normalize_addrlist above is extended to work on a list
211 * because of requirements in autocrypt.c */
212
213 struct Address *norm_addr = mutt_addr_create(NULL, buf_string(addr->mailbox));
214 norm_addr->is_intl = addr->is_intl;
215 norm_addr->intl_checked = addr->intl_checked;
216
218 return norm_addr;
219}
220
227static char *strdup_column_text(sqlite3_stmt *stmt, int index)
228{
229 const char *val = (const char *) sqlite3_column_text(stmt, index);
230 return mutt_str_dup(val);
231}
232
238{
239 return MUTT_MEM_CALLOC(1, struct AutocryptAccount);
240}
241
247{
248 if (!ptr || !*ptr)
249 return;
250
251 struct AutocryptAccount *ac = *ptr;
252 FREE(&ac->email_addr);
253 FREE(&ac->keyid);
254 FREE(&ac->keydata);
255 FREE(ptr);
256}
257
265int mutt_autocrypt_db_account_get(struct Address *addr, struct AutocryptAccount **account)
266{
267 int rc = -1;
268
269 struct Address *norm_addr = copy_normalize_addr(addr);
270 *account = NULL;
271
272 if (!AccountGetStmt)
273 {
274 if (sqlite3_prepare_v3(AutocryptDB,
275 "SELECT "
276 "email_addr, "
277 "keyid, "
278 "keydata, "
279 "prefer_encrypt, "
280 "enabled "
281 "FROM account "
282 "WHERE email_addr = ?",
283 -1, SQLITE_PREPARE_PERSISTENT, &AccountGetStmt, NULL) != SQLITE_OK)
284 {
285 goto cleanup;
286 }
287 }
288
289 if (sqlite3_bind_text(AccountGetStmt, 1, buf_string(norm_addr->mailbox), -1,
290 SQLITE_STATIC) != SQLITE_OK)
291 {
292 goto cleanup;
293 }
294
295 int result = sqlite3_step(AccountGetStmt);
296 if (result != SQLITE_ROW)
297 {
298 if (result == SQLITE_DONE)
299 rc = 0;
300 goto cleanup;
301 }
302
304 (*account)->email_addr = strdup_column_text(AccountGetStmt, 0);
305 (*account)->keyid = strdup_column_text(AccountGetStmt, 1);
306 (*account)->keydata = strdup_column_text(AccountGetStmt, 2);
307 (*account)->prefer_encrypt = sqlite3_column_int(AccountGetStmt, 3);
308 (*account)->enabled = sqlite3_column_int(AccountGetStmt, 4);
309
310 rc = 1;
311
312cleanup:
313 mutt_addr_free(&norm_addr);
314 sqlite3_reset(AccountGetStmt);
315 return rc;
316}
317
327int mutt_autocrypt_db_account_insert(struct Address *addr, const char *keyid,
328 const char *keydata, bool prefer_encrypt)
329{
330 int rc = -1;
331
332 struct Address *norm_addr = copy_normalize_addr(addr);
333
335 {
336 if (sqlite3_prepare_v3(AutocryptDB,
337 "INSERT INTO account "
338 "(email_addr, "
339 "keyid, "
340 "keydata, "
341 "prefer_encrypt, "
342 "enabled) "
343 "VALUES (?, ?, ?, ?, ?);",
344 -1, SQLITE_PREPARE_PERSISTENT, &AccountInsertStmt, NULL) != SQLITE_OK)
345 {
346 goto cleanup;
347 }
348 }
349
350 if (sqlite3_bind_text(AccountInsertStmt, 1, buf_string(norm_addr->mailbox),
351 -1, SQLITE_STATIC) != SQLITE_OK)
352 {
353 goto cleanup;
354 }
355 if (sqlite3_bind_text(AccountInsertStmt, 2, keyid, -1, SQLITE_STATIC) != SQLITE_OK)
356 goto cleanup;
357 if (sqlite3_bind_text(AccountInsertStmt, 3, keydata, -1, SQLITE_STATIC) != SQLITE_OK)
358 goto cleanup;
359 if (sqlite3_bind_int(AccountInsertStmt, 4, prefer_encrypt) != SQLITE_OK)
360 goto cleanup;
361 if (sqlite3_bind_int(AccountInsertStmt, 5, 1) != SQLITE_OK)
362 goto cleanup;
363
364 if (sqlite3_step(AccountInsertStmt) != SQLITE_DONE)
365 goto cleanup;
366
367 rc = 0;
368
369cleanup:
370 mutt_addr_free(&norm_addr);
371 sqlite3_reset(AccountInsertStmt);
372 return rc;
373}
374
382{
383 int rc = -1;
384
386 {
387 if (sqlite3_prepare_v3(AutocryptDB,
388 "UPDATE account SET "
389 "keyid = ?, "
390 "keydata = ?, "
391 "prefer_encrypt = ?, "
392 "enabled = ? "
393 "WHERE email_addr = ?;",
394 -1, SQLITE_PREPARE_PERSISTENT, &AccountUpdateStmt, NULL) != SQLITE_OK)
395 {
396 goto cleanup;
397 }
398 }
399
400 if (sqlite3_bind_text(AccountUpdateStmt, 1, acct->keyid, -1, SQLITE_STATIC) != SQLITE_OK)
401 goto cleanup;
402 if (sqlite3_bind_text(AccountUpdateStmt, 2, acct->keydata, -1, SQLITE_STATIC) != SQLITE_OK)
403 goto cleanup;
404 if (sqlite3_bind_int(AccountUpdateStmt, 3, acct->prefer_encrypt) != SQLITE_OK)
405 goto cleanup;
406 if (sqlite3_bind_int(AccountUpdateStmt, 4, acct->enabled) != SQLITE_OK)
407 goto cleanup;
408 if (sqlite3_bind_text(AccountUpdateStmt, 5, acct->email_addr, -1, SQLITE_STATIC) != SQLITE_OK)
409 goto cleanup;
410
411 if (sqlite3_step(AccountUpdateStmt) != SQLITE_DONE)
412 goto cleanup;
413
414 rc = 0;
415
416cleanup:
417 sqlite3_reset(AccountUpdateStmt);
418 return rc;
419}
420
428{
429 int rc = -1;
430
432 {
433 if (sqlite3_prepare_v3(AutocryptDB,
434 "DELETE from account "
435 "WHERE email_addr = ?;",
436 -1, SQLITE_PREPARE_PERSISTENT, &AccountDeleteStmt, NULL) != SQLITE_OK)
437 {
438 goto cleanup;
439 }
440 }
441
442 if (sqlite3_bind_text(AccountDeleteStmt, 1, acct->email_addr, -1, SQLITE_STATIC) != SQLITE_OK)
443 goto cleanup;
444
445 if (sqlite3_step(AccountDeleteStmt) != SQLITE_DONE)
446 goto cleanup;
447
448 rc = 0;
449
450cleanup:
451 sqlite3_reset(AccountDeleteStmt);
452 return rc;
453}
454
461int mutt_autocrypt_db_account_get_all(struct AutocryptAccountArray *aaa)
462{
463 if (!aaa)
464 return -1;
465
466 int rc = -1;
467 sqlite3_stmt *stmt = NULL;
468
469 /* Note, speed is not of the essence for the account management screen,
470 * so we don't bother with a persistent prepared statement */
471 if (sqlite3_prepare_v2(AutocryptDB,
472 "SELECT "
473 "email_addr, "
474 "keyid, "
475 "keydata, "
476 "prefer_encrypt, "
477 "enabled "
478 "FROM account "
479 "ORDER BY email_addr",
480 -1, &stmt, NULL) != SQLITE_OK)
481 {
482 goto cleanup;
483 }
484
485 int result = SQLITE_ERROR;
486 while ((result = sqlite3_step(stmt)) == SQLITE_ROW)
487 {
489
490 ac->email_addr = strdup_column_text(stmt, 0);
491 ac->keyid = strdup_column_text(stmt, 1);
492 ac->keydata = strdup_column_text(stmt, 2);
493 ac->prefer_encrypt = sqlite3_column_int(stmt, 3);
494 ac->enabled = sqlite3_column_int(stmt, 4);
495
496 ARRAY_ADD(aaa, ac);
497 }
498
499 if (result == SQLITE_DONE)
500 {
501 rc = ARRAY_SIZE(aaa);
502 }
503 else
504 {
505 struct AutocryptAccount **pac = NULL;
506 ARRAY_FOREACH(pac, aaa)
507 {
509 }
510 ARRAY_FREE(aaa);
511 }
512
513cleanup:
514 sqlite3_finalize(stmt);
515 return rc;
516}
517
523{
524 return MUTT_MEM_CALLOC(1, struct AutocryptPeer);
525}
526
532{
533 if (!ptr || !*ptr)
534 return;
535
536 struct AutocryptPeer *peer = *ptr;
537 FREE(&peer->email_addr);
538 FREE(&peer->keyid);
539 FREE(&peer->keydata);
540 FREE(&peer->gossip_keyid);
541 FREE(&peer->gossip_keydata);
542 FREE(ptr);
543}
544
553int mutt_autocrypt_db_peer_get(struct Address *addr, struct AutocryptPeer **peer)
554{
555 int rc = -1;
556
557 struct Address *norm_addr = copy_normalize_addr(addr);
558 *peer = NULL;
559
560 if (!PeerGetStmt)
561 {
562 if (sqlite3_prepare_v3(AutocryptDB,
563 "SELECT "
564 "email_addr, "
565 "last_seen, "
566 "autocrypt_timestamp, "
567 "keyid, "
568 "keydata, "
569 "prefer_encrypt, "
570 "gossip_timestamp, "
571 "gossip_keyid, "
572 "gossip_keydata "
573 "FROM peer "
574 "WHERE email_addr = ?",
575 -1, SQLITE_PREPARE_PERSISTENT, &PeerGetStmt, NULL) != SQLITE_OK)
576 {
577 goto cleanup;
578 }
579 }
580
581 if (sqlite3_bind_text(PeerGetStmt, 1, buf_string(norm_addr->mailbox), -1,
582 SQLITE_STATIC) != SQLITE_OK)
583 {
584 goto cleanup;
585 }
586
587 int result = sqlite3_step(PeerGetStmt);
588 if (result != SQLITE_ROW)
589 {
590 if (result == SQLITE_DONE)
591 rc = 0;
592 goto cleanup;
593 }
594
596 (*peer)->email_addr = strdup_column_text(PeerGetStmt, 0);
597 (*peer)->last_seen = sqlite3_column_int64(PeerGetStmt, 1);
598 (*peer)->autocrypt_timestamp = sqlite3_column_int64(PeerGetStmt, 2);
599 (*peer)->keyid = strdup_column_text(PeerGetStmt, 3);
600 (*peer)->keydata = strdup_column_text(PeerGetStmt, 4);
601 (*peer)->prefer_encrypt = sqlite3_column_int(PeerGetStmt, 5);
602 (*peer)->gossip_timestamp = sqlite3_column_int64(PeerGetStmt, 6);
603 (*peer)->gossip_keyid = strdup_column_text(PeerGetStmt, 7);
604 (*peer)->gossip_keydata = strdup_column_text(PeerGetStmt, 8);
605
606 rc = 1;
607
608cleanup:
609 mutt_addr_free(&norm_addr);
610 sqlite3_reset(PeerGetStmt);
611 return rc;
612}
613
622{
623 int rc = -1;
624 struct Address *norm_addr = NULL;
625
626 norm_addr = copy_normalize_addr(addr);
627
628 if (!PeerInsertStmt)
629 {
630 if (sqlite3_prepare_v3(AutocryptDB,
631 "INSERT INTO peer "
632 "(email_addr, "
633 "last_seen, "
634 "autocrypt_timestamp, "
635 "keyid, "
636 "keydata, "
637 "prefer_encrypt, "
638 "gossip_timestamp, "
639 "gossip_keyid, "
640 "gossip_keydata) "
641 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);",
642 -1, SQLITE_PREPARE_PERSISTENT, &PeerInsertStmt, NULL) != SQLITE_OK)
643 {
644 goto cleanup;
645 }
646 }
647
648 if (sqlite3_bind_text(PeerInsertStmt, 1, buf_string(norm_addr->mailbox), -1,
649 SQLITE_STATIC) != SQLITE_OK)
650 {
651 goto cleanup;
652 }
653 if (sqlite3_bind_int64(PeerInsertStmt, 2, peer->last_seen) != SQLITE_OK)
654 goto cleanup;
655 if (sqlite3_bind_int64(PeerInsertStmt, 3, peer->autocrypt_timestamp) != SQLITE_OK)
656 goto cleanup;
657 if (sqlite3_bind_text(PeerInsertStmt, 4, peer->keyid, -1, SQLITE_STATIC) != SQLITE_OK)
658 goto cleanup;
659 if (sqlite3_bind_text(PeerInsertStmt, 5, peer->keydata, -1, SQLITE_STATIC) != SQLITE_OK)
660 goto cleanup;
661 if (sqlite3_bind_int(PeerInsertStmt, 6, peer->prefer_encrypt) != SQLITE_OK)
662 goto cleanup;
663 if (sqlite3_bind_int64(PeerInsertStmt, 7, peer->gossip_timestamp) != SQLITE_OK)
664 goto cleanup;
665 if (sqlite3_bind_text(PeerInsertStmt, 8, peer->gossip_keyid, -1, SQLITE_STATIC) != SQLITE_OK)
666 goto cleanup;
667 if (sqlite3_bind_text(PeerInsertStmt, 9, peer->gossip_keydata, -1, SQLITE_STATIC) != SQLITE_OK)
668 goto cleanup;
669
670 if (sqlite3_step(PeerInsertStmt) != SQLITE_DONE)
671 goto cleanup;
672
673 rc = 0;
674
675cleanup:
676 mutt_addr_free(&norm_addr);
677 sqlite3_reset(PeerInsertStmt);
678 return rc;
679}
680
688{
689 int rc = -1;
690
691 if (!PeerUpdateStmt)
692 {
693 if (sqlite3_prepare_v3(AutocryptDB,
694 "UPDATE peer SET "
695 "last_seen = ?, "
696 "autocrypt_timestamp = ?, "
697 "keyid = ?, "
698 "keydata = ?, "
699 "prefer_encrypt = ?, "
700 "gossip_timestamp = ?, "
701 "gossip_keyid = ?, "
702 "gossip_keydata = ? "
703 "WHERE email_addr = ?;",
704 -1, SQLITE_PREPARE_PERSISTENT, &PeerUpdateStmt, NULL) != SQLITE_OK)
705 {
706 goto cleanup;
707 }
708 }
709
710 if (sqlite3_bind_int64(PeerUpdateStmt, 1, peer->last_seen) != SQLITE_OK)
711 goto cleanup;
712 if (sqlite3_bind_int64(PeerUpdateStmt, 2, peer->autocrypt_timestamp) != SQLITE_OK)
713 goto cleanup;
714 if (sqlite3_bind_text(PeerUpdateStmt, 3, peer->keyid, -1, SQLITE_STATIC) != SQLITE_OK)
715 goto cleanup;
716 if (sqlite3_bind_text(PeerUpdateStmt, 4, peer->keydata, -1, SQLITE_STATIC) != SQLITE_OK)
717 goto cleanup;
718 if (sqlite3_bind_int(PeerUpdateStmt, 5, peer->prefer_encrypt) != SQLITE_OK)
719 goto cleanup;
720 if (sqlite3_bind_int64(PeerUpdateStmt, 6, peer->gossip_timestamp) != SQLITE_OK)
721 goto cleanup;
722 if (sqlite3_bind_text(PeerUpdateStmt, 7, peer->gossip_keyid, -1, SQLITE_STATIC) != SQLITE_OK)
723 goto cleanup;
724 if (sqlite3_bind_text(PeerUpdateStmt, 8, peer->gossip_keydata, -1, SQLITE_STATIC) != SQLITE_OK)
725 goto cleanup;
726 if (sqlite3_bind_text(PeerUpdateStmt, 9, peer->email_addr, -1, SQLITE_STATIC) != SQLITE_OK)
727 goto cleanup;
728
729 if (sqlite3_step(PeerUpdateStmt) != SQLITE_DONE)
730 goto cleanup;
731
732 rc = 0;
733
734cleanup:
735 sqlite3_reset(PeerUpdateStmt);
736 return rc;
737}
738
744{
745 return MUTT_MEM_CALLOC(1, struct AutocryptPeerHistory);
746}
747
753{
754 if (!ptr || !*ptr)
755 return;
756
757 struct AutocryptPeerHistory *ph = *ptr;
758 FREE(&ph->peer_email_addr);
759 FREE(&ph->email_msgid);
760 FREE(&ph->keydata);
761 FREE(ptr);
762}
763
772 struct AutocryptPeerHistory *peerhist)
773{
774 int rc = -1;
775
776 struct Address *norm_addr = copy_normalize_addr(addr);
777
779 {
780 if (sqlite3_prepare_v3(AutocryptDB,
781 "INSERT INTO peer_history "
782 "(peer_email_addr, "
783 "email_msgid, "
784 "timestamp, "
785 "keydata) "
786 "VALUES (?, ?, ?, ?);",
787 -1, SQLITE_PREPARE_PERSISTENT,
788 &PeerHistoryInsertStmt, NULL) != SQLITE_OK)
789 {
790 goto cleanup;
791 }
792 }
793
794 if (sqlite3_bind_text(PeerHistoryInsertStmt, 1, buf_string(norm_addr->mailbox),
795 -1, SQLITE_STATIC) != SQLITE_OK)
796 {
797 goto cleanup;
798 }
799 if (sqlite3_bind_text(PeerHistoryInsertStmt, 2, peerhist->email_msgid, -1,
800 SQLITE_STATIC) != SQLITE_OK)
801 {
802 goto cleanup;
803 }
804 if (sqlite3_bind_int64(PeerHistoryInsertStmt, 3, peerhist->timestamp) != SQLITE_OK)
805 goto cleanup;
806 if (sqlite3_bind_text(PeerHistoryInsertStmt, 4, peerhist->keydata, -1, SQLITE_STATIC) != SQLITE_OK)
807 goto cleanup;
808
809 if (sqlite3_step(PeerHistoryInsertStmt) != SQLITE_DONE)
810 goto cleanup;
811
812 rc = 0;
813
814cleanup:
815 mutt_addr_free(&norm_addr);
816 sqlite3_reset(PeerHistoryInsertStmt);
817 return rc;
818}
819
825{
826 return MUTT_MEM_CALLOC(1, struct AutocryptGossipHistory);
827}
828
834{
835 if (!ptr || !*ptr)
836 return;
837
838 struct AutocryptGossipHistory *gh = *ptr;
839 FREE(&gh->peer_email_addr);
841 FREE(&gh->email_msgid);
842 FREE(&gh->gossip_keydata);
843 FREE(ptr);
844}
845
854 struct AutocryptGossipHistory *gossip_hist)
855{
856 int rc = -1;
857
858 struct Address *norm_addr = copy_normalize_addr(addr);
859
861 {
862 if (sqlite3_prepare_v3(AutocryptDB,
863 "INSERT INTO gossip_history "
864 "(peer_email_addr, "
865 "sender_email_addr, "
866 "email_msgid, "
867 "timestamp, "
868 "gossip_keydata) "
869 "VALUES (?, ?, ?, ?, ?);",
870 -1, SQLITE_PREPARE_PERSISTENT,
871 &GossipHistoryInsertStmt, NULL) != SQLITE_OK)
872 {
873 goto cleanup;
874 }
875 }
876
877 if (sqlite3_bind_text(GossipHistoryInsertStmt, 1, buf_string(norm_addr->mailbox),
878 -1, SQLITE_STATIC) != SQLITE_OK)
879 {
880 goto cleanup;
881 }
882 if (sqlite3_bind_text(GossipHistoryInsertStmt, 2, gossip_hist->sender_email_addr,
883 -1, SQLITE_STATIC) != SQLITE_OK)
884 {
885 if (sqlite3_bind_text(GossipHistoryInsertStmt, 3, gossip_hist->email_msgid,
886 -1, SQLITE_STATIC) != SQLITE_OK)
887 {
888 goto cleanup;
889 }
890 }
891 if (sqlite3_bind_int64(GossipHistoryInsertStmt, 4, gossip_hist->timestamp) != SQLITE_OK)
892 goto cleanup;
893 if (sqlite3_bind_text(GossipHistoryInsertStmt, 5, gossip_hist->gossip_keydata,
894 -1, SQLITE_STATIC) != SQLITE_OK)
895 {
896 goto cleanup;
897 }
898
899 if (sqlite3_step(GossipHistoryInsertStmt) != SQLITE_DONE)
900 goto cleanup;
901
902 rc = 0;
903
904cleanup:
905 mutt_addr_free(&norm_addr);
906 sqlite3_reset(GossipHistoryInsertStmt);
907 return rc;
908}
struct Address * mutt_addr_create(const char *personal, const char *mailbox)
Create and populate a new Address.
Definition: address.c:414
void mutt_addr_free(struct Address **ptr)
Free a single Address.
Definition: address.c:462
int mutt_addrlist_to_local(struct AddressList *al)
Convert an Address list from Punycode.
Definition: address.c:1378
bool mutt_addr_to_local(struct Address *a)
Convert an Address from Punycode.
Definition: address.c:1340
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
Definition: address.c:1293
bool mutt_addr_to_intl(struct Address *a)
Convert an Address to Punycode.
Definition: address.c:1263
Email Address Handling.
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:156
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:212
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:87
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:204
void mutt_autocrypt_db_normalize_addrlist(struct AddressList *al)
Normalise a list of Email Addresses.
Definition: db.c:179
static sqlite3_stmt * PeerUpdateStmt
Update a peer address.
Definition: db.c:51
struct AutocryptPeer * mutt_autocrypt_db_peer_new(void)
Create a new AutocryptPeer.
Definition: db.c:522
int mutt_autocrypt_db_account_delete(struct AutocryptAccount *acct)
Delete an Account from the Autocrypt database.
Definition: db.c:427
static sqlite3_stmt * PeerGetStmt
Get the matching peer addresses.
Definition: db.c:49
int mutt_autocrypt_db_peer_insert(struct Address *addr, struct AutocryptPeer *peer)
Insert a peer into the Autocrypt database.
Definition: db.c:621
struct AutocryptGossipHistory * mutt_autocrypt_db_gossip_history_new(void)
Create a new AutocryptGossipHistory.
Definition: db.c:824
void mutt_autocrypt_db_close(void)
Close the Autocrypt SQLite database connection.
Definition: db.c:133
sqlite3 * AutocryptDB
Handle to the open Autocrypt database.
Definition: db.c:56
int mutt_autocrypt_db_gossip_history_insert(struct Address *addr, struct AutocryptGossipHistory *gossip_hist)
Insert a gossip history into the Autocrypt database.
Definition: db.c:853
int mutt_autocrypt_db_account_get(struct Address *addr, struct AutocryptAccount **account)
Get Autocrypt Account data from the database.
Definition: db.c:265
int mutt_autocrypt_db_peer_get(struct Address *addr, struct AutocryptPeer **peer)
Get peer info from the Autocrypt database.
Definition: db.c:553
int mutt_autocrypt_db_peer_update(struct AutocryptPeer *peer)
Update the peer info in an Autocrypt database.
Definition: db.c:687
int mutt_autocrypt_db_account_get_all(struct AutocryptAccountArray *aaa)
Get all accounts from an Autocrypt database.
Definition: db.c:461
int mutt_autocrypt_db_account_insert(struct Address *addr, const char *keyid, const char *keydata, bool prefer_encrypt)
Insert an Account into the Autocrypt database.
Definition: db.c:327
void mutt_autocrypt_db_account_free(struct AutocryptAccount **ptr)
Free an AutocryptAccount.
Definition: db.c:246
struct AutocryptAccount * mutt_autocrypt_db_account_new(void)
Create a new AutocryptAccount.
Definition: db.c:237
static sqlite3_stmt * AccountInsertStmt
Insert a new autocrypt account.
Definition: db.c:46
void mutt_autocrypt_db_normalize_addr(struct Address *a)
Normalise an Email Address.
Definition: db.c:168
static sqlite3_stmt * PeerHistoryInsertStmt
Add to the peer history.
Definition: db.c:52
static struct Address * copy_normalize_addr(struct Address *addr)
Copy a normalised Email Address.
Definition: db.c:205
void mutt_autocrypt_db_peer_history_free(struct AutocryptPeerHistory **ptr)
Free an AutocryptPeerHistory.
Definition: db.c:752
static sqlite3_stmt * GossipHistoryInsertStmt
Add to the gossip history.
Definition: db.c:53
int mutt_autocrypt_db_account_update(struct AutocryptAccount *acct)
Update Account info in the Autocrypt database.
Definition: db.c:381
static sqlite3_stmt * AccountUpdateStmt
Update an autocrypt account.
Definition: db.c:47
void mutt_autocrypt_db_peer_free(struct AutocryptPeer **ptr)
Free an AutocryptPeer.
Definition: db.c:531
void mutt_autocrypt_db_gossip_history_free(struct AutocryptGossipHistory **ptr)
Free an AutocryptGossipHistory.
Definition: db.c:833
struct AutocryptPeerHistory * mutt_autocrypt_db_peer_history_new(void)
Create a new AutocryptPeerHistory.
Definition: db.c:743
static int autocrypt_db_create(const char *db_path)
Create an Autocrypt SQLite database.
Definition: db.c:64
static sqlite3_stmt * AccountGetStmt
Get the matching autocrypt accounts.
Definition: db.c:45
int mutt_autocrypt_db_init(bool can_create)
Initialise the Autocrypt SQLite database.
Definition: db.c:83
static sqlite3_stmt * AccountDeleteStmt
Delete an autocrypt account.
Definition: db.c:48
static char * strdup_column_text(sqlite3_stmt *stmt, int index)
Copy a string from the database.
Definition: db.c:227
static sqlite3_stmt * PeerInsertStmt
Insert a new peer address.
Definition: db.c:50
int mutt_autocrypt_db_peer_history_insert(struct Address *addr, struct AutocryptPeerHistory *peerhist)
Insert peer history into the Autocrypt database.
Definition: db.c:771
int mutt_autocrypt_schema_update(void)
Update the version number of the Autocrypt database schema.
Definition: schema.c:107
int mutt_autocrypt_schema_init(void)
Set up an Autocrypt database.
Definition: schema.c:41
int mutt_autocrypt_account_init(bool prompt)
Create a new Autocrypt account.
Definition: autocrypt.c:143
void mutt_autocrypt_scan_mailboxes(void)
Scan mailboxes for Autocrypt headers.
Definition: autocrypt.c:914
size_t buf_concat_path(struct Buffer *buf, const char *dir, const char *fname)
Join a directory name and a filename.
Definition: buffer.c:509
void buf_lower(struct Buffer *buf)
Sets a buffer to lowercase.
Definition: buffer.c:736
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:168
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
#define mutt_error(...)
Definition: logging2.h:92
#define FREE(x)
Definition: memory.h:55
#define MUTT_MEM_CALLOC(n, type)
Definition: memory.h:40
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:96
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:743
GUI display the mailboxes in a side panel.
Key value store.
An email address.
Definition: address.h:36
struct Buffer * mailbox
Mailbox and host address.
Definition: address.h:38
bool intl_checked
Checked for IDN?
Definition: address.h:41
bool is_intl
International Domain Name.
Definition: address.h:40
Autocrypt account.
Definition: lib.h:110
char * email_addr
Email address.
Definition: lib.h:111
char * keydata
PGP Key data.
Definition: lib.h:113
char * keyid
PGP Key id.
Definition: lib.h:112
bool enabled
Is this account enabled.
Definition: lib.h:115
bool prefer_encrypt
false = nopref, true = mutual
Definition: lib.h:114
Autocrypt gossip history.
Definition: lib.h:150
char * peer_email_addr
Email addressof the peer.
Definition: lib.h:151
char * email_msgid
Sender's email's message id.
Definition: lib.h:153
char * sender_email_addr
Sender's email address.
Definition: lib.h:152
char * gossip_keydata
Gossip Key data.
Definition: lib.h:155
sqlite3_int64 timestamp
Timestamp of sender's email.
Definition: lib.h:154
Autocrypt peer history.
Definition: lib.h:139
char * peer_email_addr
Email address of the peer.
Definition: lib.h:140
char * email_msgid
Message id of the email.
Definition: lib.h:141
char * keydata
PGP Key data.
Definition: lib.h:143
sqlite3_int64 timestamp
Timestamp of email.
Definition: lib.h:142
Autocrypt peer.
Definition: lib.h:123
sqlite3_int64 autocrypt_timestamp
When the email was sent.
Definition: lib.h:126
char * gossip_keydata
Gossip Key data.
Definition: lib.h:132
char * keyid
PGP Key id.
Definition: lib.h:127
char * gossip_keyid
Gossip Key id.
Definition: lib.h:131
char * keydata
PGP Key data.
Definition: lib.h:128
char * email_addr
Email address.
Definition: lib.h:124
sqlite3_int64 last_seen
When was the peer last seen.
Definition: lib.h:125
bool prefer_encrypt
false = nopref, true = mutual
Definition: lib.h:129
sqlite3_int64 gossip_timestamp
Timestamp of Gossip header.
Definition: lib.h:130
String manipulation buffer.
Definition: buffer.h:36
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46