NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
private.h File Reference

Shared constants/structs that are private to Autocrypt. More...

#include <sqlite3.h>
#include <stdbool.h>
+ Include dependency graph for private.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int mutt_autocrypt_account_init (bool prompt)
 Create a new Autocrypt account. More...
 
void mutt_autocrypt_scan_mailboxes (struct Mailbox *m)
 Scan mailboxes for Autocrypt headers. More...
 
int mutt_autocrypt_db_account_delete (struct AutocryptAccount *acct)
 Delete an Account from the Autocrypt database. More...
 
void mutt_autocrypt_db_account_free (struct AutocryptAccount **ptr)
 Free an AutocryptAccount. More...
 
int mutt_autocrypt_db_account_get (struct Address *addr, struct AutocryptAccount **account)
 Get Autocrypt Account data from the database. More...
 
int mutt_autocrypt_db_account_get_all (struct AutocryptAccount ***accounts, int *num_accounts)
 Get all accounts from an Autocrypt database. More...
 
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. More...
 
struct AutocryptAccountmutt_autocrypt_db_account_new (void)
 Create a new AutocryptAccount. More...
 
int mutt_autocrypt_db_account_update (struct AutocryptAccount *acct)
 Update Account info in the Autocrypt database. More...
 
void mutt_autocrypt_db_close (void)
 Close the Autocrypt SQLite database connection. More...
 
void mutt_autocrypt_db_gossip_history_free (struct AutocryptGossipHistory **ptr)
 Free an AutocryptGossipHistory. More...
 
int mutt_autocrypt_db_gossip_history_insert (struct Address *addr, struct AutocryptGossipHistory *gossip_hist)
 Insert a gossip history into the Autocrypt database. More...
 
struct AutocryptGossipHistorymutt_autocrypt_db_gossip_history_new (void)
 Create a new AutocryptGossipHistory. More...
 
int mutt_autocrypt_db_init (struct Mailbox *m, bool can_create)
 Initialise the Autocrypt SQLite database. More...
 
void mutt_autocrypt_db_normalize_addr (struct Address *a)
 Normalise an Email Address. More...
 
void mutt_autocrypt_db_normalize_addrlist (struct AddressList *al)
 Normalise a list of Email Addresses. More...
 
void mutt_autocrypt_db_peer_free (struct AutocryptPeer **ptr)
 Free an AutocryptPeer. More...
 
int mutt_autocrypt_db_peer_get (struct Address *addr, struct AutocryptPeer **peer)
 Get peer info from the Autocrypt database. More...
 
void mutt_autocrypt_db_peer_history_free (struct AutocryptPeerHistory **ptr)
 Free an AutocryptPeerHistory. More...
 
int mutt_autocrypt_db_peer_history_insert (struct Address *addr, struct AutocryptPeerHistory *peerhist)
 Insert peer history into the Autocrypt database. More...
 
struct AutocryptPeerHistorymutt_autocrypt_db_peer_history_new (void)
 Create a new AutocryptPeerHistory. More...
 
int mutt_autocrypt_db_peer_insert (struct Address *addr, struct AutocryptPeer *peer)
 Insert a peer into the Autocrypt database. More...
 
struct AutocryptPeermutt_autocrypt_db_peer_new (void)
 Create a new AutocryptPeer. More...
 
int mutt_autocrypt_db_peer_update (struct AutocryptPeer *peer)
 Update the peer info in an Autocrypt database. More...
 
int mutt_autocrypt_schema_init (void)
 Set up an Autocrypt database. More...
 
int mutt_autocrypt_schema_update (void)
 Update the version number of the Autocrypt database schema. More...
 
int mutt_autocrypt_gpgme_create_key (struct Address *addr, struct Buffer *keyid, struct Buffer *keydata)
 Create a GPGME key. More...
 
int mutt_autocrypt_gpgme_import_key (const char *keydata, struct Buffer *keyid)
 Read a key from GPGME. More...
 
int mutt_autocrypt_gpgme_init (void)
 Initialise GPGME. More...
 
bool mutt_autocrypt_gpgme_is_valid_key (const char *keyid)
 Is a key id valid? More...
 
int mutt_autocrypt_gpgme_select_key (struct Buffer *keyid, struct Buffer *keydata)
 Select a Autocrypt key. More...
 
int mutt_autocrypt_gpgme_select_or_create_key (struct Address *addr, struct Buffer *keyid, struct Buffer *keydata)
 Ask the user to select or create an Autocrypt key. More...
 

Variables

sqlite3 * AutocryptDB
 

Detailed Description

Shared constants/structs that are private to Autocrypt.

Authors
  • Kevin J. McCarthy

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file private.h.

Function Documentation

◆ mutt_autocrypt_account_init()

int mutt_autocrypt_account_init ( bool  prompt)

Create a new Autocrypt account.

Parameters
promptPrompt the user
Return values
0Success
-1Error

This is used the first time autocrypt is initialized, and in the account menu.

Definition at line 155 of file autocrypt.c.

156 {
157  struct Address *addr = NULL;
158  struct AutocryptAccount *account = NULL;
159  bool done = false;
160  int rc = -1;
161  bool prefer_encrypt = false;
162 
163  if (prompt)
164  {
165  /* L10N: The first time NeoMutt is started with $autocrypt set, it will
166  create $autocrypt_dir and then prompt to create an autocrypt account
167  with this message. */
168  if (mutt_yesorno(_("Create an initial autocrypt account?"), MUTT_YES) != MUTT_YES)
169  return 0;
170  }
171 
172  struct Buffer *keyid = mutt_buffer_pool_get();
173  struct Buffer *keydata = mutt_buffer_pool_get();
174 
175  const struct Address *c_from = cs_subset_address(NeoMutt->sub, "from");
176  if (c_from)
177  {
178  addr = mutt_addr_copy(c_from);
179  const char *const c_real_name = cs_subset_string(NeoMutt->sub, "real_name");
180  if (!addr->personal && c_real_name)
181  addr->personal = mutt_str_dup(c_real_name);
182  }
183 
184  struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
185  mutt_addrlist_append(&al, addr);
186 
187  do
188  {
189  /* L10N: Autocrypt is asking for the email address to use for the
190  autocrypt account. This will generate a key and add a record
191  to the database for use in autocrypt operations. */
192  if (mutt_edit_address(&al, _("Autocrypt account address: "), false) != 0)
193  goto cleanup;
194 
195  addr = TAILQ_FIRST(&al);
196  if (!addr || !addr->mailbox || TAILQ_NEXT(addr, entries))
197  {
198  /* L10N: Autocrypt prompts for an account email address, and requires
199  a single address. This is shown if they entered something invalid,
200  nothing, or more than one address for some reason. */
201  mutt_error(_("Please enter a single email address"));
202  done = false;
203  }
204  else
205  done = true;
206  } while (!done);
207 
208  addr = TAILQ_FIRST(&al);
209  if (mutt_autocrypt_db_account_get(addr, &account) < 0)
210  goto cleanup;
211  if (account)
212  {
213  /* L10N: When creating an autocrypt account, this message will be displayed
214  if there is already an account in the database with the email address
215  they just entered. */
216  mutt_error(_("That email address already has an autocrypt account"));
217  goto cleanup;
218  }
219 
220  if (mutt_autocrypt_gpgme_select_or_create_key(addr, keyid, keydata))
221  goto cleanup;
222 
223  /* L10N: Autocrypt has a setting "prefer-encrypt".
224  When the recommendation algorithm returns "available" and BOTH sender and
225  recipient choose "prefer-encrypt", encryption will be automatically
226  enabled.
227  Otherwise the UI will show encryption is "available" but the user
228  will be required to enable encryption manually. */
229  if (mutt_yesorno(_("Prefer encryption?"), MUTT_NO) == MUTT_YES)
230  prefer_encrypt = true;
231 
233  mutt_buffer_string(keydata), prefer_encrypt))
234  {
235  goto cleanup;
236  }
237 
238  rc = 0;
239 
240 cleanup:
241  if (rc == 0)
242  {
243  /* L10N: Message displayed after an autocrypt account is successfully created. */
244  mutt_message(_("Autocrypt account creation succeeded"));
245  }
246  else
247  {
248  /* L10N: Error message displayed if creating an autocrypt account failed
249  or was aborted by the user. */
250  mutt_error(_("Autocrypt account creation aborted"));
251  }
252 
254  mutt_addrlist_clear(&al);
255  mutt_buffer_pool_release(&keyid);
256  mutt_buffer_pool_release(&keydata);
257  return rc;
258 }
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
#define TAILQ_FIRST(head)
Definition: queue.h:723
#define mutt_error(...)
Definition: logging.h:88
void mutt_autocrypt_db_account_free(struct AutocryptAccount **ptr)
Free an AutocryptAccount.
Definition: db.c:246
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1470
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
String manipulation buffer.
Definition: buffer.h:33
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
#define _(a)
Definition: message.h:28
An email address.
Definition: address.h:35
char * mailbox
Mailbox and host address.
Definition: address.h:38
const struct Address * cs_subset_address(const struct ConfigSubset *sub, const char *name)
Get an Address config item by name.
Definition: helpers.c:49
struct Address * mutt_addr_copy(const struct Address *addr)
Copy the real address.
Definition: address.c:716
Container for Accounts, Notifications.
Definition: neomutt.h:36
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
int mutt_autocrypt_gpgme_select_or_create_key(struct Address *addr, struct Buffer *keyid, struct Buffer *keydata)
Ask the user to select or create an Autocrypt key.
Definition: gpgme.c:275
bool prefer_encrypt
false = nopref, true = mutual
Definition: lib.h:108
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def)
Ask the user a Yes/No question.
Definition: question.c:180
int mutt_autocrypt_db_account_get(struct Address *addr, struct AutocryptAccount **account)
Get Autocrypt Account data from the database.
Definition: db.c:265
char * personal
Real name of address.
Definition: address.h:37
Autocrypt account.
Definition: lib.h:103
#define mutt_message(...)
Definition: logging.h:87
User answered &#39;No&#39;, or assume &#39;No&#39;.
Definition: quad.h:38
#define TAILQ_NEXT(elm, field)
Definition: queue.h:832
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:637
int mutt_edit_address(struct AddressList *al, const char *field, bool expand_aliases)
Edit an email address.
Definition: send.c:187
void mutt_addrlist_append(struct AddressList *al, struct Address *a)
Append an Address to an AddressList.
Definition: address.c:1490
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:39
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:324
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_scan_mailboxes()

