NeoMutt  2025-12-11-860-g80c9cc
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
db.c
Go to the documentation of this file.
1
25
31
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#include "module_data.h"
44
51static int autocrypt_db_create(const char *db_path)
52{
54 sqlite3 *db = NULL;
55
56 if (sqlite3_open_v2(db_path, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL) != SQLITE_OK)
57 {
58 /* L10N: autocrypt couldn't open the SQLite database.
59 The %s is the full path of the database file. */
60 mutt_error(_("Unable to open autocrypt database %s"), db_path);
61 return -1;
62 }
63 mod_data->autocrypt_db = db;
65}
66
73int mutt_autocrypt_db_init(bool can_create)
74{
75 int rc = -1;
77
78 if (mod_data->autocrypt_db)
79 return 0;
80
81 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
82 const char *const c_autocrypt_dir = cs_subset_path(NeoMutt->sub, "autocrypt_dir");
83 if (!c_autocrypt || !c_autocrypt_dir)
84 return -1;
85
86 struct Buffer *db_path = buf_pool_get();
87 buf_concat_path(db_path, c_autocrypt_dir, "autocrypt.db");
88
89 struct stat st = { 0 };
90 if (stat(buf_string(db_path), &st) == 0)
91 {
92 sqlite3 *db = NULL;
93 if (sqlite3_open_v2(buf_string(db_path), &db, SQLITE_OPEN_READWRITE, NULL) != SQLITE_OK)
94 {
95 /* L10N: autocrypt couldn't open the SQLite database.
96 The %s is the full path of the database file. */
97 mutt_error(_("Unable to open autocrypt database %s"), buf_string(db_path));
98 goto cleanup;
99 }
100 mod_data->autocrypt_db = db;
101
103 goto cleanup;
104 }
105 else
106 {
107 if (!can_create)
108 goto cleanup;
109 if (autocrypt_db_create(buf_string(db_path)))
110 goto cleanup;
111 /* Don't abort the whole init process because account creation failed */
114 }
115
116 rc = 0;
117
118cleanup:
119 buf_pool_release(&db_path);
120 return rc;
121}
122
128{
129 if (!mod_data->autocrypt_db)
130 return;
131
132 sqlite3_finalize(mod_data->account_get_stmt);
133 mod_data->account_get_stmt = NULL;
134 sqlite3_finalize(mod_data->account_insert_stmt);
135 mod_data->account_insert_stmt = NULL;
136 sqlite3_finalize(mod_data->account_update_stmt);
137 mod_data->account_update_stmt = NULL;
138 sqlite3_finalize(mod_data->account_delete_stmt);
139 mod_data->account_delete_stmt = NULL;
140
141 sqlite3_finalize(mod_data->peer_get_stmt);
142 mod_data->peer_get_stmt = NULL;
143 sqlite3_finalize(mod_data->peer_insert_stmt);
144 mod_data->peer_insert_stmt = NULL;
145 sqlite3_finalize(mod_data->peer_update_stmt);
146 mod_data->peer_update_stmt = NULL;
147
148 sqlite3_finalize(mod_data->peer_history_insert_stmt);
149 mod_data->peer_history_insert_stmt = NULL;
150
151 sqlite3_finalize(mod_data->gossip_history_insert_stmt);
152 mod_data->gossip_history_insert_stmt = NULL;
153
154 sqlite3_close_v2(mod_data->autocrypt_db);
155 mod_data->autocrypt_db = NULL;
156}
157
168
173void mutt_autocrypt_db_normalize_addrlist(struct AddressList *al)
174{
176
177 struct Address *np = NULL;
178 TAILQ_FOREACH(np, al, entries)
179 {
180 buf_lower(np->mailbox);
181 }
182
183 mutt_addrlist_to_intl(al, NULL);
184}
185
199static struct Address *copy_normalize_addr(struct Address *addr)
200{
201 /* NOTE: the db functions expect a single address, so in
202 * this function we copy only the address passed in.
203 *
204 * The normalize_addrlist above is extended to work on a list
205 * because of requirements in autocrypt.c */
206
207 struct Address *norm_addr = mutt_addr_create(NULL, buf_string(addr->mailbox));
208 norm_addr->is_intl = addr->is_intl;
209 norm_addr->intl_checked = addr->intl_checked;
210
212 return norm_addr;
213}
214
221static char *strdup_column_text(sqlite3_stmt *stmt, int index)
222{
223 const char *val = (const char *) sqlite3_column_text(stmt, index);
224 return mutt_str_dup(val);
225}
226
235
241{
242 if (!ptr || !*ptr)
243 return;
244
245 struct AutocryptAccount *ac = *ptr;
246 FREE(&ac->email_addr);
247 FREE(&ac->keyid);
248 FREE(&ac->keydata);
249 FREE(ptr);
250}
251
259int mutt_autocrypt_db_account_get(struct Address *addr, struct AutocryptAccount **account)
260{
261 int rc = -1;
262
264 sqlite3 *db = mod_data->autocrypt_db;
265 sqlite3_stmt *stmt = mod_data->account_get_stmt;
266
267 struct Address *norm_addr = copy_normalize_addr(addr);
268 *account = NULL;
269
270 if (!stmt)
271 {
272 if (sqlite3_prepare_v3(db,
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, &stmt, NULL) != SQLITE_OK)
282 {
283 goto cleanup;
284 }
285 mod_data->account_get_stmt = stmt;
286 }
287
288 if (sqlite3_bind_text(stmt, 1, buf_string(norm_addr->mailbox), -1, SQLITE_STATIC) != SQLITE_OK)
289 {
290 goto cleanup;
291 }
292
293 int result = sqlite3_step(stmt);
294 if (result != SQLITE_ROW)
295 {
296 if (result == SQLITE_DONE)
297 rc = 0;
298 goto cleanup;
299 }
300
302 (*account)->email_addr = strdup_column_text(stmt, 0);
303 (*account)->keyid = strdup_column_text(stmt, 1);
304 (*account)->keydata = strdup_column_text(stmt, 2);
305 (*account)->prefer_encrypt = sqlite3_column_int(stmt, 3);
306 (*account)->enabled = sqlite3_column_int(stmt, 4);
307
308 rc = 1;
309
310cleanup:
311 mutt_addr_free(&norm_addr);
312 sqlite3_reset(stmt);
313 return rc;
314}
315
325int mutt_autocrypt_db_account_insert(struct Address *addr, const char *keyid,
326 const char *keydata, bool prefer_encrypt)
327{
328 int rc = -1;
329
331 sqlite3 *db = mod_data->autocrypt_db;
332 sqlite3_stmt *stmt = mod_data->account_insert_stmt;
333
334 struct Address *norm_addr = copy_normalize_addr(addr);
335
336 if (!stmt)
337 {
338 if (sqlite3_prepare_v3(db,
339 "INSERT INTO account "
340 "(email_addr, "
341 "keyid, "
342 "keydata, "
343 "prefer_encrypt, "
344 "enabled) "
345 "VALUES (?, ?, ?, ?, ?);",
346 -1, SQLITE_PREPARE_PERSISTENT, &stmt, NULL) != SQLITE_OK)
347 {
348 goto cleanup;
349 }
350 mod_data->account_insert_stmt = stmt;
351 }
352
353 if (sqlite3_bind_text(stmt, 1, buf_string(norm_addr->mailbox), -1, SQLITE_STATIC) != SQLITE_OK)
354 {
355 goto cleanup;
356 }
357 if (sqlite3_bind_text(stmt, 2, keyid, -1, SQLITE_STATIC) != SQLITE_OK)
358 goto cleanup;
359 if (sqlite3_bind_text(stmt, 3, keydata, -1, SQLITE_STATIC) != SQLITE_OK)
360 goto cleanup;
361 if (sqlite3_bind_int(stmt, 4, prefer_encrypt) != SQLITE_OK)
362 goto cleanup;
363 if (sqlite3_bind_int(stmt, 5, 1) != SQLITE_OK)
364 goto cleanup;
365
366 if (sqlite3_step(stmt) != SQLITE_DONE)
367 goto cleanup;
368
369 rc = 0;
370
371cleanup:
372 mutt_addr_free(&norm_addr);
373 sqlite3_reset(stmt);
374 return rc;
375}
376
384{
385 int rc = -1;
386
388 sqlite3 *db = mod_data->autocrypt_db;
389 sqlite3_stmt *stmt = mod_data->account_update_stmt;
390
391 if (!stmt)
392 {
393 if (sqlite3_prepare_v3(db,
394 "UPDATE account SET "
395 "keyid = ?, "
396 "keydata = ?, "
397 "prefer_encrypt = ?, "
398 "enabled = ? "
399 "WHERE email_addr = ?;",
400 -1, SQLITE_PREPARE_PERSISTENT, &stmt, NULL) != SQLITE_OK)
401 {
402 goto cleanup;
403 }
404 mod_data->account_update_stmt = stmt;
405 }
406
407 if (sqlite3_bind_text(stmt, 1, acct->keyid, -1, SQLITE_STATIC) != SQLITE_OK)
408 goto cleanup;
409 if (sqlite3_bind_text(stmt, 2, acct->keydata, -1, SQLITE_STATIC) != SQLITE_OK)
410 goto cleanup;
411 if (sqlite3_bind_int(stmt, 3, acct->prefer_encrypt) != SQLITE_OK)
412 goto cleanup;
413 if (sqlite3_bind_int(stmt, 4, acct->enabled) != SQLITE_OK)
414 goto cleanup;
415 if (sqlite3_bind_text(stmt, 5, acct->email_addr, -1, SQLITE_STATIC) != SQLITE_OK)
416 goto cleanup;
417
418 if (sqlite3_step(stmt) != SQLITE_DONE)
419 goto cleanup;
420
421 rc = 0;
422
423cleanup:
424 sqlite3_reset(stmt);
425 return rc;
426}
427
435{
436 int rc = -1;
437
439 sqlite3 *db = mod_data->autocrypt_db;
440 sqlite3_stmt *stmt = mod_data->account_delete_stmt;
441
442 if (!stmt)
443 {
444 if (sqlite3_prepare_v3(db,
445 "DELETE from account "
446 "WHERE email_addr = ?;",
447 -1, SQLITE_PREPARE_PERSISTENT, &stmt, NULL) != SQLITE_OK)
448 {
449 goto cleanup;
450 }
451 mod_data->account_delete_stmt = stmt;
452 }
453
454 if (sqlite3_bind_text(stmt, 1, acct->email_addr, -1, SQLITE_STATIC) != SQLITE_OK)
455 goto cleanup;
456
457 if (sqlite3_step(stmt) != SQLITE_DONE)
458 goto cleanup;
459
460 rc = 0;
461
462cleanup:
463 sqlite3_reset(stmt);
464 return rc;
465}
466
473int mutt_autocrypt_db_account_get_all(struct AutocryptAccountArray *aaa)
474{
475 if (!aaa)
476 return -1;
477
478 int rc = -1;
479 sqlite3_stmt *stmt = NULL;
480
482 sqlite3 *db = mod_data->autocrypt_db;
483
484 /* Note, speed is not of the essence for the account management screen,
485 * so we don't bother with a persistent prepared statement */
486 if (sqlite3_prepare_v2(db,
487 "SELECT "
488 "email_addr, "
489 "keyid, "
490 "keydata, "
491 "prefer_encrypt, "
492 "enabled "
493 "FROM account "
494 "ORDER BY email_addr",
495 -1, &stmt, NULL) != SQLITE_OK)
496 {
497 goto cleanup;
498 }
499
500 int result = SQLITE_ERROR;
501 while ((result = sqlite3_step(stmt)) == SQLITE_ROW)
502 {
504
505 ac->email_addr = strdup_column_text(stmt, 0);
506 ac->keyid = strdup_column_text(stmt, 1);
507 ac->keydata = strdup_column_text(stmt, 2);
508 ac->prefer_encrypt = sqlite3_column_int(stmt, 3);
509 ac->enabled = sqlite3_column_int(stmt, 4);
510
511 ARRAY_ADD(aaa, ac);
512 }
513
514 if (result == SQLITE_DONE)
515 {
516 rc = ARRAY_SIZE(aaa);
517 }
518 else
519 {
520 struct AutocryptAccount **pac = NULL;
521 ARRAY_FOREACH(pac, aaa)
522 {
524 }
525 ARRAY_FREE(aaa);
526 }
527
528cleanup:
529 sqlite3_finalize(stmt);
530 return rc;
531}
532
538{
539 return MUTT_MEM_CALLOC(1, struct AutocryptPeer);
540}
541
547{
548 if (!ptr || !*ptr)
549 return;
550
551 struct AutocryptPeer *peer = *ptr;
552 FREE(&peer->email_addr);
553 FREE(&peer->keyid);
554 FREE(&peer->keydata);
555 FREE(&peer->gossip_keyid);
556 FREE(&peer->gossip_keydata);
557 FREE(ptr);
558}
559
568int mutt_autocrypt_db_peer_get(struct Address *addr, struct AutocryptPeer **peer)
569{
570 int rc = -1;
571
573 sqlite3 *db = mod_data->autocrypt_db;
574 sqlite3_stmt *stmt = mod_data->peer_get_stmt;
575
576 struct Address *norm_addr = copy_normalize_addr(addr);
577 *peer = NULL;
578
579 if (!stmt)
580 {
581 if (sqlite3_prepare_v3(db,
582 "SELECT "
583 "email_addr, "
584 "last_seen, "
585 "autocrypt_timestamp, "
586 "keyid, "
587 "keydata, "
588 "prefer_encrypt, "
589 "gossip_timestamp, "
590 "gossip_keyid, "
591 "gossip_keydata "
592 "FROM peer "
593 "WHERE email_addr = ?",
594 -1, SQLITE_PREPARE_PERSISTENT, &stmt, NULL) != SQLITE_OK)
595 {
596 goto cleanup;
597 }
598 mod_data->peer_get_stmt = stmt;
599 }
600
601 if (sqlite3_bind_text(stmt, 1, buf_string(norm_addr->mailbox), -1, SQLITE_STATIC) != SQLITE_OK)
602 {
603 goto cleanup;
604 }
605
606 int result = sqlite3_step(stmt);
607 if (result != SQLITE_ROW)
608 {
609 if (result == SQLITE_DONE)
610 rc = 0;
611 goto cleanup;
612 }
613
615 (*peer)->email_addr = strdup_column_text(stmt, 0);
616 (*peer)->last_seen = sqlite3_column_int64(stmt, 1);
617 (*peer)->autocrypt_timestamp = sqlite3_column_int64(stmt, 2);
618 (*peer)->keyid = strdup_column_text(stmt, 3);
619 (*peer)->keydata = strdup_column_text(stmt, 4);
620 (*peer)->prefer_encrypt = sqlite3_column_int(stmt, 5);
621 (*peer)->gossip_timestamp = sqlite3_column_int64(stmt, 6);
622 (*peer)->gossip_keyid = strdup_column_text(stmt, 7);
623 (*peer)->gossip_keydata = strdup_column_text(stmt, 8);
624
625 rc = 1;
626
627cleanup:
628 mutt_addr_free(&norm_addr);
629 sqlite3_reset(stmt);
630 return rc;
631}
632
641{
642 int rc = -1;
643 struct Address *norm_addr = NULL;
644
646 sqlite3 *db = mod_data->autocrypt_db;
647 sqlite3_stmt *stmt = mod_data->peer_insert_stmt;
648
649 norm_addr = copy_normalize_addr(addr);
650
651 if (!stmt)
652 {
653 if (sqlite3_prepare_v3(db,
654 "INSERT INTO peer "
655 "(email_addr, "
656 "last_seen, "
657 "autocrypt_timestamp, "
658 "keyid, "
659 "keydata, "
660 "prefer_encrypt, "
661 "gossip_timestamp, "
662 "gossip_keyid, "
663 "gossip_keydata) "
664 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);",
665 -1, SQLITE_PREPARE_PERSISTENT, &stmt, NULL) != SQLITE_OK)
666 {
667 goto cleanup;
668 }
669 mod_data->peer_insert_stmt = stmt;
670 }
671
672 if (sqlite3_bind_text(stmt, 1, buf_string(norm_addr->mailbox), -1, SQLITE_STATIC) != SQLITE_OK)
673 {
674 goto cleanup;
675 }
676 if (sqlite3_bind_int64(stmt, 2, peer->last_seen) != SQLITE_OK)
677 goto cleanup;
678 if (sqlite3_bind_int64(stmt, 3, peer->autocrypt_timestamp) != SQLITE_OK)
679 goto cleanup;
680 if (sqlite3_bind_text(stmt, 4, peer->keyid, -1, SQLITE_STATIC) != SQLITE_OK)
681 goto cleanup;
682 if (sqlite3_bind_text(stmt, 5, peer->keydata, -1, SQLITE_STATIC) != SQLITE_OK)
683 goto cleanup;
684 if (sqlite3_bind_int(stmt, 6, peer->prefer_encrypt) != SQLITE_OK)
685 goto cleanup;
686 if (sqlite3_bind_int64(stmt, 7, peer->gossip_timestamp) != SQLITE_OK)
687 goto cleanup;
688 if (sqlite3_bind_text(stmt, 8, peer->gossip_keyid, -1, SQLITE_STATIC) != SQLITE_OK)
689 goto cleanup;
690 if (sqlite3_bind_text(stmt, 9, peer->gossip_keydata, -1, SQLITE_STATIC) != SQLITE_OK)
691 goto cleanup;
692
693 if (sqlite3_step(stmt) != SQLITE_DONE)
694 goto cleanup;
695
696 rc = 0;
697
698cleanup:
699 mutt_addr_free(&norm_addr);
700 sqlite3_reset(stmt);
701 return rc;
702}
703
711{
712 int rc = -1;
713
715 sqlite3 *db = mod_data->autocrypt_db;
716 sqlite3_stmt *stmt = mod_data->peer_update_stmt;
717
718 if (!stmt)
719 {
720 if (sqlite3_prepare_v3(db,
721 "UPDATE peer SET "
722 "last_seen = ?, "
723 "autocrypt_timestamp = ?, "
724 "keyid = ?, "
725 "keydata = ?, "
726 "prefer_encrypt = ?, "
727 "gossip_timestamp = ?, "
728 "gossip_keyid = ?, "
729 "gossip_keydata = ? "
730 "WHERE email_addr = ?;",
731 -1, SQLITE_PREPARE_PERSISTENT, &stmt, NULL) != SQLITE_OK)
732 {
733 goto cleanup;
734 }
735 mod_data->peer_update_stmt = stmt;
736 }
737
738 if (sqlite3_bind_int64(stmt, 1, peer->last_seen) != SQLITE_OK)
739 goto cleanup;
740 if (sqlite3_bind_int64(stmt, 2, peer->autocrypt_timestamp) != SQLITE_OK)
741 goto cleanup;
742 if (sqlite3_bind_text(stmt, 3, peer->keyid, -1, SQLITE_STATIC) != SQLITE_OK)
743 goto cleanup;
744 if (sqlite3_bind_text(stmt, 4, peer->keydata, -1, SQLITE_STATIC) != SQLITE_OK)
745 goto cleanup;
746 if (sqlite3_bind_int(stmt, 5, peer->prefer_encrypt) != SQLITE_OK)
747 goto cleanup;
748 if (sqlite3_bind_int64(stmt, 6, peer->gossip_timestamp) != SQLITE_OK)
749 goto cleanup;
750 if (sqlite3_bind_text(stmt, 7, peer->gossip_keyid, -1, SQLITE_STATIC) != SQLITE_OK)
751 goto cleanup;
752 if (sqlite3_bind_text(stmt, 8, peer->gossip_keydata, -1, SQLITE_STATIC) != SQLITE_OK)
753 goto cleanup;
754 if (sqlite3_bind_text(stmt, 9, peer->email_addr, -1, SQLITE_STATIC) != SQLITE_OK)
755 goto cleanup;
756
757 if (sqlite3_step(stmt) != SQLITE_DONE)
758 goto cleanup;
759
760 rc = 0;
761
762cleanup:
763 sqlite3_reset(stmt);
764 return rc;
765}
766
775
781{
782 if (!ptr || !*ptr)
783 return;
784
785 struct AutocryptPeerHistory *ph = *ptr;
786 FREE(&ph->peer_email_addr);
787 FREE(&ph->email_msgid);
788 FREE(&ph->keydata);
789 FREE(ptr);
790}
791
800 struct AutocryptPeerHistory *peerhist)
801{
802 int rc = -1;
803
805 sqlite3 *db = mod_data->autocrypt_db;
806 sqlite3_stmt *stmt = mod_data->peer_history_insert_stmt;
807
808 struct Address *norm_addr = copy_normalize_addr(addr);
809
810 if (!stmt)
811 {
812 if (sqlite3_prepare_v3(db,
813 "INSERT INTO peer_history "
814 "(peer_email_addr, "
815 "email_msgid, "
816 "timestamp, "
817 "keydata) "
818 "VALUES (?, ?, ?, ?);",
819 -1, SQLITE_PREPARE_PERSISTENT, &stmt, NULL) != SQLITE_OK)
820 {
821 goto cleanup;
822 }
823 mod_data->peer_history_insert_stmt = stmt;
824 }
825
826 if (sqlite3_bind_text(stmt, 1, buf_string(norm_addr->mailbox), -1, SQLITE_STATIC) != SQLITE_OK)
827 {
828 goto cleanup;
829 }
830 if (sqlite3_bind_text(stmt, 2, peerhist->email_msgid, -1, SQLITE_STATIC) != SQLITE_OK)
831 {
832 goto cleanup;
833 }
834 if (sqlite3_bind_int64(stmt, 3, peerhist->timestamp) != SQLITE_OK)
835 goto cleanup;
836 if (sqlite3_bind_text(stmt, 4, peerhist->keydata, -1, SQLITE_STATIC) != SQLITE_OK)
837 goto cleanup;
838
839 if (sqlite3_step(stmt) != SQLITE_DONE)
840 goto cleanup;
841
842 rc = 0;
843
844cleanup:
845 mutt_addr_free(&norm_addr);
846 sqlite3_reset(stmt);
847 return rc;
848}
849
858
864{
865 if (!ptr || !*ptr)
866 return;
867
868 struct AutocryptGossipHistory *gh = *ptr;
869 FREE(&gh->peer_email_addr);
871 FREE(&gh->email_msgid);
872 FREE(&gh->gossip_keydata);
873 FREE(ptr);
874}
875
884 struct AutocryptGossipHistory *gossip_hist)
885{
886 int rc = -1;
887
889 sqlite3 *db = mod_data->autocrypt_db;
890 sqlite3_stmt *stmt = mod_data->gossip_history_insert_stmt;
891
892 struct Address *norm_addr = copy_normalize_addr(addr);
893
894 if (!stmt)
895 {
896 if (sqlite3_prepare_v3(db,
897 "INSERT INTO gossip_history "
898 "(peer_email_addr, "
899 "sender_email_addr, "
900 "email_msgid, "
901 "timestamp, "
902 "gossip_keydata) "
903 "VALUES (?, ?, ?, ?, ?);",
904 -1, SQLITE_PREPARE_PERSISTENT, &stmt, NULL) != SQLITE_OK)
905 {
906 goto cleanup;
907 }
908 mod_data->gossip_history_insert_stmt = stmt;
909 }
910
911 if (sqlite3_bind_text(stmt, 1, buf_string(norm_addr->mailbox), -1, SQLITE_STATIC) != SQLITE_OK)
912 {
913 goto cleanup;
914 }
915 if (sqlite3_bind_text(stmt, 2, gossip_hist->sender_email_addr, -1, SQLITE_STATIC) != SQLITE_OK)
916 {
917 goto cleanup;
918 }
919 if (sqlite3_bind_text(stmt, 3, gossip_hist->email_msgid, -1, SQLITE_STATIC) != SQLITE_OK)
920 {
921 goto cleanup;
922 }
923 if (sqlite3_bind_int64(stmt, 4, gossip_hist->timestamp) != SQLITE_OK)
924 goto cleanup;
925 if (sqlite3_bind_text(stmt, 5, gossip_hist->gossip_keydata, -1, SQLITE_STATIC) != SQLITE_OK)
926 {
927 goto cleanup;
928 }
929
930 if (sqlite3_step(stmt) != SQLITE_DONE)
931 goto cleanup;
932
933 rc = 0;
934
935cleanup:
936 mutt_addr_free(&norm_addr);
937 sqlite3_reset(stmt);
938 return rc;
939}
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:1387
bool mutt_addr_to_local(struct Address *a)
Convert an Address from Punycode.
Definition address.c:1349
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
Definition address.c:1302
bool mutt_addr_to_intl(struct Address *a)
Convert an Address to Punycode.
Definition address.c:1272
Email Address Handling.
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:157
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
#define ARRAY_SIZE(head)
The number of elements stored.
Definition array.h:87
#define ARRAY_FREE(head)
Release all memory.
Definition array.h:209
void mutt_autocrypt_db_normalize_addrlist(struct AddressList *al)
Normalise a list of Email Addresses.
Definition db.c:173
struct AutocryptPeer * mutt_autocrypt_db_peer_new(void)
Create a new AutocryptPeer.
Definition db.c:537
int mutt_autocrypt_db_account_delete(struct AutocryptAccount *acct)
Delete an Account from the Autocrypt database.
Definition db.c:434
int mutt_autocrypt_db_peer_insert(struct Address *addr, struct AutocryptPeer *peer)
Insert a peer into the Autocrypt database.
Definition db.c:640
struct AutocryptGossipHistory * mutt_autocrypt_db_gossip_history_new(void)
Create a new AutocryptGossipHistory.
Definition db.c:854
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:883
int mutt_autocrypt_db_account_get(struct Address *addr, struct AutocryptAccount **account)
Get Autocrypt Account data from the database.
Definition db.c:259
int mutt_autocrypt_db_peer_get(struct Address *addr, struct AutocryptPeer **peer)
Get peer info from the Autocrypt database.
Definition db.c:568
int mutt_autocrypt_db_peer_update(struct AutocryptPeer *peer)
Update the peer info in an Autocrypt database.
Definition db.c:710
int mutt_autocrypt_db_account_get_all(struct AutocryptAccountArray *aaa)
Get all accounts from an Autocrypt database.
Definition db.c:473
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:325
void mutt_autocrypt_db_account_free(struct AutocryptAccount **ptr)
Free an AutocryptAccount.
Definition db.c:240
struct AutocryptAccount * mutt_autocrypt_db_account_new(void)
Create a new AutocryptAccount.
Definition db.c:231
void mutt_autocrypt_db_normalize_addr(struct Address *a)
Normalise an Email Address.
Definition db.c:162
static struct Address * copy_normalize_addr(struct Address *addr)
Copy a normalised Email Address.
Definition db.c:199
void mutt_autocrypt_db_peer_history_free(struct AutocryptPeerHistory **ptr)
Free an AutocryptPeerHistory.
Definition db.c:780
int mutt_autocrypt_db_account_update(struct AutocryptAccount *acct)
Update Account info in the Autocrypt database.
Definition db.c:383
void mutt_autocrypt_db_peer_free(struct AutocryptPeer **ptr)
Free an AutocryptPeer.
Definition db.c:546
void mutt_autocrypt_db_gossip_history_free(struct AutocryptGossipHistory **ptr)
Free an AutocryptGossipHistory.
Definition db.c:863
struct AutocryptPeerHistory * mutt_autocrypt_db_peer_history_new(void)
Create a new AutocryptPeerHistory.
Definition db.c:771
void mutt_autocrypt_db_close(struct AutocryptModuleData *mod_data)
Close the Autocrypt SQLite database connection.
Definition db.c:127
static int autocrypt_db_create(const char *db_path)
Create an Autocrypt SQLite database.
Definition db.c:51
int mutt_autocrypt_db_init(bool can_create)
Initialise the Autocrypt SQLite database.
Definition db.c:73
static char * strdup_column_text(sqlite3_stmt *stmt, int index)
Copy a string from the database.
Definition db.c:221
int mutt_autocrypt_db_peer_history_insert(struct Address *addr, struct AutocryptPeerHistory *peerhist)
Insert peer history into the Autocrypt database.
Definition db.c:799
Autocrypt end-to-end encryption.
Autocrypt private Module data.
Shared constants/structs that are private to Autocrypt.
int mutt_autocrypt_schema_update(void)
Update the version number of the Autocrypt database schema.
Definition schema.c:111
int mutt_autocrypt_schema_init(void)
Set up an Autocrypt database.
Definition schema.c:43
int mutt_autocrypt_account_init(bool prompt)
Create a new Autocrypt account.
Definition autocrypt.c:150
void mutt_autocrypt_scan_mailboxes(void)
Scan mailboxes for Autocrypt headers.
Definition autocrypt.c:937
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:734
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:94
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:52
@ MODULE_ID_AUTOCRYPT
ModuleAutocrypt, Autocrypt
Definition module_api.h:50
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:257
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:663
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
#define TAILQ_FOREACH(var, head, field)
Definition queue.h:782
An email address.
Definition address.h:35
struct Buffer * mailbox
Mailbox and host address.
Definition address.h:37
bool intl_checked
Checked for IDN?
Definition address.h:40
bool is_intl
International Domain Name.
Definition address.h:39
Autocrypt account.
Definition lib.h:114
char * email_addr
Email address.
Definition lib.h:115
char * keydata
PGP Key data.
Definition lib.h:117
char * keyid
PGP Key id.
Definition lib.h:116
bool enabled
Is this account enabled.
Definition lib.h:119
bool prefer_encrypt
false = nopref, true = mutual
Definition lib.h:118
Autocrypt gossip history.
Definition lib.h:154
char * peer_email_addr
Email addressof the peer.
Definition lib.h:155
char * email_msgid
Sender's email's message id.
Definition lib.h:157
char * sender_email_addr
Sender's email address.
Definition lib.h:156
char * gossip_keydata
Gossip Key data.
Definition lib.h:159
sqlite3_int64 timestamp
Timestamp of sender's email.
Definition lib.h:158
Autocrypt private Module data.
Definition module_data.h:32
sqlite3_stmt * account_delete_stmt
Delete an autocrypt account.
Definition module_data.h:39
sqlite3_stmt * account_insert_stmt
Insert a new autocrypt account.
Definition module_data.h:41
sqlite3_stmt * peer_get_stmt
Get the matching peer addresses.
Definition module_data.h:44
sqlite3_stmt * account_get_stmt
Get the matching autocrypt accounts.
Definition module_data.h:40
sqlite3_stmt * account_update_stmt
Update an autocrypt account.
Definition module_data.h:42
sqlite3_stmt * peer_history_insert_stmt
Add to the peer history.
Definition module_data.h:45
sqlite3_stmt * peer_update_stmt
Update a peer address.
Definition module_data.h:47
sqlite3 * autocrypt_db
Autocrypt database.
Definition module_data.h:38
sqlite3_stmt * gossip_history_insert_stmt
Add to the gossip history.
Definition module_data.h:43
sqlite3_stmt * peer_insert_stmt
Insert a new peer address.
Definition module_data.h:46
Autocrypt peer history.
Definition lib.h:143
char * peer_email_addr
Email address of the peer.
Definition lib.h:144
char * email_msgid
Message id of the email.
Definition lib.h:145
char * keydata
PGP Key data.
Definition lib.h:147
sqlite3_int64 timestamp
Timestamp of email.
Definition lib.h:146
Autocrypt peer.
Definition lib.h:127
sqlite3_int64 autocrypt_timestamp
When the email was sent.
Definition lib.h:130
char * gossip_keydata
Gossip Key data.
Definition lib.h:136
char * keyid
PGP Key id.
Definition lib.h:131
char * gossip_keyid
Gossip Key id.
Definition lib.h:135
char * keydata
PGP Key data.
Definition lib.h:132
char * email_addr
Email address.
Definition lib.h:128
sqlite3_int64 last_seen
When was the peer last seen.
Definition lib.h:129
bool prefer_encrypt
false = nopref, true = mutual
Definition lib.h:133
sqlite3_int64 gossip_timestamp
Timestamp of Gossip header.
Definition lib.h:134
String manipulation buffer.
Definition buffer.h:36
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49