From: Richard Russon Date: Wed, 7 Aug 2019 21:20:12 +0000 (+0100) Subject: tidy code X-Git-Tag: 2019-10-25~97^2~11 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d857761923ae975f7d8bee92e37cf37e7e7055c2;p=neomutt tidy code - boolify variables, members - reduce variable scope - initialise pointers - bracket logic - name parameters in prototypes --- diff --git a/autocrypt/autocrypt.c b/autocrypt/autocrypt.c index 834c5aa7c..3719babbd 100644 --- a/autocrypt/autocrypt.c +++ b/autocrypt/autocrypt.c @@ -45,11 +45,10 @@ * @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; @@ -57,7 +56,7 @@ static int autocrypt_dir_init(int can_create) 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 @@ -87,7 +86,7 @@ static int autocrypt_dir_init(int can_create) * @retval 0 Success * @retval -1 Error */ -int mutt_autocrypt_init(int can_create) +int mutt_autocrypt_init(bool can_create) { if (AutocryptDB) return 0; @@ -129,13 +128,13 @@ void mutt_autocrypt_cleanup(void) * 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) { @@ -168,7 +167,7 @@ int mutt_autocrypt_account_init(int 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); @@ -212,7 +211,7 @@ int mutt_autocrypt_account_init(int prompt) 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; @@ -248,18 +247,18 @@ 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) @@ -283,7 +282,7 @@ int mutt_autocrypt_process_autocrypt_header(struct Email *e, struct Envelope *en 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; @@ -316,28 +315,28 @@ int mutt_autocrypt_process_autocrypt_header(struct Email *e, struct Envelope *en 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)) @@ -398,27 +397,24 @@ cleanup: */ 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) @@ -427,10 +423,10 @@ int mutt_autocrypt_process_gossip_header(struct Email *e, struct Envelope *prot_ /* 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); @@ -440,15 +436,16 @@ int mutt_autocrypt_process_gossip_header(struct Email *e, struct Envelope *prot_ 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 @@ -473,7 +470,7 @@ int mutt_autocrypt_process_gossip_header(struct Email *e, struct Envelope *prot_ 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 @@ -481,16 +478,16 @@ int mutt_autocrypt_process_gossip_header(struct Email *e, struct Envelope *prot_ 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) @@ -527,7 +524,10 @@ int mutt_autocrypt_process_gossip_header(struct Email *e, struct Envelope *prot_ 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; @@ -557,11 +557,10 @@ enum AutocryptRec mutt_autocrypt_ui_recommendation(struct Email *e, char **keyli 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); @@ -577,7 +576,7 @@ enum AutocryptRec mutt_autocrypt_ui_recommendation(struct Email *e, char **keyli 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); @@ -611,21 +610,21 @@ enum AutocryptRec mutt_autocrypt_ui_recommendation(struct Email *e, char **keyli 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 { @@ -670,7 +669,7 @@ int mutt_autocrypt_set_sign_as_default_key(struct Email *e) 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); @@ -702,10 +701,8 @@ cleanup: * @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); @@ -713,7 +710,7 @@ static void write_autocrypt_header_line(FILE *fp, const char *addr, while (*keydata) { - count = 0; + int count = 0; fputs("\t", fp); while (*keydata && count < 75) { @@ -737,7 +734,7 @@ int mutt_autocrypt_write_autocrypt_header(struct Envelope *env, FILE *fp) 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); @@ -771,12 +768,11 @@ cleanup: */ 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); @@ -797,14 +793,11 @@ int mutt_autocrypt_generate_gossip_list(struct Email *e) 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); @@ -820,7 +813,7 @@ int mutt_autocrypt_generate_gossip_list(struct Email *e) 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)) @@ -828,7 +821,7 @@ int mutt_autocrypt_generate_gossip_list(struct Email *e) 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; @@ -840,7 +833,8 @@ int mutt_autocrypt_generate_gossip_list(struct Email *e) 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; @@ -857,7 +851,7 @@ int mutt_autocrypt_generate_gossip_list(struct Email *e) 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; @@ -885,16 +879,12 @@ int mutt_autocrypt_generate_gossip_list(struct Email *e) */ 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 @@ -903,11 +893,11 @@ void mutt_autocrypt_scan_mailboxes(void) 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); @@ -915,7 +905,7 @@ void mutt_autocrypt_scan_mailboxes(void) /* 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); } diff --git a/autocrypt/autocrypt.h b/autocrypt/autocrypt.h index 74bb34321..3ae6be826 100644 --- a/autocrypt/autocrypt.h +++ b/autocrypt/autocrypt.h @@ -29,7 +29,6 @@ struct Email; struct Envelope; -WHERE sqlite3 *AutocryptDB; /** * struct AutocryptAccount - Autocrypt account @@ -39,8 +38,8 @@ struct AutocryptAccount 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; }; /** @@ -53,7 +52,7 @@ struct AutocryptPeer 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; @@ -97,7 +96,7 @@ enum AutocryptRec 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); diff --git a/autocrypt/autocrypt_acct_menu.c b/autocrypt/autocrypt_acct_menu.c index 8536573a5..7922b671e 100644 --- a/autocrypt/autocrypt_acct_menu.c +++ b/autocrypt/autocrypt_acct_menu.c @@ -143,11 +143,11 @@ static const char *account_format_str(char *dest, size_t destlen, size_t col, in * @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); } @@ -158,27 +158,25 @@ static void account_entry(char *s, size_t slen, struct Menu *m, int num) */ 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 @@ -203,11 +201,9 @@ static struct Menu *create_menu(void) */ 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); @@ -256,31 +252,27 @@ static void toggle_prefer_encrypt(struct Entry *entry) */ 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(); @@ -290,7 +282,8 @@ void mutt_autocrypt_account_menu(void) 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); @@ -308,7 +301,7 @@ void mutt_autocrypt_account_menu(void) 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; } @@ -317,7 +310,7 @@ void mutt_autocrypt_account_menu(void) 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; } diff --git a/autocrypt/autocrypt_db.c b/autocrypt/autocrypt_db.c index 3746fb410..6d15e87ba 100644 --- a/autocrypt/autocrypt_db.c +++ b/autocrypt/autocrypt_db.c @@ -42,6 +42,8 @@ static sqlite3_stmt *PeerUpdateStmt; 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 @@ -69,11 +71,9 @@ static int autocrypt_db_create(const char *db_path) * @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; @@ -81,9 +81,10 @@ int mutt_autocrypt_db_init(int can_create) 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) @@ -91,7 +92,7 @@ int mutt_autocrypt_db_init(int 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 @@ -194,15 +195,13 @@ void mutt_autocrypt_db_normalize_addrlist(struct AddressList *al) */ 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; @@ -255,10 +254,9 @@ void mutt_autocrypt_db_account_free(struct AutocryptAccount **account) */ 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) @@ -281,7 +279,7 @@ int mutt_autocrypt_db_account_get(struct Address *addr, struct AutocryptAccount 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) @@ -314,12 +312,11 @@ cleanup: * @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) { @@ -450,7 +447,7 @@ int mutt_autocrypt_db_account_get_all(struct AutocryptAccount ***accounts, int * { 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; @@ -480,7 +477,8 @@ int mutt_autocrypt_db_account_get_all(struct AutocryptAccount ***accounts, int * 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); @@ -541,10 +539,9 @@ void mutt_autocrypt_db_peer_free(struct AutocryptPeer **peer) */ 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) @@ -571,7 +568,7 @@ int mutt_autocrypt_db_peer_get(struct Address *addr, struct AutocryptPeer **peer 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) @@ -754,9 +751,8 @@ int mutt_autocrypt_db_peer_history_insert(struct Address *addr, 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) { @@ -830,9 +826,8 @@ int mutt_autocrypt_db_gossip_history_insert(struct Address *addr, 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) { diff --git a/autocrypt/autocrypt_gpgme.c b/autocrypt/autocrypt_gpgme.c index 58f312174..3880b2024 100644 --- a/autocrypt/autocrypt_gpgme.c +++ b/autocrypt/autocrypt_gpgme.c @@ -37,9 +37,7 @@ */ 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) @@ -145,7 +143,6 @@ int mutt_autocrypt_gpgme_create_key(struct Address *addr, struct Buffer *keyid, { 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 }; @@ -166,8 +163,9 @@ int mutt_autocrypt_gpgme_create_key(struct Address *addr, struct Buffer *keyid, 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: @@ -221,14 +219,12 @@ int mutt_autocrypt_gpgme_import_key(const char *keydata, struct Buffer *keyid) { 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; @@ -238,7 +234,7 @@ int mutt_autocrypt_gpgme_import_key(const char *keydata, struct Buffer *keyid) 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); @@ -257,14 +253,14 @@ cleanup: * @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; @@ -272,9 +268,9 @@ int mutt_autocrypt_gpgme_is_valid_key(const char *keyid) 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); diff --git a/autocrypt/autocrypt_private.h b/autocrypt/autocrypt_private.h index 5570a57ea..35690370a 100644 --- a/autocrypt/autocrypt_private.h +++ b/autocrypt/autocrypt_private.h @@ -28,24 +28,29 @@ 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); @@ -63,6 +68,6 @@ int mutt_autocrypt_schema_update(void); 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 */ diff --git a/autocrypt/autocrypt_schema.c b/autocrypt/autocrypt_schema.c index 211ecdfb5..b8b982ad1 100644 --- a/autocrypt/autocrypt_schema.c +++ b/autocrypt/autocrypt_schema.c @@ -31,10 +31,9 @@ */ 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, " @@ -99,7 +98,7 @@ int mutt_autocrypt_schema_init(void) 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; @@ -107,7 +106,7 @@ int mutt_autocrypt_schema_update(void) if (sqlite3_step(stmt) != SQLITE_ROW) goto cleanup; - version = sqlite3_column_int(stmt, 0); + int version = sqlite3_column_int(stmt, 0); if (version > 1) { diff --git a/commands.c b/commands.c index 69db23fb1..a92f3bb5a 100644 --- a/commands.c +++ b/commands.c @@ -106,14 +106,13 @@ static void process_protected_headers(struct Email *e) 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) diff --git a/email/body.h b/email/body.h index 338251c9a..78cab06a5 100644 --- a/email/body.h +++ b/email/body.h @@ -82,8 +82,7 @@ struct Body 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 diff --git a/email/envelope.c b/email/envelope.c index 9c4d8877e..068de6232 100644 --- a/email/envelope.c +++ b/email/envelope.c @@ -63,11 +63,11 @@ struct Envelope *mutt_env_new(void) */ void mutt_free_autocrypthdr(struct AutocryptHeader **p) { - struct AutocryptHeader *cur; - if (!p) return; + struct AutocryptHeader *cur = NULL; + while (*p) { cur = *p; diff --git a/email/envelope.h b/email/envelope.h index dd10beded..0824694ad 100644 --- a/email/envelope.h +++ b/email/envelope.h @@ -42,8 +42,8 @@ struct AutocryptHeader { char *addr; char *keydata; - unsigned int prefer_encrypt : 1; - unsigned int invalid : 1; + bool prefer_encrypt : 1; + bool invalid : 1; struct AutocryptHeader *next; }; #endif @@ -97,7 +97,7 @@ void mutt_env_to_local (struct Envelope *e); #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 */ diff --git a/email/parse.c b/email/parse.c index 1c92cd438..9a393cffa 100644 --- a/email/parse.c +++ b/email/parse.c @@ -104,14 +104,13 @@ void mutt_auto_subscribe(const char *mailto) * 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 */ @@ -258,7 +257,7 @@ static void parse_content_disposition(const char *s, struct Body *ct) 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); @@ -470,7 +469,7 @@ void mutt_parse_content_type(const char *s, struct Body *ct) *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, @@ -559,10 +558,10 @@ static struct AutocryptHeader *parse_autocrypt(struct AutocryptHeader *head, con 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; } @@ -573,7 +572,7 @@ static struct AutocryptHeader *parse_autocrypt(struct AutocryptHeader *head, con { if (autocrypt->addr) { - autocrypt->invalid = 1; + autocrypt->invalid = true; goto cleanup; } autocrypt->addr = p->value; @@ -582,13 +581,13 @@ static struct AutocryptHeader *parse_autocrypt(struct AutocryptHeader *head, con 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; @@ -596,7 +595,7 @@ static struct AutocryptHeader *parse_autocrypt(struct AutocryptHeader *head, con } else if (p->attribute && (p->attribute[0] != '_')) { - autocrypt->invalid = 1; + autocrypt->invalid = true; goto cleanup; } } @@ -604,7 +603,7 @@ static struct AutocryptHeader *parse_autocrypt(struct AutocryptHeader *head, con /* 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); @@ -956,7 +955,7 @@ int mutt_rfc822_parse_line(struct Envelope *env, struct Email *e, char *line, if (C_Autocrypt) { env->autocrypt = parse_autocrypt(env->autocrypt, p); - matched = 1; + matched = true; } } else if (mutt_str_strcasecmp(line + 1, "utocrypt-gossip") == 0) @@ -964,7 +963,7 @@ int mutt_rfc822_parse_line(struct Envelope *env, struct Email *e, char *line, if (C_Autocrypt) { env->autocrypt_gossip = parse_autocrypt(env->autocrypt_gossip, p); - matched = 1; + matched = true; } } #endif diff --git a/globals.h b/globals.h index df686eafd..b46684f73 100644 --- a/globals.h +++ b/globals.h @@ -87,6 +87,11 @@ WHERE int CurrentMenu; ///< Current Menu, e.g. #MENU_PAGER 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 @@ -99,8 +104,6 @@ WHERE char *C_AttachFormat; ///< Config: printf-like format str #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 diff --git a/imap/message.c b/imap/message.c index 71c23d92c..c7562c7e7 100644 --- a/imap/message.c +++ b/imap/message.c @@ -1036,7 +1036,7 @@ static int read_headers_fetch_new(struct Mailbox *m, unsigned int msn_begin, 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 " @@ -1049,7 +1049,7 @@ static int read_headers_fetch_new(struct Mailbox *m, unsigned int msn_begin, 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) { diff --git a/ncrypt/crypt.c b/ncrypt/crypt.c index ef15b5345..3037dc399 100644 --- a/ncrypt/crypt.c +++ b/ncrypt/crypt.c @@ -169,21 +169,21 @@ bool crypt_valid_passphrase(SecurityFlags flags) * @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; } @@ -329,8 +329,8 @@ int mutt_protect(struct Email *e, char *keylist, int postpone) 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; } @@ -967,8 +967,8 @@ int crypt_get_keys(struct Email *e, char **keylist, bool oppenc_mode) 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 diff --git a/ncrypt/cryptglue.c b/ncrypt/cryptglue.c index a64b58a04..10bd46da3 100644 --- a/ncrypt/cryptglue.c +++ b/ncrypt/cryptglue.c @@ -199,16 +199,14 @@ bool crypt_pgp_valid_passphrase(void) 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; } } @@ -241,16 +239,14 @@ int crypt_pgp_application_handler(struct Body *m, struct State *s) 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; } } @@ -329,19 +325,16 @@ struct Body *crypt_pgp_sign_message(struct Body *a) /** * 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; diff --git a/ncrypt/ncrypt.h b/ncrypt/ncrypt.h index 2f25628d0..f24870897 100644 --- a/ncrypt/ncrypt.h +++ b/ncrypt/ncrypt.h @@ -198,7 +198,7 @@ SecurityFlags mutt_is_malformed_multipart_pgp_encrypted(struct Body *b); 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); diff --git a/send.c b/send.c index 5cb730c71..495492685 100644 --- a/send.c +++ b/send.c @@ -207,7 +207,7 @@ static void add_mailing_lists(struct AddressList *out, const struct AddressList * @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; @@ -283,14 +283,14 @@ static int edit_envelope(struct Envelope *en, SendFlags flags) 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; } @@ -1634,7 +1634,7 @@ static int save_fcc(struct Email *e, char *fcc, size_t fcc_len, struct Body *cle /* 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 */ @@ -1776,7 +1776,7 @@ static int postpone_message(struct Email *e_post, struct Email *e_cur, char *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); @@ -2488,7 +2488,7 @@ int ci_send_message(SendFlags flags, struct Email *e_templ, const char *tempfile 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); diff --git a/send.h b/send.h index 5c38fb456..35b95df0e 100644 --- a/send.h +++ b/send.h @@ -103,7 +103,7 @@ typedef uint16_t SendFlags; ///< Flags for ci_send_message(), e.g. # 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);