void mutt_autocrypt_scan_mailboxes ( struct Mailbox m)

Scan mailboxes for Autocrypt headers.

Parameters
mMailbox

This is invoked during the first autocrypt initialization, to scan one or more mailboxes for autocrypt headers.

Due to the implementation, header-cached headers are not scanned, so this routine just opens up the mailboxes with $header_cache temporarily disabled.

Definition at line 933 of file autocrypt.c.

934 {
935 #ifdef USE_HCACHE
936  const char *c_header_cache = cs_subset_path(NeoMutt->sub, "header_cache");
937  char *old_hdrcache = mutt_str_dup(c_header_cache);
938  c_header_cache = NULL;
939 #endif
940 
941  struct Buffer *folderbuf = mutt_buffer_pool_get();
942 
943  /* L10N: The first time autocrypt is enabled, NeoMutt will ask to scan
944  through one or more mailboxes for Autocrypt: headers. Those headers are
945  then captured in the database as peer records and used for encryption.
946  If this is answered yes, they will be prompted for a mailbox. */
947  enum QuadOption scan =
948  mutt_yesorno(_("Scan a mailbox for autocrypt headers?"), MUTT_YES);
949  while (scan == MUTT_YES)
950  {
951  // L10N: The prompt for a mailbox to scan for Autocrypt: headers
952  if ((!mutt_buffer_enter_fname(_("Scan mailbox"), folderbuf, true, m, false,
953  NULL, NULL, MUTT_SEL_NO_FLAGS)) &&
954  (!mutt_buffer_is_empty(folderbuf)))
955  {
956  mutt_buffer_expand_path_regex(folderbuf, false);
957  struct Mailbox *m_ac = mx_path_resolve(mutt_buffer_string(folderbuf));
958  /* NOTE: I am purposely *not* executing folder hooks here,
959  * as they can do all sorts of things like push into the getch() buffer.
960  * Authentication should be in account-hooks. */
962  mx_mbox_close(m_ac);
963  mutt_buffer_reset(folderbuf);
964  }
965 
966  /* L10N: This is the second prompt to see if the user would like
967  to scan more than one mailbox for Autocrypt headers.
968  I'm purposely being extra verbose; asking first then prompting
969  for a mailbox. This is because this is a one-time operation
970  and I don't want them to accidentally ctrl-g and abort it. */
971  scan = mutt_yesorno(_("Scan another mailbox for autocrypt headers?"), MUTT_YES);
972  }
973 
974 #ifdef USE_HCACHE
975  cs_subset_str_native_set(NeoMutt->sub, "header_cache", (intptr_t) old_hdrcache, NULL);
976  old_hdrcache = NULL;
977 #endif
978  mutt_buffer_pool_release(&folderbuf);
979 }
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:79
bool mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags)
Open a mailbox and parse it.
Definition: mx.c:304
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
String manipulation buffer.
Definition: buffer.h:33
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
#define _(a)
Definition: message.h:28
#define MUTT_SEL_NO_FLAGS
No flags are set.
Definition: browser.h:36
enum MxStatus mx_mbox_close(struct Mailbox *m)
Save changes and close mailbox.
Definition: mx.c:610
Container for Accounts, Notifications.
Definition: neomutt.h:36
QuadOption
Possible values for a quad-option.
Definition: quad.h:35
void mutt_buffer_expand_path_regex(struct Buffer *buf, bool regex)
Create the canonical path (with regex char escaping)
Definition: muttlib.c:134
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
int cs_subset_str_native_set(const struct ConfigSubset *sub, const char *name, intptr_t value, struct Buffer *err)
Natively set the value of a string config item.
Definition: subset.c:305
A mailbox.
Definition: mailbox.h:81
#define MUTT_READONLY
Open in read-only mode.
Definition: mxapi.h:63
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:194
enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def)
Ask the user a Yes/No question.
Definition: question.c:180
int mutt_buffer_enter_fname(const char *prompt, struct Buffer *fname, bool mailbox, struct Mailbox *m, bool multiple, char ***files, int *numfiles, SelectFileFlags flags)
Ask the user to select a file.
Definition: curs_lib.c:513
struct Mailbox * mx_path_resolve(const char *path)
Get a Mailbox for a path.
Definition: mx.c:1668
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:252
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_db_account_delete()

int mutt_autocrypt_db_account_delete ( struct AutocryptAccount acct)

Delete an Account from the Autocrypt database.

Parameters
acctAccount to delete
Return values
0Success
-1Error

Definition at line 421 of file db.c.

422 {
423  int rc = -1;
424 
425  if (!AccountDeleteStmt)
426  {
427  if (sqlite3_prepare_v3(AutocryptDB,
428  "DELETE from account "
429  "WHERE email_addr = ?;",
430  -1, SQLITE_PREPARE_PERSISTENT, &AccountDeleteStmt, NULL) != SQLITE_OK)
431  {
432  goto cleanup;
433  }
434  }
435 
436  if (sqlite3_bind_text(AccountDeleteStmt, 1, acct->email_addr, -1, SQLITE_STATIC) != SQLITE_OK)
437  goto cleanup;
438 
439  if (sqlite3_step(AccountDeleteStmt) != SQLITE_DONE)
440  goto cleanup;
441 
442  rc = 0;
443 
444 cleanup:
445  sqlite3_reset(AccountDeleteStmt);
446  return rc;
447 }
sqlite3 * AutocryptDB
Definition: db.c:52
char * email_addr
Definition: lib.h:105
static sqlite3_stmt * AccountDeleteStmt
Definition: db.c:45
+ Here is the caller graph for this function:

◆ mutt_autocrypt_db_account_free()

void mutt_autocrypt_db_account_free ( struct AutocryptAccount **  ptr)

Free an AutocryptAccount.

Parameters
ptrAccount to free

Definition at line 246 of file db.c.

247 {
248  if (!ptr || !*ptr)
249  return;
250 
251  struct AutocryptAccount *ac = *ptr;
252  FREE(&ac->email_addr);
253  FREE(&ac->keyid);
254  FREE(&ac->keydata);
255  FREE(ptr);
256 }
char * email_addr
Definition: lib.h:105
char * keyid
Definition: lib.h:106
Autocrypt account.
Definition: lib.h:103
char * keydata
Definition: lib.h:107
#define FREE(x)
Definition: memory.h:40
+ Here is the caller graph for this function:

◆ mutt_autocrypt_db_account_get()

int mutt_autocrypt_db_account_get ( struct Address addr,
struct AutocryptAccount **  account 
)

Get Autocrypt Account data from the database.

Parameters
[in]addrEmail Address to lookup
[out]accountMatched account
Return values
0Success
-1Error

Definition at line 265 of file db.c.

