56 if (sqlite3_open_v2(db_path, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL) != SQLITE_OK)
60 mutt_error(
_(
"Unable to open autocrypt database %s"), db_path);
83 if (!c_autocrypt || !c_autocrypt_dir)
89 struct stat st = { 0 };
93 if (sqlite3_open_v2(
buf_string(db_path), &db, SQLITE_OPEN_READWRITE, NULL) != SQLITE_OK)
223 const char *val = (
const char *) sqlite3_column_text(stmt, index);
272 if (sqlite3_prepare_v3(db,
280 "WHERE email_addr = ?",
281 -1, SQLITE_PREPARE_PERSISTENT, &stmt, NULL) != SQLITE_OK)
288 if (sqlite3_bind_text(stmt, 1,
buf_string(norm_addr->
mailbox), -1, SQLITE_STATIC) != SQLITE_OK)
293 int result = sqlite3_step(stmt);
294 if (result != SQLITE_ROW)
296 if (result == SQLITE_DONE)
305 (*account)->prefer_encrypt = sqlite3_column_int(stmt, 3);
306 (*account)->enabled = sqlite3_column_int(stmt, 4);
326 const char *keydata,
bool prefer_encrypt)
338 if (sqlite3_prepare_v3(db,
339 "INSERT INTO account "
345 "VALUES (?, ?, ?, ?, ?);",
346 -1, SQLITE_PREPARE_PERSISTENT, &stmt, NULL) != SQLITE_OK)
353 if (sqlite3_bind_text(stmt, 1,
buf_string(norm_addr->
mailbox), -1, SQLITE_STATIC) != SQLITE_OK)
357 if (sqlite3_bind_text(stmt, 2, keyid, -1, SQLITE_STATIC) != SQLITE_OK)
359 if (sqlite3_bind_text(stmt, 3, keydata, -1, SQLITE_STATIC) != SQLITE_OK)
361 if (sqlite3_bind_int(stmt, 4, prefer_encrypt) != SQLITE_OK)
363 if (sqlite3_bind_int(stmt, 5, 1) != SQLITE_OK)
366 if (sqlite3_step(stmt) != SQLITE_DONE)
393 if (sqlite3_prepare_v3(db,
394 "UPDATE account SET "
397 "prefer_encrypt = ?, "
399 "WHERE email_addr = ?;",
400 -1, SQLITE_PREPARE_PERSISTENT, &stmt, NULL) != SQLITE_OK)
407 if (sqlite3_bind_text(stmt, 1, acct->
keyid, -1, SQLITE_STATIC) != SQLITE_OK)
409 if (sqlite3_bind_text(stmt, 2, acct->
keydata, -1, SQLITE_STATIC) != SQLITE_OK)
413 if (sqlite3_bind_int(stmt, 4, acct->
enabled) != SQLITE_OK)
415 if (sqlite3_bind_text(stmt, 5, acct->
email_addr, -1, SQLITE_STATIC) != SQLITE_OK)
418 if (sqlite3_step(stmt) != SQLITE_DONE)
444 if (sqlite3_prepare_v3(db,
445 "DELETE from account "
446 "WHERE email_addr = ?;",
447 -1, SQLITE_PREPARE_PERSISTENT, &stmt, NULL) != SQLITE_OK)
454 if (sqlite3_bind_text(stmt, 1, acct->
email_addr, -1, SQLITE_STATIC) != SQLITE_OK)
457 if (sqlite3_step(stmt) != SQLITE_DONE)
479 sqlite3_stmt *stmt = NULL;
486 if (sqlite3_prepare_v2(db,
494 "ORDER BY email_addr",
495 -1, &stmt, NULL) != SQLITE_OK)
500 int result = SQLITE_ERROR;
501 while ((result = sqlite3_step(stmt)) == SQLITE_ROW)
509 ac->
enabled = sqlite3_column_int(stmt, 4);
514 if (result == SQLITE_DONE)
529 sqlite3_finalize(stmt);
581 if (sqlite3_prepare_v3(db,
585 "autocrypt_timestamp, "
593 "WHERE email_addr = ?",
594 -1, SQLITE_PREPARE_PERSISTENT, &stmt, NULL) != SQLITE_OK)
601 if (sqlite3_bind_text(stmt, 1,
buf_string(norm_addr->
mailbox), -1, SQLITE_STATIC) != SQLITE_OK)
606 int result = sqlite3_step(stmt);
607 if (result != SQLITE_ROW)
609 if (result == SQLITE_DONE)
616 (*peer)->last_seen = sqlite3_column_int64(stmt, 1);
617 (*peer)->autocrypt_timestamp = sqlite3_column_int64(stmt, 2);
620 (*peer)->prefer_encrypt = sqlite3_column_int(stmt, 5);
621 (*peer)->gossip_timestamp = sqlite3_column_int64(stmt, 6);
643 struct Address *norm_addr = NULL;
653 if (sqlite3_prepare_v3(db,
657 "autocrypt_timestamp, "
664 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);",
665 -1, SQLITE_PREPARE_PERSISTENT, &stmt, NULL) != SQLITE_OK)
672 if (sqlite3_bind_text(stmt, 1,
buf_string(norm_addr->
mailbox), -1, SQLITE_STATIC) != SQLITE_OK)
676 if (sqlite3_bind_int64(stmt, 2, peer->
last_seen) != SQLITE_OK)
680 if (sqlite3_bind_text(stmt, 4, peer->
keyid, -1, SQLITE_STATIC) != SQLITE_OK)
682 if (sqlite3_bind_text(stmt, 5, peer->
keydata, -1, SQLITE_STATIC) != SQLITE_OK)
688 if (sqlite3_bind_text(stmt, 8, peer->
gossip_keyid, -1, SQLITE_STATIC) != SQLITE_OK)
690 if (sqlite3_bind_text(stmt, 9, peer->
gossip_keydata, -1, SQLITE_STATIC) != SQLITE_OK)
693 if (sqlite3_step(stmt) != SQLITE_DONE)
720 if (sqlite3_prepare_v3(db,
723 "autocrypt_timestamp = ?, "
726 "prefer_encrypt = ?, "
727 "gossip_timestamp = ?, "
729 "gossip_keydata = ? "
730 "WHERE email_addr = ?;",
731 -1, SQLITE_PREPARE_PERSISTENT, &stmt, NULL) != SQLITE_OK)
738 if (sqlite3_bind_int64(stmt, 1, peer->
last_seen) != SQLITE_OK)
742 if (sqlite3_bind_text(stmt, 3, peer->
keyid, -1, SQLITE_STATIC) != SQLITE_OK)
744 if (sqlite3_bind_text(stmt, 4, peer->
keydata, -1, SQLITE_STATIC) != SQLITE_OK)
750 if (sqlite3_bind_text(stmt, 7, peer->
gossip_keyid, -1, SQLITE_STATIC) != SQLITE_OK)
752 if (sqlite3_bind_text(stmt, 8, peer->
gossip_keydata, -1, SQLITE_STATIC) != SQLITE_OK)
754 if (sqlite3_bind_text(stmt, 9, peer->
email_addr, -1, SQLITE_STATIC) != SQLITE_OK)
757 if (sqlite3_step(stmt) != SQLITE_DONE)
812 if (sqlite3_prepare_v3(db,
813 "INSERT INTO peer_history "
818 "VALUES (?, ?, ?, ?);",
819 -1, SQLITE_PREPARE_PERSISTENT, &stmt, NULL) != SQLITE_OK)
826 if (sqlite3_bind_text(stmt, 1,
buf_string(norm_addr->
mailbox), -1, SQLITE_STATIC) != SQLITE_OK)
830 if (sqlite3_bind_text(stmt, 2, peerhist->
email_msgid, -1, SQLITE_STATIC) != SQLITE_OK)
834 if (sqlite3_bind_int64(stmt, 3, peerhist->
timestamp) != SQLITE_OK)
836 if (sqlite3_bind_text(stmt, 4, peerhist->
keydata, -1, SQLITE_STATIC) != SQLITE_OK)
839 if (sqlite3_step(stmt) != SQLITE_DONE)
896 if (sqlite3_prepare_v3(db,
897 "INSERT INTO gossip_history "
899 "sender_email_addr, "
903 "VALUES (?, ?, ?, ?, ?);",
904 -1, SQLITE_PREPARE_PERSISTENT, &stmt, NULL) != SQLITE_OK)
911 if (sqlite3_bind_text(stmt, 1,
buf_string(norm_addr->
mailbox), -1, SQLITE_STATIC) != SQLITE_OK)
915 if (sqlite3_bind_text(stmt, 2, gossip_hist->
sender_email_addr, -1, SQLITE_STATIC) != SQLITE_OK)
919 if (sqlite3_bind_text(stmt, 3, gossip_hist->
email_msgid, -1, SQLITE_STATIC) != SQLITE_OK)
923 if (sqlite3_bind_int64(stmt, 4, gossip_hist->
timestamp) != SQLITE_OK)
925 if (sqlite3_bind_text(stmt, 5, gossip_hist->
gossip_keydata, -1, SQLITE_STATIC) != SQLITE_OK)
930 if (sqlite3_step(stmt) != SQLITE_DONE)
struct Address * mutt_addr_create(const char *personal, const char *mailbox)
Create and populate a new Address.
void mutt_addr_free(struct Address **ptr)
Free a single Address.
int mutt_addrlist_to_local(struct AddressList *al)
Convert an Address list from Punycode.
bool mutt_addr_to_local(struct Address *a)
Convert an Address from Punycode.
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
bool mutt_addr_to_intl(struct Address *a)
Convert an Address to Punycode.
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
#define ARRAY_SIZE(head)
The number of elements stored.
#define ARRAY_FREE(head)
Release all memory.
void mutt_autocrypt_db_normalize_addrlist(struct AddressList *al)
Normalise a list of Email Addresses.
struct AutocryptPeer * mutt_autocrypt_db_peer_new(void)
Create a new AutocryptPeer.
int mutt_autocrypt_db_account_delete(struct AutocryptAccount *acct)
Delete an Account from the Autocrypt database.
int mutt_autocrypt_db_peer_insert(struct Address *addr, struct AutocryptPeer *peer)
Insert a peer into the Autocrypt database.
struct AutocryptGossipHistory * mutt_autocrypt_db_gossip_history_new(void)
Create a new AutocryptGossipHistory.
int mutt_autocrypt_db_gossip_history_insert(struct Address *addr, struct AutocryptGossipHistory *gossip_hist)
Insert a gossip history into the Autocrypt database.
int mutt_autocrypt_db_account_get(struct Address *addr, struct AutocryptAccount **account)
Get Autocrypt Account data from the database.
int mutt_autocrypt_db_peer_get(struct Address *addr, struct AutocryptPeer **peer)
Get peer info from the Autocrypt database.
int mutt_autocrypt_db_peer_update(struct AutocryptPeer *peer)
Update the peer info in an Autocrypt database.
int mutt_autocrypt_db_account_get_all(struct AutocryptAccountArray *aaa)
Get all accounts from an Autocrypt database.
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.
void mutt_autocrypt_db_account_free(struct AutocryptAccount **ptr)
Free an AutocryptAccount.
struct AutocryptAccount * mutt_autocrypt_db_account_new(void)
Create a new AutocryptAccount.
void mutt_autocrypt_db_normalize_addr(struct Address *a)
Normalise an Email Address.
static struct Address * copy_normalize_addr(struct Address *addr)
Copy a normalised Email Address.
void mutt_autocrypt_db_peer_history_free(struct AutocryptPeerHistory **ptr)
Free an AutocryptPeerHistory.
int mutt_autocrypt_db_account_update(struct AutocryptAccount *acct)
Update Account info in the Autocrypt database.
void mutt_autocrypt_db_peer_free(struct AutocryptPeer **ptr)
Free an AutocryptPeer.
void mutt_autocrypt_db_gossip_history_free(struct AutocryptGossipHistory **ptr)
Free an AutocryptGossipHistory.
struct AutocryptPeerHistory * mutt_autocrypt_db_peer_history_new(void)
Create a new AutocryptPeerHistory.
void mutt_autocrypt_db_close(struct AutocryptModuleData *mod_data)
Close the Autocrypt SQLite database connection.
static int autocrypt_db_create(const char *db_path)
Create an Autocrypt SQLite database.
int mutt_autocrypt_db_init(bool can_create)
Initialise the Autocrypt SQLite database.
static char * strdup_column_text(sqlite3_stmt *stmt, int index)
Copy a string from the database.
int mutt_autocrypt_db_peer_history_insert(struct Address *addr, struct AutocryptPeerHistory *peerhist)
Insert peer history into the Autocrypt database.
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.
int mutt_autocrypt_schema_init(void)
Set up an Autocrypt database.
int mutt_autocrypt_account_init(bool prompt)
Create a new Autocrypt account.
void mutt_autocrypt_scan_mailboxes(void)
Scan mailboxes for Autocrypt headers.
size_t buf_concat_path(struct Buffer *buf, const char *dir, const char *fname)
Join a directory name and a filename.
void buf_lower(struct Buffer *buf)
Sets a buffer to lowercase.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
#define FREE(x)
Free memory and set the pointer to NULL.
#define MUTT_MEM_CALLOC(n, type)
@ MODULE_ID_AUTOCRYPT
ModuleAutocrypt, Autocrypt
Convenience wrapper for the library headers.
char * mutt_str_dup(const char *str)
Copy a string, safely.
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
#define TAILQ_FOREACH(var, head, field)
struct Buffer * mailbox
Mailbox and host address.
bool intl_checked
Checked for IDN?
bool is_intl
International Domain Name.
char * email_addr
Email address.
char * keydata
PGP Key data.
bool enabled
Is this account enabled.
bool prefer_encrypt
false = nopref, true = mutual
Autocrypt gossip history.
char * peer_email_addr
Email addressof the peer.
char * email_msgid
Sender's email's message id.
char * sender_email_addr
Sender's email address.
char * gossip_keydata
Gossip Key data.
sqlite3_int64 timestamp
Timestamp of sender's email.
Autocrypt private Module data.
sqlite3_stmt * account_delete_stmt
Delete an autocrypt account.
sqlite3_stmt * account_insert_stmt
Insert a new autocrypt account.
sqlite3_stmt * peer_get_stmt
Get the matching peer addresses.
sqlite3_stmt * account_get_stmt
Get the matching autocrypt accounts.
sqlite3_stmt * account_update_stmt
Update an autocrypt account.
sqlite3_stmt * peer_history_insert_stmt
Add to the peer history.
sqlite3_stmt * peer_update_stmt
Update a peer address.
sqlite3 * autocrypt_db
Autocrypt database.
sqlite3_stmt * gossip_history_insert_stmt
Add to the gossip history.
sqlite3_stmt * peer_insert_stmt
Insert a new peer address.
char * peer_email_addr
Email address of the peer.
char * email_msgid
Message id of the email.
char * keydata
PGP Key data.
sqlite3_int64 timestamp
Timestamp of email.
sqlite3_int64 autocrypt_timestamp
When the email was sent.
char * gossip_keydata
Gossip Key data.
char * gossip_keyid
Gossip Key id.
char * keydata
PGP Key data.
char * email_addr
Email address.
sqlite3_int64 last_seen
When was the peer last seen.
bool prefer_encrypt
false = nopref, true = mutual
sqlite3_int64 gossip_timestamp
Timestamp of Gossip header.
String manipulation buffer.
Container for Accounts, Notifications.
struct ConfigSubset * sub
Inherited config items.