84static int print_val(FILE *fp,
const char *pfx,
const char *value,
87 while (value && (value[0] !=
'\0'))
89 if (fputc(*value, fp) == EOF)
95 if (fputs(
"\n ", fp) < 0)
101 if ((value[1] !=
'\0') && pfx && (pfx[0] !=
'\0') && (fputs(pfx, fp) == EOF))
104 if ((chflags &
CH_DISPLAY) && ((value[1] ==
' ') || (value[1] ==
'\t')))
107 while ((value[0] !=
'\0') && ((value[0] ==
' ') || (value[0] ==
'\t')))
109 if (fputc(
'\t', fp) == EOF)
134 if (!value || (*value ==
'\0') || !vlen)
137 const char *p = value;
138 char buf[8192] = { 0 };
139 int first = 1, col = 0, l = 0;
143 chflags, (
int) ((value[vlen - 1] ==
'\n') ? vlen - 1 : vlen), value);
145 if (tag && *tag && (fprintf(fp,
"%s%s: ",
NONULL(pfx), tag) < 0))
149 while (p && (p[0] !=
'\0'))
156 l =
MIN(
sizeof(buf) - 1, next - p);
166 (buf[0] ==
'\n' ?
"\\n" : buf), col, w, *next);
171 if (!first && !enc && col && ((col + w) >= wraplen))
175 if (fprintf(fp,
"\n%s",
NONULL(pfx)) <= 0)
184 while ((pc[0] !=
'\0') && ((pc[0] ==
' ') || (pc[0] ==
'\t')))
189 if (fputc(
'\t', fp) == EOF)
191 if (
print_val(fp, pfx, pc, chflags, col) < 0)
195 else if (
print_val(fp, pfx, buf, chflags, col) < 0)
207 const char *sp = next;
208 while ((sp[0] !=
'\0') && ((sp[0] ==
' ') || (sp[0] ==
'\t')))
224 if (col && ((l == 0) || (buf[l - 1] !=
'\n')))
225 if (putc(
'\n', fp) == EOF)
243 while (p && (p[0] !=
'\0'))
246 if ((p[0] ==
'\r') && (p[1] ==
'\n') && ((p[2] ==
' ') || (p[2] ==
'\t')))
252 else if ((p[0] ==
'\n') && ((p[1] ==
' ') || (p[1] ==
'\t')))
278 const char *cb = *(
const char **) b;
298 const char *t = strchr(start,
':');
299 if (!t || (t >= end))
305 const size_t vallen = end - start;
306 const bool short_enough = (pfxw + max <= wraplen);
309 NONULL(pfx), (
int) (vallen - 1) , start,
310 (short_enough ?
"short enough" :
"too long"), max,
311 (short_enough ?
"<=" :
">"), wraplen);
314 const char *valbuf = NULL, *tagbuf = NULL;
323 if (fputs(pfx, fp) == EOF)
343 while ((*t ==
' ') || (*t ==
'\t'))
346 const char *s =
is_from ? start : t;
348 rc =
fold_one_header(fp, tagbuf, valbuf, end - s, pfx, wraplen, chflags);
372 char *
const colon = strchr(
NONULL(tmp->
data),
':');
427 char *last = NULL, *line = NULL;
428 int max = 0, w, rc = -1;
434 if (!display || c_weed)
441 if ((c_wrap_headers < 78) || (c_wrap_headers > 998))
444 wraplen = c_wrap_headers;
446 else if (wraplen <= 0)
458 if (fprintf(fp,
"%s%s: %s\n",
NONULL(pfx), tag, v) <= 0)
490 if ((*p !=
' ') && (*p !=
'\t'))
526 if (++length == trim)
541 for (
size_t i = 0; i < length; i++)
544 fputs(ref[i]->
data, fp);
641 fprintf(fp,
"Newsgroups: %s\n", env->
newsgroups);
643 fputs(
"Newsgroups:\n", fp);
646 fprintf(fp,
"Followup-To: %s\n", env->
followup_to);
648 fputs(
"Followup-To:\n", fp);
654 fputs(
"X-Comment-To:\n", fp);
658 if (hide_protected_subject &&
662 const char *
const c_crypt_protected_headers_subject =
cs_subset_string(sub,
"crypt_protected_headers_subject");
673 fputs(
"Subject:\n", fp);
678 fprintf(fp,
"Message-ID: %s\n", env->
message_id);
686 fputs(
"Reply-To:\n", fp);
706 fputs(
"References:", fp);
714 fputs(
"MIME-Version: 1.0\n", fp);
721 fputs(
"In-Reply-To:", fp);
742 fprintf(fp,
"User-Agent: NeoMutt/%s%s\n", PACKAGE_VERSION,
GitVer);
745 return (ferror(fp) == 0) ? 0 : -1;
763 char buf[256] = { 0 };
765 fprintf(fp,
"Content-Type: %s/%s",
TYPE(b), b->
subtype);
791 snprintf(buf,
sizeof(buf),
"\"%s\"", cont->
value);
794 if ((len + tmplen + 2) > 76)
805 fprintf(fp,
"%s=%s", cont->
attribute, buf);
815 fprintf(fp,
"Content-ID: <%s>\n", b->
content_id);
818 fprintf(fp,
"Content-Language: %s\n", b->
language);
821 fprintf(fp,
"Content-Description: %s\n", b->
description);
825 const char *dispstr[] = {
"inline",
"attachment",
"form-data" };
827 if (b->
disposition <
sizeof(dispstr) /
sizeof(
char *))
829 fprintf(fp,
"Content-Disposition: %s", dispstr[b->
disposition]);
841 char *t = strrchr(fn,
'/');
857 if ((len + tmplen + 2) > 76)
868 fprintf(fp,
"%s=%s", cont->
attribute, buf);
886 const bool c_crypt_protected_headers_write =
cs_subset_bool(sub,
"crypt_protected_headers_write");
887 bool c_autocrypt =
false;
892 if ((c_crypt_protected_headers_write || c_autocrypt) && b->
mime_headers)
899 return ferror(fp) ? -1 : 0;
void mutt_addr_cat(char *buf, size_t buflen, const char *value, const char *specials)
Copy a string and wrap it in quotes if it contains special characters.
void mutt_addrlist_write_file(const struct AddressList *al, FILE *fp, const char *header)
Wrapper for mutt_write_address()
Autocrypt end-to-end encryption.
int mutt_autocrypt_write_gossip_headers(struct Envelope *env, FILE *fp)
Write the Autocrypt gossip headers to a file.
int mutt_autocrypt_write_autocrypt_header(struct Envelope *env, FILE *fp)
Write the Autocrypt header to a file.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Convenience wrapper for the config headers.
#define CH_DISPLAY
Display result to user.
uint32_t CopyHeaderFlags
Flags for mutt_copy_header(), e.g. CH_UPDATE.
#define CH_NO_FLAGS
No flags are set.
size_t mutt_strnwidth(const char *s, size_t n)
Measure a string's width in screen cells.
size_t mutt_strwidth(const char *s)
Measure a string's width in screen cells.
Structs that make up an email.
bool is_from(const char *s, char *path, size_t pathlen, time_t *tp)
Is a string a 'From' header line?
bool OptNewsSend
(pseudo) used to change behavior when posting
#define mutt_debug(LEVEL,...)
Convenience wrapper for the gui headers.
@ LL_DEBUG5
Log at debug level 5.
@ LL_DEBUG2
Log at debug level 2.
@ LL_DEBUG1
Log at debug level 1.
int mutt_mb_width(const char *str, int col, bool indent)
Measure a string's display width (in screen columns)
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
#define mutt_array_size(x)
const char MimeSpecials[]
Characters that need special treatment in MIME.
@ DISP_INLINE
Content is inline.
@ DISP_NONE
No preferred disposition.
#define ICONV_ILLEGAL_SEQ
Error value for iconv() - Illegal sequence.
void mutt_date_make_date(struct Buffer *buf, bool local)
Write a date in RFC822 format to a buffer.
Convenience wrapper for the library headers.
char * mutt_strn_dup(const char *begin, size_t len)
Duplicate a sub-string.
int mutt_istrn_cmp(const char *a, const char *b, size_t num)
Compare two strings ignoring case (to a maximum), safely.
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
char * mutt_str_dup(const char *str)
Copy a string, safely.
char * mutt_str_skip_email_wsp(const char *s)
Skip over whitespace as defined by RFC5322.
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
const char * mutt_str_find_word(const char *src)
Find the end of a word (non-space)
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
void mutt_param_free(struct ParameterList *pl)
Free a ParameterList.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
#define TAILQ_FOREACH(var, head, field)
#define STAILQ_FOREACH(var, head, field)
#define STAILQ_EMPTY(head)
#define TAILQ_HEAD_INITIALIZER(head)
#define TAILQ_EMPTY(head)
size_t rfc2231_encode_string(struct ParameterList *head, const char *attribute, char *value)
Encode a string to be suitable for an RFC2231 header.
char * language
content-language (RFC8255)
char * content_id
Content-Id (RFC2392)
char * d_filename
filename to be used for the content-disposition header If NULL, filename is used instead.
struct Envelope * mime_headers
Memory hole protected headers.
struct ParameterList parameter
Parameters of the content-type.
bool use_disp
Content-Disposition uses filename= ?
char * description
content-description
unsigned int disposition
content-disposition, ContentDisposition
char * subtype
content-type subtype
unsigned int encoding
content-transfer-encoding, ContentEncoding
char * filename
When sending a message, this is the file to which this structure refers.
String manipulation buffer.
A set of inherited config items.
struct ListHead userhdrs
user defined headers
char *const subject
Email's subject.
struct AddressList to
Email's 'To' list.
char * followup_to
List of 'followup-to' fields.
struct AddressList reply_to
Email's 'reply-to'.
char * message_id
Message ID.
char * x_comment_to
List of 'X-comment-to' fields.
char * newsgroups
List of newsgroups.
struct AddressList mail_followup_to
Email's 'mail-followup-to'.
struct AddressList cc
Email's 'Cc' list.
struct AddressList sender
Email's sender.
struct ListHead references
message references (in reverse order)
struct ListHead in_reply_to
in-reply-to header content
struct AddressList bcc
Email's 'Bcc' list.
struct AddressList from
Email's 'From' list.
Attribute associated with a MIME part.
char * attribute
Parameter name.
char * value
Parameter value.
Which headers have been overridden.
bool is_overridden[mutt_array_size(UserhdrsOverrideHeaders)]
Which email headers have been overridden.