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);
}
/**
*/
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;
*/
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;
*/
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");
}
/**
*/
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;
*/
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;
}
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;
}
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);
}
}
* 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);
}
/**
*/
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);
}
/**
*/
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);
}
/**
*/
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);
}
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;
}
/**
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';
}
}
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)
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)
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)
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,
*/
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)));
}
/**
*/
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;
}
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;
}
{
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;
}
*/
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;
}
/**
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;
}
/**
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;
}
*/
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;
}
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)
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;
/* 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)
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;
}
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,
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;
*/
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;
}
/**
*/
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)