NeoMutt
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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 SQL statements
42static sqlite3_stmt *AccountGetStmt = NULL;
43static sqlite3_stmt *AccountInsertStmt = NULL;
44static sqlite3_stmt *AccountUpdateStmt = NULL;
45static sqlite3_stmt *AccountDeleteStmt = NULL;
46static sqlite3_stmt *PeerGetStmt = NULL;
47static sqlite3_stmt *PeerInsertStmt = NULL;
48static sqlite3_stmt *PeerUpdateStmt = NULL;
49static sqlite3_stmt *PeerHistoryInsertStmt = NULL;
50static sqlite3_stmt *GossipHistoryInsertStmt = NULL;
51
53sqlite3 *AutocryptDB = NULL;
54
61static int autocrypt_db_create(const char *db_path)
62{
63 if (sqlite3_open_v2(db_path, &AutocryptDB,
64 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL) != SQLITE_OK)
65 {
66 /* L10N: s is the path to the database.
67 For some reason sqlite3 failed to open that database file. */
68 mutt_error(_("Unable to open autocrypt database %s"), db_path);
69 return -1;
70 }
72}
73
80int mutt_autocrypt_db_init(bool can_create)
81{
82 int rc = -1;
83
84 if (AutocryptDB)
85 return 0;
86
87 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
88 const char *const c_autocrypt_dir = cs_subset_path(NeoMutt->sub, "autocrypt_dir");
89 if (!c_autocrypt || !c_autocrypt_dir)
90 return -1;
91
92 struct Buffer *db_path = buf_pool_get();
93 buf_concat_path(db_path, c_autocrypt_dir, "autocrypt.db");
94
95 struct stat st = { 0 };
96 if (stat(buf_string(db_path), &st) == 0)
97 {
98 if (sqlite3_open_v2(buf_string(db_path), &AutocryptDB, 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"), buf_string(db_path));
103 goto cleanup;
104 }
105
107 goto cleanup;
108 }
109 else
110 {
111 if (!can_create)
112 goto cleanup;
113 if (autocrypt_db_create(buf_string(db_path)))
114 goto cleanup;
115 /* Don't abort the whole init process because account creation failed */
118 }
119
120 rc = 0;
121
122cleanup:
123 buf_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{
168 buf_lower(a->mailbox);
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 {
183 buf_lower(np->mailbox);
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 buf_copy(norm_addr->mailbox, 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, buf_string(norm_addr->mailbox), -1,
288 SQLITE_STATIC) != SQLITE_OK)
289 {
290 goto cleanup;
291 }
292
293 int result = sqlite3_step(AccountGetStmt);
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(AccountGetStmt, 0);
303 (*account)->keyid = strdup_column_text(AccountGetStmt, 1);
304 (*account)->keydata = strdup_column_text(AccountGetStmt, 2);
305 (*account)->prefer_encrypt = sqlite3_column_int(AccountGetStmt, 3);
306 (*account)->enabled = sqlite3_column_int(AccountGetStmt, 4);
307
308 rc = 1;
309
310cleanup:
311 mutt_addr_free(&norm_addr);
312 sqlite3_reset(AccountGetStmt);
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
330 struct Address *norm_addr = copy_normalize_addr(addr);
331
333 {
334 if (sqlite3_prepare_v3(AutocryptDB,
335 "INSERT INTO account "
336 "(email_addr, "
337 "keyid, "
338 "keydata, "
339 "prefer_encrypt, "
340 "enabled) "
341 "VALUES (?, ?, ?, ?, ?);",
342 -1, SQLITE_PREPARE_PERSISTENT, &AccountInsertStmt, NULL) != SQLITE_OK)
343 {
344 goto cleanup;
345 }
346 }
347
348 if (sqlite3_bind_text(AccountInsertStmt, 1, buf_string(norm_addr->mailbox),
349 -1, SQLITE_STATIC) != SQLITE_OK)
350 {
351 goto cleanup;
352 }
353 if (sqlite3_bind_text(AccountInsertStmt, 2, keyid, -1, SQLITE_STATIC) != SQLITE_OK)
354 goto cleanup;
355 if (sqlite3_bind_text(AccountInsertStmt, 3, keydata, -1, SQLITE_STATIC) != SQLITE_OK)
356 goto cleanup;
357 if (sqlite3_bind_int(AccountInsertStmt, 4, prefer_encrypt) != SQLITE_OK)
358 goto cleanup;
359 if (sqlite3_bind_int(AccountInsertStmt, 5, 1) != SQLITE_OK)
360 goto cleanup;
361
362 if (sqlite3_step(AccountInsertStmt) != SQLITE_DONE)
363 goto cleanup;
364
365 rc = 0;
366
367cleanup:
368 mutt_addr_free(&norm_addr);
369 sqlite3_reset(AccountInsertStmt);
370 return rc;
371}
372
380{
381 int rc = -1;
382
384 {
385 if (sqlite3_prepare_v3(AutocryptDB,
386 "UPDATE account SET "
387 "keyid = ?, "
388 "keydata = ?, "
389 "prefer_encrypt = ?, "
390 "enabled = ? "
391 "WHERE email_addr = ?;",
392 -1, SQLITE_PREPARE_PERSISTENT, &AccountUpdateStmt, NULL) != SQLITE_OK)
393 {
394 goto cleanup;
395 }
396 }
397
398 if (sqlite3_bind_text(AccountUpdateStmt, 1, acct->keyid, -1, SQLITE_STATIC) != SQLITE_OK)
399 goto cleanup;
400 if (sqlite3_bind_text(AccountUpdateStmt, 2, acct->keydata, -1, SQLITE_STATIC) != SQLITE_OK)
401 goto cleanup;
402 if (sqlite3_bind_int(AccountUpdateStmt, 3, acct->prefer_encrypt) != SQLITE_OK)
403 goto cleanup;
404 if (sqlite3_bind_int(AccountUpdateStmt, 4, acct->enabled) != SQLITE_OK)
405 goto cleanup;
406 if (sqlite3_bind_text(AccountUpdateStmt, 5, acct->email_addr, -1, SQLITE_STATIC) != SQLITE_OK)
407 goto cleanup;
408
409 if (sqlite3_step(AccountUpdateStmt) != SQLITE_DONE)
410 goto cleanup;
411
412 rc = 0;
413
414cleanup:
415 sqlite3_reset(AccountUpdateStmt);
416 return rc;
417}
418
426{
427 int rc = -1;
428
430 {
431 if (sqlite3_prepare_v3(AutocryptDB,
432 "DELETE from account "
433 "WHERE email_addr = ?;",
434 -1, SQLITE_PREPARE_PERSISTENT, &AccountDeleteStmt, NULL) != SQLITE_OK)
435 {
436 goto cleanup;
437 }
438 }
439
440 if (sqlite3_bind_text(AccountDeleteStmt, 1, acct->email_addr, -1, SQLITE_STATIC) != SQLITE_OK)
441 goto cleanup;
442
443 if (sqlite3_step(AccountDeleteStmt) != SQLITE_DONE)
444 goto cleanup;
445
446 rc = 0;
447
448cleanup:
449 sqlite3_reset(AccountDeleteStmt);
450 return rc;
451}
452
460int mutt_autocrypt_db_account_get_all(struct AutocryptAccount ***accounts, int *num_accounts)
461{
462 int rc = -1, result;
463 sqlite3_stmt *stmt = NULL;
464 struct AutocryptAccount **results = NULL;
465 int results_len = 0, results_count = 0;
466
467 *accounts = NULL;
468 *num_accounts = 0;
469
470 /* Note, speed is not of the essence for the account management screen,
471 * so we don't bother with a persistent prepared statement */
472 if (sqlite3_prepare_v2(AutocryptDB,
473 "SELECT "
474 "email_addr, "
475 "keyid, "
476 "keydata, "
477 "prefer_encrypt, "
478 "enabled "
479 "FROM account "
480 "ORDER BY email_addr",
481 -1, &stmt, NULL) != SQLITE_OK)
482 {
483 goto cleanup;
484 }
485
486 while ((result = sqlite3_step(stmt)) == SQLITE_ROW)
487 {
488 if (results_count == results_len)
489 {
490 results_len += 5;
491 mutt_mem_realloc(&results, results_len * sizeof(struct AutocryptAccount *));
492 }
493
495 results[results_count++] = account;
496
497 account->email_addr = strdup_column_text(stmt, 0);
498 account->keyid = strdup_column_text(stmt, 1);
499 account->keydata = strdup_column_text(stmt, 2);
500 account->prefer_encrypt = sqlite3_column_int(stmt, 3);
501 account->enabled = sqlite3_column_int(stmt, 4);
502 }
503
504 if (result == SQLITE_DONE)
505 {
506 *accounts = results;
507 rc = *num_accounts = results_count;
508 }
509 else
510 {
511 while (results_count > 0)
512 mutt_autocrypt_db_account_free(&results[--results_count]);
513 FREE(&results);
514 }
515
516cleanup:
517 sqlite3_finalize(stmt);
518 return rc;
519}
520
526{
527 return mutt_mem_calloc(1, sizeof(struct AutocryptPeer));
528}
529
535{
536 if (!ptr || !*ptr)
537 return;
538
539 struct AutocryptPeer *peer = *ptr;
540 FREE(&peer->email_addr);
541 FREE(&peer->keyid);
542 FREE(&peer->keydata);
543 FREE(&peer->gossip_keyid);
544 FREE(&peer->gossip_keydata);
545 FREE(ptr);
546}
547
556int mutt_autocrypt_db_peer_get(struct Address *addr, struct AutocryptPeer **peer)
557{
558 int rc = -1;
559
560 struct Address *norm_addr = copy_normalize_addr(addr);
561 *peer = NULL;
562
563 if (!PeerGetStmt)
564 {
565 if (sqlite3_prepare_v3(AutocryptDB,
566 "SELECT "
567 "email_addr, "
568 "last_seen, "
569 "autocrypt_timestamp, "
570 "keyid, "
571 "keydata, "
572 "prefer_encrypt, "
573 "gossip_timestamp, "
574 "gossip_keyid, "
575 "gossip_keydata "
576 "FROM peer "
577 "WHERE email_addr = ?",
578 -1, SQLITE_PREPARE_PERSISTENT, &PeerGetStmt, NULL) != SQLITE_OK)
579 {
580 goto cleanup;
581 }
582 }
583
584 if (sqlite3_bind_text(PeerGetStmt, 1, buf_string(norm_addr->mailbox), -1,
585 SQLITE_STATIC) != SQLITE_OK)
586 {
587 goto cleanup;
588 }
589
590 int result = sqlite3_step(PeerGetStmt);
591 if (result != SQLITE_ROW)
592 {
593 if (result == SQLITE_DONE)
594 rc = 0;
595 goto cleanup;
596 }
597
599 (*peer)->email_addr = strdup_column_text(PeerGetStmt, 0);
600 (*peer)->last_seen = sqlite3_column_int64(PeerGetStmt, 1);
601 (*peer)->autocrypt_timestamp = sqlite3_column_int64(PeerGetStmt, 2);
602 (*peer)->keyid = strdup_column_text(PeerGetStmt, 3);
603 (*peer)->keydata = strdup_column_text(PeerGetStmt, 4);
604 (*peer)->prefer_encrypt = sqlite3_column_int(PeerGetStmt, 5);
605 (*peer)->gossip_timestamp = sqlite3_column_int64(PeerGetStmt, 6);
606 (*peer)->gossip_keyid = strdup_column_text(PeerGetStmt, 7);
607 (*peer)->gossip_keydata = strdup_column_text(PeerGetStmt, 8);
608
609 rc = 1;
610
611cleanup:
612 mutt_addr_free(&norm_addr);
613 sqlite3_reset(PeerGetStmt);
614 return rc;
615}
616
625{
626 int rc = -1;
627 struct Address *norm_addr = NULL;
628
629 norm_addr = copy_normalize_addr(addr);
630
631 if (!PeerInsertStmt)
632 {
633 if (sqlite3_prepare_v3(AutocryptDB,
634 "INSERT INTO peer "
635 "(email_addr, "
636 "last_seen, "
637 "autocrypt_timestamp, "
638 "keyid, "
639 "keydata, "
640 "prefer_encrypt, "
641 "gossip_timestamp, "
642 "gossip_keyid, "
643 "gossip_keydata) "
644 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);",
645 -1, SQLITE_PREPARE_PERSISTENT, &PeerInsertStmt, NULL) != SQLITE_OK)
646 {
647 goto cleanup;
648 }
649 }
650
651 if (sqlite3_bind_text(PeerInsertStmt, 1, buf_string(norm_addr->mailbox), -1,
652 SQLITE_STATIC) != SQLITE_OK)
653 {
654 goto cleanup;
655 }
656 if (sqlite3_bind_int64(PeerInsertStmt, 2, peer->last_seen) != SQLITE_OK)
657 goto cleanup;
658 if (sqlite3_bind_int64(PeerInsertStmt, 3, peer->autocrypt_timestamp) != SQLITE_OK)
659 goto cleanup;
660 if (sqlite3_bind_text(PeerInsertStmt, 4, peer->keyid, -1, SQLITE_STATIC) != SQLITE_OK)
661 goto cleanup;
662 if (sqlite3_bind_text(PeerInsertStmt, 5, peer->keydata, -1, SQLITE_STATIC) != SQLITE_OK)
663 goto cleanup;
664 if (sqlite3_bind_int(PeerInsertStmt, 6, peer->prefer_encrypt) != SQLITE_OK)
665 goto cleanup;
666 if (sqlite3_bind_int64(PeerInsertStmt, 7, peer->gossip_timestamp) != SQLITE_OK)
667 goto cleanup;
668 if (sqlite3_bind_text(PeerInsertStmt, 8, peer->gossip_keyid, -1, SQLITE_STATIC) != SQLITE_OK)
669 goto cleanup;
670 if (sqlite3_bind_text(PeerInsertStmt, 9, peer->gossip_keydata, -1, SQLITE_STATIC) != SQLITE_OK)
671 goto cleanup;
672
673 if (sqlite3_step(PeerInsertStmt) != SQLITE_DONE)
674 goto cleanup;
675
676 rc = 0;
677
678cleanup:
679 mutt_addr_free(&norm_addr);
680 sqlite3_reset(PeerInsertStmt);
681 return rc;
682}
683
691{
692 int rc = -1;
693
694 if (!PeerUpdateStmt)
695 {
696 if (sqlite3_prepare_v3(AutocryptDB,
697 "UPDATE peer SET "
698 "last_seen = ?, "
699 "autocrypt_timestamp = ?, "
700 "keyid = ?, "
701 "keydata = ?, "
702 "prefer_encrypt = ?, "
703 "gossip_timestamp = ?, "
704 "gossip_keyid = ?, "
705 "gossip_keydata = ? "
706 "WHERE email_addr = ?;",
707 -1, SQLITE_PREPARE_PERSISTENT, &PeerUpdateStmt, NULL) != SQLITE_OK)
708 {
709 goto cleanup;
710 }
711 }
712
713 if (sqlite3_bind_int64(PeerUpdateStmt, 1, peer->last_seen) != SQLITE_OK)
714 goto cleanup;
715 if (sqlite3_bind_int64(PeerUpdateStmt, 2, peer->autocrypt_timestamp) != SQLITE_OK)
716 goto cleanup;
717 if (sqlite3_bind_text(PeerUpdateStmt, 3, peer->keyid, -1, SQLITE_STATIC) != SQLITE_OK)
718 goto cleanup;
719 if (sqlite3_bind_text(PeerUpdateStmt, 4, peer->keydata, -1, SQLITE_STATIC) != SQLITE_OK)
720 goto cleanup;
721 if (sqlite3_bind_int(PeerUpdateStmt, 5, peer->prefer_encrypt) != SQLITE_OK)
722 goto cleanup;
723 if (sqlite3_bind_int64(PeerUpdateStmt, 6, peer->gossip_timestamp) != SQLITE_OK)
724 goto cleanup;
725 if (sqlite3_bind_text(PeerUpdateStmt, 7, peer->gossip_keyid, -1, SQLITE_STATIC) != SQLITE_OK)
726 goto cleanup;
727 if (sqlite3_bind_text(PeerUpdateStmt, 8, peer->gossip_keydata, -1, SQLITE_STATIC) != SQLITE_OK)
728 goto cleanup;
729 if (sqlite3_bind_text(PeerUpdateStmt, 9, peer->email_addr, -1, SQLITE_STATIC) != SQLITE_OK)
730 goto cleanup;
731
732 if (sqlite3_step(PeerUpdateStmt) != SQLITE_DONE)
733 goto cleanup;
734
735 rc = 0;
736
737cleanup:
738 sqlite3_reset(PeerUpdateStmt);
739 return rc;
740}
741
747{
748 return mutt_mem_calloc(1, sizeof(struct AutocryptPeerHistory));
749}
750
756{
757 if (!ptr || !*ptr)
758 return;
759
760 struct AutocryptPeerHistory *ph = *ptr;
761 FREE(&ph->peer_email_addr);
762 FREE(&ph->email_msgid);
763 FREE(&ph->keydata);
764 FREE(ptr);
765}
766
775 struct AutocryptPeerHistory *peerhist)
776{
777 int rc = -1;
778
779 struct Address *norm_addr = copy_normalize_addr(addr);
780
782 {
783 if (sqlite3_prepare_v3(AutocryptDB,
784 "INSERT INTO peer_history "
785 "(peer_email_addr, "
786 "email_msgid, "
787 "timestamp, "
788 "keydata) "
789 "VALUES (?, ?, ?, ?);",
790 -1, SQLITE_PREPARE_PERSISTENT,
791 &PeerHistoryInsertStmt, NULL) != SQLITE_OK)
792 {
793 goto cleanup;
794 }
795 }
796
797 if (sqlite3_bind_text(PeerHistoryInsertStmt, 1, buf_string(norm_addr->mailbox),
798 -1, SQLITE_STATIC) != SQLITE_OK)
799 {
800 goto cleanup;
801 }
802 if (sqlite3_bind_text(PeerHistoryInsertStmt, 2, peerhist->email_msgid, -1,
803 SQLITE_STATIC) != SQLITE_OK)
804 {
805 goto cleanup;
806 }
807 if (sqlite3_bind_int64(PeerHistoryInsertStmt, 3, peerhist->timestamp) != SQLITE_OK)
808 goto cleanup;
809 if (sqlite3_bind_text(PeerHistoryInsertStmt, 4, peerhist->keydata, -1, SQLITE_STATIC) != SQLITE_OK)
810 goto cleanup;
811
812 if (sqlite3_step(PeerHistoryInsertStmt) != SQLITE_DONE)
813 goto cleanup;
814
815 rc = 0;
816
817cleanup:
818 mutt_addr_free(&norm_addr);
819 sqlite3_reset(PeerHistoryInsertStmt);
820 return rc;
821}
822
828{
829 return mutt_mem_calloc(1, sizeof(struct AutocryptGossipHistory));
830}
831
837{
838 if (!ptr || !*ptr)
839 return;
840
841 struct AutocryptGossipHistory *gh = *ptr;
842 FREE(&gh->peer_email_addr);
844 FREE(&gh->email_msgid);
845 FREE(&gh->gossip_keydata);
846 FREE(ptr);
847}
848
857 struct AutocryptGossipHistory *gossip_hist)
858{
859 int rc = -1;
860
861 struct Address *norm_addr = copy_normalize_addr(addr);
862
864 {
865 if (sqlite3_prepare_v3(AutocryptDB,
866 "INSERT INTO gossip_history "
867 "(peer_email_addr, "
868 "sender_email_addr, "
869 "email_msgid, "
870 "timestamp, "
871 "gossip_keydata) "
872 "VALUES (?, ?, ?, ?, ?);",
873 -1, SQLITE_PREPARE_PERSISTENT,
874 &GossipHistoryInsertStmt, NULL) != SQLITE_OK)
875 {
876 goto cleanup;
877 }
878 }
879
880 if (sqlite3_bind_text(GossipHistoryInsertStmt, 1, buf_string(norm_addr->mailbox),
881 -1, SQLITE_STATIC) != SQLITE_OK)
882 {
883 goto cleanup;
884 }
885 if (sqlite3_bind_text(GossipHistoryInsertStmt, 2, gossip_hist->sender_email_addr,
886 -1, SQLITE_STATIC) != SQLITE_OK)
887 {
888 if (sqlite3_bind_text(GossipHistoryInsertStmt, 3, gossip_hist->email_msgid,
889 -1, SQLITE_STATIC) != SQLITE_OK)
890 {
891 goto cleanup;
892 }
893 }
894 if (sqlite3_bind_int64(GossipHistoryInsertStmt, 4, gossip_hist->timestamp) != SQLITE_OK)
895 goto cleanup;
896 if (sqlite3_bind_text(GossipHistoryInsertStmt, 5, gossip_hist->gossip_keydata,
897 -1, SQLITE_STATIC) != SQLITE_OK)
898 {
899 goto cleanup;
900 }
901
902 if (sqlite3_step(GossipHistoryInsertStmt) != SQLITE_DONE)
903 goto cleanup;
904
905 rc = 0;
906
907cleanup:
908 mutt_addr_free(&norm_addr);
909 sqlite3_reset(GossipHistoryInsertStmt);
910 return rc;
911}
void mutt_addr_free(struct Address **ptr)
Free a single Address.
Definition: address.c:460
struct Address * mutt_addr_new(void)
Create a new Address.
Definition: address.c:399
int mutt_addrlist_to_local(struct AddressList *al)
Convert an Address list from Punycode.
Definition: address.c:1379
bool mutt_addr_to_local(struct Address *a)
Convert an Address from Punycode.
Definition: address.c:1341
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
Definition: address.c:1294
bool mutt_addr_to_intl(struct Address *a)
Convert an Address to Punycode.
Definition: address.c:1264
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
Update a peer address.
Definition: db.c:48
struct AutocryptPeer * mutt_autocrypt_db_peer_new(void)
Create a new AutocryptPeer.
Definition: db.c:525
int mutt_autocrypt_db_account_delete(struct AutocryptAccount *acct)
Delete an Account from the Autocrypt database.
Definition: db.c:425
static sqlite3_stmt * PeerGetStmt
Get the matching peer addresses.
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:624
struct AutocryptGossipHistory * mutt_autocrypt_db_gossip_history_new(void)
Create a new AutocryptGossipHistory.
Definition: db.c:827
void mutt_autocrypt_db_close(void)
Close the Autocrypt SQLite database connection.
Definition: db.c:130
sqlite3 * AutocryptDB
Handle to the open Autocrypt database.
Definition: db.c:53
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:856
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:556
int mutt_autocrypt_db_peer_update(struct AutocryptPeer *peer)
Update the peer info in an Autocrypt database.
Definition: db.c:690
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:244
struct AutocryptAccount * mutt_autocrypt_db_account_new(void)
Create a new AutocryptAccount.
Definition: db.c:235
static sqlite3_stmt * AccountInsertStmt
Insert a new autocrypt account.
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
Add to the peer history.
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:755
static sqlite3_stmt * GossipHistoryInsertStmt
Add to the gossip history.
Definition: db.c:50
int mutt_autocrypt_db_account_update(struct AutocryptAccount *acct)
Update Account info in the Autocrypt database.
Definition: db.c:379
int mutt_autocrypt_db_account_get_all(struct AutocryptAccount ***accounts, int *num_accounts)
Get all accounts from an Autocrypt database.
Definition: db.c:460
static sqlite3_stmt * AccountUpdateStmt
Update an autocrypt account.
Definition: db.c:44
void mutt_autocrypt_db_peer_free(struct AutocryptPeer **ptr)
Free an AutocryptPeer.
Definition: db.c:534
void mutt_autocrypt_db_gossip_history_free(struct AutocryptGossipHistory **ptr)
Free an AutocryptGossipHistory.
Definition: db.c:836
struct AutocryptPeerHistory * mutt_autocrypt_db_peer_history_new(void)
Create a new AutocryptPeerHistory.
Definition: db.c:746
static int autocrypt_db_create(const char *db_path)
Create an Autocrypt SQLite database.
Definition: db.c:61
static sqlite3_stmt * AccountGetStmt
Get the matching autocrypt accounts.
Definition: db.c:42
int mutt_autocrypt_db_init(bool can_create)
Initialise the Autocrypt SQLite database.
Definition: db.c:80
static sqlite3_stmt * AccountDeleteStmt
Delete an autocrypt account.
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
Insert a new peer address.
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:774
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: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:572
size_t buf_concat_path(struct Buffer *buf, const char *dir, const char *fname)
Join a directory name and a filename.
Definition: buffer.c:484
void buf_lower(struct Buffer *buf)
Sets a buffer to lowercase.
Definition: buffer.c:701
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:93
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:169
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
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: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: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:251
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: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:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45