NeoMutt  2023-03-22-27-g3cb248
Teaching an old dog new tricks
DOXYGEN
db.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stddef.h>
31#include <sqlite3.h>
32#include <stdbool.h>
33#include <sys/stat.h>
34#include "private.h"
35#include "mutt/lib.h"
36#include "address/lib.h"
37#include "config/lib.h"
38#include "core/lib.h"
39#include "lib.h"
40
41/* Prepared statements */
42static sqlite3_stmt *AccountGetStmt;
43static sqlite3_stmt *AccountInsertStmt;
44static sqlite3_stmt *AccountUpdateStmt;
45static sqlite3_stmt *AccountDeleteStmt;
46static sqlite3_stmt *PeerGetStmt;
47static sqlite3_stmt *PeerInsertStmt;
48static sqlite3_stmt *PeerUpdateStmt;
49static sqlite3_stmt *PeerHistoryInsertStmt;
50static sqlite3_stmt *GossipHistoryInsertStmt;
51
52sqlite3 *AutocryptDB = NULL;
53
60static int autocrypt_db_create(const char *db_path)
61{
62 if (sqlite3_open_v2(db_path, &AutocryptDB,
63 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL) != SQLITE_OK)
64 {
65 /* L10N: s is the path to the database.
66 For some reason sqlite3 failed to open that database file. */
67 mutt_error(_("Unable to open autocrypt database %s"), db_path);
68 return -1;
69 }
71}
72
79int mutt_autocrypt_db_init(bool can_create)
80{
81 int rc = -1;
82
83 if (AutocryptDB)
84 return 0;
85
86 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
87 const char *const c_autocrypt_dir = cs_subset_path(NeoMutt->sub, "autocrypt_dir");
88 if (!c_autocrypt || !c_autocrypt_dir)
89 return -1;
90
91 struct Buffer *db_path = mutt_buffer_pool_get();
92 mutt_buffer_concat_path(db_path, c_autocrypt_dir, "autocrypt.db");
93
94 struct stat st = { 0 };
95 if (stat(mutt_buffer_string(db_path), &st) == 0)
96 {
97 if (sqlite3_open_v2(mutt_buffer_string(db_path), &AutocryptDB,
98 SQLITE_OPEN_READWRITE, NULL) != SQLITE_OK)
99 {
100 /* L10N: Error message if autocrypt couldn't open the SQLite database
101 for some reason. The %s is the full path of the database file. */
102 mutt_error(_("Unable to open autocrypt database %s"), mutt_buffer_string(db_path));
103 goto cleanup;
104 }
105
107 goto cleanup;
108 }
109 else
110 {
111 if (!can_create)
112 goto cleanup;
114 goto cleanup;
115 /* Don't abort the whole init process because account creation failed */
118 }
119
120 rc = 0;
121
122cleanup:
123 mutt_buffer_pool_release(&db_path);
124 return rc;
125}
126
131{
132 if (!AutocryptDB)
133 return;
134
135 sqlite3_finalize(AccountGetStmt);
136 AccountGetStmt = NULL;
137 sqlite3_finalize(AccountInsertStmt);
138 AccountInsertStmt = NULL;
139 sqlite3_finalize(AccountUpdateStmt);
140 AccountUpdateStmt = NULL;
141 sqlite3_finalize(AccountDeleteStmt);
142 AccountDeleteStmt = NULL;
143
144 sqlite3_finalize(PeerGetStmt);
145 PeerGetStmt = NULL;
146 sqlite3_finalize(PeerInsertStmt);
147 PeerInsertStmt = NULL;
148 sqlite3_finalize(PeerUpdateStmt);
149 PeerUpdateStmt = NULL;
150
151 sqlite3_finalize(PeerHistoryInsertStmt);
153
154 sqlite3_finalize(GossipHistoryInsertStmt);
156
157 sqlite3_close_v2(AutocryptDB);
158 AutocryptDB = NULL;
159}
160
166{
170}
171
176void mutt_autocrypt_db_normalize_addrlist(struct AddressList *al)
177{
179
180 struct Address *np = NULL;
181 TAILQ_FOREACH(np, al, entries)
182 {
184 }
185
186 mutt_addrlist_to_intl(al, NULL);
187}
188
202static struct Address *copy_normalize_addr(struct Address *addr)
203{
204 /* NOTE: the db functions expect a single address, so in
205 * this function we copy only the address passed in.
206 *
207 * The normalize_addrlist above is extended to work on a list
208 * because of requirements in autocrypt.c */
209
210 struct Address *norm_addr = mutt_addr_new();
211 norm_addr->mailbox = mutt_str_dup(addr->mailbox);
212 norm_addr->is_intl = addr->is_intl;
213 norm_addr->intl_checked = addr->intl_checked;
214
216 return norm_addr;
217}
218
225static char *strdup_column_text(sqlite3_stmt *stmt, int index)
226{
227 const char *val = (const char *) sqlite3_column_text(stmt, index);
228 return mutt_str_dup(val);
229}
230
236{
237 return mutt_mem_calloc(1, sizeof(struct AutocryptAccount));
238}
239
245{
246 if (!ptr || !*ptr)
247 return;
248
249 struct AutocryptAccount *ac = *ptr;
250 FREE(&ac->email_addr);
251 FREE(&ac->keyid);
252 FREE(&ac->keydata);
253 FREE(ptr);
254}
255
263int mutt_autocrypt_db_account_get(struct Address *addr, struct AutocryptAccount **account)
264{
265 int rc = -1;
266
267 struct Address *norm_addr = copy_normalize_addr(addr);
268 *account = NULL;
269
270 if (!AccountGetStmt)
271 {
272 if (sqlite3_prepare_v3(AutocryptDB,
273 "SELECT "
274 "email_addr, "
275 "keyid, "
276 "keydata, "
277 "prefer_encrypt, "
278 "enabled "
279 "FROM account "
280 "WHERE email_addr = ?",
281 -1, SQLITE_PREPARE_PERSISTENT, &AccountGetStmt, NULL) != SQLITE_OK)
282 {
283 goto cleanup;
284 }
285 }
286
287 if (sqlite3_bind_text(AccountGetStmt, 1, norm_addr->mailbox, -1, SQLITE_STATIC) != SQLITE_OK)
288 goto cleanup;
289
290 int result = sqlite3_step(AccountGetStmt);
291 if (result != SQLITE_ROW)
292 {
293 if (result == SQLITE_DONE)
294 rc = 0;
295 goto cleanup;
296 }
297
299 (*account)->email_addr = strdup_column_text(AccountGetStmt, 0);
300 (*account)->keyid = strdup_column_text(AccountGetStmt, 1);
301 (*account)->keydata = strdup_column_text(AccountGetStmt, 2);
302 (*account)->prefer_encrypt = sqlite3_column_int(AccountGetStmt, 3);
303 (*account)->enabled = sqlite3_column_int(AccountGetStmt, 4);
304
305 rc = 1;
306
307cleanup:
308 mutt_addr_free(&norm_addr);
309 sqlite3_reset(AccountGetStmt);
310 return rc;
311}
312
322int mutt_autocrypt_db_account_insert(struct Address *addr, const char *keyid,
323 const char *keydata, bool prefer_encrypt)
324{
325 int rc = -1;
326
327 struct Address *norm_addr = copy_normalize_addr(addr);
328
330 {
331 if (sqlite3_prepare_v3(AutocryptDB,
332 "INSERT INTO account "
333 "(email_addr, "
334 "keyid, "
335 "keydata, "
336 "prefer_encrypt, "
337 "enabled) "
338 "VALUES (?, ?, ?, ?, ?);",
339 -1, SQLITE_PREPARE_PERSISTENT, &AccountInsertStmt, NULL) != SQLITE_OK)
340 {
341 goto cleanup;
342 }
343 }
344
345 if (sqlite3_bind_text(AccountInsertStmt, 1, norm_addr->mailbox, -1, SQLITE_STATIC) != SQLITE_OK)
346 goto cleanup;
347 if (sqlite3_bind_text(AccountInsertStmt, 2, keyid, -1, SQLITE_STATIC) != SQLITE_OK)
348 goto cleanup;
349 if (sqlite3_bind_text(AccountInsertStmt, 3, keydata, -1, SQLITE_STATIC) != SQLITE_OK)
350 goto cleanup;
351 if (sqlite3_bind_int(AccountInsertStmt, 4, prefer_encrypt) != SQLITE_OK)
352 goto cleanup;
353 if (sqlite3_bind_int(AccountInsertStmt, 5, 1) != SQLITE_OK)
354 goto cleanup;
355
356 if (sqlite3_step(AccountInsertStmt) != SQLITE_DONE)
357 goto cleanup;
358
359 rc = 0;
360
361cleanup:
362 mutt_addr_free(&norm_addr);
363 sqlite3_reset(AccountInsertStmt);
364 return rc;
365}
366
374{
375 int rc = -1;
376
378 {
379 if (sqlite3_prepare_v3(AutocryptDB,
380 "UPDATE account SET "
381 "keyid = ?, "
382 "keydata = ?, "
383 "prefer_encrypt = ?, "
384 "enabled = ? "
385 "WHERE email_addr = ?;",
386 -1, SQLITE_PREPARE_PERSISTENT, &AccountUpdateStmt, NULL) != SQLITE_OK)
387 {
388 goto cleanup;
389 }
390 }
391
392 if (sqlite3_bind_text(AccountUpdateStmt, 1, acct->keyid, -1, SQLITE_STATIC) != SQLITE_OK)
393 goto cleanup;
394 if (sqlite3_bind_text(AccountUpdateStmt, 2, acct->keydata, -1, SQLITE_STATIC) != SQLITE_OK)
395 goto cleanup;
396 if (sqlite3_bind_int(AccountUpdateStmt, 3, acct->prefer_encrypt) != SQLITE_OK)
397 goto cleanup;
398 if (sqlite3_bind_int(AccountUpdateStmt, 4, acct->enabled) != SQLITE_OK)
399 goto cleanup;
400 if (sqlite3_bind_text(AccountUpdateStmt, 5, acct->email_addr, -1, SQLITE_STATIC) != SQLITE_OK)
401 goto cleanup;
402
403 if (sqlite3_step(AccountUpdateStmt) != SQLITE_DONE)
404 goto cleanup;
405
406 rc = 0;
407
408cleanup:
409 sqlite3_reset(AccountUpdateStmt);
410 return rc;
411}
412
420{
421 int rc = -1;
422
424 {
425 if (sqlite3_prepare_v3(AutocryptDB,
426 "DELETE from account "
427 "WHERE email_addr = ?;",
428 -1, SQLITE_PREPARE_PERSISTENT, &AccountDeleteStmt, NULL) != SQLITE_OK)
429 {
430 goto cleanup;
431 }
432 }
433
434 if (sqlite3_bind_text(AccountDeleteStmt, 1, acct->email_addr, -1, SQLITE_STATIC) != SQLITE_OK)
435 goto cleanup;
436
437 if (sqlite3_step(AccountDeleteStmt) != SQLITE_DONE)
438 goto cleanup;
439
440 rc = 0;
441
442cleanup:
443 sqlite3_reset(AccountDeleteStmt);
444 return rc;
445}
446
454int mutt_autocrypt_db_account_get_all(struct AutocryptAccount ***accounts, int *num_accounts)
455{
456 int rc = -1, result;
457 sqlite3_stmt *stmt = NULL;
458 struct AutocryptAccount **results = NULL;
459 int results_len = 0, results_count = 0;
460
461 *accounts = NULL;
462 *num_accounts = 0;
463
464 /* Note, speed is not of the essence for the account management screen,
465 * so we don't bother with a persistent prepared statement */
466 if (sqlite3_prepare_v2(AutocryptDB,
467 "SELECT "
468 "email_addr, "
469 "keyid, "
470 "keydata, "
471 "prefer_encrypt, "
472 "enabled "
473 "FROM account "
474 "ORDER BY email_addr",
475 -1, &stmt, NULL) != SQLITE_OK)
476 {
477 goto cleanup;
478 }
479
480 while ((result = sqlite3_step(stmt)) == SQLITE_ROW)
481 {
482 if (results_count == results_len)
483 {
484 results_len += 5;
485 mutt_mem_realloc(&results, results_len * sizeof(struct AutocryptAccount *));
486 }
487
489 results[results_count++] = account;
490
491 account->email_addr = strdup_column_text(stmt, 0);
492 account->keyid = strdup_column_text(stmt, 1);
493 account->keydata = strdup_column_text(stmt, 2);
494 account->prefer_encrypt = sqlite3_column_int(stmt, 3);
495 account->enabled = sqlite3_column_int(stmt, 4);
496 }
497
498 if (result == SQLITE_DONE)
499 {
500 *accounts = results;
501 rc = *num_accounts = results_count;
502 }
503 else
504 {
505 while (results_count > 0)
506 mutt_autocrypt_db_account_free(&results[--results_count]);
507 FREE(&results);
508 }
509
510cleanup:
511 sqlite3_finalize(stmt);
512 return rc;
513}
514
520{
521 return mutt_mem_calloc(1, sizeof(struct AutocryptPeer));
522}
523
529{
530 if (!ptr || !*ptr)
531 return;
532
533 struct AutocryptPeer *peer = *ptr;
534 FREE(&peer->email_addr);
535 FREE(&peer->keyid);
536 FREE(&peer->keydata);
537 FREE(&peer->gossip_keyid);
538 FREE(&peer->gossip_keydata);
539 FREE(ptr);
540}
541
550int mutt_autocrypt_db_peer_get(struct Address *addr, struct AutocryptPeer **peer)
551{
552 int rc = -1;
553
554 struct Address *norm_addr = copy_normalize_addr(addr);
555 *peer = NULL;
556
557 if (!PeerGetStmt)
558 {
559 if (sqlite3_prepare_v3(AutocryptDB,
560 "SELECT "
561 "email_addr, "
562 "last_seen, "
563 "autocrypt_timestamp, "
564 "keyid, "
565 "keydata, "
566 "prefer_encrypt, "
567 "gossip_timestamp, "
568 "gossip_keyid, "
569 "gossip_keydata "
570 "FROM peer "
571 "WHERE email_addr = ?",
572 -1, SQLITE_PREPARE_PERSISTENT, &PeerGetStmt, NULL) != SQLITE_OK)
573 {
574 goto cleanup;
575 }
576 }
577
578 if (sqlite3_bind_text(PeerGetStmt, 1, norm_addr->mailbox, -1, SQLITE_STATIC) != SQLITE_OK)
579 goto cleanup;
580
581 int result = sqlite3_step(PeerGetStmt);
582 if (result != SQLITE_ROW)
583 {
584 if (result == SQLITE_DONE)
585 rc = 0;
586 goto cleanup;
587 }
588
590 (*peer)->email_addr = strdup_column_text(PeerGetStmt, 0);
591 (*peer)->last_seen = sqlite3_column_int64(PeerGetStmt, 1);
592 (*peer)->autocrypt_timestamp = sqlite3_column_int64(PeerGetStmt, 2);
593 (*peer)->keyid = strdup_column_text(PeerGetStmt, 3);
594 (*peer)->keydata = strdup_column_text(PeerGetStmt, 4);
595 (*peer)->prefer_encrypt = sqlite3_column_int(PeerGetStmt, 5);
596 (*peer)->gossip_timestamp = sqlite3_column_int64(PeerGetStmt, 6);
597 (*peer)->gossip_keyid = strdup_column_text(PeerGetStmt, 7);
598 (*peer)->gossip_keydata = strdup_column_text(PeerGetStmt, 8);
599
600 rc = 1;
601
602cleanup:
603 mutt_addr_free(&norm_addr);
604 sqlite3_reset(PeerGetStmt);
605 return rc;
606}
607
616{
617 int rc = -1;
618 struct Address *norm_addr = NULL;
619
620 norm_addr = copy_normalize_addr(addr);
621
622 if (!PeerInsertStmt)
623 {
624 if (sqlite3_prepare_v3(AutocryptDB,
625 "INSERT INTO peer "
626 "(email_addr, "
627 "last_seen, "
628 "autocrypt_timestamp, "
629 "keyid, "
630 "keydata, "
631 "prefer_encrypt, "
632 "gossip_timestamp, "
633 "gossip_keyid, "
634 "gossip_keydata) "
635 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);",
636 -1, SQLITE_PREPARE_PERSISTENT, &PeerInsertStmt, NULL) != SQLITE_OK)
637 {
638 goto cleanup;
639 }
640 }
641
642 if (sqlite3_bind_text(PeerInsertStmt, 1, norm_addr->mailbox, -1, SQLITE_STATIC) != SQLITE_OK)
643 goto cleanup;
644 if (sqlite3_bind_int64(PeerInsertStmt, 2, peer->last_seen) != SQLITE_OK)
645 goto cleanup;
646 if (sqlite3_bind_int64(PeerInsertStmt, 3, peer->autocrypt_timestamp) != SQLITE_OK)
647 goto cleanup;
648 if (sqlite3_bind_text(PeerInsertStmt, 4, peer->keyid, -1, SQLITE_STATIC) != SQLITE_OK)
649 goto cleanup;
650 if (sqlite3_bind_text(PeerInsertStmt, 5, peer->keydata, -1, SQLITE_STATIC) != SQLITE_OK)
651 goto cleanup;
652 if (sqlite3_bind_int(PeerInsertStmt, 6, peer->prefer_encrypt) != SQLITE_OK)
653 goto cleanup;
654 if (sqlite3_bind_int64(PeerInsertStmt, 7, peer->gossip_timestamp) != SQLITE_OK)
655 goto cleanup;
656 if (sqlite3_bind_text(PeerInsertStmt, 8, peer->gossip_keyid, -1, SQLITE_STATIC) != SQLITE_OK)
657 goto cleanup;
658 if (sqlite3_bind_text(PeerInsertStmt, 9, peer->gossip_keydata, -1, SQLITE_STATIC) != SQLITE_OK)
659 goto cleanup;
660
661 if (sqlite3_step(PeerInsertStmt) != SQLITE_DONE)
662 goto cleanup;
663
664 rc = 0;
665
666cleanup:
667 mutt_addr_free(&norm_addr);
668 sqlite3_reset(PeerInsertStmt);
669 return rc;
670}
671
679{
680 int rc = -1;
681
682 if (!PeerUpdateStmt)
683 {
684 if (sqlite3_prepare_v3(AutocryptDB,
685 "UPDATE peer SET "
686 "last_seen = ?, "
687 "autocrypt_timestamp = ?, "
688 "keyid = ?, "
689 "keydata = ?, "
690 "prefer_encrypt = ?, "
691 "gossip_timestamp = ?, "
692 "gossip_keyid = ?, "
693 "gossip_keydata = ? "
694 "WHERE email_addr = ?;",
695 -1, SQLITE_PREPARE_PERSISTENT, &PeerUpdateStmt, NULL) != SQLITE_OK)
696 {
697 goto cleanup;
698 }
699 }
700
701 if (sqlite3_bind_int64(PeerUpdateStmt, 1, peer->last_seen) != SQLITE_OK)
702 goto cleanup;
703 if (sqlite3_bind_int64(PeerUpdateStmt, 2, peer->autocrypt_timestamp) != SQLITE_OK)
704 goto cleanup;
705 if (sqlite3_bind_text(PeerUpdateStmt, 3, peer->keyid, -1, SQLITE_STATIC) != SQLITE_OK)
706 goto cleanup;
707 if (sqlite3_bind_text(PeerUpdateStmt, 4, peer->keydata, -1, SQLITE_STATIC) != SQLITE_OK)
708 goto cleanup;
709 if (sqlite3_bind_int(PeerUpdateStmt, 5, peer->prefer_encrypt) != SQLITE_OK)
710 goto cleanup;
711 if (sqlite3_bind_int64(PeerUpdateStmt, 6, peer->gossip_timestamp) != SQLITE_OK)
712 goto cleanup;
713 if (sqlite3_bind_text(PeerUpdateStmt, 7, peer->gossip_keyid, -1, SQLITE_STATIC) != SQLITE_OK)
714 goto cleanup;
715 if (sqlite3_bind_text(PeerUpdateStmt, 8, peer->gossip_keydata, -1, SQLITE_STATIC) != SQLITE_OK)
716 goto cleanup;
717 if (sqlite3_bind_text(PeerUpdateStmt, 9, peer->email_addr, -1, SQLITE_STATIC) != SQLITE_OK)
718 goto cleanup;
719
720 if (sqlite3_step(PeerUpdateStmt) != SQLITE_DONE)
721 goto cleanup;
722
723 rc = 0;
724
725cleanup:
726 sqlite3_reset(PeerUpdateStmt);
727 return rc;
728}
729
735{
736 return mutt_mem_calloc(1, sizeof(struct AutocryptPeerHistory));
737}
738
744{
745 if (!ptr || !*ptr)
746 return;
747
748 struct AutocryptPeerHistory *ph = *ptr;
749 FREE(&ph->peer_email_addr);
750 FREE(&ph->email_msgid);
751 FREE(&ph->keydata);
752 FREE(ptr);
753}
754
763 struct AutocryptPeerHistory *peerhist)
764{
765 int rc = -1;
766
767 struct Address *norm_addr = copy_normalize_addr(addr);
768
770 {
771 if (sqlite3_prepare_v3(AutocryptDB,
772 "INSERT INTO peer_history "
773 "(peer_email_addr, "
774 "email_msgid, "
775 "timestamp, "
776 "keydata) "
777 "VALUES (?, ?, ?, ?);",
778 -1, SQLITE_PREPARE_PERSISTENT,
779 &PeerHistoryInsertStmt, NULL) != SQLITE_OK)
780 {
781 goto cleanup;
782 }
783 }
784
785 if (sqlite3_bind_text(PeerHistoryInsertStmt, 1, norm_addr->mailbox, -1, SQLITE_STATIC) != SQLITE_OK)
786 goto cleanup;
787 if (sqlite3_bind_text(PeerHistoryInsertStmt, 2, peerhist->email_msgid, -1,
788 SQLITE_STATIC) != SQLITE_OK)
789 {
790 goto cleanup;
791 }
792 if (sqlite3_bind_int64(PeerHistoryInsertStmt, 3, peerhist->timestamp) != SQLITE_OK)
793 goto cleanup;
794 if (sqlite3_bind_text(PeerHistoryInsertStmt, 4, peerhist->keydata, -1, SQLITE_STATIC) != SQLITE_OK)
795 goto cleanup;
796
797 if (sqlite3_step(PeerHistoryInsertStmt) != SQLITE_DONE)
798 goto cleanup;
799
800 rc = 0;
801
802cleanup:
803 mutt_addr_free(&norm_addr);
804 sqlite3_reset(PeerHistoryInsertStmt);
805 return rc;
806}
807
813{
814 return mutt_mem_calloc(1, sizeof(struct AutocryptGossipHistory));
815}
816
822{
823 if (!ptr || !*ptr)
824 return;
825
826 struct AutocryptGossipHistory *gh = *ptr;
827 FREE(&gh->peer_email_addr);
829 FREE(&gh->email_msgid);
830 FREE(&gh->gossip_keydata);
831 FREE(ptr);
832}
833
842 struct AutocryptGossipHistory *gossip_hist)
843{
844 int rc = -1;
845
846 struct Address *norm_addr = copy_normalize_addr(addr);
847
849 {
850 if (sqlite3_prepare_v3(AutocryptDB,
851 "INSERT INTO gossip_history "
852 "(peer_email_addr, "
853 "sender_email_addr, "
854 "email_msgid, "
855 "timestamp, "
856 "gossip_keydata) "
857 "VALUES (?, ?, ?, ?, ?);",
858 -1, SQLITE_PREPARE_PERSISTENT,
859 &GossipHistoryInsertStmt, NULL) != SQLITE_OK)
860 {
861 goto cleanup;
862 }
863 }
864
865 if (sqlite3_bind_text(GossipHistoryInsertStmt, 1, norm_addr->mailbox, -1,
866 SQLITE_STATIC) != SQLITE_OK)
867 {
868 goto cleanup;
869 }
870 if (sqlite3_bind_text(GossipHistoryInsertStmt, 2, gossip_hist->sender_email_addr,
871 -1, SQLITE_STATIC) != SQLITE_OK)
872 {
873 if (sqlite3_bind_text(GossipHistoryInsertStmt, 3, gossip_hist->email_msgid,
874 -1, SQLITE_STATIC) != SQLITE_OK)
875 {
876 goto cleanup;
877 }
878 }
879 if (sqlite3_bind_int64(GossipHistoryInsertStmt, 4, gossip_hist->timestamp) != SQLITE_OK)
880 goto cleanup;
881 if (sqlite3_bind_text(GossipHistoryInsertStmt, 5, gossip_hist->gossip_keydata,
882 -1, SQLITE_STATIC) != SQLITE_OK)
883 {
884 goto cleanup;
885 }
886
887 if (sqlite3_step(GossipHistoryInsertStmt) != SQLITE_DONE)
888 goto cleanup;
889
890 rc = 0;
891
892cleanup:
893 mutt_addr_free(&norm_addr);
894 sqlite3_reset(GossipHistoryInsertStmt);
895 return rc;
896}
void mutt_addr_free(struct Address **ptr)
Free a single Address.
Definition: address.c:444
struct Address * mutt_addr_new(void)
Create a new Address.
Definition: address.c:389
int mutt_addrlist_to_local(struct AddressList *al)
Convert an Address list from Punycode.
Definition: address.c:1361
bool mutt_addr_to_local(struct Address *a)
Convert an Address from Punycode.
Definition: address.c:1324
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
Definition: address.c:1278
bool mutt_addr_to_intl(struct Address *a)
Convert an Address to Punycode.
Definition: address.c:1249
Email Address Handling.
void mutt_autocrypt_db_normalize_addrlist(struct AddressList *al)
Normalise a list of Email Addresses.
Definition: db.c:176
static sqlite3_stmt * PeerUpdateStmt
Definition: db.c:48
struct AutocryptPeer * mutt_autocrypt_db_peer_new(void)
Create a new AutocryptPeer.
Definition: db.c:519
int mutt_autocrypt_db_account_delete(struct AutocryptAccount *acct)
Delete an Account from the Autocrypt database.
Definition: db.c:419
static sqlite3_stmt * PeerGetStmt
Definition: db.c:46
int mutt_autocrypt_db_peer_insert(struct Address *addr, struct AutocryptPeer *peer)
Insert a peer into the Autocrypt database.
Definition: db.c:615
struct AutocryptGossipHistory * mutt_autocrypt_db_gossip_history_new(void)
Create a new AutocryptGossipHistory.
Definition: db.c:812
void mutt_autocrypt_db_close(void)
Close the Autocrypt SQLite database connection.
Definition: db.c:130
sqlite3 * AutocryptDB
Definition: db.c:52
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:841
int mutt_autocrypt_db_account_get(struct Address *addr, struct AutocryptAccount **account)
Get Autocrypt Account data from the database.
Definition: db.c:263
int mutt_autocrypt_db_peer_get(struct Address *addr, struct AutocryptPeer **peer)
Get peer info from the Autocrypt database.
Definition: db.c:550
int mutt_autocrypt_db_peer_update(struct AutocryptPeer *peer)
Update the peer info in an Autocrypt database.
Definition: db.c:678
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:322
void mutt_autocrypt_db_account_free(struct AutocryptAccount **ptr)
Free an AutocryptAccount.
Definition: db.c:244
struct AutocryptAccount * mutt_autocrypt_db_account_new(void)
Create a new AutocryptAccount.
Definition: db.c:235
static sqlite3_stmt * AccountInsertStmt
Definition: db.c:43
void mutt_autocrypt_db_normalize_addr(struct Address *a)
Normalise an Email Address.
Definition: db.c:165
static sqlite3_stmt * PeerHistoryInsertStmt
Definition: db.c:49
static struct Address * copy_normalize_addr(struct Address *addr)
Copy a normalised Email Address.
Definition: db.c:202
void mutt_autocrypt_db_peer_history_free(struct AutocryptPeerHistory **ptr)
Free an AutocryptPeerHistory.
Definition: db.c:743
static sqlite3_stmt * GossipHistoryInsertStmt
Definition: db.c:50
int mutt_autocrypt_db_account_update(struct AutocryptAccount *acct)
Update Account info in the Autocrypt database.
Definition: db.c:373
int mutt_autocrypt_db_account_get_all(struct AutocryptAccount ***accounts, int *num_accounts)
Get all accounts from an Autocrypt database.
Definition: db.c:454
static sqlite3_stmt * AccountUpdateStmt
Definition: db.c:44
void mutt_autocrypt_db_peer_free(struct AutocryptPeer **ptr)
Free an AutocryptPeer.
Definition: db.c:528
void mutt_autocrypt_db_gossip_history_free(struct AutocryptGossipHistory **ptr)
Free an AutocryptGossipHistory.
Definition: db.c:821
struct AutocryptPeerHistory * mutt_autocrypt_db_peer_history_new(void)
Create a new AutocryptPeerHistory.
Definition: db.c:734
static int autocrypt_db_create(const char *db_path)
Create an Autocrypt SQLite database.
Definition: db.c:60
static sqlite3_stmt * AccountGetStmt
Definition: db.c:42
int mutt_autocrypt_db_init(bool can_create)
Initialise the Autocrypt SQLite database.
Definition: db.c:79
static sqlite3_stmt * AccountDeleteStmt
Definition: db.c:45
static char * strdup_column_text(sqlite3_stmt *stmt, int index)
Copy a string from the database.
Definition: db.c:225
static sqlite3_stmt * PeerInsertStmt
Definition: db.c:47
int mutt_autocrypt_db_peer_history_insert(struct Address *addr, struct AutocryptPeerHistory *peerhist)
Insert peer history into the Autocrypt database.
Definition: db.c:762
int mutt_autocrypt_schema_update(void)
Update the version number of the Autocrypt database schema.
Definition: schema.c:106
int mutt_autocrypt_schema_init(void)
Set up an Autocrypt database.
Definition: schema.c:40
int mutt_autocrypt_account_init(bool prompt)
Create a new Autocrypt account.
Definition: autocrypt.c:153
void mutt_autocrypt_scan_mailboxes(void)
Scan mailboxes for Autocrypt headers.
Definition: autocrypt.c:921
size_t mutt_buffer_concat_path(struct Buffer *buf, const char *dir, const char *fname)
Join a directory name and a filename.
Definition: buffer.c:427
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:78
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:194
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
#define mutt_error(...)
Definition: logging.h:87
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
#define FREE(x)
Definition: memory.h:43
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:250
char * mutt_str_lower(char *str)
Convert all characters in the string to lowercase.
Definition: string.c:384
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
GUI display the mailboxes in a side panel.
Key value store.
An email address.
Definition: address.h:36
bool intl_checked
Checked for IDN?
Definition: address.h:41
char * mailbox
Mailbox and host address.
Definition: address.h:38
bool is_intl
International Domain Name.
Definition: address.h:40
Autocrypt account.
Definition: lib.h:106
char * email_addr
Email address.
Definition: lib.h:107
char * keydata
PGP Key data.
Definition: lib.h:109
char * keyid
PGP Key id.
Definition: lib.h:108
bool enabled
Is this account enabled.
Definition: lib.h:111
bool prefer_encrypt
false = nopref, true = mutual
Definition: lib.h:110
Autocrypt gossip history.
Definition: lib.h:145
char * peer_email_addr
Email addressof the peer.
Definition: lib.h:146
char * email_msgid
Sender's email's message id.
Definition: lib.h:148
char * sender_email_addr
Sender's email address.
Definition: lib.h:147
char * gossip_keydata
Gossip Key data.
Definition: lib.h:150
sqlite3_int64 timestamp
Timestamp of sender's email.
Definition: lib.h:149
Autocrypt peer history.
Definition: lib.h:134
char * peer_email_addr
Email address of the peer.
Definition: lib.h:135
char * email_msgid
Message id of the email.
Definition: lib.h:136
char * keydata
PGP Key data.
Definition: lib.h:138
sqlite3_int64 timestamp
Timestamp of email.
Definition: lib.h:137
Autocrypt peer.
Definition: lib.h:118
sqlite3_int64 autocrypt_timestamp
When the email was sent.
Definition: lib.h:121
char * gossip_keydata
Gossip Key data.
Definition: lib.h:127
char * keyid
PGP Key id.
Definition: lib.h:122
char * gossip_keyid
Gossip Key id.
Definition: lib.h:126
char * keydata
PGP Key data.
Definition: lib.h:123
char * email_addr
Email address.
Definition: lib.h:119
sqlite3_int64 last_seen
When was the peer last seen.
Definition: lib.h:120
bool prefer_encrypt
false = nopref, true = mutual
Definition: lib.h:124
sqlite3_int64 gossip_timestamp
Timestamp of Gossip header.
Definition: lib.h:125
String manipulation buffer.
Definition: buffer.h:34
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39