266 {
267  int rc = -1;
268 
269  struct Address *norm_addr = copy_normalize_addr(addr);
270  *account = NULL;
271 
272  if (!AccountGetStmt)
273  {
274  if (sqlite3_prepare_v3(AutocryptDB,
275  "SELECT "
276  "email_addr, "
277  "keyid, "
278  "keydata, "
279  "prefer_encrypt, "
280  "enabled "
281  "FROM account "
282  "WHERE email_addr = ?",
283  -1, SQLITE_PREPARE_PERSISTENT, &AccountGetStmt, NULL) != SQLITE_OK)
284  {
285  goto cleanup;
286  }
287  }
288 
289  if (sqlite3_bind_text(AccountGetStmt, 1, norm_addr->mailbox, -1, SQLITE_STATIC) != SQLITE_OK)
290  goto cleanup;
291 
292  int result = sqlite3_step(AccountGetStmt);
293  if (result != SQLITE_ROW)
294  {
295  if (result == SQLITE_DONE)
296  rc = 0;
297  goto cleanup;
298  }
299 
300  *account = mutt_autocrypt_db_account_new();
301  (*account)->email_addr = strdup_column_text(AccountGetStmt, 0);
302  (*account)->keyid = strdup_column_text(AccountGetStmt, 1);
303  (*account)->keydata = strdup_column_text(AccountGetStmt, 2);
304  (*account)->prefer_encrypt = sqlite3_column_int(AccountGetStmt, 3);
305  (*account)->enabled = sqlite3_column_int(AccountGetStmt, 4);
306 
307  rc = 1;
308 
309 cleanup:
310  mutt_addr_free(&norm_addr);
311  sqlite3_reset(AccountGetStmt);
312  return rc;
313 }
sqlite3 * AutocryptDB
Definition: db.c:52
struct AutocryptAccount * mutt_autocrypt_db_account_new(void)
Create a new AutocryptAccount.
Definition: db.c:237
An email address.
Definition: address.h:35
char * mailbox
Mailbox and host address.
Definition: address.h:38
void mutt_addr_free(struct Address **ptr)
Free a single Address.
Definition: address.c:440
static struct Address * copy_normalize_addr(struct Address *addr)
Copy a normalised Email Address.
Definition: db.c:204
static sqlite3_stmt * AccountGetStmt
Definition: db.c:42
static char * strdup_column_text(sqlite3_stmt *stmt, int index)
Copy a string from the database.
Definition: db.c:227
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_db_account_get_all()

int mutt_autocrypt_db_account_get_all ( struct AutocryptAccount ***  accounts,
int *  num_accounts 
)

Get all accounts from an Autocrypt database.

Parameters
[out]accountsList of accounts
[out]num_accountsNumber of accounts
Return values
0Success
-1Error

Definition at line 456 of file db.c.

457 {
458  int rc = -1, result;
459  sqlite3_stmt *stmt = NULL;
460  struct AutocryptAccount **results = NULL;
461  int results_len = 0, results_count = 0;
462 
463  *accounts = NULL;
464  *num_accounts = 0;
465 
466  /* Note, speed is not of the essence for the account management screen,
467  * so we don't bother with a persistent prepared statement */
468  if (sqlite3_prepare_v2(AutocryptDB,
469  "SELECT "
470  "email_addr, "
471  "keyid, "
472  "keydata, "
473  "prefer_encrypt, "
474  "enabled "
475  "FROM account "
476  "ORDER BY email_addr",
477  -1, &stmt, NULL) != SQLITE_OK)
478  {
479  goto cleanup;
480  }
481 
482  while ((result = sqlite3_step(stmt)) == SQLITE_ROW)
483  {
484  if (results_count == results_len)
485  {
486  results_len += 5;
487  mutt_mem_realloc(&results, results_len * sizeof(struct AutocryptAccount *));
488  }
489 
491  results[results_count++] = account;
492 
493  account->email_addr = strdup_column_text(stmt, 0);
494  account->keyid = strdup_column_text(stmt, 1);
495  account->keydata = strdup_column_text(stmt, 2);
496  account->prefer_encrypt = sqlite3_column_int(stmt, 3);
497  account->enabled = sqlite3_column_int(stmt, 4);
498  }
499 
500  if (result == SQLITE_DONE)
501  {
502  *accounts = results;
503  rc = *num_accounts = results_count;
504  }
505  else
506  {
507  while (results_count > 0)
508  mutt_autocrypt_db_account_free(&results[--results_count]);
509  FREE(&results);
510  }
511 
512 cleanup:
513  sqlite3_finalize(stmt);
514  return rc;
515 }
sqlite3 * AutocryptDB
Definition: db.c:52
void mutt_autocrypt_db_account_free(struct AutocryptAccount **ptr)
Free an AutocryptAccount.
Definition: db.c:246
struct AutocryptAccount * mutt_autocrypt_db_account_new(void)
Create a new AutocryptAccount.
Definition: db.c:237
char * email_addr
Definition: lib.h:105
char * keyid
Definition: lib.h:106
bool enabled
Definition: lib.h:109
bool prefer_encrypt
false = nopref, true = mutual
Definition: lib.h:108
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
Autocrypt account.
Definition: lib.h:103
char * keydata
Definition: lib.h:107
#define FREE(x)
Definition: memory.h:40
static char * strdup_column_text(sqlite3_stmt *stmt, int index)
Copy a string from the database.
Definition: db.c:227
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_db_account_insert()

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.

Parameters
addrEmail Address for the account
keyidAutocrypt KeyID
keydataAutocrypt key data
prefer_encryptWhether the account prefers encryption
Return values
0Success
-1Error

Definition at line 324 of file db.c.

326 {
327  int rc = -1;
328 
329  struct Address *norm_addr = copy_normalize_addr(addr);
330 
331  if (!AccountInsertStmt)
332  {
333  if (sqlite3_prepare_v3(AutocryptDB,
334  "INSERT INTO account "
335  "(email_addr, "
336  "keyid, "
337  "keydata, "
338  "prefer_encrypt, "
339  "enabled) "
340  "VALUES (?, ?, ?, ?, ?);",
341  -1, SQLITE_PREPARE_PERSISTENT, &AccountInsertStmt, NULL) != SQLITE_OK)
342  {
343  goto cleanup;
344  }
345  }
346 
347  if (sqlite3_bind_text(AccountInsertStmt, 1, norm_addr->mailbox, -1, SQLITE_STATIC) != SQLITE_OK)
348  goto cleanup;
349  if (sqlite3_bind_text(AccountInsertStmt, 2, keyid, -1, SQLITE_STATIC) != SQLITE_OK)
350  goto cleanup;
351  if (sqlite3_bind_text(AccountInsertStmt, 3, keydata, -1, SQLITE_STATIC) != SQLITE_OK)
352  goto cleanup;
353  if (sqlite3_bind_int(AccountInsertStmt, 4, prefer_encrypt) != SQLITE_OK)
354  goto cleanup;
355  if (sqlite3_bind_int(AccountInsertStmt, 5, 1) != SQLITE_OK)
356  goto cleanup;
357 
358  if (sqlite3_step(AccountInsertStmt) != SQLITE_DONE)
359  goto cleanup;
360 
361  rc = 0;
362 
363 cleanup:
364  mutt_addr_free(&norm_addr);
365  sqlite3_reset(AccountInsertStmt);
366  return rc;
367 }
sqlite3 * AutocryptDB
Definition: db.c:52
An email address.
Definition: address.h:35
char * mailbox
Mailbox and host address.
Definition: address.h:38
void mutt_addr_free(struct Address **ptr)
Free a single Address.
Definition: address.c:440
static sqlite3_stmt * AccountInsertStmt
Definition: db.c:43
static struct Address * copy_normalize_addr(struct Address *addr)
Copy a normalised Email Address.
Definition: db.c:204
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_db_account_new()

struct AutocryptAccount* mutt_autocrypt_db_account_new ( void  )

Create a new AutocryptAccount.

Return values
ptrNew AutocryptAccount

Definition at line 237 of file db.c.

