From: Richard Russon Date: Thu, 26 Apr 2018 20:22:39 +0000 (+0100) Subject: flatten ifs X-Git-Tag: neomutt-20180512~27^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f7ca5df1a88fb27536819c0e90bf8d12a4cb0851;p=neomutt flatten ifs --- diff --git a/commands.c b/commands.c index 95468dd0f..e0804b5bd 100644 --- a/commands.c +++ b/commands.c @@ -628,24 +628,24 @@ void mutt_shell_escape(void) char buf[LONG_STRING]; buf[0] = '\0'; - if (mutt_get_field(_("Shell command: "), buf, sizeof(buf), MUTT_CMD) == 0) - { - if (!buf[0] && Shell) - mutt_str_strfcpy(buf, Shell, sizeof(buf)); - if (buf[0]) - { - mutt_window_clearline(MuttMessageWindow, 0); - mutt_endwin(); - fflush(stdout); - int rc = mutt_system(buf); - if (rc == -1) - mutt_debug(1, "Error running \"%s\"!", buf); - - if ((rc != 0) || WaitKey) - mutt_any_key_to_continue(NULL); - mutt_buffy_check(true); - } - } + if (mutt_get_field(_("Shell command: "), buf, sizeof(buf), MUTT_CMD) != 0) + return; + + if (!buf[0] && Shell) + mutt_str_strfcpy(buf, Shell, sizeof(buf)); + if (!buf[0]) + return; + + mutt_window_clearline(MuttMessageWindow, 0); + mutt_endwin(); + fflush(stdout); + int rc = mutt_system(buf); + if (rc == -1) + mutt_debug(1, "Error running \"%s\"!", buf); + + if ((rc != 0) || WaitKey) + mutt_any_key_to_continue(NULL); + mutt_buffy_check(true); } /** diff --git a/conn/socket.c b/conn/socket.c index 36fe1baca..fb496885e 100644 --- a/conn/socket.c +++ b/conn/socket.c @@ -73,18 +73,18 @@ struct ConnectionList *mutt_socket_head(void) */ static int socket_preconnect(void) { - if (mutt_str_strlen(Preconnect)) + if (!Preconnect) + return 0; + + mutt_debug(2, "Executing preconnect: %s\n", Preconnect); + const int rc = mutt_system(Preconnect); + mutt_debug(2, "Preconnect result: %d\n", rc); + if (rc != 0) { - mutt_debug(2, "Executing preconnect: %s\n", Preconnect); - const int rc = mutt_system(Preconnect); - mutt_debug(2, "Preconnect result: %d\n", rc); - if (rc != 0) - { - const int save_errno = errno; - mutt_perror(_("Preconnect command failed.")); + const int save_errno = errno; + mutt_perror(_("Preconnect command failed.")); - return save_errno; - } + return save_errno; } return 0; diff --git a/conn/ssl.c b/conn/ssl.c index 7b0dcfb74..cb6a4f894 100644 --- a/conn/ssl.c +++ b/conn/ssl.c @@ -503,26 +503,27 @@ static bool compare_certificates(X509 *cert, X509 *peercert, */ static bool check_certificate_expiration(X509 *peercert, bool silent) { - if (SslVerifyDates != MUTT_NO) + if (SslVerifyDates == MUTT_NO) + return true; + + if (X509_cmp_current_time(X509_get_notBefore(peercert)) >= 0) { - if (X509_cmp_current_time(X509_get_notBefore(peercert)) >= 0) + if (!silent) { - if (!silent) - { - mutt_debug(2, "Server certificate is not yet valid\n"); - mutt_error(_("Server certificate is not yet valid")); - } - return false; + mutt_debug(2, "Server certificate is not yet valid\n"); + mutt_error(_("Server certificate is not yet valid")); } - if (X509_cmp_current_time(X509_get_notAfter(peercert)) <= 0) + return false; + } + + if (X509_cmp_current_time(X509_get_notAfter(peercert)) <= 0) + { + if (!silent) { - if (!silent) - { - mutt_debug(2, "Server certificate has expired\n"); - mutt_error(_("Server certificate has expired")); - } - return false; + mutt_debug(2, "Server certificate has expired\n"); + mutt_error(_("Server certificate has expired")); } + return false; } return true; @@ -684,18 +685,18 @@ static int ssl_socket_write(struct Connection *conn, const char *buf, size_t len */ static void ssl_get_client_cert(struct SslSockData *ssldata, struct Connection *conn) { - if (SslClientCert) - { - mutt_debug(2, "Using client certificate %s\n", SslClientCert); - SSL_CTX_set_default_passwd_cb_userdata(ssldata->ctx, &conn->account); - SSL_CTX_set_default_passwd_cb(ssldata->ctx, ssl_passwd_cb); - SSL_CTX_use_certificate_file(ssldata->ctx, SslClientCert, SSL_FILETYPE_PEM); - SSL_CTX_use_PrivateKey_file(ssldata->ctx, SslClientCert, SSL_FILETYPE_PEM); - - /* if we are using a client cert, SASL may expect an external auth name */ - if (mutt_account_getuser(&conn->account) < 0) - mutt_debug(1, "Couldn't get user info\n"); - } + if (!SslClientCert) + return; + + mutt_debug(2, "Using client certificate %s\n", SslClientCert); + SSL_CTX_set_default_passwd_cb_userdata(ssldata->ctx, &conn->account); + SSL_CTX_set_default_passwd_cb(ssldata->ctx, ssl_passwd_cb); + SSL_CTX_use_certificate_file(ssldata->ctx, SslClientCert, SSL_FILETYPE_PEM); + SSL_CTX_use_PrivateKey_file(ssldata->ctx, SslClientCert, SSL_FILETYPE_PEM); + + /* if we are using a client cert, SASL may expect an external auth name */ + if (mutt_account_getuser(&conn->account) < 0) + mutt_debug(1, "Couldn't get user info\n"); } /** @@ -706,9 +707,7 @@ static void ssl_get_client_cert(struct SslSockData *ssldata, struct Connection * */ static int ssl_socket_close_and_restore(struct Connection *conn) { - int rc; - - rc = ssl_socket_close(conn); + int rc = ssl_socket_close(conn); conn->conn_read = raw_socket_read; conn->conn_write = raw_socket_write; conn->conn_close = raw_socket_close; diff --git a/curs_main.c b/curs_main.c index 78e3e2c21..33a896474 100644 --- a/curs_main.c +++ b/curs_main.c @@ -229,37 +229,37 @@ static int ci_previous_undeleted(int msgno) */ static int ci_first_message(void) { - if (Context && Context->msgcount) - { - int old = -1; - for (int i = 0; i < Context->vcount; i++) - { - if (!Context->hdrs[Context->v2r[i]]->read && - !Context->hdrs[Context->v2r[i]]->deleted) - { - if (!Context->hdrs[Context->v2r[i]]->old) - return i; - else if (old == -1) - old = i; - } - } - if (old != -1) - return old; + if (!Context || !Context->msgcount) + return 0; - /* If Sort is reverse and not threaded, the latest message is first. - * If Sort is threaded, the latest message is first iff exactly one - * of Sort and SortAux are reverse. - */ - if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) || - ((Sort & SORT_MASK) == SORT_THREADS && ((Sort ^ SortAux) & SORT_REVERSE))) - { - return 0; - } - else + int old = -1; + for (int i = 0; i < Context->vcount; i++) + { + if (!Context->hdrs[Context->v2r[i]]->read && !Context->hdrs[Context->v2r[i]]->deleted) { - return (Context->vcount ? Context->vcount - 1 : 0); + if (!Context->hdrs[Context->v2r[i]]->old) + return i; + else if (old == -1) + old = i; } } + if (old != -1) + return old; + + /* If Sort is reverse and not threaded, the latest message is first. + * If Sort is threaded, the latest message is first iff exactly one + * of Sort and SortAux are reverse. + */ + if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) || + ((Sort & SORT_MASK) == SORT_THREADS && ((Sort ^ SortAux) & SORT_REVERSE))) + { + return 0; + } + else + { + return (Context->vcount ? Context->vcount - 1 : 0); + } + return 0; } diff --git a/group.c b/group.c index f92150b63..75f82c29b 100644 --- a/group.c +++ b/group.c @@ -188,15 +188,14 @@ int mutt_group_context_remove_regex(struct GroupContext *ctx, const char *s) bool mutt_group_match(struct Group *g, const char *s) { - struct Address *ap = NULL; + if (!g || !s) + return false; - if (s && g) - { - if (mutt_regexlist_match(g->rs, s)) + if (mutt_regexlist_match(g->rs, s)) + return true; + for (struct Address *ap = g->as; ap; ap = ap->next) + if (ap->mailbox && (mutt_str_strcasecmp(s, ap->mailbox) == 0)) return true; - for (ap = g->as; ap; ap = ap->next) - if (ap->mailbox && (mutt_str_strcasecmp(s, ap->mailbox) == 0)) - return true; - } + return false; } diff --git a/hook.c b/hook.c index d7eac9504..a910f05a3 100644 --- a/hook.c +++ b/hook.c @@ -527,28 +527,28 @@ static int addr_hook(char *path, size_t pathlen, int type, struct Context *ctx, void mutt_default_save(char *path, size_t pathlen, struct Header *hdr) { *path = '\0'; - if (addr_hook(path, pathlen, MUTT_SAVEHOOK, Context, hdr) != 0) + if (addr_hook(path, pathlen, MUTT_SAVEHOOK, Context, hdr) == 0) + return; + + struct Address *addr = NULL; + struct Envelope *env = hdr->env; + bool from_me = mutt_addr_is_user(env->from); + + if (!from_me && env->reply_to && env->reply_to->mailbox) + addr = env->reply_to; + else if (!from_me && env->from && env->from->mailbox) + addr = env->from; + else if (env->to && env->to->mailbox) + addr = env->to; + else if (env->cc && env->cc->mailbox) + addr = env->cc; + else + addr = NULL; + if (addr) { - struct Address *addr = NULL; - struct Envelope *env = hdr->env; - bool from_me = mutt_addr_is_user(env->from); - - if (!from_me && env->reply_to && env->reply_to->mailbox) - addr = env->reply_to; - else if (!from_me && env->from && env->from->mailbox) - addr = env->from; - else if (env->to && env->to->mailbox) - addr = env->to; - else if (env->cc && env->cc->mailbox) - addr = env->cc; - else - addr = NULL; - if (addr) - { - char tmp[_POSIX_PATH_MAX]; - mutt_safe_path(tmp, sizeof(tmp), addr); - snprintf(path, pathlen, "=%s", tmp); - } + char tmp[_POSIX_PATH_MAX]; + mutt_safe_path(tmp, sizeof(tmp), addr); + snprintf(path, pathlen, "=%s", tmp); } } diff --git a/imap/message.c b/imap/message.c index ce82b4015..18f08348c 100644 --- a/imap/message.c +++ b/imap/message.c @@ -579,18 +579,18 @@ static void set_changed_flag(struct Context *ctx, struct Header *h, * cmd_parse_fetch(). We don't want to count a local modification * to the header flag as a "change". */ - if ((old_hd_flag != new_hd_flag) || (!local_changes)) - { - if (new_hd_flag != h_flag) - { - if (server_changes) - *server_changes = 1; + if ((old_hd_flag == new_hd_flag) && local_changes) + return; - /* Local changes have priority */ - if (!local_changes) - mutt_set_flag(ctx, h, flag_name, new_hd_flag); - } - } + if (new_hd_flag == h_flag) + return; + + if (server_changes) + *server_changes = 1; + + /* Local changes have priority */ + if (!local_changes) + mutt_set_flag(ctx, h, flag_name, new_hd_flag); } /** @@ -1580,13 +1580,13 @@ int imap_cache_clean(struct ImapData *idata) */ void imap_free_header_data(struct ImapHeaderData **data) { - if (*data) - { - /* this should be safe even if the list wasn't used */ - FREE(&((*data)->flags_system)); - FREE(&((*data)->flags_remote)); - FREE(data); - } + if (!data || !*data) + return; + + /* this should be safe even if the list wasn't used */ + FREE(&((*data)->flags_system)); + FREE(&((*data)->flags_remote)); + FREE(data); } /** diff --git a/imap/utf7.c b/imap/utf7.c index a7d9854c3..3a38c68e7 100644 --- a/imap/utf7.c +++ b/imap/utf7.c @@ -317,19 +317,19 @@ bail: */ void imap_utf_encode(struct ImapData *idata, char **s) { - if (Charset) + if (!Charset || !s) + return; + + char *t = mutt_str_strdup(*s); + if (t && (mutt_ch_convert_string(&t, Charset, "utf-8", 0) == 0)) { - char *t = mutt_str_strdup(*s); - if (t && mutt_ch_convert_string(&t, Charset, "utf-8", 0) == 0) - { - FREE(s); - if (idata->unicode) - *s = mutt_str_strdup(t); - else - *s = utf8_to_utf7(t, strlen(t), NULL, 0); - } - FREE(&t); + FREE(s); + if (idata->unicode) + *s = mutt_str_strdup(t); + else + *s = utf8_to_utf7(t, strlen(t), NULL, 0); } + FREE(&t); } /** @@ -339,21 +339,21 @@ void imap_utf_encode(struct ImapData *idata, char **s) */ void imap_utf_decode(struct ImapData *idata, char **s) { + if (!Charset) + return; + char *t = NULL; - if (Charset) - { - if (idata->unicode) - t = mutt_str_strdup(*s); - else - t = utf7_to_utf8(*s, strlen(*s), 0, 0); + if (idata->unicode) + t = mutt_str_strdup(*s); + else + t = utf7_to_utf8(*s, strlen(*s), 0, 0); - if (t && mutt_ch_convert_string(&t, "utf-8", Charset, 0) == 0) - { - FREE(s); - *s = t; - } - else - FREE(&t); + if (t && mutt_ch_convert_string(&t, "utf-8", Charset, 0) == 0) + { + FREE(s); + *s = t; } + else + FREE(&t); } diff --git a/init.c b/init.c index c440b8b78..e406590ad 100644 --- a/init.c +++ b/init.c @@ -3080,16 +3080,16 @@ finish: static void matches_ensure_morespace(int current) { - if (current > MatchesListsize - 2) - { - int base_space = MAX(NUMVARS, NUMCOMMANDS) + 1; - int extra_space = MatchesListsize - base_space; - extra_space *= 2; - const int space = base_space + extra_space; - mutt_mem_realloc(&Matches, space * sizeof(char *)); - memset(&Matches[current + 1], 0, space - current); - MatchesListsize = space; - } + if (current <= (MatchesListsize - 2)) + return; + + int base_space = MAX(NUMVARS, NUMCOMMANDS) + 1; + int extra_space = MatchesListsize - base_space; + extra_space *= 2; + const int space = base_space + extra_space; + mutt_mem_realloc(&Matches, space * sizeof(char *)); + memset(&Matches[current + 1], 0, space - current); + MatchesListsize = space; } /** @@ -3106,19 +3106,19 @@ static void candidate(char *dest, char *try, const char *src, size_t len) if (!dest || !try || !src) return; - if (strstr(src, try) == src) + if (strstr(src, try) != src) + return; + + matches_ensure_morespace(NumMatched); + Matches[NumMatched++] = src; + if (dest[0] == 0) + mutt_str_strfcpy(dest, src, len); + else { - matches_ensure_morespace(NumMatched); - Matches[NumMatched++] = src; - if (dest[0] == 0) - mutt_str_strfcpy(dest, src, len); - else - { - int l; - for (l = 0; src[l] && src[l] == dest[l]; l++) - ; - dest[l] = '\0'; - } + int l; + for (l = 0; src[l] && src[l] == dest[l]; l++) + ; + dest[l] = '\0'; } } diff --git a/menu.c b/menu.c index e19a5970b..51ba73809 100644 --- a/menu.c +++ b/menu.c @@ -472,20 +472,20 @@ void menu_redraw_current(struct Menu *menu) static void menu_redraw_prompt(struct Menu *menu) { - if (menu->dialog) + if (!menu || !menu->dialog) + return; + + if (OptMsgErr) { - if (OptMsgErr) - { - mutt_sleep(1); - OptMsgErr = false; - } + mutt_sleep(1); + OptMsgErr = false; + } - if (ErrorBufMessage) - mutt_clear_error(); + if (ErrorBufMessage) + mutt_clear_error(); - mutt_window_mvaddstr(menu->messagewin, 0, 0, menu->prompt); - mutt_window_clrtoeol(menu->messagewin); - } + mutt_window_mvaddstr(menu->messagewin, 0, 0, menu->prompt); + mutt_window_clrtoeol(menu->messagewin); } void menu_check_recenter(struct Menu *menu) @@ -667,11 +667,11 @@ void menu_half_up(struct Menu *menu) void menu_top_page(struct Menu *menu) { - if (menu->current != menu->top) - { - menu->current = menu->top; - menu->redraw = REDRAW_MOTION; - } + if (menu->current == menu->top) + return; + + menu->current = menu->top; + menu->redraw = REDRAW_MOTION; } void menu_bottom_page(struct Menu *menu) diff --git a/mh.c b/mh.c index 35e47ea8f..4bb4dd20f 100644 --- a/mh.c +++ b/mh.c @@ -107,16 +107,16 @@ static inline struct MhData *mh_data(struct Context *ctx) static void mhs_alloc(struct MhSequences *mhs, int i) { - if (i > mhs->max || !mhs->flags) - { - const int newmax = i + 128; - int j = mhs->flags ? mhs->max + 1 : 0; - mutt_mem_realloc(&mhs->flags, sizeof(mhs->flags[0]) * (newmax + 1)); - while (j <= newmax) - mhs->flags[j++] = 0; + if ((i <= mhs->max) && mhs->flags) + return; - mhs->max = newmax; - } + const int newmax = i + 128; + int j = mhs->flags ? mhs->max + 1 : 0; + mutt_mem_realloc(&mhs->flags, sizeof(mhs->flags[0]) * (newmax + 1)); + while (j <= newmax) + mhs->flags[j++] = 0; + + mhs->max = newmax; } static void mhs_free_sequences(struct MhSequences *mhs) @@ -818,13 +818,12 @@ struct Header *maildir_parse_message(int magic, const char *fname, bool is_old, struct Header *h) { FILE *f = fopen(fname, "r"); - if (f) - { - h = maildir_parse_stream(magic, f, fname, is_old, h); - mutt_file_fclose(&f); - return h; - } - return NULL; + if (!f) + return NULL; + + h = maildir_parse_stream(magic, f, fname, is_old, h); + mutt_file_fclose(&f); + return h; } static int maildir_parse_dir(struct Context *ctx, struct Maildir ***last, diff --git a/mutt/date.c b/mutt/date.c index c0aa89cb6..79bb9836f 100644 --- a/mutt/date.c +++ b/mutt/date.c @@ -160,12 +160,11 @@ static time_t compute_tz(time_t g, struct tm *utc) */ static int is_leap_year_feb(struct tm *tm) { - if (tm->tm_mon == 1) - { - int y = tm->tm_year + 1900; - return (((y & 3) == 0) && (((y % 100) != 0) || ((y % 400) == 0))); - } - return 0; + if (tm->tm_mon != 1) + return 0; + + int y = tm->tm_year + 1900; + return (((y & 3) == 0) && (((y % 100) != 0) || ((y % 400) == 0))); } /** diff --git a/mutt/file.c b/mutt/file.c index b3e69ab4b..2017523d7 100644 --- a/mutt/file.c +++ b/mutt/file.c @@ -166,20 +166,20 @@ int mutt_file_fclose(FILE **f) */ int mutt_file_fsync_close(FILE **f) { + if (!f || !*f) + return 0; + int r = 0; - if (*f) + if (fflush(*f) || fsync(fileno(*f))) { - if (fflush(*f) || fsync(fileno(*f))) - { - int save_errno = errno; - r = -1; - mutt_file_fclose(f); - errno = save_errno; - } - else - r = mutt_file_fclose(f); + int save_errno = errno; + r = -1; + mutt_file_fclose(f); + errno = save_errno; } + else + r = mutt_file_fclose(f); return r; } diff --git a/mutt_lua.c b/mutt_lua.c index a78b590b5..e21cb6b66 100644 --- a/mutt_lua.c +++ b/mutt_lua.c @@ -363,23 +363,23 @@ static void luaopen_mutt(lua_State *l) static bool lua_init(lua_State **l) { + if (l && *l) + return true; + + mutt_debug(2, " * lua_init()\n"); + *l = luaL_newstate(); + if (!*l) { - mutt_debug(2, " * lua_init()\n"); - *l = luaL_newstate(); - - if (!*l) - { - mutt_error("Error: Couldn't load the lua interpreter."); - return false; - } + mutt_error("Error: Couldn't load the lua interpreter."); + return false; + } - lua_atpanic(*l, handle_panic); + lua_atpanic(*l, handle_panic); - /* load various Lua libraries */ - luaL_openlibs(*l); - luaopen_mutt(*l); - } + /* load various Lua libraries */ + luaL_openlibs(*l); + luaopen_mutt(*l); return true; } diff --git a/mutt_notmuch.c b/mutt_notmuch.c index dcfc7e57d..8c3490ddf 100644 --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -598,13 +598,13 @@ static notmuch_database_t *get_db(struct NmCtxData *data, bool writable) { if (!data) return NULL; - if (!data->db) - { - const char *db_filename = get_db_filename(data); + if (data->db) + return data->db; + + const char *db_filename = get_db_filename(data); + if (db_filename) + data->db = do_database_open(db_filename, writable, true); - if (db_filename) - data->db = do_database_open(db_filename, writable, true); - } return data->db; } @@ -616,20 +616,18 @@ static notmuch_database_t *get_db(struct NmCtxData *data, bool writable) */ static int release_db(struct NmCtxData *data) { - if (data && data->db) - { - mutt_debug(1, "nm: db close\n"); + if (!data || !data->db) + return -1; + + mutt_debug(1, "nm: db close\n"); #ifdef NOTMUCH_API_3 - notmuch_database_destroy(data->db); + notmuch_database_destroy(data->db); #else - notmuch_database_close(data->db); + notmuch_database_close(data->db); #endif - data->db = NULL; - data->longrun = false; - return 0; - } - - return -1; + data->db = NULL; + data->longrun = false; + return 0; } /** @@ -644,16 +642,14 @@ static int db_trans_begin(struct NmCtxData *data) if (!data || !data->db) return -1; - if (!data->trans) - { - mutt_debug(2, "nm: db trans start\n"); - if (notmuch_database_begin_atomic(data->db)) - return -1; - data->trans = true; - return 1; - } + if (data->trans) + return 0; - return 0; + mutt_debug(2, "nm: db trans start\n"); + if (notmuch_database_begin_atomic(data->db)) + return -1; + data->trans = true; + return 1; } /** @@ -667,13 +663,13 @@ static int db_trans_end(struct NmCtxData *data) if (!data || !data->db) return -1; - if (data->trans) - { - mutt_debug(2, "nm: db trans end\n"); - data->trans = false; - if (notmuch_database_end_atomic(data->db)) - return -1; - } + if (!data->trans) + return 0; + + mutt_debug(2, "nm: db trans end\n"); + data->trans = false; + if (notmuch_database_end_atomic(data->db)) + return -1; return 0; } @@ -1724,24 +1720,25 @@ done: */ static unsigned int count_query(notmuch_database_t *db, const char *qstr) { - unsigned int res = 0; notmuch_query_t *q = notmuch_query_create(db, qstr); + if (!q) + return 0; - if (q) - { - apply_exclude_tags(q); + unsigned int res = 0; + + apply_exclude_tags(q); #if LIBNOTMUCH_CHECK_VERSION(5, 0, 0) - if (notmuch_query_count_messages(q, &res) != NOTMUCH_STATUS_SUCCESS) - res = 0; /* may not be defined on error */ + if (notmuch_query_count_messages(q, &res) != NOTMUCH_STATUS_SUCCESS) + res = 0; /* may not be defined on error */ #elif LIBNOTMUCH_CHECK_VERSION(4, 3, 0) - if (notmuch_query_count_messages_st(q, &res) != NOTMUCH_STATUS_SUCCESS) - res = 0; /* may not be defined on error */ + if (notmuch_query_count_messages_st(q, &res) != NOTMUCH_STATUS_SUCCESS) + res = 0; /* may not be defined on error */ #else - res = notmuch_query_count_messages(q); + res = notmuch_query_count_messages(q); #endif - notmuch_query_destroy(q); - mutt_debug(1, "nm: count '%s', result=%d\n", qstr, res); - } + notmuch_query_destroy(q); + mutt_debug(1, "nm: count '%s', result=%d\n", qstr, res); + return res; } diff --git a/ncrypt/crypt.c b/ncrypt/crypt.c index 68d6396ad..8e33817dc 100644 --- a/ncrypt/crypt.c +++ b/ncrypt/crypt.c @@ -353,20 +353,18 @@ int mutt_is_multipart_signed(struct Body *b) int mutt_is_multipart_encrypted(struct Body *b) { - if (WithCrypto & APPLICATION_PGP) - { - char *p = NULL; + if ((WithCrypto & APPLICATION_PGP) == 0) + return 0; - if (!b || b->type != TYPEMULTIPART || !b->subtype || - (mutt_str_strcasecmp(b->subtype, "encrypted") != 0) || - !(p = mutt_param_get(&b->parameter, "protocol")) || - (mutt_str_strcasecmp(p, "application/pgp-encrypted") != 0)) - return 0; + char *p = NULL; - return PGPENCRYPT; - } + if (!b || b->type != TYPEMULTIPART || !b->subtype || + (mutt_str_strcasecmp(b->subtype, "encrypted") != 0) || + !(p = mutt_param_get(&b->parameter, "protocol")) || + (mutt_str_strcasecmp(p, "application/pgp-encrypted") != 0)) + return 0; - return 0; + return PGPENCRYPT; } int mutt_is_valid_multipart_pgp_encrypted(struct Body *b) @@ -499,62 +497,62 @@ int mutt_is_application_smime(struct Body *m) if (!m) return 0; - if ((m->type & TYPEAPPLICATION) && m->subtype) + if (((m->type & TYPEAPPLICATION) == 0) || !m->subtype) + return 0; + + char *t = NULL; + bool complain = false; + /* S/MIME MIME types don't need x- anymore, see RFC2311 */ + if ((mutt_str_strcasecmp(m->subtype, "x-pkcs7-mime") == 0) || + (mutt_str_strcasecmp(m->subtype, "pkcs7-mime") == 0)) { - char *t = NULL; - bool complain = false; - /* S/MIME MIME types don't need x- anymore, see RFC2311 */ - if ((mutt_str_strcasecmp(m->subtype, "x-pkcs7-mime") == 0) || - (mutt_str_strcasecmp(m->subtype, "pkcs7-mime") == 0)) + t = mutt_param_get(&m->parameter, "smime-type"); + if (t) { - t = mutt_param_get(&m->parameter, "smime-type"); - if (t) - { - if (mutt_str_strcasecmp(t, "enveloped-data") == 0) - return SMIMEENCRYPT; - else if (mutt_str_strcasecmp(t, "signed-data") == 0) - return (SMIMESIGN | SMIMEOPAQUE); - else - return 0; - } - /* Netscape 4.7 uses - * Content-Description: S/MIME Encrypted Message - * instead of Content-Type parameter - */ - if (mutt_str_strcasecmp(m->description, "S/MIME Encrypted Message") == 0) + if (mutt_str_strcasecmp(t, "enveloped-data") == 0) return SMIMEENCRYPT; - complain = true; + else if (mutt_str_strcasecmp(t, "signed-data") == 0) + return (SMIMESIGN | SMIMEOPAQUE); + else + return 0; } - else if (mutt_str_strcasecmp(m->subtype, "octet-stream") != 0) - return 0; + /* Netscape 4.7 uses + * Content-Description: S/MIME Encrypted Message + * instead of Content-Type parameter + */ + if (mutt_str_strcasecmp(m->description, "S/MIME Encrypted Message") == 0) + return SMIMEENCRYPT; + complain = true; + } + else if (mutt_str_strcasecmp(m->subtype, "octet-stream") != 0) + return 0; - t = mutt_param_get(&m->parameter, "name"); + t = mutt_param_get(&m->parameter, "name"); - if (!t) - t = m->d_filename; - if (!t) - t = m->filename; - if (!t) - { - if (complain) - mutt_message( - _("S/MIME messages with no hints on content are unsupported.")); - return 0; - } + if (!t) + t = m->d_filename; + if (!t) + t = m->filename; + if (!t) + { + if (complain) + mutt_message( + _("S/MIME messages with no hints on content are unsupported.")); + return 0; + } - /* no .p7c, .p10 support yet. */ + /* no .p7c, .p10 support yet. */ - size_t len = mutt_str_strlen(t) - 4; - if (len > 0 && *(t + len) == '.') - { - len++; - if (mutt_str_strcasecmp((t + len), "p7m") == 0) - /* Not sure if this is the correct thing to do, but - it's required for compatibility with Outlook */ - return (SMIMESIGN | SMIMEOPAQUE); - else if (mutt_str_strcasecmp((t + len), "p7s") == 0) - return (SMIMESIGN | SMIMEOPAQUE); - } + size_t len = mutt_str_strlen(t) - 4; + if (len > 0 && *(t + len) == '.') + { + len++; + if (mutt_str_strcasecmp((t + len), "p7m") == 0) + /* Not sure if this is the correct thing to do, but + it's required for compatibility with Outlook */ + return (SMIMESIGN | SMIMEOPAQUE); + else if (mutt_str_strcasecmp((t + len), "p7s") == 0) + return (SMIMESIGN | SMIMEOPAQUE); } return 0; diff --git a/ncrypt/crypt_gpgme.c b/ncrypt/crypt_gpgme.c index 7be7fa5f5..f9d94a6bc 100644 --- a/ncrypt/crypt_gpgme.c +++ b/ncrypt/crypt_gpgme.c @@ -4805,15 +4805,15 @@ static void init_common(void) /* this initialization should only run one time, but it may be called by * either pgp_gpgme_init or smime_gpgme_init */ static bool has_run = false; - if (!has_run) - { - gpgme_check_version(NULL); - gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL)); + if (has_run) + return; + + gpgme_check_version(NULL); + gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL)); #ifdef ENABLE_NLS - gpgme_set_locale(NULL, LC_MESSAGES, setlocale(LC_MESSAGES, NULL)); + gpgme_set_locale(NULL, LC_MESSAGES, setlocale(LC_MESSAGES, NULL)); #endif - has_run = true; - } + has_run = true; } static void init_pgp(void) diff --git a/newsrc.c b/newsrc.c index 9f36874c4..08e6a39b9 100644 --- a/newsrc.c +++ b/newsrc.c @@ -72,26 +72,26 @@ struct BodyCache; static struct NntpData *nntp_data_find(struct NntpServer *nserv, const char *group) { struct NntpData *nntp_data = mutt_hash_find(nserv->groups_hash, group); - - if (!nntp_data) + if (nntp_data) + return nntp_data; + + size_t len = strlen(group) + 1; + /* create NntpData structure and add it to hash */ + nntp_data = mutt_mem_calloc(1, sizeof(struct NntpData) + len); + nntp_data->group = (char *) nntp_data + sizeof(struct NntpData); + mutt_str_strfcpy(nntp_data->group, group, len); + nntp_data->nserv = nserv; + nntp_data->deleted = true; + mutt_hash_insert(nserv->groups_hash, nntp_data->group, nntp_data); + + /* add NntpData to list */ + if (nserv->groups_num >= nserv->groups_max) { - size_t len = strlen(group) + 1; - /* create NntpData structure and add it to hash */ - nntp_data = mutt_mem_calloc(1, sizeof(struct NntpData) + len); - nntp_data->group = (char *) nntp_data + sizeof(struct NntpData); - mutt_str_strfcpy(nntp_data->group, group, len); - nntp_data->nserv = nserv; - nntp_data->deleted = true; - mutt_hash_insert(nserv->groups_hash, nntp_data->group, nntp_data); - - /* add NntpData to list */ - if (nserv->groups_num >= nserv->groups_max) - { - nserv->groups_max *= 2; - mutt_mem_realloc(&nserv->groups_list, nserv->groups_max * sizeof(nntp_data)); - } - nserv->groups_list[nserv->groups_num++] = nntp_data; + nserv->groups_max *= 2; + mutt_mem_realloc(&nserv->groups_list, nserv->groups_max * sizeof(nntp_data)); } + nserv->groups_list[nserv->groups_num++] = nntp_data; + return nntp_data; } diff --git a/recvattach.c b/recvattach.c index 7ea552ec1..03e129c1d 100644 --- a/recvattach.c +++ b/recvattach.c @@ -889,22 +889,22 @@ static int recvattach_pgp_check_traditional(struct AttachCtx *actx, struct Menu static void recvattach_edit_content_type(struct AttachCtx *actx, struct Menu *menu, struct Header *hdr) { - if (mutt_edit_content_type(hdr, CURATTACH->content, CURATTACH->fp) == 1) + if (mutt_edit_content_type(hdr, CURATTACH->content, CURATTACH->fp) != 1) + return; + + /* The mutt_update_recvattach_menu() will overwrite any changes + * made to a decrypted CURATTACH->content, so warn the user. */ + if (CURATTACH->decrypted) { - /* The mutt_update_recvattach_menu() will overwrite any changes - * made to a decrypted CURATTACH->content, so warn the user. */ - if (CURATTACH->decrypted) - { - mutt_message( - _("Structural changes to decrypted attachments are not supported")); - mutt_sleep(1); - } - /* Editing the content type can rewrite the body structure. */ - for (int i = 0; i < actx->idxlen; i++) - actx->idx[i]->content = NULL; - mutt_actx_free_entries(actx); - mutt_update_recvattach_menu(actx, menu, 1); + mutt_message( + _("Structural changes to decrypted attachments are not supported")); + mutt_sleep(1); } + /* Editing the content type can rewrite the body structure. */ + for (int i = 0; i < actx->idxlen; i++) + actx->idx[i]->content = NULL; + mutt_actx_free_entries(actx); + mutt_update_recvattach_menu(actx, menu, 1); } int mutt_attach_display_loop(struct Menu *menu, int op, struct Header *hdr, diff --git a/sendlib.c b/sendlib.c index 4f70856cd..9c88733a4 100644 --- a/sendlib.c +++ b/sendlib.c @@ -2213,25 +2213,23 @@ static void encode_headers(struct ListHead *h) const char *mutt_fqdn(short may_hide_host) { - char *p = NULL; + if (!Hostname || (Hostname[0] == '@')) + return NULL; - if (Hostname && Hostname[0] != '@') - { - p = Hostname; + char *p = Hostname; - if (may_hide_host && HiddenHost) - { - p = strchr(Hostname, '.'); - if (p) - p++; + if (may_hide_host && HiddenHost) + { + p = strchr(Hostname, '.'); + if (p) + p++; - /* sanity check: don't hide the host if - * the fqdn is something like detebe.org. - */ + /* sanity check: don't hide the host if + * the fqdn is something like detebe.org. + */ - if (!p || !strchr(p, '.')) - p = Hostname; - } + if (!p || !strchr(p, '.')) + p = Hostname; } return p; diff --git a/signal.c b/signal.c index ec720a5f5..e14b21f61 100644 --- a/signal.c +++ b/signal.c @@ -173,17 +173,17 @@ void mutt_signal_init(void) */ void mutt_block_signals(void) { - if (!OptSignalsBlocked) - { - sigemptyset(&Sigset); - sigaddset(&Sigset, SIGTERM); - sigaddset(&Sigset, SIGHUP); - sigaddset(&Sigset, SIGTSTP); - sigaddset(&Sigset, SIGINT); - sigaddset(&Sigset, SIGWINCH); - sigprocmask(SIG_BLOCK, &Sigset, 0); - OptSignalsBlocked = true; - } + if (OptSignalsBlocked) + return; + + sigemptyset(&Sigset); + sigaddset(&Sigset, SIGTERM); + sigaddset(&Sigset, SIGHUP); + sigaddset(&Sigset, SIGTSTP); + sigaddset(&Sigset, SIGINT); + sigaddset(&Sigset, SIGWINCH); + sigprocmask(SIG_BLOCK, &Sigset, 0); + OptSignalsBlocked = true; } /** @@ -191,56 +191,56 @@ void mutt_block_signals(void) */ void mutt_unblock_signals(void) { - if (OptSignalsBlocked) - { - sigprocmask(SIG_UNBLOCK, &Sigset, 0); - OptSignalsBlocked = false; - } + if (!OptSignalsBlocked) + return; + + sigprocmask(SIG_UNBLOCK, &Sigset, 0); + OptSignalsBlocked = false; } void mutt_block_signals_system(void) { struct sigaction sa; - if (!OptSysSignalsBlocked) - { - /* POSIX: ignore SIGINT and SIGQUIT & block SIGCHLD before exec */ - sa.sa_handler = SIG_IGN; - sa.sa_flags = 0; - sigemptyset(&sa.sa_mask); - sigaction(SIGINT, &sa, &SysOldInt); - sigaction(SIGQUIT, &sa, &SysOldQuit); + if (OptSysSignalsBlocked) + return; - sigemptyset(&SigsetSys); - sigaddset(&SigsetSys, SIGCHLD); - sigprocmask(SIG_BLOCK, &SigsetSys, 0); - OptSysSignalsBlocked = true; - } + /* POSIX: ignore SIGINT and SIGQUIT & block SIGCHLD before exec */ + sa.sa_handler = SIG_IGN; + sa.sa_flags = 0; + sigemptyset(&sa.sa_mask); + sigaction(SIGINT, &sa, &SysOldInt); + sigaction(SIGQUIT, &sa, &SysOldQuit); + + sigemptyset(&SigsetSys); + sigaddset(&SigsetSys, SIGCHLD); + sigprocmask(SIG_BLOCK, &SigsetSys, 0); + OptSysSignalsBlocked = true; } void mutt_unblock_signals_system(int catch) { - if (OptSysSignalsBlocked) + if (!OptSysSignalsBlocked) + return; + + sigprocmask(SIG_UNBLOCK, &SigsetSys, NULL); + if (catch) { - sigprocmask(SIG_UNBLOCK, &SigsetSys, NULL); - if (catch) - { - sigaction(SIGQUIT, &SysOldQuit, NULL); - sigaction(SIGINT, &SysOldInt, NULL); - } - else - { - struct sigaction sa; - - sa.sa_handler = SIG_DFL; - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; - sigaction(SIGQUIT, &sa, NULL); - sigaction(SIGINT, &sa, NULL); - } - - OptSysSignalsBlocked = false; + sigaction(SIGQUIT, &SysOldQuit, NULL); + sigaction(SIGINT, &SysOldInt, NULL); } + else + { + struct sigaction sa; + + sa.sa_handler = SIG_DFL; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + sigaction(SIGQUIT, &sa, NULL); + sigaction(SIGINT, &sa, NULL); + } + + OptSysSignalsBlocked = false; } void mutt_allow_interrupt(int disposition)