* @retval 0 Success
* @retval -1 Error
*/
-static int autocrypt_dir_init(int can_create)
+static int autocrypt_dir_init(bool can_create)
{
int rc = 0;
struct stat sb;
- struct Buffer *prompt = NULL;
if (!stat(C_AutocryptDir, &sb))
return 0;
if (!can_create)
return -1;
- prompt = mutt_buffer_pool_get();
+ struct Buffer *prompt = mutt_buffer_pool_get();
/* L10N:
%s is a directory. Mutt is looking for a directory it needs
for some reason (e.g. autocrypt, header cache, bcache), but it
* @retval 0 Success
* @retval -1 Error
*/
-int mutt_autocrypt_init(int can_create)
+int mutt_autocrypt_init(bool can_create)
{
if (AutocryptDB)
return 0;
* This is used the first time autocrypt is initialized,
* and in the account menu.
*/
-int mutt_autocrypt_account_init(int prompt)
+int mutt_autocrypt_account_init(bool prompt)
{
struct Address *addr = NULL;
struct AutocryptAccount *account = NULL;
bool done = false;
int rc = -1;
- int prefer_encrypt = 0;
+ bool prefer_encrypt = false;
if (prompt)
{
autocrypt account. This will generate a key and add a record
to the database for use in autocrypt operations.
*/
- if (mutt_edit_address(&al, _("Autocrypt account address: "), 0) != 0)
+ if (mutt_edit_address(&al, _("Autocrypt account address: "), false) != 0)
goto cleanup;
addr = TAILQ_FIRST(&al);
will be required to enable encryption manually.
*/
if (mutt_yesorno(_("Prefer encryption?"), MUTT_NO) == MUTT_YES)
- prefer_encrypt = 1;
+ prefer_encrypt = true;
if (mutt_autocrypt_db_account_insert(addr, mutt_b2s(keyid), mutt_b2s(keydata), prefer_encrypt))
goto cleanup;
*/
int mutt_autocrypt_process_autocrypt_header(struct Email *e, struct Envelope *env)
{
- struct AutocryptHeader *ac_hdr, *valid_ac_hdr = NULL;
+ struct AutocryptHeader *valid_ac_hdr = NULL;
struct timeval now;
struct AutocryptPeer *peer = NULL;
struct AutocryptPeerHistory *peerhist = NULL;
struct Buffer *keyid = NULL;
- int update_db = 0, insert_db = 0, insert_db_history = 0, import_gpg = 0;
+ bool update_db = false, insert_db = false, insert_db_history = false, import_gpg = false;
int rc = -1;
if (!C_Autocrypt)
return 0;
- if (mutt_autocrypt_init(0))
+ if (mutt_autocrypt_init(false))
return -1;
if (!e || !e->content || !env)
if (e->date_sent > (now.tv_sec + 7 * 24 * 60 * 60))
return 0;
- for (ac_hdr = env->autocrypt; ac_hdr; ac_hdr = ac_hdr->next)
+ for (struct AutocryptHeader *ac_hdr = env->autocrypt; ac_hdr; ac_hdr = ac_hdr->next)
{
if (ac_hdr->invalid)
continue;
if (e->date_sent > peer->last_seen)
{
- update_db = 1;
+ update_db = true;
peer->last_seen = e->date_sent;
}
if (valid_ac_hdr)
{
- update_db = 1;
+ update_db = true;
peer->autocrypt_timestamp = e->date_sent;
peer->prefer_encrypt = valid_ac_hdr->prefer_encrypt;
if (mutt_str_strcmp(peer->keydata, valid_ac_hdr->keydata) != 0)
{
- import_gpg = 1;
- insert_db_history = 1;
+ import_gpg = true;
+ insert_db_history = true;
mutt_str_replace(&peer->keydata, valid_ac_hdr->keydata);
}
}
}
else if (valid_ac_hdr)
{
- import_gpg = 1;
- insert_db = 1;
- insert_db_history = 1;
+ import_gpg = true;
+ insert_db = true;
+ insert_db_history = true;
}
if (!(import_gpg || insert_db || update_db))
*/
int mutt_autocrypt_process_gossip_header(struct Email *e, struct Envelope *prot_headers)
{
- struct Envelope *env;
- struct AutocryptHeader *ac_hdr;
struct timeval now;
struct AutocryptPeer *peer = NULL;
struct AutocryptGossipHistory *gossip_hist = NULL;
- struct Address *peer_addr;
+ struct Address *peer_addr = NULL;
struct Address ac_hdr_addr = { 0 };
- struct Buffer *keyid = NULL;
- int update_db = 0, insert_db = 0, insert_db_history = 0, import_gpg = 0;
+ bool update_db = false, insert_db = false, insert_db_history = false, import_gpg = false;
int rc = -1;
if (!C_Autocrypt)
return 0;
- if (mutt_autocrypt_init(0))
+ if (mutt_autocrypt_init(false))
return -1;
if (!e || !e->env || !prot_headers)
return 0;
- env = e->env;
+ struct Envelope *env = e->env;
struct Address *from = TAILQ_FIRST(&env->from);
if (!from)
/* Ignore emails that appear to be more than a week in the future,
* since they can block all future updates during that time. */
gettimeofday(&now, NULL);
- if (e->date_sent > (now.tv_sec + 7 * 24 * 60 * 60))
+ if (e->date_sent > (now.tv_sec + (7 * 24 * 60 * 60)))
return 0;
- keyid = mutt_buffer_pool_get();
+ struct Buffer *keyid = mutt_buffer_pool_get();
struct AddressList recips = TAILQ_HEAD_INITIALIZER(recips);
mutt_addrlist_copy(&recips, &env->reply_to, false);
mutt_autocrypt_db_normalize_addrlist(&recips);
- for (ac_hdr = prot_headers->autocrypt_gossip; ac_hdr; ac_hdr = ac_hdr->next)
+ for (struct AutocryptHeader *ac_hdr = prot_headers->autocrypt_gossip; ac_hdr;
+ ac_hdr = ac_hdr->next)
{
if (ac_hdr->invalid)
continue;
/* normalize for comparison against recipient list */
mutt_str_replace(&ac_hdr_addr.mailbox, ac_hdr->addr);
- ac_hdr_addr.is_intl = 1;
- ac_hdr_addr.intl_checked = 1;
+ ac_hdr_addr.is_intl = true;
+ ac_hdr_addr.intl_checked = true;
mutt_autocrypt_db_normalize_addr(&ac_hdr_addr);
/* Check to make sure the address is in the recipient list. Since the
continue;
}
- update_db = 1;
+ update_db = true;
peer->gossip_timestamp = e->date_sent;
/* This is slightly different from the autocrypt 1.1 spec.
* Avoid setting an empty peer.gossip_keydata with a value that matches
if ((peer->gossip_keydata && (mutt_str_strcmp(peer->gossip_keydata, ac_hdr->keydata) != 0)) ||
(!peer->gossip_keydata && (mutt_str_strcmp(peer->keydata, ac_hdr->keydata) != 0)))
{
- import_gpg = 1;
- insert_db_history = 1;
+ import_gpg = true;
+ insert_db_history = true;
mutt_str_replace(&peer->gossip_keydata, ac_hdr->keydata);
}
}
else
{
- import_gpg = 1;
- insert_db = 1;
- insert_db_history = 1;
+ import_gpg = true;
+ insert_db = true;
+ insert_db_history = true;
}
if (!peer)
mutt_autocrypt_db_peer_free(&peer);
mutt_autocrypt_db_gossip_history_free(&gossip_hist);
mutt_buffer_reset(keyid);
- update_db = insert_db = insert_db_history = import_gpg = 0;
+ update_db = false;
+ insert_db = false;
+ insert_db_history = false;
+ import_gpg = false;
}
rc = 0;
struct AutocryptAccount *account = NULL;
struct AutocryptPeer *peer = NULL;
struct Address *recip = NULL;
- int all_encrypt = 1, has_discourage = 0;
- struct Buffer *keylist_buf = NULL;
- const char *matching_key;
+ bool all_encrypt = true, has_discourage = false;
+ const char *matching_key = NULL;
- if (!C_Autocrypt || mutt_autocrypt_init(0) || !e)
+ if (!C_Autocrypt || mutt_autocrypt_init(false) || !e)
return AUTOCRYPT_REC_OFF;
struct Address *from = TAILQ_FIRST(&e->env->from);
if (!account->enabled)
goto cleanup;
- keylist_buf = mutt_buffer_pool_get();
+ struct Buffer *keylist_buf = mutt_buffer_pool_get();
mutt_buffer_addstr(keylist_buf, account->keyid);
struct AddressList recips = TAILQ_HEAD_INITIALIZER(recips);
matching_key = peer->keyid;
if (!(peer->last_seen && peer->autocrypt_timestamp) ||
- (peer->last_seen - peer->autocrypt_timestamp > 35 * 24 * 60 * 60))
+ (peer->last_seen - peer->autocrypt_timestamp > (35 * 24 * 60 * 60)))
{
- has_discourage = 1;
- all_encrypt = 0;
+ has_discourage = true;
+ all_encrypt = false;
}
if (!account->prefer_encrypt || !peer->prefer_encrypt)
- all_encrypt = 0;
+ all_encrypt = false;
}
else if (mutt_autocrypt_gpgme_is_valid_key(peer->gossip_keyid))
{
matching_key = peer->gossip_keyid;
- has_discourage = 1;
- all_encrypt = 0;
+ has_discourage = true;
+ all_encrypt = false;
}
else
{
int rc = -1;
struct AutocryptAccount *account = NULL;
- if (!C_Autocrypt || mutt_autocrypt_init(0) || !e)
+ if (!C_Autocrypt || mutt_autocrypt_init(false) || !e)
return -1;
struct Address *from = TAILQ_FIRST(&e->env->from);
* @param keydata Raw Autocrypt data
*/
static void write_autocrypt_header_line(FILE *fp, const char *addr,
- int prefer_encrypt, const char *keydata)
+ bool prefer_encrypt, const char *keydata)
{
- int count = 0;
-
fprintf(fp, "addr=%s; ", addr);
if (prefer_encrypt)
fputs("prefer-encrypt=mutual; ", fp);
while (*keydata)
{
- count = 0;
+ int count = 0;
fputs("\t", fp);
while (*keydata && count < 75)
{
int rc = -1;
struct AutocryptAccount *account = NULL;
- if (!C_Autocrypt || mutt_autocrypt_init(0) || !env)
+ if (!C_Autocrypt || mutt_autocrypt_init(false) || !env)
return -1;
struct Address *from = TAILQ_FIRST(&env->from);
*/
int mutt_autocrypt_write_gossip_headers(struct Envelope *env, FILE *fp)
{
- struct AutocryptHeader *gossip;
-
- if (!C_Autocrypt || mutt_autocrypt_init(0) || !env)
+ if (!C_Autocrypt || mutt_autocrypt_init(false) || !env)
return -1;
- for (gossip = env->autocrypt_gossip; gossip; gossip = gossip->next)
+ for (struct AutocryptHeader *gossip = env->autocrypt_gossip; gossip;
+ gossip = gossip->next)
{
fputs("Autocrypt-Gossip: ", fp);
write_autocrypt_header_line(fp, gossip->addr, 0, gossip->keydata);
struct AutocryptPeer *peer = NULL;
struct AutocryptAccount *account = NULL;
struct Address *recip = NULL;
- struct AutocryptHeader *gossip;
- const char *keydata, *addr;
- struct Envelope *mime_headers;
- if (!C_Autocrypt || mutt_autocrypt_init(0) || !e)
+ if (!C_Autocrypt || mutt_autocrypt_init(false) || !e)
return -1;
- mime_headers = e->content->mime_headers;
+ struct Envelope *mime_headers = e->content->mime_headers;
if (!mime_headers)
mime_headers = e->content->mime_headers = mutt_env_new();
mutt_free_autocrypthdr(&mime_headers->autocrypt_gossip);
if (mutt_autocrypt_db_peer_get(recip, &peer) <= 0)
continue;
- keydata = NULL;
+ const char *keydata = NULL;
if (mutt_autocrypt_gpgme_is_valid_key(peer->keyid))
keydata = peer->keydata;
else if (mutt_autocrypt_gpgme_is_valid_key(peer->gossip_keyid))
if (keydata)
{
- gossip = mutt_new_autocrypthdr();
+ struct AutocryptHeader *gossip = mutt_new_autocrypthdr();
gossip->addr = mutt_str_strdup(peer->email_addr);
gossip->keydata = mutt_str_strdup(keydata);
gossip->next = mime_headers->autocrypt_gossip;
TAILQ_FOREACH(recip, &e->env->reply_to, entries)
{
- addr = keydata = NULL;
+ const char *addr = NULL;
+ const char *keydata = NULL;
if (mutt_autocrypt_db_account_get(recip, &account) > 0)
{
addr = account->email_addr;
if (keydata)
{
- gossip = mutt_new_autocrypthdr();
+ struct AutocryptHeader *gossip = mutt_new_autocrypthdr();
gossip->addr = mutt_str_strdup(addr);
gossip->keydata = mutt_str_strdup(keydata);
gossip->next = mime_headers->autocrypt_gossip;
*/
void mutt_autocrypt_scan_mailboxes(void)
{
- int scan;
- struct Buffer *folderbuf = NULL;
- struct Context *ctx = NULL;
-
#ifdef USE_HCACHE
char *old_hdrcache = C_HeaderCache;
C_HeaderCache = NULL;
#endif
- folderbuf = mutt_buffer_pool_get();
+ struct Buffer *folderbuf = mutt_buffer_pool_get();
/* L10N:
The first time autocrypt is enabled, Mutt will ask to scan
and used for encryption.
If this is answered yes, they will be prompted for a mailbox.
*/
- scan = mutt_yesorno(_("Scan a mailbox for autocrypt headers?"), MUTT_YES);
+ int scan = mutt_yesorno(_("Scan a mailbox for autocrypt headers?"), MUTT_YES);
while (scan == MUTT_YES)
{
// L10N: The prompt for a mailbox to scan for Autocrypt: headers
- if ((!mutt_buffer_enter_fname(_("Scan mailbox"), folderbuf, 1)) &&
+ if ((!mutt_buffer_enter_fname(_("Scan mailbox"), folderbuf, true)) &&
(mutt_buffer_len(folderbuf) > 0))
{
mutt_buffer_expand_path_regex(folderbuf, false);
/* NOTE: I am purposely *not* executing folder hooks here,
* as they can do all sorts of things like push into the getch() buffer.
* Authentication should be in account-hooks. */
- ctx = mx_mbox_open(m, MUTT_READONLY);
+ struct Context *ctx = mx_mbox_open(m, MUTT_READONLY);
mx_mbox_close(&ctx);
mutt_buffer_reset(folderbuf);
}
struct Email;
struct Envelope;
-WHERE sqlite3 *AutocryptDB;
/**
* struct AutocryptAccount - Autocrypt account
char *email_addr;
char *keyid;
char *keydata;
- int prefer_encrypt; /* 0 = nopref, 1 = mutual */
- int enabled;
+ bool prefer_encrypt; /* false = nopref, true = mutual */
+ bool enabled;
};
/**
sqlite3_int64 autocrypt_timestamp;
char *keyid;
char *keydata;
- int prefer_encrypt; /* 0 = nopref, 1 = mutual */
+ bool prefer_encrypt; /* false = nopref, true = mutual */
sqlite3_int64 gossip_timestamp;
char *gossip_keyid;
char *gossip_keydata;
void mutt_autocrypt_account_menu (void);
void mutt_autocrypt_cleanup (void);
int mutt_autocrypt_generate_gossip_list (struct Email *e);
-int mutt_autocrypt_init (int);
+int mutt_autocrypt_init (bool can_create);
int mutt_autocrypt_process_autocrypt_header(struct Email *e, struct Envelope *env);
int mutt_autocrypt_process_gossip_header (struct Email *e, struct Envelope *prot_headers);
int mutt_autocrypt_set_sign_as_default_key (struct Email *e);
* @param menu Menu to use
* @param num Line in the Menu
*/
-static void account_entry(char *s, size_t slen, struct Menu *m, int num)
+static void account_entry(char *buf, size_t buflen, struct Menu *menu, int num)
{
- struct Entry *entry = &((struct Entry *) m->data)[num];
+ struct Entry *entry = &((struct Entry *) menu->data)[num];
- mutt_expando_format(s, slen, 0, MuttIndexWindow->cols,
+ mutt_expando_format(buf, buflen, 0, MuttIndexWindow->cols,
NONULL(C_AutocryptAcctFormat), account_format_str,
(unsigned long) entry, MUTT_FORMAT_ARROWCURSOR);
}
*/
static struct Menu *create_menu(void)
{
- struct Menu *menu = NULL;
struct AutocryptAccount **accounts = NULL;
- struct Entry *entries = NULL;
- int num_accounts = 0, i;
- char *helpstr;
+ int num_accounts = 0;
if (mutt_autocrypt_db_account_get_all(&accounts, &num_accounts) < 0)
return NULL;
- menu = mutt_menu_new(MENU_AUTOCRYPT_ACCT);
+ struct Menu *menu = mutt_menu_new(MENU_AUTOCRYPT_ACCT);
menu->menu_make_entry = account_entry;
/* menu->tag = account_tag; */
// L10N: Autocrypt Account Management Menu title
menu->title = _("Autocrypt Accounts");
- helpstr = mutt_mem_malloc(256);
+ char *helpstr = mutt_mem_malloc(256);
menu->help = mutt_compile_help(helpstr, 256, MENU_AUTOCRYPT_ACCT, AutocryptAcctHelp);
- menu->data = entries = mutt_mem_calloc(num_accounts, sizeof(struct Entry));
+ struct Entry *entries = mutt_mem_calloc(num_accounts, sizeof(struct Entry));
+ menu->data = entries;
menu->max = num_accounts;
- for (i = 0; i < num_accounts; i++)
+ for (int i = 0; i < num_accounts; i++)
{
entries[i].num = i + 1;
/* note: we are transfering the account pointer to the entries
*/
static void free_menu(struct Menu **menu)
{
- int i;
- struct Entry *entries;
+ struct Entry *entries = (struct Entry *) (*menu)->data;
- entries = (struct Entry *) (*menu)->data;
- for (i = 0; i < (*menu)->max; i++)
+ for (int i = 0; i < (*menu)->max; i++)
{
mutt_autocrypt_db_account_free(&entries[i].account);
mutt_addr_free(&entries[i].addr);
*/
void mutt_autocrypt_account_menu(void)
{
- struct Menu *menu;
- int done = 0, op;
- struct Entry *entry;
- char msg[128];
-
if (!C_Autocrypt)
return;
- if (mutt_autocrypt_init(0))
+ if (mutt_autocrypt_init(false))
return;
- menu = create_menu();
+ struct Menu *menu = create_menu();
if (!menu)
return;
+ bool done = false;
while (!done)
{
- switch ((op = mutt_menu_loop(menu)))
+ switch (mutt_menu_loop(menu))
{
case OP_EXIT:
- done = 1;
+ done = true;
break;
case OP_AUTOCRYPT_CREATE_ACCT:
- if (!mutt_autocrypt_account_init(0))
+ if (!mutt_autocrypt_account_init(false))
{
free_menu(&menu);
menu = create_menu();
case OP_AUTOCRYPT_DELETE_ACCT:
if (menu->data)
{
- entry = (struct Entry *) (menu->data) + menu->current;
+ struct Entry *entry = (struct Entry *) (menu->data) + menu->current;
+ char msg[128];
snprintf(msg, sizeof(msg),
// L10N: Confirmation message when deleting an autocrypt account
_("Really delete account \"%s\"?"), entry->addr->mailbox);
case OP_AUTOCRYPT_TOGGLE_ACTIVE:
if (menu->data)
{
- entry = (struct Entry *) (menu->data) + menu->current;
+ struct Entry *entry = (struct Entry *) (menu->data) + menu->current;
toggle_active(entry);
menu->redraw |= REDRAW_FULL;
}
case OP_AUTOCRYPT_TOGGLE_PREFER:
if (menu->data)
{
- entry = (struct Entry *) (menu->data) + menu->current;
+ struct Entry *entry = (struct Entry *) (menu->data) + menu->current;
toggle_prefer_encrypt(entry);
menu->redraw |= REDRAW_FULL;
}
static sqlite3_stmt *PeerHistoryInsertStmt;
static sqlite3_stmt *GossipHistoryInsertStmt;
+sqlite3 *AutocryptDB = NULL;
+
/**
* autocrypt_db_create - Create an Autocrypt sqlite database
* @param db_path Path to database file
* @retval 0 Success
* @retval -1 Error
*/
-int mutt_autocrypt_db_init(int can_create)
+int mutt_autocrypt_db_init(bool can_create)
{
int rc = -1;
- struct Buffer *db_path = NULL;
- struct stat sb;
if (AutocryptDB)
return 0;
if (!C_Autocrypt || !C_AutocryptDir)
return -1;
- db_path = mutt_buffer_pool_get();
+ struct Buffer *db_path = mutt_buffer_pool_get();
mutt_buffer_concat_path(db_path, C_AutocryptDir, "autocrypt.db");
+ struct stat sb;
if (stat(mutt_b2s(db_path), &sb))
{
if (!can_create)
if (autocrypt_db_create(mutt_b2s(db_path)))
goto cleanup;
/* Don't abort the whole init process because account creation failed */
- mutt_autocrypt_account_init(1);
+ mutt_autocrypt_account_init(true);
mutt_autocrypt_scan_mailboxes();
}
else
*/
static struct Address *copy_normalize_addr(struct Address *addr)
{
- struct Address *norm_addr = NULL;
-
/* NOTE: the db functions expect a single address, so in
* this function we copy only the address passed in.
*
* The normalize_addrlist above is extended to work on a list
* because of requirements in autocrypt.c */
- norm_addr = mutt_addr_new();
+ struct Address *norm_addr = mutt_addr_new();
norm_addr->mailbox = mutt_str_strdup(addr->mailbox);
norm_addr->is_intl = addr->is_intl;
norm_addr->intl_checked = addr->intl_checked;
*/
int mutt_autocrypt_db_account_get(struct Address *addr, struct AutocryptAccount **account)
{
- int rc = -1, result;
- struct Address *norm_addr = NULL;
+ int rc = -1;
- norm_addr = copy_normalize_addr(addr);
+ struct Address *norm_addr = copy_normalize_addr(addr);
*account = NULL;
if (!AccountGetStmt)
if (sqlite3_bind_text(AccountGetStmt, 1, norm_addr->mailbox, -1, SQLITE_STATIC) != SQLITE_OK)
goto cleanup;
- result = sqlite3_step(AccountGetStmt);
+ int result = sqlite3_step(AccountGetStmt);
if (result != SQLITE_ROW)
{
if (result == SQLITE_DONE)
* @retval -1 Error
*/
int mutt_autocrypt_db_account_insert(struct Address *addr, const char *keyid,
- const char *keydata, int prefer_encrypt)
+ const char *keydata, bool prefer_encrypt)
{
int rc = -1;
- struct Address *norm_addr = NULL;
- norm_addr = copy_normalize_addr(addr);
+ struct Address *norm_addr = copy_normalize_addr(addr);
if (!AccountInsertStmt)
{
{
int rc = -1, result;
sqlite3_stmt *stmt = NULL;
- struct AutocryptAccount **results = NULL, *account;
+ struct AutocryptAccount **results = NULL;
int results_len = 0, results_count = 0;
*accounts = NULL;
mutt_mem_realloc(&results, results_len * sizeof(struct AutocryptAccount *));
}
- results[results_count++] = account = mutt_autocrypt_db_account_new();
+ struct AutocryptAccount *account = mutt_autocrypt_db_account_new();
+ results[results_count++] = account;
account->email_addr = strdup_column_text(stmt, 0);
account->keyid = strdup_column_text(stmt, 1);
*/
int mutt_autocrypt_db_peer_get(struct Address *addr, struct AutocryptPeer **peer)
{
- int rc = -1, result;
- struct Address *norm_addr = NULL;
+ int rc = -1;
- norm_addr = copy_normalize_addr(addr);
+ struct Address *norm_addr = copy_normalize_addr(addr);
*peer = NULL;
if (!PeerGetStmt)
if (sqlite3_bind_text(PeerGetStmt, 1, norm_addr->mailbox, -1, SQLITE_STATIC) != SQLITE_OK)
goto cleanup;
- result = sqlite3_step(PeerGetStmt);
+ int result = sqlite3_step(PeerGetStmt);
if (result != SQLITE_ROW)
{
if (result == SQLITE_DONE)
struct AutocryptPeerHistory *peerhist)
{
int rc = -1;
- struct Address *norm_addr = NULL;
- norm_addr = copy_normalize_addr(addr);
+ struct Address *norm_addr = copy_normalize_addr(addr);
if (!PeerHistoryInsertStmt)
{
struct AutocryptGossipHistory *gossip_hist)
{
int rc = -1;
- struct Address *norm_addr = NULL;
- norm_addr = copy_normalize_addr(addr);
+ struct Address *norm_addr = copy_normalize_addr(addr);
if (!GossipHistoryInsertStmt)
{
*/
static int create_gpgme_context(gpgme_ctx_t *ctx)
{
- gpgme_error_t err;
-
- err = gpgme_new(ctx);
+ gpgme_error_t err = gpgme_new(ctx);
if (!err)
err = gpgme_ctx_set_engine_info(*ctx, GPGME_PROTOCOL_OpenPGP, NULL, C_AutocryptDir);
if (err)
{
int rc = -1;
gpgme_ctx_t ctx = NULL;
- gpgme_error_t err;
gpgme_genkey_result_t keyresult;
gpgme_key_t primary_key = NULL;
char buf[1024] = { 0 };
mutt_message(_("Generating autocrypt key..."));
/* Primary key */
- err = gpgme_op_createkey(ctx, buf, "ed25519", 0, 0, NULL,
- GPGME_CREATE_NOPASSWD | GPGME_CREATE_FORCE | GPGME_CREATE_NOEXPIRE);
+ gpgme_error_t err = gpgme_op_createkey(ctx, buf, "ed25519", 0, 0, NULL,
+ GPGME_CREATE_NOPASSWD | GPGME_CREATE_FORCE |
+ GPGME_CREATE_NOEXPIRE);
if (err)
{
/* L10N:
{
int rc = -1;
gpgme_ctx_t ctx = NULL;
- struct Buffer *raw_keydata = NULL;
gpgme_data_t dh = NULL;
- gpgme_import_result_t result;
if (create_gpgme_context(&ctx))
goto cleanup;
- raw_keydata = mutt_buffer_pool_get();
+ struct Buffer *raw_keydata = mutt_buffer_pool_get();
if (!mutt_b64_buffer_decode(raw_keydata, keydata))
goto cleanup;
if (gpgme_op_import(ctx, dh))
goto cleanup;
- result = gpgme_op_import_result(ctx);
+ gpgme_import_result_t result = gpgme_op_import_result(ctx);
if (!result->imports || !result->imports->fpr)
goto cleanup;
mutt_buffer_strcpy(keyid, result->imports->fpr);
* @param keyid Key id to check
* @retval true If key id is valid
*/
-int mutt_autocrypt_gpgme_is_valid_key(const char *keyid)
+bool mutt_autocrypt_gpgme_is_valid_key(const char *keyid)
{
- int rc = 0;
+ bool rc = false;
gpgme_ctx_t ctx = NULL;
gpgme_key_t key = NULL;
if (!keyid)
- return 0;
+ return false;
if (create_gpgme_context(&ctx))
goto cleanup;
if (gpgme_get_key(ctx, keyid, &key, 0))
goto cleanup;
- rc = 1;
+ rc = true;
if (key->revoked || key->expired || key->disabled || key->invalid || !key->can_encrypt)
- rc = 0;
+ rc = false;
cleanup:
gpgme_key_unref(key);
struct Address;
struct AddressList;
+struct AutocryptAccount;
+struct AutocryptGossipHistory;
+struct AutocryptPeer;
+struct AutocryptPeerHistory;
struct Buffer;
+extern sqlite3 *AutocryptDB;
-int mutt_autocrypt_account_init(int prompt);
+int mutt_autocrypt_account_init(bool prompt);
void mutt_autocrypt_scan_mailboxes(void);
int mutt_autocrypt_db_account_delete(struct AutocryptAccount *acct);
void mutt_autocrypt_db_account_free(struct AutocryptAccount **account);
int mutt_autocrypt_db_account_get(struct Address *addr, struct AutocryptAccount **account);
int mutt_autocrypt_db_account_get_all(struct AutocryptAccount ***accounts, int *num_accounts);
-int mutt_autocrypt_db_account_insert(struct Address *addr, const char *keyid, const char *keydata, int prefer_encrypt);
+int mutt_autocrypt_db_account_insert(struct Address *addr, const char *keyid, const char *keydata, bool prefer_encrypt);
struct AutocryptAccount * mutt_autocrypt_db_account_new(void);
int mutt_autocrypt_db_account_update(struct AutocryptAccount *acct);
void mutt_autocrypt_db_close(void);
void mutt_autocrypt_db_gossip_history_free(struct AutocryptGossipHistory **gossip_hist);
int mutt_autocrypt_db_gossip_history_insert(struct Address *addr, struct AutocryptGossipHistory *gossip_hist);
struct AutocryptGossipHistory *mutt_autocrypt_db_gossip_history_new(void);
-int mutt_autocrypt_db_init(int can_create);
+int mutt_autocrypt_db_init(bool can_create);
void mutt_autocrypt_db_normalize_addr(struct Address *a);
void mutt_autocrypt_db_normalize_addrlist(struct AddressList *al);
void mutt_autocrypt_db_peer_free(struct AutocryptPeer **peer);
int mutt_autocrypt_gpgme_create_key(struct Address *addr, struct Buffer *keyid, struct Buffer *keydata);
int mutt_autocrypt_gpgme_import_key(const char *keydata, struct Buffer *keyid);
int mutt_autocrypt_gpgme_init(void);
-int mutt_autocrypt_gpgme_is_valid_key(const char *keyid);
+bool mutt_autocrypt_gpgme_is_valid_key(const char *keyid);
#endif /* MUTT_AUTOCRYPT_AUTOCRYPT_PRIVATE_H */
*/
int mutt_autocrypt_schema_init(void)
{
- const char *schema;
char *errmsg = NULL;
- schema = "BEGIN TRANSACTION; "
+ const char *schema = "BEGIN TRANSACTION; "
"CREATE TABLE account ("
"email_addr text primary key not null, "
int mutt_autocrypt_schema_update(void)
{
sqlite3_stmt *stmt = NULL;
- int rc = -1, version;
+ int rc = -1;
if (sqlite3_prepare_v2(AutocryptDB, "SELECT version FROM schema;", -1, &stmt, NULL) != SQLITE_OK)
goto cleanup;
if (sqlite3_step(stmt) != SQLITE_ROW)
goto cleanup;
- version = sqlite3_column_int(stmt, 0);
+ int version = sqlite3_column_int(stmt, 0);
if (version > 1)
{
struct Envelope *prot_headers = NULL;
regmatch_t pmatch[1];
- if (!C_CryptProtectedHeadersRead
#ifdef USE_AUTOCRYPT
- && !C_Autocrypt
-#endif
- )
- {
+ if (!C_CryptProtectedHeadersRead && !C_Autocrypt)
return;
- }
+#else
+ if (!C_CryptProtectedHeadersRead)
+ return;
+#endif
/* Grab protected headers to update in the index */
if (e->security & SEC_SIGN)
bool warnsig : 1; ///< Maybe good signature
bool badsig : 1; ///< Bad cryptographic signature (needed to check encrypted s/mime-signatures)
#ifdef USE_AUTOCRYPT
- unsigned int is_autocrypt : 1; /* used to flag autocrypt-decrypted messages
- * for replying */
+ bool is_autocrypt : 1; ///< Flag autocrypt-decrypted messages for replying
#endif
bool collapsed : 1; ///< Used by recvattach
*/
void mutt_free_autocrypthdr(struct AutocryptHeader **p)
{
- struct AutocryptHeader *cur;
-
if (!p)
return;
+ struct AutocryptHeader *cur = NULL;
+
while (*p)
{
cur = *p;
{
char *addr;
char *keydata;
- unsigned int prefer_encrypt : 1;
- unsigned int invalid : 1;
+ bool prefer_encrypt : 1;
+ bool invalid : 1;
struct AutocryptHeader *next;
};
#endif
#ifdef USE_AUTOCRYPT
#define mutt_new_autocrypthdr() mutt_mem_calloc(1, sizeof(struct AutocryptHeader))
-void mutt_free_autocrypthdr (struct AutocryptHeader **p);
+void mutt_free_autocrypthdr(struct AutocryptHeader **p);
#endif
#endif /* MUTT_EMAIL_ENVELOPE_H */
* The allow_value_spaces parameter allows parsing those values which
* are split by spaces when unfolded.
*/
-static void parse_parameters(struct ParameterList *param, const char *s, int allow_value_spaces)
+static void parse_parameters(struct ParameterList *param, const char *s, bool allow_value_spaces)
{
struct Parameter *pnew = NULL;
- struct Buffer *buf = NULL;
const char *p = NULL;
size_t i;
- buf = mutt_buffer_pool_get();
+ struct Buffer *buf = mutt_buffer_pool_get();
/* allow_value_spaces, especially with autocrypt keydata, can result
* in quite large parameter values. avoid frequent reallocs by
* pre-sizing */
if (s)
{
s = mutt_str_skip_email_wsp(s + 1);
- parse_parameters(&parms, s, 0);
+ parse_parameters(&parms, s, false);
s = mutt_param_get(&parms, "filename");
if (s)
mutt_str_replace(&ct->filename, s);
*pc++ = 0;
while (*pc && IS_SPACE(*pc))
pc++;
- parse_parameters(&ct->parameter, pc, 0);
+ parse_parameters(&ct->parameter, pc, false);
/* Some pre-RFC1521 gateways still use the "name=filename" convention,
* but if a filename has already been set in the content-disposition,
autocrypt->next = head;
struct ParameterList pl = TAILQ_HEAD_INITIALIZER(pl);
- parse_parameters(&pl, s, 1);
+ parse_parameters(&pl, s, true);
if (TAILQ_EMPTY(&pl))
{
- autocrypt->invalid = 1;
+ autocrypt->invalid = true;
goto cleanup;
}
{
if (autocrypt->addr)
{
- autocrypt->invalid = 1;
+ autocrypt->invalid = true;
goto cleanup;
}
autocrypt->addr = p->value;
else if (mutt_str_strcasecmp(p->attribute, "prefer-encrypt") == 0)
{
if (mutt_str_strcasecmp(p->value, "mutual") == 0)
- autocrypt->prefer_encrypt = 1;
+ autocrypt->prefer_encrypt = true;
}
else if (mutt_str_strcasecmp(p->attribute, "keydata") == 0)
{
if (autocrypt->keydata)
{
- autocrypt->invalid = 1;
+ autocrypt->invalid = true;
goto cleanup;
}
autocrypt->keydata = p->value;
}
else if (p->attribute && (p->attribute[0] != '_'))
{
- autocrypt->invalid = 1;
+ autocrypt->invalid = true;
goto cleanup;
}
}
/* Checking the addr against From, and for multiple valid headers
* occurs later, after all the headers are parsed. */
if (!autocrypt->addr || !autocrypt->keydata)
- autocrypt->invalid = 1;
+ autocrypt->invalid = true;
cleanup:
mutt_param_free(&pl);
if (C_Autocrypt)
{
env->autocrypt = parse_autocrypt(env->autocrypt, p);
- matched = 1;
+ matched = true;
}
}
else if (mutt_str_strcasecmp(line + 1, "utocrypt-gossip") == 0)
if (C_Autocrypt)
{
env->autocrypt_gossip = parse_autocrypt(env->autocrypt_gossip, p);
- matched = 1;
+ matched = true;
}
}
#endif
WHERE struct AliasList Aliases INITVAL(TAILQ_HEAD_INITIALIZER(Aliases)); ///< List of all the user's email aliases
+#ifdef USE_AUTOCRYPT
+WHERE char *AutocryptSignAs; ///< Autocrypt Key id to sign as
+WHERE char *AutocryptDefaultKey; ///< Autocrypt default key id (used for postponing messages)
+#endif
+
/* All the variables below are backing for config items */
WHERE struct Address *C_EnvelopeFromAddress; ///< Config: Manually set the sender for outgoing messages
#ifdef USE_AUTOCRYPT
WHERE char *C_AutocryptAcctFormat; ///< Config: Format of the autocrypt account menu
WHERE char *C_AutocryptDir; ///< Config: Location of autocrypt files, including the GPG keyring and sqlite database
-WHERE char *AutocryptSignAs; /* This is used in ncrypt/crypt_gpgme.c */
-WHERE char *AutocryptDefaultKey; /* Used for postponing messages */
#endif
WHERE char *C_ConfigCharset; ///< Config: Character set that the config files are in
WHERE char *C_CryptProtectedHeadersSubject; ///< Config: Use this as the subject for encrypted emails
char tempfile[_POSIX_PATH_MAX];
FILE *fp = NULL;
struct ImapHeader h;
- struct Buffer *b = NULL, *hdr_list = NULL;
+ struct Buffer *b = NULL;
static const char *const want_headers =
"DATE FROM SENDER SUBJECT TO CC MESSAGE-ID REFERENCES CONTENT-TYPE "
"CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES LIST-POST X-LABEL "
if (!adata || (adata->mailbox != m))
return -1;
- hdr_list = mutt_buffer_pool_get();
+ struct Buffer *hdr_list = mutt_buffer_pool_get();
mutt_buffer_strcpy(hdr_list, want_headers);
if (C_ImapHeaders)
{
* @retval 0 Success
* @retval -1 Error
*/
-int mutt_protect(struct Email *e, char *keylist, int postpone)
+int mutt_protect(struct Email *e, char *keylist, bool postpone)
{
struct Body *pbody = NULL, *tmp_pbody = NULL;
struct Body *tmp_smime_pbody = NULL;
struct Body *tmp_pgp_pbody = NULL;
- int security, sign, has_retainable_sig = 0;
+ bool has_retainable_sig = false;
if (!WithCrypto)
return -1;
- security = e->security;
- sign = security & (SEC_AUTOCRYPT | SEC_SIGN);
+ int security = e->security;
+ int sign = security & (SEC_AUTOCRYPT | SEC_SIGN);
if (postpone)
{
- sign = 0;
+ sign = SEC_NO_FLAGS;
security &= ~SEC_SIGN;
}
if (!tmp_pbody)
goto bail;
- has_retainable_sig = 1;
- sign = 0;
+ has_retainable_sig = true;
+ sign = SEC_NO_FLAGS;
pbody = tmp_pbody;
tmp_pgp_pbody = tmp_pbody;
}
if (!oppenc_mode && (e->security & SEC_AUTOCRYPT))
{
if (mutt_autocrypt_ui_recommendation(e, keylist) <= AUTOCRYPT_REC_NO)
- return (-1);
- return (0);
+ return -1;
+ return 0;
}
#endif
int crypt_pgp_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur)
{
#ifdef USE_AUTOCRYPT
- int result;
-
if (C_Autocrypt)
{
OptAutocryptGpgme = true;
- result = pgp_gpgme_decrypt_mime(fp_in, fp_out, b, cur);
+ int result = pgp_gpgme_decrypt_mime(fp_in, fp_out, b, cur);
OptAutocryptGpgme = false;
if (result == 0)
{
- b->is_autocrypt = 1;
+ b->is_autocrypt = true;
return result;
}
}
int crypt_pgp_encrypted_handler(struct Body *a, struct State *s)
{
#ifdef USE_AUTOCRYPT
- int result;
-
if (C_Autocrypt)
{
OptAutocryptGpgme = true;
- result = pgp_gpgme_encrypted_handler(a, s);
+ int result = pgp_gpgme_encrypted_handler(a, s);
OptAutocryptGpgme = false;
if (result == 0)
{
- a->is_autocrypt = 1;
+ a->is_autocrypt = true;
return result;
}
}
/**
* crypt_pgp_encrypt_message - Wrapper for CryptModuleSpecs::pgp_encrypt_message()
*/
-struct Body *crypt_pgp_encrypt_message(struct Email *e, struct Body *a,
- char *keylist, int sign)
+struct Body *crypt_pgp_encrypt_message(struct Email *e, struct Body *a, char *keylist, int sign)
{
#ifdef USE_AUTOCRYPT
- struct Body *result;
-
if (e->security & SEC_AUTOCRYPT)
{
if (mutt_autocrypt_set_sign_as_default_key(e))
return NULL;
OptAutocryptGpgme = true;
- result = pgp_gpgme_encrypt_message(a, keylist, sign);
+ struct Body *result = pgp_gpgme_encrypt_message(a, keylist, sign);
OptAutocryptGpgme = false;
return result;
SecurityFlags mutt_is_multipart_encrypted(struct Body *b);
SecurityFlags mutt_is_multipart_signed(struct Body *b);
int mutt_is_valid_multipart_pgp_encrypted(struct Body *b);
-int mutt_protect(struct Email *e, char *keylist, int);
+int mutt_protect(struct Email *e, char *keylist, bool postpone);
int mutt_protected_headers_handler(struct Body *m, struct State *s);
bool mutt_should_hide_protected_subject(struct Email *e);
int mutt_signed_handler(struct Body *a, struct State *s);
* @retval 0 Success
* @retval -1 Failure
*/
-int mutt_edit_address(struct AddressList *al, const char *field, int expand_aliases)
+int mutt_edit_address(struct AddressList *al, const char *field, bool expand_aliases)
{
char buf[8192];
char *err = NULL;
else
#endif
{
- if ((mutt_edit_address(&en->to, _("To: "), 1) == -1) || TAILQ_EMPTY(&en->to))
+ if ((mutt_edit_address(&en->to, _("To: "), true) == -1) || TAILQ_EMPTY(&en->to))
return -1;
- if (C_Askcc && (mutt_edit_address(&en->cc, _("Cc: "), 1) == -1))
+ if (C_Askcc && (mutt_edit_address(&en->cc, _("Cc: "), true) == -1))
return -1;
- if (C_Askbcc && (mutt_edit_address(&en->bcc, _("Bcc: "), 1) == -1))
+ if (C_Askbcc && (mutt_edit_address(&en->bcc, _("Bcc: "), true) == -1))
return -1;
if (C_ReplyWithXorig && (flags & (SEND_REPLY | SEND_LIST_REPLY | SEND_GROUP_REPLY)) &&
- (mutt_edit_address(&en->from, "From: ", 1) == -1))
+ (mutt_edit_address(&en->from, "From: ", true) == -1))
{
return -1;
}
/* this means writing only the main part */
e->content = clear_content->parts;
- if (mutt_protect(e, pgpkeylist, 0) == -1)
+ if (mutt_protect(e, pgpkeylist, false) == -1)
{
/* we can't do much about it at this point, so
* fallback to saving the whole thing to fcc */
{
pgpkeylist = mutt_str_strdup(encrypt_as);
clear_content = e_post->content;
- if (mutt_protect(e_post, pgpkeylist, 1) == -1)
+ if (mutt_protect(e_post, pgpkeylist, true) == -1)
{
FREE(&pgpkeylist);
e_post->content = mutt_remove_multipart(e_post->content);
clear_content = e_templ->content;
if ((crypt_get_keys(e_templ, &pgpkeylist, 0) == -1) ||
- (mutt_protect(e_templ, pgpkeylist, 0) == -1))
+ (mutt_protect(e_templ, pgpkeylist, false) == -1))
{
e_templ->content = mutt_remove_multipart(e_templ->content);
int ci_send_message(SendFlags flags, struct Email *e_templ, const char *tempfile, struct Context *ctx, struct EmailList *el);
void mutt_add_to_reference_headers(struct Envelope *env, struct Envelope *curenv);
struct Address *mutt_default_from(void);
-int mutt_edit_address(struct AddressList *al, const char *field, int expand_aliases);
+int mutt_edit_address(struct AddressList *al, const char *field, bool expand_aliases);
void mutt_encode_descriptions(struct Body *b, bool recurse);
int mutt_fetch_recips(struct Envelope *out, struct Envelope *in, SendFlags flags);
void mutt_fix_reply_recipients(struct Envelope *env);