238 {
239  return mutt_mem_calloc(1, sizeof(struct AutocryptAccount));
240 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
Autocrypt account.
Definition: lib.h:103
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_db_account_update()

int mutt_autocrypt_db_account_update ( struct AutocryptAccount acct)

Update Account info in the Autocrypt database.

Parameters
acctAutocrypt Account data
Return values
0Success
-1Error

Definition at line 375 of file db.c.

376 {
377  int rc = -1;
378 
379  if (!AccountUpdateStmt)
380  {
381  if (sqlite3_prepare_v3(AutocryptDB,
382  "UPDATE account SET "
383  "keyid = ?, "
384  "keydata = ?, "
385  "prefer_encrypt = ?, "
386  "enabled = ? "
387  "WHERE email_addr = ?;",
388  -1, SQLITE_PREPARE_PERSISTENT, &AccountUpdateStmt, NULL) != SQLITE_OK)
389  {
390  goto cleanup;
391  }
392  }
393 
394  if (sqlite3_bind_text(AccountUpdateStmt, 1, acct->keyid, -1, SQLITE_STATIC) != SQLITE_OK)
395  goto cleanup;
396  if (sqlite3_bind_text(AccountUpdateStmt, 2, acct->keydata, -1, SQLITE_STATIC) != SQLITE_OK)
397  goto cleanup;
398  if (sqlite3_bind_int(AccountUpdateStmt, 3, acct->prefer_encrypt) != SQLITE_OK)
399  goto cleanup;
400  if (sqlite3_bind_int(AccountUpdateStmt, 4, acct->enabled) != SQLITE_OK)
401  goto cleanup;
402  if (sqlite3_bind_text(AccountUpdateStmt, 5, acct->email_addr, -1, SQLITE_STATIC) != SQLITE_OK)
403  goto cleanup;
404 
405  if (sqlite3_step(AccountUpdateStmt) != SQLITE_DONE)
406  goto cleanup;
407 
408  rc = 0;
409 
410 cleanup:
411  sqlite3_reset(AccountUpdateStmt);
412  return rc;
413 }
sqlite3 * AutocryptDB
Definition: db.c:52
char * email_addr
Definition: lib.h:105
char * keyid
Definition: lib.h:106
static sqlite3_stmt * AccountUpdateStmt
Definition: db.c:44
bool enabled
Definition: lib.h:109
bool prefer_encrypt
false = nopref, true = mutual
Definition: lib.h:108
char * keydata
Definition: lib.h:107
+ Here is the caller graph for this function:

◆ mutt_autocrypt_db_close()

void mutt_autocrypt_db_close ( void  )

Close the Autocrypt SQLite database connection.

Definition at line 132 of file db.c.

133 {
134  if (!AutocryptDB)
135  return;
136 
137  sqlite3_finalize(AccountGetStmt);
138  AccountGetStmt = NULL;
139  sqlite3_finalize(AccountInsertStmt);
140  AccountInsertStmt = NULL;
141  sqlite3_finalize(AccountUpdateStmt);
142  AccountUpdateStmt = NULL;
143  sqlite3_finalize(AccountDeleteStmt);
144  AccountDeleteStmt = NULL;
145 
146  sqlite3_finalize(PeerGetStmt);
147  PeerGetStmt = NULL;
148  sqlite3_finalize(PeerInsertStmt);
149  PeerInsertStmt = NULL;
150  sqlite3_finalize(PeerUpdateStmt);
151  PeerUpdateStmt = NULL;
152 
153  sqlite3_finalize(PeerHistoryInsertStmt);
154  PeerHistoryInsertStmt = NULL;
155 
156  sqlite3_finalize(GossipHistoryInsertStmt);
158 
159  sqlite3_close_v2(AutocryptDB);
160  AutocryptDB = NULL;
161 }
sqlite3 * AutocryptDB
Definition: db.c:52
static sqlite3_stmt * AccountUpdateStmt
Definition: db.c:44
static sqlite3_stmt * AccountInsertStmt
Definition: db.c:43
static sqlite3_stmt * PeerGetStmt
Definition: db.c:46
static sqlite3_stmt * GossipHistoryInsertStmt
Definition: db.c:50
static sqlite3_stmt * PeerUpdateStmt
Definition: db.c:48
static sqlite3_stmt * AccountDeleteStmt
Definition: db.c:45
static sqlite3_stmt * AccountGetStmt
Definition: db.c:42
static sqlite3_stmt * PeerInsertStmt
Definition: db.c:47
static sqlite3_stmt * PeerHistoryInsertStmt
Definition: db.c:49
+ Here is the caller graph for this function:

◆ mutt_autocrypt_db_gossip_history_free()

void mutt_autocrypt_db_gossip_history_free ( struct AutocryptGossipHistory **  ptr)

Free an AutocryptGossipHistory.

Parameters
ptrAutocryptGossipHistory to free

Definition at line 823 of file db.c.

824 {
825  if (!ptr || !*ptr)
826  return;
827 
828  struct AutocryptGossipHistory *gh = *ptr;
829  FREE(&gh->peer_email_addr);
830  FREE(&gh->sender_email_addr);
831  FREE(&gh->email_msgid);
832  FREE(&gh->gossip_keydata);
833  FREE(ptr);
834 }
char * peer_email_addr
Definition: lib.h:144
char * sender_email_addr
Definition: lib.h:145
char * email_msgid
Definition: lib.h:146
Autocrypt gossip history.
Definition: lib.h:142
#define FREE(x)
Definition: memory.h:40
char * gossip_keydata
Definition: lib.h:148
+ Here is the caller graph for this function:

◆ mutt_autocrypt_db_gossip_history_insert()

int mutt_autocrypt_db_gossip_history_insert ( struct Address addr,
struct AutocryptGossipHistory gossip_hist 
)

Insert a gossip history into the Autocrypt database.

Parameters
addrEmail Address
gossip_histGossip history to insert
Return values
0Success
-1Error

Definition at line 843 of file db.c.

845 {
846  int rc = -1;
847 
848  struct Address *norm_addr = copy_normalize_addr(addr);
849 
851  {
852  if (sqlite3_prepare_v3(AutocryptDB,
853  "INSERT INTO gossip_history "
854  "(peer_email_addr, "
855  "sender_email_addr, "
856  "email_msgid, "
857  "timestamp, "
858  "gossip_keydata) "
859  "VALUES (?, ?, ?, ?, ?);",
860  -1, SQLITE_PREPARE_PERSISTENT,
861  &GossipHistoryInsertStmt, NULL) != SQLITE_OK)
862  {
863  goto cleanup;
864  }
865  }
866 
867  if (sqlite3_bind_text(GossipHistoryInsertStmt, 1, norm_addr->mailbox, -1,
868  SQLITE_STATIC) != SQLITE_OK)
869  {
870  goto cleanup;
871  }
872  if (sqlite3_bind_text(GossipHistoryInsertStmt, 2, gossip_hist->sender_email_addr,
873  -1, SQLITE_STATIC) != SQLITE_OK)
874  {
875  if (sqlite3_bind_text(GossipHistoryInsertStmt, 3, gossip_hist->email_msgid,
876  -1, SQLITE_STATIC) != SQLITE_OK)
877  {
878  goto cleanup;
879  }
880  }
881  if (sqlite3_bind_int64(GossipHistoryInsertStmt, 4, gossip_hist->timestamp) != SQLITE_OK)
882  goto cleanup;
883  if (sqlite3_bind_text(GossipHistoryInsertStmt, 5, gossip_hist->gossip_keydata,
884  -1, SQLITE_STATIC) != SQLITE_OK)
885  {
886  goto cleanup;
887  }
888 
889  if (sqlite3_step(GossipHistoryInsertStmt) != SQLITE_DONE)
890  goto cleanup;
891 
892  rc = 0;
893 
894 cleanup:
895  mutt_addr_free(&norm_addr);
896  sqlite3_reset(GossipHistoryInsertStmt);
897  return rc;
898 }
sqlite3 * AutocryptDB
Definition: db.c:52
An email address.
Definition: address.h:35
char * mailbox
Mailbox and host address.
Definition: address.h:38
void mutt_addr_free(struct Address **ptr)
Free a single Address.
Definition: address.c:440
char * sender_email_addr
Definition: lib.h:145
char * email_msgid
Definition: lib.h:146
static struct Address * copy_normalize_addr(struct Address *addr)
Copy a normalised Email Address.
Definition: db.c:204
static sqlite3_stmt * GossipHistoryInsertStmt
Definition: db.c:50
char * gossip_keydata
Definition: lib.h:148
sqlite3_int64 timestamp
Definition: lib.h:147
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_db_gossip_history_new()

struct AutocryptGossipHistory* mutt_autocrypt_db_gossip_history_new ( void  )

Create a new AutocryptGossipHistory.

Return values
ptrNew AutocryptGossipHistory

Definition at line 814 of file db.c.

815 {
816  return mutt_mem_calloc(1, sizeof(struct AutocryptGossipHistory));
817 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
Autocrypt gossip history.
Definition: lib.h:142
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_db_init()

int mutt_autocrypt_db_init ( struct Mailbox m,
bool  can_create 
)

Initialise the Autocrypt SQLite database.

Parameters
mMailbox
can_createIf true, the directory may be created
Return values
0Success
-1Error

Definition at line 80 of file db.c.

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 =
89  cs_subset_path(NeoMutt->sub, "autocrypt_dir");
90  if (!c_autocrypt || !c_autocrypt_dir)
91  return -1;
92 
93  struct Buffer *db_path = mutt_buffer_pool_get();
94  mutt_buffer_concat_path(db_path, c_autocrypt_dir, "autocrypt.db");
95 
96  struct stat sb;
97  if (stat(mutt_buffer_string(db_path), &sb) == 0)
98  {
99  if (sqlite3_open_v2(mutt_buffer_string(db_path), &AutocryptDB,
100  SQLITE_OPEN_READWRITE, NULL) != SQLITE_OK)
101  {
102  /* L10N: Error message if autocrypt couldn't open the SQLite database
103  for some reason. The %s is the full path of the database file. */
104  mutt_error(_("Unable to open autocrypt database %s"), mutt_buffer_string(db_path));
105  goto cleanup;
106  }
107 
109  goto cleanup;
110  }
111  else
112  {
113  if (!can_create)
114  goto cleanup;
116  goto cleanup;
117  /* Don't abort the whole init process because account creation failed */
120  }
121 
122  rc = 0;
123 
124 cleanup:
125  mutt_buffer_pool_release(&db_path);
126  return rc;
127 }
sqlite3 * AutocryptDB
Definition: db.c:52
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
#define mutt_error(...)
Definition: logging.h:88
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
Container for Accounts, Notifications.
Definition: neomutt.h:36
int mutt_autocrypt_account_init(bool prompt)
Create a new Autocrypt account.
Definition: autocrypt.c:155
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
void mutt_autocrypt_scan_mailboxes(struct Mailbox *m)
Scan mailboxes for Autocrypt headers.
Definition: autocrypt.c:933
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:194
static int autocrypt_db_create(const char *db_path)
Create an Autocrypt SQLite database.
Definition: db.c:60
size_t mutt_buffer_concat_path(struct Buffer *buf, const char *dir, const char *fname)
Join a directory name and a filename.
Definition: buffer.c:374
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
int mutt_autocrypt_schema_update(void)
Update the version number of the Autocrypt database schema.
Definition: schema.c:104
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_db_normalize_addr()

void mutt_autocrypt_db_normalize_addr ( struct Address a)

Normalise an Email Address.

Parameters
aAddress to normalise

Definition at line 167 of file db.c.

168 {
172 }
char * mailbox
Mailbox and host address.
Definition: address.h:38
bool mutt_addr_to_local(struct Address *a)
Convert an Address from Punycode.
Definition: address.c:1351
bool mutt_addr_to_intl(struct Address *a)
Convert an Address to Punycode.
Definition: address.c:1276
char * mutt_str_lower(char *str)
Convert all characters in the string to lowercase.
Definition: string.c:504
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_db_normalize_addrlist()

void mutt_autocrypt_db_normalize_addrlist ( struct AddressList *  al)

Normalise a list of Email Addresses.

Parameters
alList of Addresses to normalise

Definition at line 178 of file db.c.

179 {
181 
182  struct Address *np = NULL;
183  TAILQ_FOREACH(np, al, entries)
184  {
185  mutt_str_lower(np->mailbox);
186  }
187 
188  mutt_addrlist_to_intl(al, NULL);
189 }
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
int mutt_addrlist_to_local(struct AddressList *al)
Convert an Address list from Punycode.
Definition: address.c:1388
An email address.
Definition: address.h:35
char * mailbox
Mailbox and host address.
Definition: address.h:38
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
Definition: address.c:1305
char * mutt_str_lower(char *str)
Convert all characters in the string to lowercase.
Definition: string.c:504
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_db_peer_free()

void mutt_autocrypt_db_peer_free ( struct AutocryptPeer **  ptr)

Free an AutocryptPeer.

Parameters
ptrAutocryptPeer to free

Definition at line 530 of file db.c.

531 {
532  if (!ptr || !*ptr)
533  return;
534 
535  struct AutocryptPeer *peer = *ptr;
536  FREE(&peer->email_addr);
537  FREE(&peer->keyid);
538  FREE(&peer->keydata);
539  FREE(&peer->gossip_keyid);
540  FREE(&peer->gossip_keydata);
541  FREE(ptr);
542 }
char * keydata
Definition: lib.h:121
char * gossip_keydata
Definition: lib.h:125
Autocrypt peer.
Definition: lib.h:115
char * email_addr
Definition: lib.h:117
char * gossip_keyid
Definition: lib.h:124
#define FREE(x)
Definition: memory.h:40
char * keyid
Definition: lib.h:120
+ Here is the caller graph for this function:

◆ mutt_autocrypt_db_peer_get()

int mutt_autocrypt_db_peer_get ( struct Address addr,
struct AutocryptPeer **  peer 
)

Get peer info from the Autocrypt database.

Parameters
[in]addrEmail Address to look up
[out]peerMatching Autocrypt Peer
Return values
0Success, no matches
1Success, a match
-1Error

Definition at line 552 of file db.c.

553 {
554  int rc = -1;
555 
556  struct Address *norm_addr = copy_normalize_addr(addr);
557  *peer = NULL;
558 
559  if (!PeerGetStmt)
560  {
561  if (sqlite3_prepare_v3(AutocryptDB,
562  "SELECT "
563  "email_addr, "
564  "last_seen, "
565  "autocrypt_timestamp, "
566  "keyid, "
567  "keydata, "
568  "prefer_encrypt, "
569  "gossip_timestamp, "
570  "gossip_keyid, "
571  "gossip_keydata "
572  "FROM peer "
573  "WHERE email_addr = ?",
574  -1, SQLITE_PREPARE_PERSISTENT, &PeerGetStmt, NULL) != SQLITE_OK)
575  {
576  goto cleanup;
577  }
578  }
579 
580  if (sqlite3_bind_text(PeerGetStmt, 1, norm_addr->mailbox, -1, SQLITE_STATIC) != SQLITE_OK)
581  goto cleanup;
582 
583  int result = sqlite3_step(PeerGetStmt);
584  if (result != SQLITE_ROW)
585  {
586  if (result == SQLITE_DONE)
587  rc = 0;
588  goto cleanup;
589  }
590 
591  *peer = mutt_autocrypt_db_peer_new();
592  (*peer)->email_addr = strdup_column_text(PeerGetStmt, 0);
593  (*peer)->last_seen = sqlite3_column_int64(PeerGetStmt, 1);
594  (*peer)->autocrypt_timestamp = sqlite3_column_int64(PeerGetStmt, 2);
595  (*peer)->keyid = strdup_column_text(PeerGetStmt, 3);
596  (*peer)->keydata = strdup_column_text(PeerGetStmt, 4);
597  (*peer)->prefer_encrypt = sqlite3_column_int(PeerGetStmt, 5);
598  (*peer)->gossip_timestamp = sqlite3_column_int64(PeerGetStmt, 6);
599  (*peer)->gossip_keyid = strdup_column_text(PeerGetStmt, 7);
600  (*peer)->gossip_keydata = strdup_column_text(PeerGetStmt, 8);
601 
602  rc = 1;
603 
604 cleanup:
605  mutt_addr_free(&norm_addr);
606  sqlite3_reset(PeerGetStmt);
607  return rc;
608 }
sqlite3 * AutocryptDB
Definition: db.c:52
struct AutocryptPeer * mutt_autocrypt_db_peer_new(void)
Create a new AutocryptPeer.
Definition: db.c:521
An email address.
Definition: address.h:35
char * mailbox
Mailbox and host address.
Definition: address.h:38
void mutt_addr_free(struct Address **ptr)
Free a single Address.
Definition: address.c:440
static struct Address * copy_normalize_addr(struct Address *addr)
Copy a normalised Email Address.
Definition: db.c:204
static sqlite3_stmt * PeerGetStmt
Definition: db.c:46
static char * strdup_column_text(sqlite3_stmt *stmt, int index)
Copy a string from the database.
Definition: db.c:227
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_db_peer_history_free()

void mutt_autocrypt_db_peer_history_free ( struct AutocryptPeerHistory **  ptr)

Free an AutocryptPeerHistory.

Parameters
ptrAutocryptPeerHistory to free

Definition at line 745 of file db.c.

746 {
747  if (!ptr || !*ptr)
748  return;
749 
750  struct AutocryptPeerHistory *ph = *ptr;
751  FREE(&ph->peer_email_addr);
752  FREE(&ph->email_msgid);
753  FREE(&ph->keydata);
754  FREE(ptr);
755 }
char * email_msgid
Definition: lib.h:134
Autocrypt peer history.
Definition: lib.h:131
char * keydata
Definition: lib.h:136
#define FREE(x)
Definition: memory.h:40
char * peer_email_addr
Definition: lib.h:133
+ Here is the caller graph for this function:

◆ mutt_autocrypt_db_peer_history_insert()

int mutt_autocrypt_db_peer_history_insert ( struct Address addr,
struct AutocryptPeerHistory peerhist 
)

Insert peer history into the Autocrypt database.

Parameters
addrEmail Address
peerhistPeer history to insert
Return values
0Success
-1Error

Definition at line 764 of file db.c.

766 {
767  int rc = -1;
768 
769  struct Address *norm_addr = copy_normalize_addr(addr);
770 
772  {
773  if (sqlite3_prepare_v3(AutocryptDB,
774  "INSERT INTO peer_history "
775  "(peer_email_addr, "
776  "email_msgid, "
777  "timestamp, "
778  "keydata) "
779  "VALUES (?, ?, ?, ?);",
780  -1, SQLITE_PREPARE_PERSISTENT,
781  &PeerHistoryInsertStmt, NULL) != SQLITE_OK)
782  {
783  goto cleanup;
784  }
785  }
786 
787  if (sqlite3_bind_text(PeerHistoryInsertStmt, 1, norm_addr->mailbox, -1, SQLITE_STATIC) != SQLITE_OK)
788  goto cleanup;
789  if (sqlite3_bind_text(PeerHistoryInsertStmt, 2, peerhist->email_msgid, -1,
790  SQLITE_STATIC) != SQLITE_OK)
791  {
792  goto cleanup;
793  }
794  if (sqlite3_bind_int64(PeerHistoryInsertStmt, 3, peerhist->timestamp) != SQLITE_OK)
795  goto cleanup;
796  if (sqlite3_bind_text(PeerHistoryInsertStmt, 4, peerhist->keydata, -1, SQLITE_STATIC) != SQLITE_OK)
797  goto cleanup;
798 
799  if (sqlite3_step(PeerHistoryInsertStmt) != SQLITE_DONE)
800  goto cleanup;
801 
802  rc = 0;
803 
804 cleanup:
805  mutt_addr_free(&norm_addr);
806  sqlite3_reset(PeerHistoryInsertStmt);
807  return rc;
808 }
sqlite3 * AutocryptDB
Definition: db.c:52
char * email_msgid
Definition: lib.h:134
sqlite3_int64 timestamp
Definition: lib.h:135
An email address.
Definition: address.h:35
char * mailbox
Mailbox and host address.
Definition: address.h:38
void mutt_addr_free(struct Address **ptr)
Free a single Address.
Definition: address.c:440
static struct Address * copy_normalize_addr(struct Address *addr)
Copy a normalised Email Address.
Definition: db.c:204
char * keydata
Definition: lib.h:136
static sqlite3_stmt * PeerHistoryInsertStmt
Definition: db.c:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_db_peer_history_new()

struct AutocryptPeerHistory* mutt_autocrypt_db_peer_history_new ( void  )

Create a new AutocryptPeerHistory.

Return values
ptrNew AutocryptPeerHistory

Definition at line 736 of file db.c.

737 {
738  return mutt_mem_calloc(1, sizeof(struct AutocryptPeerHistory));
739 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
Autocrypt peer history.
Definition: lib.h:131
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_db_peer_insert()

int mutt_autocrypt_db_peer_insert ( struct Address addr,
struct AutocryptPeer peer 
)

Insert a peer into the Autocrypt database.

Parameters
addrEmail Address
peerAutocryptPeer to insert
Return values
0Success
-1Error

Definition at line 617 of file db.c.

618 {
619  int rc = -1;
620  struct Address *norm_addr = NULL;
621 
622  norm_addr = copy_normalize_addr(addr);
623 
624  if (!PeerInsertStmt)
625  {
626  if (sqlite3_prepare_v3(AutocryptDB,
627  "INSERT INTO peer "
628  "(email_addr, "
629  "last_seen, "
630  "autocrypt_timestamp, "
631  "keyid, "
632  "keydata, "
633  "prefer_encrypt, "
634  "gossip_timestamp, "
635  "gossip_keyid, "
636  "gossip_keydata) "
637  "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);",
638  -1, SQLITE_PREPARE_PERSISTENT, &PeerInsertStmt, NULL) != SQLITE_OK)
639  {
640  goto cleanup;
641  }
642  }
643 
644  if (sqlite3_bind_text(PeerInsertStmt, 1, norm_addr->mailbox, -1, SQLITE_STATIC) != SQLITE_OK)
645  goto cleanup;
646  if (sqlite3_bind_int64(PeerInsertStmt, 2, peer->last_seen) != SQLITE_OK)
647  goto cleanup;
648  if (sqlite3_bind_int64(PeerInsertStmt, 3, peer->autocrypt_timestamp) != SQLITE_OK)
649  goto cleanup;
650  if (sqlite3_bind_text(PeerInsertStmt, 4, peer->keyid, -1, SQLITE_STATIC) != SQLITE_OK)
651  goto cleanup;
652  if (sqlite3_bind_text(PeerInsertStmt, 5, peer->keydata, -1, SQLITE_STATIC) != SQLITE_OK)
653  goto cleanup;
654  if (sqlite3_bind_int(PeerInsertStmt, 6, peer->prefer_encrypt) != SQLITE_OK)
655  goto cleanup;
656  if (sqlite3_bind_int64(PeerInsertStmt, 7, peer->gossip_timestamp) != SQLITE_OK)
657  goto cleanup;
658  if (sqlite3_bind_text(PeerInsertStmt, 8, peer->gossip_keyid, -1, SQLITE_STATIC) != SQLITE_OK)
659  goto cleanup;
660  if (sqlite3_bind_text(PeerInsertStmt, 9, peer->gossip_keydata, -1, SQLITE_STATIC) != SQLITE_OK)
661  goto cleanup;
662 
663  if (sqlite3_step(PeerInsertStmt) != SQLITE_DONE)
664  goto cleanup;
665 
666  rc = 0;
667 
668 cleanup:
669  mutt_addr_free(&norm_addr);
670  sqlite3_reset(PeerInsertStmt);
671  return rc;
672 }
sqlite3 * AutocryptDB
Definition: db.c:52
char * keydata
Definition: lib.h:121
An email address.
Definition: address.h:35
char * mailbox
Mailbox and host address.
Definition: address.h:38
void mutt_addr_free(struct Address **ptr)
Free a single Address.
Definition: address.c:440
char * gossip_keydata
Definition: lib.h:125
sqlite3_int64 gossip_timestamp
Definition: lib.h:123
sqlite3_int64 autocrypt_timestamp
Definition: lib.h:119
static struct Address * copy_normalize_addr(struct Address *addr)
Copy a normalised Email Address.
Definition: db.c:204
sqlite3_int64 last_seen
Definition: lib.h:118
char * gossip_keyid
Definition: lib.h:124
bool prefer_encrypt
false = nopref, true = mutual
Definition: lib.h:122
static sqlite3_stmt * PeerInsertStmt
Definition: db.c:47
char * keyid
Definition: lib.h:120
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_db_peer_new()

struct AutocryptPeer* mutt_autocrypt_db_peer_new ( void  )

Create a new AutocryptPeer.

Return values
ptrNew AutocryptPeer

Definition at line 521 of file db.c.

522 {
523  return mutt_mem_calloc(1, sizeof(struct AutocryptPeer));
524 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
Autocrypt peer.
Definition: lib.h:115
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_db_peer_update()

int mutt_autocrypt_db_peer_update ( struct AutocryptPeer peer)

Update the peer info in an Autocrypt database.

Parameters
peerAutocryptPeer to update
Return values
0Success
-1Error

Definition at line 680 of file db.c.

681 {
682  int rc = -1;
683 
684  if (!PeerUpdateStmt)
685  {
686  if (sqlite3_prepare_v3(AutocryptDB,
687  "UPDATE peer SET "
688  "last_seen = ?, "
689  "autocrypt_timestamp = ?, "
690  "keyid = ?, "
691  "keydata = ?, "
692  "prefer_encrypt = ?, "
693  "gossip_timestamp = ?, "
694  "gossip_keyid = ?, "
695  "gossip_keydata = ? "
696  "WHERE email_addr = ?;",
697  -1, SQLITE_PREPARE_PERSISTENT, &PeerUpdateStmt, NULL) != SQLITE_OK)
698  {
699  goto cleanup;
700  }
701  }
702 
703  if (sqlite3_bind_int64(PeerUpdateStmt, 1, peer->last_seen) != SQLITE_OK)
704  goto cleanup;
705  if (sqlite3_bind_int64(PeerUpdateStmt, 2, peer->autocrypt_timestamp) != SQLITE_OK)
706  goto cleanup;
707  if (sqlite3_bind_text(PeerUpdateStmt, 3, peer->keyid, -1, SQLITE_STATIC) != SQLITE_OK)
708  goto cleanup;
709  if (sqlite3_bind_text(PeerUpdateStmt, 4, peer->keydata, -1, SQLITE_STATIC) != SQLITE_OK)
710  goto cleanup;
711  if (sqlite3_bind_int(PeerUpdateStmt, 5, peer->prefer_encrypt) != SQLITE_OK)
712  goto cleanup;
713  if (sqlite3_bind_int64(PeerUpdateStmt, 6, peer->gossip_timestamp) != SQLITE_OK)
714  goto cleanup;
715  if (sqlite3_bind_text(PeerUpdateStmt, 7, peer->gossip_keyid, -1, SQLITE_STATIC) != SQLITE_OK)
716  goto cleanup;
717  if (sqlite3_bind_text(PeerUpdateStmt, 8, peer->gossip_keydata, -1, SQLITE_STATIC) != SQLITE_OK)
718  goto cleanup;
719  if (sqlite3_bind_text(PeerUpdateStmt, 9, peer->email_addr, -1, SQLITE_STATIC) != SQLITE_OK)
720  goto cleanup;
721 
722  if (sqlite3_step(PeerUpdateStmt) != SQLITE_DONE)
723  goto cleanup;
724 
725  rc = 0;
726 
727 cleanup:
728  sqlite3_reset(PeerUpdateStmt);
729  return rc;
730 }
sqlite3 * AutocryptDB
Definition: db.c:52
char * keydata
Definition: lib.h:121
char * gossip_keydata
Definition: lib.h:125
sqlite3_int64 gossip_timestamp
Definition: lib.h:123
sqlite3_int64 autocrypt_timestamp
Definition: lib.h:119
char * email_addr
Definition: lib.h:117
sqlite3_int64 last_seen
Definition: lib.h:118
char * gossip_keyid
Definition: lib.h:124
static sqlite3_stmt * PeerUpdateStmt
Definition: db.c:48
bool prefer_encrypt
false = nopref, true = mutual
Definition: lib.h:122
char * keyid
Definition: lib.h:120
+ Here is the caller graph for this function:

◆ mutt_autocrypt_schema_init()

int mutt_autocrypt_schema_init ( void  )

Set up an Autocrypt database.

Definition at line 38 of file schema.c.

39 {
40  char *errmsg = NULL;
41 
42  const char *schema = "BEGIN TRANSACTION; "
43 
44  "CREATE TABLE account ("
45  "email_addr text primary key not null, "
46  "keyid text, "
47  "keydata text, "
48  "prefer_encrypt int, "
49  "enabled int);"
50 
51  "CREATE TABLE peer ("
52  "email_addr text primary key not null, "
53  "last_seen int, "
54  "autocrypt_timestamp int, "
55  "keyid text, "
56  "keydata text, "
57  "prefer_encrypt int, "
58  "gossip_timestamp int, "
59  "gossip_keyid text, "
60  "gossip_keydata text);"
61 
62  "CREATE TABLE peer_history ("
63  "peer_email_addr text not null, "
64  "email_msgid text, "
65  "timestamp int, "
66  "keydata text);"
67 
68  "CREATE INDEX peer_history_email "
69  "ON peer_history ("
70  "peer_email_addr);"
71 
72  "CREATE TABLE gossip_history ("
73  "peer_email_addr text not null, "
74  "sender_email_addr text, "
75  "email_msgid text, "
76  "timestamp int, "
77  "gossip_keydata text);"
78 
79  "CREATE INDEX gossip_history_email "
80  "ON gossip_history ("
81  "peer_email_addr);"
82 
83  "CREATE TABLE schema ("
84  "version int);"
85 
86  "INSERT into schema (version) values (1);"
87 
88  "COMMIT TRANSACTION";
89 
90  if (sqlite3_exec(AutocryptDB, schema, NULL, NULL, &errmsg) != SQLITE_OK)
91  {
92  mutt_debug(LL_DEBUG1, "mutt_autocrypt_schema_init() returned %s\n", errmsg);
93  sqlite3_free(errmsg);
94  return -1;
95  }
96  return 0;
97 }
sqlite3 * AutocryptDB
Definition: db.c:52
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Log at debug level 1.
Definition: logging.h:40
+ Here is the caller graph for this function:

◆ mutt_autocrypt_schema_update()

int mutt_autocrypt_schema_update ( void  )

Update the version number of the Autocrypt database schema.

Return values
0Success
-1Error

Definition at line 104 of file schema.c.

105 {
106  sqlite3_stmt *stmt = NULL;
107  int rc = -1;
108 
109  if (sqlite3_prepare_v2(AutocryptDB, "SELECT version FROM schema;", -1, &stmt, NULL) != SQLITE_OK)
110  goto cleanup;
111 
112  if (sqlite3_step(stmt) != SQLITE_ROW)
113  goto cleanup;
114 
115  int version = sqlite3_column_int(stmt, 0);
116 
117  if (version > 1)
118  {
119  /* L10N: The autocrypt database keeps track of schema version numbers.
120  This error occurs if the version number is too high.
121  Presumably because this is an old version of NeoMutt and the
122  database was upgraded by a future version. */
123  mutt_error(_("Autocrypt database version is too new"));
124  goto cleanup;
125  }
126 
127  /* TODO: schema version upgrades go here.
128  * Bump one by one, each update inside a transaction. */
129 
130  rc = 0;
131 
132 cleanup:
133  sqlite3_finalize(stmt);
134  return rc;
135 }
sqlite3 * AutocryptDB
Definition: db.c:52
#define mutt_error(...)
Definition: logging.h:88
#define _(a)
Definition: message.h:28
+ Here is the caller graph for this function:

◆ mutt_autocrypt_gpgme_create_key()

int mutt_autocrypt_gpgme_create_key ( struct Address addr,
struct Buffer keyid,
struct Buffer keydata 
)

Create a GPGME key.

Parameters
addrEmail Address
keyidKey id
keydataKey data
Return values
0Success
-1Error

Definition at line 155 of file gpgme.c.

157 {
158  int rc = -1;
159  gpgme_ctx_t ctx = NULL;
160  gpgme_genkey_result_t keyresult = NULL;
161  gpgme_key_t primary_key = NULL;
162  char buf[1024] = { 0 };
163 
164  /* GPGME says addresses should not be in idna form */
165  struct Address *copy = mutt_addr_copy(addr);
166  mutt_addr_to_local(copy);
167  mutt_addr_write(buf, sizeof(buf), copy, false);
168  mutt_addr_free(&copy);
169 
170  if (create_gpgme_context(&ctx))
171  goto cleanup;
172 
173  /* L10N: Message displayed just before a GPG key is generated for a created
174  autocrypt account. */
175  mutt_message(_("Generating autocrypt key..."));
176 
177  /* Primary key */
178  gpgme_error_t err = gpgme_op_createkey(ctx, buf, "ed25519", 0, 0, NULL,
179  GPGME_CREATE_NOPASSWD | GPGME_CREATE_FORCE |
180  GPGME_CREATE_NOEXPIRE);
181  if (err)
182  {
183  /* L10N: GPGME was unable to generate a key for some reason.
184  %s is the error message returned by GPGME. */
185  mutt_error(_("Error creating autocrypt key: %s"), gpgme_strerror(err));
186  goto cleanup;
187  }
188  keyresult = gpgme_op_genkey_result(ctx);
189  if (!keyresult->fpr)
190  goto cleanup;
191  mutt_buffer_strcpy(keyid, keyresult->fpr);
192  mutt_debug(LL_DEBUG1, "Generated key with id %s\n", mutt_buffer_string(keyid));
193 
194  /* Get gpgme_key_t to create the secondary key and export keydata */
195  err = gpgme_get_key(ctx, mutt_buffer_string(keyid), &primary_key, 0);
196  if (err)
197  goto cleanup;
198 
199  /* Secondary key */
200  err = gpgme_op_createsubkey(ctx, primary_key, "cv25519", 0, 0,
201  GPGME_CREATE_NOPASSWD | GPGME_CREATE_NOEXPIRE);
202  if (err)
203  {
204  mutt_error(_("Error creating autocrypt key: %s"), gpgme_strerror(err));
205  goto cleanup;
206  }
207 
208  /* get keydata */
209  if (export_keydata(ctx, primary_key, keydata))
210  goto cleanup;
211  mutt_debug(LL_DEBUG1, "key has keydata *%s*\n", mutt_buffer_string(keydata));
212 
213  rc = 0;
214 
215 cleanup:
216  gpgme_key_unref(primary_key);
217  gpgme_release(ctx);
218  return rc;
219 }
#define mutt_error(...)
Definition: logging.h:88
static int export_keydata(gpgme_ctx_t ctx, gpgme_key_t key, struct Buffer *keydata)
Export Key data from GPGME into a Buffer.
Definition: gpgme.c:81
#define _(a)
Definition: message.h:28
An email address.
Definition: address.h:35
struct Address * mutt_addr_copy(const struct Address *addr)
Copy the real address.
Definition: address.c:716
void mutt_addr_free(struct Address **ptr)
Free a single Address.
Definition: address.c:440
bool mutt_addr_to_local(struct Address *a)
Convert an Address from Punycode.
Definition: address.c:1351
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
static int create_gpgme_context(gpgme_ctx_t *ctx)
Create a GPGME context.
Definition: gpgme.c:48
size_t mutt_addr_write(char *buf, size_t buflen, struct Address *addr, bool display)
Write a single Address to a buffer.
Definition: address.c:1025
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
Log at debug level 1.
Definition: logging.h:40
#define mutt_message(...)
Definition: logging.h:87
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_gpgme_import_key()

int mutt_autocrypt_gpgme_import_key ( const char *  keydata,
struct Buffer keyid 
)

Read a key from GPGME.

Parameters
keydataBuffer for key data
keyidBuffer for key id
Return values
0Success
-1Error

Definition at line 316 of file gpgme.c.

317 {
318  int rc = -1;
319  gpgme_ctx_t ctx = NULL;
320  gpgme_data_t dh = NULL;
321 
322  if (create_gpgme_context(&ctx))
323  goto cleanup;
324 
325  struct Buffer *raw_keydata = mutt_buffer_pool_get();
326  if (!mutt_b64_buffer_decode(raw_keydata, keydata))
327  goto cleanup;
328 
329  if (gpgme_data_new_from_mem(&dh, mutt_buffer_string(raw_keydata),
330  mutt_buffer_len(raw_keydata), 0))
331  {
332  goto cleanup;
333  }
334 
335  if (gpgme_op_import(ctx, dh))
336  goto cleanup;
337 
338  gpgme_import_result_t result = gpgme_op_import_result(ctx);
339  if (!result->imports || !result->imports->fpr)
340  goto cleanup;
341  mutt_buffer_strcpy(keyid, result->imports->fpr);
342 
343  rc = 0;
344 
345 cleanup:
346  gpgme_data_release(dh);
347  gpgme_release(ctx);
348  mutt_buffer_pool_release(&raw_keydata);
349  return rc;
350 }
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
String manipulation buffer.
Definition: buffer.h:33
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
static int create_gpgme_context(gpgme_ctx_t *ctx)
Create a GPGME context.
Definition: gpgme.c:48
size_t mutt_buffer_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:356
int mutt_b64_buffer_decode(struct Buffer *buf, const char *in)
Convert null-terminated base64 string to raw bytes.
Definition: base64.c:209
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_gpgme_init()

int mutt_autocrypt_gpgme_init ( void  )

Initialise GPGME.

Definition at line 67 of file gpgme.c.

68 {
70  return 0;
71 }
void pgp_gpgme_init(void)
Implements CryptModuleSpecs::init() -.
Definition: crypt_gpgme.c:4164
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_gpgme_is_valid_key()

bool mutt_autocrypt_gpgme_is_valid_key ( const char *  keyid)

Is a key id valid?

Parameters
keyidKey id to check
Return values
trueKey id is valid

Definition at line 357 of file gpgme.c.

358 {
359  bool rc = false;
360  gpgme_ctx_t ctx = NULL;
361  gpgme_key_t key = NULL;
362 
363  if (!keyid)
364  return false;
365 
366  if (create_gpgme_context(&ctx))
367  goto cleanup;
368 
369  if (gpgme_get_key(ctx, keyid, &key, 0))
370  goto cleanup;
371 
372  rc = true;
373  if (key->revoked || key->expired || key->disabled || key->invalid || !key->can_encrypt)
374  rc = false;
375 
376 cleanup:
377  gpgme_key_unref(key);
378  gpgme_release(ctx);
379  return rc;
380 }
static int create_gpgme_context(gpgme_ctx_t *ctx)
Create a GPGME context.
Definition: gpgme.c:48
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_gpgme_select_key()

int mutt_autocrypt_gpgme_select_key ( struct Buffer keyid,
struct Buffer keydata 
)

Select a Autocrypt key.

Parameters
[in]keyidKey id to select
[out]keydataBuffer for resulting Key data
Return values
0Success
-1Error

Definition at line 228 of file gpgme.c.

229 {
230  int rc = -1;
231  gpgme_ctx_t ctx = NULL;
232  gpgme_key_t key = NULL;
233 
234  OptAutocryptGpgme = true;
235  if (mutt_gpgme_select_secret_key(keyid))
236  goto cleanup;
237 
238  if (create_gpgme_context(&ctx))
239  goto cleanup;
240 
241  if (gpgme_get_key(ctx, mutt_buffer_string(keyid), &key, 0))
242  goto cleanup;
243 
244  if (key->revoked || key->expired || key->disabled || key->invalid ||
245  !key->can_encrypt || !key->can_sign)
246  {
247  /* L10N: After selecting a key for an autocrypt account,
248  this is displayed if the key was revoked/expired/disabled/invalid
249  or can't be used for both signing and encryption.
250  %s is the key fingerprint. */
251  mutt_error(_("The key %s is not usable for autocrypt"), mutt_buffer_string(keyid));
252  goto cleanup;
253  }
254 
255  if (export_keydata(ctx, key, keydata))
256  goto cleanup;
257 
258  rc = 0;
259 
260 cleanup:
261  OptAutocryptGpgme = false;
262  gpgme_key_unref(key);
263  gpgme_release(ctx);
264  return rc;
265 }
#define mutt_error(...)
Definition: logging.h:88
static int export_keydata(gpgme_ctx_t ctx, gpgme_key_t key, struct Buffer *keydata)
Export Key data from GPGME into a Buffer.
Definition: gpgme.c:81
#define _(a)
Definition: message.h:28
WHERE bool OptAutocryptGpgme
(pseudo) use Autocrypt context inside ncrypt/crypt_gpgme.c
Definition: options.h:33
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
static int create_gpgme_context(gpgme_ctx_t *ctx)
Create a GPGME context.
Definition: gpgme.c:48
int mutt_gpgme_select_secret_key(struct Buffer *keyid)
Select a private Autocrypt key for a new account.
Definition: crypt_gpgme.c:3976
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_autocrypt_gpgme_select_or_create_key()

int mutt_autocrypt_gpgme_select_or_create_key ( struct Address addr,
struct Buffer keyid,
struct Buffer keydata 
)

Ask the user to select or create an Autocrypt key.

Parameters
addrEmail Address
keyidKey id
keydataKey data
Return values
0Success
-1Error

Definition at line 275 of file gpgme.c.

277 {
278  int rc = -1;
279 
280  /* L10N: During autocrypt account creation, this prompt asks the
281  user whether they want to create a new GPG key for the account,
282  or select an existing account from the keyring. */
283  const char *prompt = _("(c)reate new, or (s)elect existing GPG key?");
284  /* L10N: The letters corresponding to the
285  "(c)reate new, or (s)elect existing GPG key?" prompt. */
286  const char *letters = _("cs");
287 
288  int choice = mutt_multi_choice(prompt, letters);
289  switch (choice)
290  {
291  case 2: /* select existing */
292  rc = mutt_autocrypt_gpgme_select_key(keyid, keydata);
293  if (rc == 0)
294  break;
295 
296  /* L10N: During autocrypt account creation, if selecting an existing key fails
297  for some reason, we prompt to see if they want to create a key instead. */
298  if (mutt_yesorno(_("Create a new GPG key for this account, instead?"), MUTT_YES) == MUTT_NO)
299  break;
300  /* fallthrough */
301 
302  case 1: /* create new */
303  rc = mutt_autocrypt_gpgme_create_key(addr, keyid, keydata);
304  }
305 
306  return rc;
307 }
int mutt_autocrypt_gpgme_create_key(struct Address *addr, struct Buffer *keyid, struct Buffer *keydata)
Create a GPGME key.
Definition: gpgme.c:155
#define _(a)
Definition: message.h:28
int mutt_autocrypt_gpgme_select_key(struct Buffer *keyid, struct Buffer *keydata)
Select a Autocrypt key.
Definition: gpgme.c:228
int mutt_multi_choice(const char *prompt, const char *letters)
Offer the user a multiple choice question.
Definition: question.c:49
enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def)
Ask the user a Yes/No question.
Definition: question.c:180
User answered &#39;No&#39;, or assume &#39;No&#39;.
Definition: quad.h:38
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ AutocryptDB

sqlite3* AutocryptDB

Definition at line 52 of file db.c.