From: Richard Russon Date: Sat, 14 Jul 2018 23:22:50 +0000 (+0100) Subject: boolify parse functions X-Git-Tag: 2019-10-25~755^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cf6d969625041490490fa29f61b8a53061d90e5e;p=neomutt boolify parse functions --- diff --git a/buffy.c b/buffy.c index 6cbfa1a3f..810f21ada 100644 --- a/buffy.c +++ b/buffy.c @@ -132,7 +132,7 @@ static bool test_last_status_new(FILE *f) return false; hdr = mutt_header_new(); - tmp_envelope = mutt_rfc822_read_header(f, hdr, 0, 0); + tmp_envelope = mutt_rfc822_read_header(f, hdr, false, false); if (!(hdr->read || hdr->old)) result = true; diff --git a/email/parse.c b/email/parse.c index a4dcf138e..76864238d 100644 --- a/email/parse.c +++ b/email/parse.c @@ -489,9 +489,9 @@ void mutt_parse_content_type(char *s, struct Body *ct) * and the information put in the Envelope or Header. */ int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, - char *p, short user_hdrs, short weed, short do_2047) + char *p, bool user_hdrs, bool weed, bool do_2047) { - int matched = 0; + bool matched = false; switch (tolower(line[0])) { @@ -499,12 +499,12 @@ int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, if (mutt_str_strcasecmp(line + 1, "pparently-to") == 0) { e->to = mutt_addr_parse_list(e->to, p); - matched = 1; + matched = true; } else if (mutt_str_strcasecmp(line + 1, "pparently-from") == 0) { e->from = mutt_addr_parse_list(e->from, p); - matched = 1; + matched = true; } break; @@ -512,7 +512,7 @@ int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, if (mutt_str_strcasecmp(line + 1, "cc") == 0) { e->bcc = mutt_addr_parse_list(e->bcc, p); - matched = 1; + matched = true; } break; @@ -520,7 +520,7 @@ int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, if (mutt_str_strcasecmp(line + 1, "c") == 0) { e->cc = mutt_addr_parse_list(e->cc, p); - matched = 1; + matched = true; } else if (mutt_str_strncasecmp(line + 1, "ontent-", 7) == 0) { @@ -528,19 +528,19 @@ int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, { if (hdr) mutt_parse_content_type(p, hdr->content); - matched = 1; + matched = true; } else if (mutt_str_strcasecmp(line + 8, "language") == 0) { if (hdr) parse_content_language(p, hdr->content); - matched = 1; + matched = true; } else if (mutt_str_strcasecmp(line + 8, "transfer-encoding") == 0) { if (hdr) hdr->content->encoding = mutt_check_encoding(p); - matched = 1; + matched = true; } else if (mutt_str_strcasecmp(line + 8, "length") == 0) { @@ -550,7 +550,7 @@ int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, if (hdr->content->length < 0) hdr->content->length = -1; } - matched = 1; + matched = true; } else if (mutt_str_strcasecmp(line + 8, "description") == 0) { @@ -559,13 +559,13 @@ int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, mutt_str_replace(&hdr->content->description, p); rfc2047_decode(&hdr->content->description); } - matched = 1; + matched = true; } else if (mutt_str_strcasecmp(line + 8, "disposition") == 0) { if (hdr) parse_content_disposition(p, hdr->content); - matched = 1; + matched = true; } } break; @@ -585,7 +585,7 @@ int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, hdr->zoccident = tz.zoccident; } } - matched = 1; + matched = true; } break; @@ -601,7 +601,7 @@ int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, if (mutt_str_strcasecmp("rom", line + 1) == 0) { e->from = mutt_addr_parse_list(e->from, p); - matched = 1; + matched = true; } #ifdef USE_NNTP else if (mutt_str_strcasecmp(line + 1, "ollowup-to") == 0) @@ -611,7 +611,7 @@ int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, mutt_str_remove_trailing_ws(p); e->followup_to = mutt_str_strdup(mutt_str_skip_whitespace(p)); } - matched = 1; + matched = true; } #endif break; @@ -621,7 +621,7 @@ int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, { mutt_list_free(&e->in_reply_to); parse_references(&e->in_reply_to, p); - matched = 1; + matched = true; } break; @@ -637,7 +637,7 @@ int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, hdr->lines = 0; } - matched = 1; + matched = true; } else if (mutt_str_strcasecmp(line + 1, "ist-Post") == 0) { @@ -661,7 +661,7 @@ int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, } } } - matched = 1; + matched = true; } break; @@ -670,14 +670,14 @@ int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, { if (hdr) hdr->mime = true; - matched = 1; + matched = true; } else if (mutt_str_strcasecmp(line + 1, "essage-id") == 0) { /* We add a new "Message-ID:" when building a message */ FREE(&e->message_id); e->message_id = mutt_extract_message_id(p, NULL); - matched = 1; + matched = true; } else if (mutt_str_strncasecmp(line + 1, "ail-", 4) == 0) { @@ -686,12 +686,12 @@ int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, /* override the Reply-To: field */ mutt_addr_free(&e->reply_to); e->reply_to = mutt_addr_parse_list(e->reply_to, p); - matched = 1; + matched = true; } else if (mutt_str_strcasecmp(line + 5, "followup-to") == 0) { e->mail_followup_to = mutt_addr_parse_list(e->mail_followup_to, p); - matched = 1; + matched = true; } } break; @@ -703,7 +703,7 @@ int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, FREE(&e->newsgroups); mutt_str_remove_trailing_ws(p); e->newsgroups = mutt_str_strdup(mutt_str_skip_whitespace(p)); - matched = 1; + matched = true; } break; #endif @@ -722,17 +722,17 @@ int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, { mutt_list_free(&e->references); parse_references(&e->references, p); - matched = 1; + matched = true; } else if (mutt_str_strcasecmp(line + 1, "eply-to") == 0) { e->reply_to = mutt_addr_parse_list(e->reply_to, p); - matched = 1; + matched = true; } else if (mutt_str_strcasecmp(line + 1, "eturn-path") == 0) { e->return_path = mutt_addr_parse_list(e->return_path, p); - matched = 1; + matched = true; } else if (mutt_str_strcasecmp(line + 1, "eceived") == 0) { @@ -751,12 +751,12 @@ int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, { if (!e->subject) e->subject = mutt_str_strdup(p); - matched = 1; + matched = true; } else if (mutt_str_strcasecmp(line + 1, "ender") == 0) { e->sender = mutt_addr_parse_list(e->sender, p); - matched = 1; + matched = true; } else if (mutt_str_strcasecmp(line + 1, "tatus") == 0) { @@ -779,7 +779,7 @@ int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, p++; } } - matched = 1; + matched = true; } else if (((mutt_str_strcasecmp("upersedes", line + 1) == 0) || (mutt_str_strcasecmp("upercedes", line + 1) == 0)) && @@ -794,7 +794,7 @@ int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, if (mutt_str_strcasecmp(line + 1, "o") == 0) { e->to = mutt_addr_parse_list(e->to, p); - matched = 1; + matched = true; } break; @@ -822,32 +822,32 @@ int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, p++; } } - matched = 1; + matched = true; } else if (mutt_str_strcasecmp(line + 1, "-label") == 0) { FREE(&e->x_label); e->x_label = mutt_str_strdup(p); - matched = 1; + matched = true; } #ifdef USE_NNTP else if (mutt_str_strcasecmp(line + 1, "-comment-to") == 0) { if (!e->x_comment_to) e->x_comment_to = mutt_str_strdup(p); - matched = 1; + matched = true; } else if (mutt_str_strcasecmp(line + 1, "ref") == 0) { if (!e->xref) e->xref = mutt_str_strdup(p); - matched = 1; + matched = true; } #endif else if (mutt_str_strcasecmp(line + 1, "-original-to") == 0) { e->x_original_to = mutt_addr_parse_list(e->x_original_to, p); - matched = 1; + matched = true; } default: @@ -954,7 +954,7 @@ char *mutt_rfc822_read_line(FILE *f, char *line, size_t *linelen) * Caller should free the Envelope using mutt_env_free(). */ struct Envelope *mutt_rfc822_read_header(FILE *f, struct Header *hdr, - short user_hdrs, short weed) + bool user_hdrs, bool weed) { struct Envelope *e = mutt_env_new(); char *line = mutt_mem_malloc(LONG_STRING); @@ -1053,7 +1053,7 @@ struct Envelope *mutt_rfc822_read_header(FILE *f, struct Header *hdr, if (!*p) continue; /* skip empty header fields */ - mutt_rfc822_parse_line(e, hdr, line, p, user_hdrs, weed, 1); + mutt_rfc822_parse_line(e, hdr, line, p, user_hdrs, weed, true); } FREE(&line); @@ -1367,7 +1367,7 @@ struct Body *mutt_rfc822_parse_message(FILE *fp, struct Body *parent) { parent->hdr = mutt_header_new(); parent->hdr->offset = ftello(fp); - parent->hdr->env = mutt_rfc822_read_header(fp, parent->hdr, 0, 0); + parent->hdr->env = mutt_rfc822_read_header(fp, parent->hdr, false, false); struct Body *msg = parent->hdr->content; /* ignore the length given in the content-length since it could be wrong diff --git a/email/parse.h b/email/parse.h index df36d1092..4015f89e5 100644 --- a/email/parse.h +++ b/email/parse.h @@ -38,9 +38,9 @@ void mutt_parse_content_type(char *s, struct Body *ct); struct Body * mutt_parse_multipart(FILE *fp, const char *boundary, LOFF_T end_off, bool digest); void mutt_parse_part(FILE *fp, struct Body *b); struct Body * mutt_read_mime_header(FILE *fp, bool digest); -int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, char *p, short user_hdrs, short weed, short do_2047); +int mutt_rfc822_parse_line(struct Envelope *e, struct Header *hdr, char *line, char *p, bool user_hdrs, bool weed, bool do_2047); struct Body * mutt_rfc822_parse_message(FILE *fp, struct Body *parent); -struct Envelope *mutt_rfc822_read_header(FILE *f, struct Header *hdr, short user_hdrs, short weed); +struct Envelope *mutt_rfc822_read_header(FILE *f, struct Header *hdr, bool user_hdrs, bool weed); char * mutt_rfc822_read_line(FILE *f, char *line, size_t *linelen); #endif /* _EMAIL_PARSE_H */ diff --git a/email/rfc2231.c b/email/rfc2231.c index 6418b0e10..87b3fda3a 100644 --- a/email/rfc2231.c +++ b/email/rfc2231.c @@ -321,7 +321,8 @@ void rfc2231_decode_parameters(struct ParameterList *p) */ int rfc2231_encode_string(char **pd) { - int ext = 0, encode = 0; + int ext = 0; + bool encode = false; char *charset = NULL, *s = NULL, *t = NULL, *e = NULL, *d = NULL; size_t slen, dlen = 0; @@ -346,13 +347,13 @@ int rfc2231_encode_string(char **pd) } if (!mutt_ch_is_us_ascii(charset)) - encode = 1; + encode = true; for (s = d, slen = dlen; slen; s++, slen--) { if ((*s < 0x20) || (*s >= 0x7f)) { - encode = 1; + encode = true; ext++; } else if (strchr(MimeSpecials, *s) || strchr("*'%", *s)) diff --git a/imap/message.c b/imap/message.c index 878ec75c8..027ed2920 100644 --- a/imap/message.c +++ b/imap/message.c @@ -880,7 +880,7 @@ int imap_read_headers(struct ImapData *idata, unsigned int msn_begin, unsigned i rewind(fp); /* NOTE: if Date: header is missing, mutt_rfc822_read_header depends * on h.received being set */ - ctx->hdrs[idx]->env = mutt_rfc822_read_header(fp, ctx->hdrs[idx], 0, 0); + ctx->hdrs[idx]->env = mutt_rfc822_read_header(fp, ctx->hdrs[idx], false, false); /* content built as a side-effect of mutt_rfc822_read_header */ ctx->hdrs[idx]->content->length = h.content_length; ctx->size += h.content_length; @@ -1152,7 +1152,7 @@ parsemsg: * picked up in mutt_rfc822_read_header, we mark the message (and context * changed). Another possibility: ignore Status on IMAP? */ read = h->read; - newenv = mutt_rfc822_read_header(msg->fp, h, 0, 0); + newenv = mutt_rfc822_read_header(msg->fp, h, false, false); mutt_env_merge(h->env, &newenv); /* see above. We want the new status in h->read, so we unset it manually diff --git a/maildir/mh.c b/maildir/mh.c index 7bdead18d..a8b078544 100644 --- a/maildir/mh.c +++ b/maildir/mh.c @@ -890,7 +890,7 @@ struct Header *maildir_parse_stream(int magic, FILE *f, const char *fname, if (!h) h = mutt_header_new(); - h->env = mutt_rfc822_read_header(f, h, 0, 0); + h->env = mutt_rfc822_read_header(f, h, false, false); fstat(fileno(f), &st); diff --git a/main.c b/main.c index a22beafda..d608d6232 100644 --- a/main.c +++ b/main.c @@ -863,7 +863,7 @@ int main(int argc, char *argv[], char *envp[]) } context_hdr->content->length = st.st_size; - if (mutt_prepare_template(fin, NULL, msg, context_hdr, 0) < 0) + if (mutt_prepare_template(fin, NULL, msg, context_hdr, false) < 0) { mutt_error(_("Cannot parse message template: %s"), draft_file); mutt_env_free(&opts_env); diff --git a/mbox/mbox.c b/mbox/mbox.c index a51124f66..3581c179f 100644 --- a/mbox/mbox.c +++ b/mbox/mbox.c @@ -188,7 +188,7 @@ static int mmdf_parse_mailbox(struct Context *ctx) else hdr->received = t - mutt_date_local_tz(t); - hdr->env = mutt_rfc822_read_header(ctx->fp, hdr, 0, 0); + hdr->env = mutt_rfc822_read_header(ctx->fp, hdr, false, false); loc = ftello(ctx->fp); if (loc < 0) @@ -335,7 +335,7 @@ static int mbox_parse_mailbox(struct Context *ctx) curhdr->offset = loc; curhdr->index = ctx->msgcount; - curhdr->env = mutt_rfc822_read_header(ctx->fp, curhdr, 0, 0); + curhdr->env = mutt_rfc822_read_header(ctx->fp, curhdr, false, false); /* if we know how long this message is, either just skip over the body, * or if we don't know how many lines there are, count them now (this will diff --git a/mutt_header.c b/mutt_header.c index 45ab8a694..20d097842 100644 --- a/mutt_header.c +++ b/mutt_header.c @@ -222,7 +222,7 @@ void mutt_edit_headers(const char *editor, const char *body, struct Header *msg, return; } - n = mutt_rfc822_read_header(ifp, NULL, 1, 0); + n = mutt_rfc822_read_header(ifp, NULL, true, false); while ((i = fread(buffer, 1, sizeof(buffer), ifp)) > 0) fwrite(buffer, 1, i, ofp); mutt_file_fclose(&ofp); diff --git a/mutt_url.c b/mutt_url.c index eabdd46cd..e29c14ac0 100644 --- a/mutt_url.c +++ b/mutt_url.c @@ -95,7 +95,7 @@ int url_parse_mailto(struct Envelope *e, char **body, const char *src) safe_asprintf(&scratch, "%s: %s", tag, value); scratch[taglen] = 0; /* overwrite the colon as mutt_rfc822_parse_line expects */ value = mutt_str_skip_email_wsp(&scratch[taglen + 1]); - mutt_rfc822_parse_line(e, NULL, scratch, value, 1, 0, 1); + mutt_rfc822_parse_line(e, NULL, scratch, value, true, false, true); FREE(&scratch); } } diff --git a/nntp/nntp.c b/nntp/nntp.c index 4214f7db6..1890b8f68 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -1191,7 +1191,7 @@ static int parse_overview_line(char *line, void *data) /* parse header */ hdr = ctx->hdrs[ctx->msgcount] = mutt_header_new(); - hdr->env = mutt_rfc822_read_header(fp, hdr, 0, 0); + hdr->env = mutt_rfc822_read_header(fp, hdr, false, false); hdr->env->newsgroups = mutt_str_strdup(nntp_data->group); hdr->received = hdr->date_sent; mutt_file_fclose(&fp); @@ -1451,7 +1451,7 @@ static int nntp_fetch_headers(struct Context *ctx, void *hc, anum_t first, /* parse header */ hdr = ctx->hdrs[ctx->msgcount] = mutt_header_new(); - hdr->env = mutt_rfc822_read_header(fp, hdr, 0, 0); + hdr->env = mutt_rfc822_read_header(fp, hdr, false, false); hdr->received = hdr->date_sent; mutt_file_fclose(&fp); } @@ -1732,7 +1732,7 @@ static int nntp_msg_open(struct Context *ctx, struct Message *msg, int msgno) mutt_hash_delete(ctx->subj_hash, hdr->env->real_subj, hdr); mutt_env_free(&hdr->env); - hdr->env = mutt_rfc822_read_header(msg->fp, hdr, 0, 0); + hdr->env = mutt_rfc822_read_header(msg->fp, hdr, false, false); if (ctx->id_hash && hdr->env->message_id) mutt_hash_insert(ctx->id_hash, hdr->env->message_id, hdr); @@ -2475,7 +2475,7 @@ int nntp_check_msgid(struct Context *ctx, const char *msgid) mx_alloc_memory(ctx); struct Header *hdr = ctx->hdrs[ctx->msgcount] = mutt_header_new(); hdr->data = mutt_mem_calloc(1, sizeof(struct NntpHeaderData)); - hdr->env = mutt_rfc822_read_header(fp, hdr, 0, 0); + hdr->env = mutt_rfc822_read_header(fp, hdr, false, false); mutt_file_fclose(&fp); /* get article number */ diff --git a/pop/pop.c b/pop/pop.c index d096ea094..a2d7993ed 100644 --- a/pop/pop.c +++ b/pop/pop.c @@ -164,7 +164,7 @@ static int pop_read_header(struct PopData *pop_data, struct Header *h) case 0: { rewind(f); - h->env = mutt_rfc822_read_header(f, h, 0, 0); + h->env = mutt_rfc822_read_header(f, h, false, false); h->content->length = length - h->content->offset + 1; rewind(f); while (!feof(f)) @@ -734,7 +734,7 @@ static int pop_msg_open(struct Context *ctx, struct Message *msg, int msgno) mutt_hash_delete(ctx->subj_hash, h->env->real_subj, h); mutt_label_hash_remove(ctx, h); mutt_env_free(&h->env); - h->env = mutt_rfc822_read_header(msg->fp, h, 0, 0); + h->env = mutt_rfc822_read_header(msg->fp, h, false, false); if (ctx->subj_hash && h->env->real_subj) mutt_hash_insert(ctx->subj_hash, h->env->real_subj, h); mutt_label_hash_add(ctx, h); diff --git a/postpone.c b/postpone.c index c08ad79d2..3c9d03ee4 100644 --- a/postpone.c +++ b/postpone.c @@ -319,7 +319,7 @@ int mutt_get_postponed(struct Context *ctx, struct Header *hdr, return -1; } - if (mutt_prepare_template(NULL, PostContext, hdr, h, 0) < 0) + if (mutt_prepare_template(NULL, PostContext, hdr, h, false) < 0) { mx_fastclose_mailbox(PostContext); FREE(&PostContext); @@ -559,7 +559,7 @@ int mutt_parse_crypt_hdr(const char *p, int set_empty_signas, int crypt_app) * @retval -1 Error */ int mutt_prepare_template(FILE *fp, struct Context *ctx, struct Header *newhdr, - struct Header *hdr, short resend) + struct Header *hdr, bool resend) { struct Message *msg = NULL; char file[PATH_MAX]; @@ -582,7 +582,7 @@ int mutt_prepare_template(FILE *fp, struct Context *ctx, struct Header *newhdr, fseeko(fp, hdr->offset, SEEK_SET); newhdr->offset = hdr->offset; /* enable header weeding for resent messages */ - newhdr->env = mutt_rfc822_read_header(fp, newhdr, 1, resend); + newhdr->env = mutt_rfc822_read_header(fp, newhdr, true, resend); newhdr->content->length = hdr->content->length; mutt_parse_part(fp, newhdr->content); diff --git a/protos.h b/protos.h index fca4081e3..f9bfedeac 100644 --- a/protos.h +++ b/protos.h @@ -57,7 +57,7 @@ int mutt_change_flag(struct Header *h, int bf); int mutt_complete(char *buf, size_t buflen); int mutt_edit_message(struct Context *ctx, struct Header *hdr); int mutt_view_message(struct Context *ctx, struct Header *hdr); -int mutt_prepare_template(FILE *fp, struct Context *ctx, struct Header *newhdr, struct Header *hdr, short resend); +int mutt_prepare_template(FILE *fp, struct Context *ctx, struct Header *newhdr, struct Header *hdr, bool resend); int mutt_enter_string(char *buf, size_t buflen, int col, int flags); int mutt_enter_string_full(char *buf, size_t buflen, int col, int flags, int multiple, char ***files, int *numfiles, struct EnterState *state); diff --git a/send.c b/send.c index 7a4760945..e53ca11d8 100644 --- a/send.c +++ b/send.c @@ -1298,7 +1298,7 @@ int mutt_resend_message(FILE *fp, struct Context *ctx, struct Header *cur) { struct Header *msg = mutt_header_new(); - if (mutt_prepare_template(fp, ctx, msg, cur, 1) < 0) + if (mutt_prepare_template(fp, ctx, msg, cur, true) < 0) { mutt_header_free(&msg); return -1; diff --git a/sendlib.c b/sendlib.c index 21a9723d9..6d66cff8b 100644 --- a/sendlib.c +++ b/sendlib.c @@ -1509,7 +1509,7 @@ struct Body *mutt_make_message_attach(struct Context *ctx, struct Header *hdr, b body->hdr = mutt_header_new(); body->hdr->offset = 0; /* we don't need the user headers here */ - body->hdr->env = mutt_rfc822_read_header(fp, body->hdr, 0, 0); + body->hdr->env = mutt_rfc822_read_header(fp, body->hdr, false, false); if (WithCrypto) body->hdr->security = pgp; mutt_update_encoding(body);