NeoMutt  2024-10-02-37-gfa9146
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_new();
214 buf_copy(norm_addr->mailbox, addr->mailbox);
215 norm_addr->is_intl = addr->is_intl;
216 norm_addr->intl_checked = addr->intl_checked;
217
219 return norm_addr;
220}
221
228static char *strdup_column_text(sqlite3_stmt *stmt, int index)
229{
230 const char *val = (const char *) sqlite3_column_text(stmt, index);
231 return mutt_str_dup(val);
232}
233
239{
240 return mutt_mem_calloc(1, sizeof(struct AutocryptAccount));
241}
242
248{
249 if (!ptr || !*ptr)
250 return;
251
252 struct AutocryptAccount *ac = *ptr;
253 FREE(&ac->email_addr);
254 FREE(&ac->keyid);
255 FREE(&ac->keydata);
256 FREE(ptr);
257}
258
266int mutt_autocrypt_db_account_get(struct Address *addr, struct AutocryptAccount **account)
267{
268 int rc = -1;
269
270 struct Address *norm_addr = copy_normalize_addr(addr);
271 *account = NULL;
272
273 if (!AccountGetStmt)
274 {
275 if (sqlite3_prepare_v3(AutocryptDB,
276 "SELECT "
277 "email_addr, "
278 "keyid, "
279 "keydata, "
280 "prefer_encrypt, "
281 "enabled "
282 "FROM account "
283 "WHERE email_addr = ?",
284 -1, SQLITE_PREPARE_PERSISTENT, &AccountGetStmt, NULL) != SQLITE_OK)
285 {
286 goto cleanup;
287 }
288 }
289
290 if (sqlite3_bind_text(AccountGetStmt, 1, buf_string(norm_addr->mailbox), -1,
291 SQLITE_STATIC) != SQLITE_OK)
292 {
293 goto cleanup;
294 }
295
296 int result = sqlite3_step(AccountGetStmt);
297 if (result != SQLITE_ROW)
298 {
299 if (result == SQLITE_DONE)
300 rc = 0;
301 goto cleanup;
302 }
303
305 (*account)->email_addr = strdup_column_text(AccountGetStmt, 0);
306 (*account)->keyid = strdup_column_text(AccountGetStmt, 1);
307 (*account)->keydata = strdup_column_text(AccountGetStmt, 2);
308 (*account)->prefer_encrypt = sqlite3_column_int(AccountGetStmt, 3);
309 (*account)->enabled = sqlite3_column_int(AccountGetStmt, 4);
310
311 rc = 1;
312
313cleanup:
314 mutt_addr_free(&norm_addr);
315 sqlite3_reset(AccountGetStmt);
316 return rc;
317}
318
328int mutt_autocrypt_db_account_insert(struct Address *addr, const char *keyid,
329 const char *keydata, bool prefer_encrypt)
330{
331 int rc = -1;
332
333 struct Address *norm_addr = copy_normalize_addr(addr);
334
336 {
337 if (sqlite3_prepare_v3(AutocryptDB,
338 "INSERT INTO account "
339 "(email_addr, "
340 "keyid, "
341 "keydata, "
342 "prefer_encrypt, "
343 "enabled) "
344 "VALUES (?, ?, ?, ?, ?);",
345 -1, SQLITE_PREPARE_PERSISTENT, &AccountInsertStmt, NULL) != SQLITE_OK)
346 {
347 goto cleanup;
348 }
349 }
350
351 if (sqlite3_bind_text(AccountInsertStmt, 1, buf_string(norm_addr->mailbox),
352 -1, SQLITE_STATIC) != SQLITE_OK)
353 {
354 goto cleanup;
355 }
356 if (sqlite3_bind_text(AccountInsertStmt, 2, keyid, -1, SQLITE_STATIC) != SQLITE_OK)
357 goto cleanup;
358 if (sqlite3_bind_text(AccountInsertStmt, 3, keydata, -1, SQLITE_STATIC) != SQLITE_OK)
359 goto cleanup;
360 if (sqlite3_bind_int(AccountInsertStmt, 4, prefer_encrypt) != SQLITE_OK)
361 goto cleanup;
362 if (sqlite3_bind_int(AccountInsertStmt, 5, 1) != SQLITE_OK)
363 goto cleanup;
364
365 if (sqlite3_step(AccountInsertStmt) != SQLITE_DONE)
366 goto cleanup;
367
368 rc = 0;
369
370cleanup:
371 mutt_addr_free(&norm_addr);
372 sqlite3_reset(AccountInsertStmt);
373 return rc;
374}
375
383{
384 int rc = -1;
385
387 {
388 if (sqlite3_prepare_v3(AutocryptDB,
389 "UPDATE account SET "
390 "keyid = ?, "
391 "keydata = ?, "
392 "prefer_encrypt = ?, "
393 "enabled = ? "
394 "WHERE email_addr = ?;",
395 -1, SQLITE_PREPARE_PERSISTENT, &AccountUpdateStmt, NULL) != SQLITE_OK)
396 {
397 goto cleanup;
398 }
399 }
400
401 if (sqlite3_bind_text(AccountUpdateStmt, 1, acct->keyid, -1, SQLITE_STATIC) != SQLITE_OK)
402 goto cleanup;
403 if (sqlite3_bind_text(AccountUpdateStmt, 2, acct->keydata, -1, SQLITE_STATIC) != SQLITE_OK)
404 goto cleanup;
405 if (sqlite3_bind_int(AccountUpdateStmt, 3, acct->prefer_encrypt) != SQLITE_OK)
406 goto cleanup;
407 if (sqlite3_bind_int(AccountUpdateStmt, 4, acct->enabled) != SQLITE_OK)
408 goto cleanup;
409 if (sqlite3_bind_text(AccountUpdateStmt, 5, acct->email_addr, -1, SQLITE_STATIC) != SQLITE_OK)
410 goto cleanup;
411
412 if (sqlite3_step(AccountUpdateStmt) != SQLITE_DONE)
413 goto cleanup;
414
415 rc = 0;
416
417cleanup:
418 sqlite3_reset(AccountUpdateStmt);
419 return rc;
420}
421
429{
430 int rc = -1;
431
433 {
434 if (sqlite3_prepare_v3(AutocryptDB,
435 "DELETE from account "
436 "WHERE email_addr = ?;",
437 -1, SQLITE_PREPARE_PERSISTENT, &AccountDeleteStmt, NULL) != SQLITE_OK)
438 {
439 goto cleanup;
440 }
441 }
442
443 if (sqlite3_bind_text(AccountDeleteStmt, 1, acct->email_addr, -1, SQLITE_STATIC) != SQLITE_OK)
444 goto cleanup;
445
446 if (sqlite3_step(AccountDeleteStmt) != SQLITE_DONE)
447 goto cleanup;
448
449 rc = 0;
450
451cleanup:
452 sqlite3_reset(AccountDeleteStmt);
453 return rc;
454}
455
463int mutt_autocrypt_db_account_get_all(struct AutocryptAccount ***accounts, int *num_accounts)
464{
465 int rc = -1, result;
466 sqlite3_stmt *stmt = NULL;
467 struct AutocryptAccount **results = NULL;
468 int results_len = 0, results_count = 0;
469
470 *accounts = NULL;
471 *num_accounts = 0;
472
473 /* Note, speed is not of the essence for the account management screen,
474 * so we don't bother with a persistent prepared statement */
475 if (sqlite3_prepare_v2(AutocryptDB,
476 "SELECT "
477 "email_addr, "
478 "keyid, "
479 "keydata, "
480 "prefer_encrypt, "
481 "enabled "
482 "FROM account "
483 "ORDER BY email_addr",
484 -1, &stmt, NULL) != SQLITE_OK)
485 {
486 goto cleanup;
487 }
488
489 while ((result = sqlite3_step(stmt)) == SQLITE_ROW)
490 {
491 if (results_count == results_len)
492 {
493 results_len += 5;
494 mutt_mem_realloc(&results, results_len * sizeof(struct AutocryptAccount *));
495 }
496
498 results[results_count++] = account;
499
500 account->email_addr = strdup_column_text(stmt, 0);
501 account->keyid = strdup_column_text(stmt, 1);
502 account->keydata = strdup_column_text(stmt, 2);
503 account->prefer_encrypt = sqlite3_column_int(stmt, 3);
504 account->enabled = sqlite3_column_int(stmt, 4);
505 }
506
507 if (result == SQLITE_DONE)
508 {
509 *accounts = results;
510 rc = *num_accounts = results_count;
511 }
512 else
513 {
514 while (results_count > 0)
515 mutt_autocrypt_db_account_free(&results[--results_count]);
516 FREE(&results);
517 }
518
519cleanup:
520 sqlite3_finalize(stmt);
521 return rc;
522}
523
529{
530 return mutt_mem_calloc(1, sizeof(struct AutocryptPeer));
531}
532
538{
539 if (!ptr || !*ptr)
540 return;
541
542 struct AutocryptPeer *peer = *ptr;
543 FREE(&peer->email_addr);
544 FREE(&peer->keyid);
545 FREE(&peer->keydata);
546 FREE(&peer->gossip_keyid);
547 FREE(&peer->gossip_keydata);
548 FREE(ptr);
549}
550
559int mutt_autocrypt_db_peer_get(struct Address *addr, struct AutocryptPeer **peer)
560{
561 int rc = -1;
562
563 struct Address *norm_addr = copy_normalize_addr(addr);
564 *peer = NULL;
565
566 if (!PeerGetStmt)
567 {
568 if (sqlite3_prepare_v3(AutocryptDB,
569 "SELECT "
570 "email_addr, "
571 "last_seen, "
572 "autocrypt_timestamp, "
573 "keyid, "
574 "keydata, "
575 "prefer_encrypt, "
576 "gossip_timestamp, "
577 "gossip_keyid, "
578 "gossip_keydata "
579 "FROM peer "
580 "WHERE email_addr = ?",
581 -1, SQLITE_PREPARE_PERSISTENT, &PeerGetStmt, NULL) != SQLITE_OK)
582 {
583 goto cleanup;
584 }
585 }
586
587 if (sqlite3_bind_text(PeerGetStmt, 1, buf_string(norm_addr->mailbox), -1,
588 SQLITE_STATIC) != SQLITE_OK)
589 {
590 goto cleanup;
591 }
592
593 int result = sqlite3_step(PeerGetStmt);
594 if (result != SQLITE_ROW)
595 {
596 if (result == SQLITE_DONE)
597 rc = 0;
598 goto cleanup;
599 }
600
602 (*peer)->email_addr = strdup_column_text(PeerGetStmt, 0);
603 (*peer)->last_seen = sqlite3_column_int64(PeerGetStmt, 1);
604 (*peer)->autocrypt_timestamp = sqlite3_column_int64(PeerGetStmt, 2);
605 (*peer)->keyid = strdup_column_text(PeerGetStmt, 3);
606 (*peer)->keydata = strdup_column_text(PeerGetStmt, 4);
607 (*peer)->prefer_encrypt = sqlite3_column_int(PeerGetStmt, 5);
608 (*peer)->gossip_timestamp = sqlite3_column_int64(PeerGetStmt, 6);
609 (*peer)->gossip_keyid = strdup_column_text(PeerGetStmt, 7);
610 (*peer)->gossip_keydata = strdup_column_text(PeerGetStmt, 8);
611
612 rc = 1;
613
614cleanup:
615 mutt_addr_free(&norm_addr);
616 sqlite3_reset(PeerGetStmt);
617 return rc;
618}
619
628{
629 int rc = -1;
630 struct Address *norm_addr = NULL;
631
632 norm_addr = copy_normalize_addr(addr);
633
634 if (!PeerInsertStmt)
635 {
636 if (sqlite3_prepare_v3(AutocryptDB,
637 "INSERT INTO peer "
638 "(email_addr, "
639 "last_seen, "
640 "autocrypt_timestamp, "
641 "keyid, "
642 "keydata, "
643 "prefer_encrypt, "
644 "gossip_timestamp, "
645 "gossip_keyid, "
646 "gossip_keydata) "
647 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);",
648 -1, SQLITE_PREPARE_PERSISTENT, &PeerInsertStmt, NULL) != SQLITE_OK)
649 {
650 goto cleanup;
651 }
652 }
653
654 if (sqlite3_bind_text(PeerInsertStmt, 1, buf_string(norm_addr->mailbox), -1,
655 SQLITE_STATIC) != SQLITE_OK)
656 {
657 goto cleanup;
658 }
659 if (sqlite3_bind_int64(PeerInsertStmt, 2, peer->last_seen) != SQLITE_OK)
660 goto cleanup;
661 if (sqlite3_bind_int64(PeerInsertStmt, 3, peer->autocrypt_timestamp) != SQLITE_OK)
662 goto cleanup;
663 if (sqlite3_bind_text(PeerInsertStmt, 4, peer->keyid, -1, SQLITE_STATIC) != SQLITE_OK)
664 goto cleanup;
665 if (sqlite3_bind_text(PeerInsertStmt, 5, peer->keydata, -1, SQLITE_STATIC) != SQLITE_OK)
666 goto cleanup;
667 if (sqlite3_bind_int(PeerInsertStmt, 6, peer->prefer_encrypt) != SQLITE_OK)
668 goto cleanup;
669 if (sqlite3_bind_int64(PeerInsertStmt, 7, peer->gossip_timestamp) != SQLITE_OK)
670 goto cleanup;
671 if (sqlite3_bind_text(PeerInsertStmt, 8, peer->gossip_keyid, -1, SQLITE_STATIC) != SQLITE_OK)
672 goto cleanup;
673 if (sqlite3_bind_text(PeerInsertStmt, 9, peer->gossip_keydata, -1, SQLITE_STATIC) != SQLITE_OK)
674 goto cleanup;
675
676 if (sqlite3_step(PeerInsertStmt) != SQLITE_DONE)
677 goto cleanup;
678
679 rc = 0;
680
681cleanup:
682 mutt_addr_free(&norm_addr);
683 sqlite3_reset(PeerInsertStmt);
684 return rc;
685}
686
694{
695 int rc = -1;
696
697 if (!PeerUpdateStmt)
698 {
699 if (sqlite3_prepare_v3(AutocryptDB,
700 "UPDATE peer SET "
701 "last_seen = ?, "
702 "autocrypt_timestamp = ?, "
703 "keyid = ?, "
704 "keydata = ?, "
705 "prefer_encrypt = ?, "
706 "gossip_timestamp = ?, "
707 "gossip_keyid = ?, "
708 "gossip_keydata = ? "
709 "WHERE email_addr = ?;",
710 -1, SQLITE_PREPARE_PERSISTENT, &PeerUpdateStmt, NULL) != SQLITE_OK)
711 {
712 goto cleanup;
713 }
714 }
715
716 if (sqlite3_bind_int64(PeerUpdateStmt, 1, peer->last_seen) != SQLITE_OK)
717 goto cleanup;
718 if (sqlite3_bind_int64(PeerUpdateStmt, 2, peer->autocrypt_timestamp) != SQLITE_OK)
719 goto cleanup;
720 if (sqlite3_bind_text(PeerUpdateStmt, 3, peer->keyid, -1, SQLITE_STATIC) != SQLITE_OK)
721 goto cleanup;
722 if (sqlite3_bind_text(PeerUpdateStmt, 4, peer->keydata, -1, SQLITE_STATIC) != SQLITE_OK)
723 goto cleanup;
724 if (sqlite3_bind_int(PeerUpdateStmt, 5, peer->prefer_encrypt) != SQLITE_OK)
725 goto cleanup;
726 if (sqlite3_bind_int64(PeerUpdateStmt, 6, peer->gossip_timestamp) != SQLITE_OK)
727 goto cleanup;
728 if (sqlite3_bind_text(PeerUpdateStmt, 7, peer->gossip_keyid, -1, SQLITE_STATIC) != SQLITE_OK)
729 goto cleanup;
730 if (sqlite3_bind_text(PeerUpdateStmt, 8, peer->gossip_keydata, -1, SQLITE_STATIC) != SQLITE_OK)
731 goto cleanup;
732 if (sqlite3_bind_text(PeerUpdateStmt, 9, peer->email_addr, -1, SQLITE_STATIC) != SQLITE_OK)
733 goto cleanup;
734
735 if (sqlite3_step(PeerUpdateStmt) != SQLITE_DONE)
736 goto cleanup;
737
738 rc = 0;
739
740cleanup:
741 sqlite3_reset(PeerUpdateStmt);
742 return rc;
743}
744
750{
751 return mutt_mem_calloc(1, sizeof(struct AutocryptPeerHistory));
752}
753
759{
760 if (!ptr || !*ptr)
761 return;
762
763 struct AutocryptPeerHistory *ph = *ptr;
764 FREE(&ph->peer_email_addr);
765 FREE(&ph->email_msgid);
766 FREE(&ph->keydata);
767 FREE(ptr);
768}
769
778 struct AutocryptPeerHistory *peerhist)
779{
780 int rc = -1;
781
782 struct Address *norm_addr = copy_normalize_addr(addr);
783
785 {
786 if (sqlite3_prepare_v3(AutocryptDB,
787 "INSERT INTO peer_history "
788 "(peer_email_addr, "
789 "email_msgid, "
790 "timestamp, "
791 "keydata) "
792 "VALUES (?, ?, ?, ?);",
793 -1, SQLITE_PREPARE_PERSISTENT,
794 &PeerHistoryInsertStmt, NULL) != SQLITE_OK)
795 {
796 goto cleanup;
797 }
798 }
799
800 if (sqlite3_bind_text(PeerHistoryInsertStmt, 1, buf_string(norm_addr->mailbox),
801 -1, SQLITE_STATIC) != SQLITE_OK)
802 {
803 goto cleanup;
804 }
805 if (sqlite3_bind_text(PeerHistoryInsertStmt, 2, peerhist->email_msgid, -1,
806 SQLITE_STATIC) != SQLITE_OK)
807 {
808 goto cleanup;
809 }
810 if (sqlite3_bind_int64(PeerHistoryInsertStmt, 3, peerhist->timestamp) != SQLITE_OK)
811 goto cleanup;
812 if (sqlite3_bind_text(PeerHistoryInsertStmt, 4, peerhist->keydata, -1, SQLITE_STATIC) != SQLITE_OK)
813 goto cleanup;
814
815 if (sqlite3_step(PeerHistoryInsertStmt) != SQLITE_DONE)
816 goto cleanup;
817
818 rc = 0;
819
820cleanup:
821 mutt_addr_free(&norm_addr);
822 sqlite3_reset(PeerHistoryInsertStmt);
823 return rc;
824}
825
831{
832 return mutt_mem_calloc(1, sizeof(struct AutocryptGossipHistory));
833}
834
840{
841 if (!ptr || !*ptr)
842 return;
843
844 struct AutocryptGossipHistory *gh = *ptr;
845 FREE(&gh->peer_email_addr);
847 FREE(&gh->email_msgid);
848 FREE(&gh->gossip_keydata);
849 FREE(ptr);
850}
851
860 struct AutocryptGossipHistory *gossip_hist)
861{
862 int rc = -1;
863
864 struct Address *norm_addr = copy_normalize_addr(addr);
865
867 {
868 if (sqlite3_prepare_v3(AutocryptDB,
869 "INSERT INTO gossip_history "
870 "(peer_email_addr, "
871 "sender_email_addr, "
872 "email_msgid, "
873 "timestamp, "
874 "gossip_keydata) "
875 "VALUES (?, ?, ?, ?, ?);",
876 -1, SQLITE_PREPARE_PERSISTENT,
877 &GossipHistoryInsertStmt, NULL) != SQLITE_OK)
878 {
879 goto cleanup;
880 }
881 }
882
883 if (sqlite3_bind_text(GossipHistoryInsertStmt, 1, buf_string(norm_addr->mailbox),
884 -1, SQLITE_STATIC) != SQLITE_OK)
885 {
886 goto cleanup;
887 }
888 if (sqlite3_bind_text(GossipHistoryInsertStmt, 2, gossip_hist->sender_email_addr,
889 -1, SQLITE_STATIC) != SQLITE_OK)
890 {
891 if (sqlite3_bind_text(GossipHistoryInsertStmt, 3, gossip_hist->email_msgid,
892 -1, SQLITE_STATIC) != SQLITE_OK)
893 {
894 goto cleanup;
895 }
896 }
897 if (sqlite3_bind_int64(GossipHistoryInsertStmt, 4, gossip_hist->timestamp) != SQLITE_OK)
898 goto cleanup;
899 if (sqlite3_bind_text(GossipHistoryInsertStmt, 5, gossip_hist->gossip_keydata,
900 -1, SQLITE_STATIC) != SQLITE_OK)
901 {
902 goto cleanup;
903 }
904
905 if (sqlite3_step(GossipHistoryInsertStmt) != SQLITE_DONE)
906 goto cleanup;
907
908 rc = 0;
909
910cleanup:
911 mutt_addr_free(&norm_addr);
912 sqlite3_reset(GossipHistoryInsertStmt);
913 return rc;
914}
void mutt_addr_free(struct Address **ptr)
Free a single Address.
Definition: address.c:462
struct Address * mutt_addr_new(void)
Create a new Address.
Definition: address.c:401
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.
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:528
int mutt_autocrypt_db_account_delete(struct AutocryptAccount *acct)
Delete an Account from the Autocrypt database.
Definition: db.c:428
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:627
struct AutocryptGossipHistory * mutt_autocrypt_db_gossip_history_new(void)
Create a new AutocryptGossipHistory.
Definition: db.c:830
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:859
int mutt_autocrypt_db_account_get(struct Address *addr, struct AutocryptAccount **account)
Get Autocrypt Account data from the database.
Definition: db.c:266
int mutt_autocrypt_db_peer_get(struct Address *addr, struct AutocryptPeer **peer)
Get peer info from the Autocrypt database.
Definition: db.c:559
int mutt_autocrypt_db_peer_update(struct AutocryptPeer *peer)
Update the peer info in an Autocrypt database.
Definition: db.c:693
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:328
void mutt_autocrypt_db_account_free(struct AutocryptAccount **ptr)
Free an AutocryptAccount.
Definition: db.c:247
struct AutocryptAccount * mutt_autocrypt_db_account_new(void)
Create a new AutocryptAccount.
Definition: db.c:238
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:758
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:382
int mutt_autocrypt_db_account_get_all(struct AutocryptAccount ***accounts, int *num_accounts)
Get all accounts from an Autocrypt database.
Definition: db.c:463
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:537
void mutt_autocrypt_db_gossip_history_free(struct AutocryptGossipHistory **ptr)
Free an AutocryptGossipHistory.
Definition: db.c:839
struct AutocryptPeerHistory * mutt_autocrypt_db_peer_history_new(void)
Create a new AutocryptPeerHistory.
Definition: db.c:749
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:228
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:777
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_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
Definition: buffer.c:601
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
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:115
#define FREE(x)
Definition: memory.h:45
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:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
#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
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:107
char * email_addr
Email address.
Definition: lib.h:108
char * keydata
PGP Key data.
Definition: lib.h:110
char * keyid
PGP Key id.
Definition: lib.h:109
bool enabled
Is this account enabled.
Definition: lib.h:112
bool prefer_encrypt
false = nopref, true = mutual
Definition: lib.h:111
Autocrypt gossip history.
Definition: lib.h:146
char * peer_email_addr
Email addressof the peer.
Definition: lib.h:147
char * email_msgid
Sender's email's message id.
Definition: lib.h:149
char * sender_email_addr
Sender's email address.
Definition: lib.h:148
char * gossip_keydata
Gossip Key data.
Definition: lib.h:151
sqlite3_int64 timestamp
Timestamp of sender's email.
Definition: lib.h:150
Autocrypt peer history.
Definition: lib.h:135
char * peer_email_addr
Email address of the peer.
Definition: lib.h:136
char * email_msgid
Message id of the email.
Definition: lib.h:137
char * keydata
PGP Key data.
Definition: lib.h:139
sqlite3_int64 timestamp
Timestamp of email.
Definition: lib.h:138
Autocrypt peer.
Definition: lib.h:119
sqlite3_int64 autocrypt_timestamp
When the email was sent.
Definition: lib.h:122
char * gossip_keydata
Gossip Key data.
Definition: lib.h:128
char * keyid
PGP Key id.
Definition: lib.h:123
char * gossip_keyid
Gossip Key id.
Definition: lib.h:127
char * keydata
PGP Key data.
Definition: lib.h:124
char * email_addr
Email address.
Definition: lib.h:120
sqlite3_int64 last_seen
When was the peer last seen.
Definition: lib.h:121
bool prefer_encrypt
false = nopref, true = mutual
Definition: lib.h:125
sqlite3_int64 gossip_timestamp
Timestamp of Gossip header.
Definition: lib.h:126
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