64 const char *quoted_date);
77static void add_one_header(
struct HeaderArray *headers,
size_t pos,
char *value)
82 char *new_value = NULL;
107int mutt_copy_hdr(FILE *fp_in, FILE *fp_out, LOFF_T off_start, LOFF_T off_end,
111 bool this_is_from =
false;
113 char buf[1024] = { 0 };
118 char *this_one = NULL;
119 size_t this_one_len = 0;
124 if (ftello(fp_in) != off_start)
135 while (ftello(fp_in) < off_end)
137 nl = strchr(buf,
'\n');
139 if (!fgets(buf,
sizeof(buf), fp_in))
143 if (nl && (buf[0] !=
' ') && (buf[0] !=
'\t'))
156 else if ((buf[0] ==
'\n') || ((buf[0] ==
'\r') && (buf[1] ==
'\n')))
190 if (!ignore && (fputs(buf, fp_out) == EOF))
217 while (ftello(fp_in) < off_end)
219 nl = strchr(buf,
'\n');
222 if (!fgets(buf,
sizeof(buf), fp_in))
226 if (nl && (buf[0] !=
' ') && (buf[0] !=
'\t'))
238 if ((this_one_len > 2) && (this_one[this_one_len - 2] ==
'\r') &&
239 (this_one[this_one_len - 1] ==
'\n'))
241 this_one[this_one_len - 2] =
'\n';
242 this_one[this_one_len - 1] =
'\0';
251 this_is_from =
false;
259 else if ((buf[0] ==
'\n') || ((buf[0] ==
'\r') && (buf[1] ==
'\n')))
318 size_t match_len = 0;
325 if ((match == -1) || (hdr_order_len > match_len))
328 match_len = hdr_order_len;
350 this_one_len += blen;
381 if (!error && hp && *hp)
387 const char *pre = (chflags &
CH_PREFIX) ? prefix : NULL;
397 if (fputs(*hp, fp_out) == EOF)
427 char *temp_hdr = NULL;
442 char chsbuf[128] = { 0 };
443 char buf[128] = { 0 };
444 fputs(
"MIME-Version: 1.0\n", fp_out);
445 fputs(
"Content-Transfer-Encoding: 8bit\n", fp_out);
446 fputs(
"Content-Type: text/plain; charset=", fp_out);
456 fputs(
"In-Reply-To:", fp_out);
461 fputs(np->
data, fp_out);
468 fputs(
"References:", fp_out);
477 fputs(
"Status: ", fp_out);
487 fputs(
"X-Status: ", fp_out);
498 fprintf(fp_out,
"Content-Length: " OFF_T_FMT
"\n", e->
body->
length);
500 fprintf(fp_out,
"Lines: %d\n", e->
lines);
511 char buf[1024] = { 0 };
515 fputs(
"Folder: ", fp_out);
526 fputs(
"Tags: ", fp_out);
542 rfc2047_encode(&temp_hdr, NULL,
sizeof(
"X-Label:"), c_send_charset);
562 rfc2047_encode(&temp_hdr, NULL,
sizeof(
"Subject:"), c_send_charset);
577 fputs(prefix, fp_out);
581 if (ferror(fp_out) || feof(fp_out))
608 for (
long l = b->
length; l; l--)
610 const int ch = getc(fp);
621 *length -= b->
length - (89 + datelen);
623 for (
long l = 10; b->
length >= l; l *= 10)
657 LOFF_T new_offset = -1;
672 setlocale(LC_TIME,
NONULL(c_attribution_locale));
674 setlocale(LC_TIME,
"");
687 int rc_attach_del = -1;
688 LOFF_T new_length = body->
length;
689 struct Buffer *quoted_date = NULL;
699 goto attach_del_cleanup;
704 goto attach_del_cleanup;
706 new_lines = e->
lines - del;
710 goto attach_del_cleanup;
711 fprintf(fp_out,
"Content-Length: " OFF_T_FMT
"\n", new_length);
715 fprintf(fp_out,
"Lines: %d\n", new_lines);
718 if (ferror(fp_out) || feof(fp_out))
719 goto attach_del_cleanup;
720 new_offset = ftello(fp_out);
724 goto attach_del_cleanup;
726 goto attach_del_cleanup;
730 LOFF_T fail = ((ftello(fp_out) - new_offset) - new_length);
733 mutt_error(ngettext(
"The length calculation was wrong by %ld byte",
734 "The length calculation was wrong by %ld bytes", fail),
743 e->
lines = new_lines;
744 body->
offset = new_offset;
746 body->
length = new_length;
765 new_offset = ftello(fp_out);
771 struct State state = { 0 };
800 struct Body *cur = NULL;
811 fputs(
"MIME-Version: 1.0\n", fp_out);
826 mutt_error(
_(
"No decryption engine available for message"));
860 size_t bytes = body->
length;
864 while (((c = fgetc(fp_in)) != EOF) && bytes--)
883 body->
offset = new_offset;
909 if (!msg || !e->
body)
913 if (fp_out == msg->
fp)
920 if ((rc == 0) && (ferror(fp_out) || feof(fp_out)))
942 char buf[256] = { 0 };
948 if (!fgets(buf,
sizeof(buf), fp_in))
988 const bool own_msg = !msg;
1017 struct Body *part = NULL;
1019 for (part = b->
parts; part; part = part->
next)
1033 "Content-Type: message/external-body; access-type=x-mutt-deleted;\n"
1034 "\texpiration=%s; length=" OFF_T_FMT
"\n"
1036 quoted_date, part->
length);
1083 switch (tolower((
unsigned char) *s))
1162 struct Buffer buf = { 0 };
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
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.
size_t mutt_addrlist_write_wrap(const struct AddressList *al, struct Buffer *buf, const char *header)
Write an AddressList to a buffer, perform line wrapping.
int mutt_addrlist_to_local(struct AddressList *al)
Convert an Address list from Punycode.
int mutt_addrlist_parse(struct AddressList *al, const char *s)
Parse a list of email addresses.
#define ARRAY_SET(head, idx, elem)
Set an element in the array.
#define ARRAY_RESERVE(head, num)
Reserve memory for the array.
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
#define ARRAY_HEAD(name, type)
Define a named struct for arrays of elements of a certain type.
#define ARRAY_FREE(head)
Release all memory.
#define ARRAY_GET(head, idx)
Return the element at index.
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
void buf_dequote_comment(struct Buffer *buf)
Un-escape characters in an email address comment.
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
void mutt_pretty_mailbox(char *buf, size_t buflen)
Shorten a mailbox path using '~' or '='.
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
const struct Slist * cs_subset_slist(const struct ConfigSubset *sub, const char *name)
Get a string-list 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.
const struct Expando * cs_subset_expando(const struct ConfigSubset *sub, const char *name)
Get an Expando config item by name.
Convenience wrapper for the config headers.
const char * cc_charset(void)
Get the cached value of $charset.
static int append_message(struct Mailbox *dest, FILE *fp_in, struct Mailbox *src, struct Email *e, CopyMessageFlags cmflags, CopyHeaderFlags chflags)
Appends a copy of the given message to a mailbox.
static int address_header_decode(char **h)
Parse an email's headers.
int mutt_copy_header(FILE *fp_in, struct Email *e, FILE *fp_out, CopyHeaderFlags chflags, const char *prefix, int wraplen)
Copy Email header.
int mutt_append_message(struct Mailbox *m_dst, struct Mailbox *m_src, struct Email *e, struct Message *msg, CopyMessageFlags cmflags, CopyHeaderFlags chflags)
Append a message.
int mutt_copy_hdr(FILE *fp_in, FILE *fp_out, LOFF_T off_start, LOFF_T off_end, CopyHeaderFlags chflags, const char *prefix, int wraplen)
Copy header from one file to another.
int mutt_copy_message(FILE *fp_out, struct Email *e, struct Message *msg, CopyMessageFlags cmflags, CopyHeaderFlags chflags, int wraplen)
Copy a message from a Mailbox.
static int count_delete_lines(FILE *fp, struct Body *b, LOFF_T *length, size_t datelen)
Count lines to be deleted in this email body.
static void add_one_header(struct HeaderArray *headers, size_t pos, char *value)
Add a header to a Headers array.
int mutt_copy_message_fp(FILE *fp_out, FILE *fp_in, struct Email *e, CopyMessageFlags cmflags, CopyHeaderFlags chflags, int wraplen)
Make a copy of a message from a FILE pointer.
static int copy_delete_attach(struct Body *b, FILE *fp_in, FILE *fp_out, const char *quoted_date)
Copy a message, deleting marked attachments.
Duplicate the structure of an entire email.
#define CH_DECODE
Do RFC2047 header decoding.
#define MUTT_CM_WEED
Weed message/rfc822 attachment headers.
#define MUTT_CM_REPLYING
Replying the message.
#define MUTT_CM_PREFIX
Quote the header and body.
#define CH_XMIT
Transmitting this message? (Ignore Lines: and Content-Length:)
#define MUTT_CM_UPDATE
Update structs on sync.
#define MUTT_CM_VERIFY
Do signature verification.
#define CH_PREFIX
Quote header using $indent_string string?
#define CH_UPDATE
Update the status and x-status fields?
#define CH_NOSTATUS
Suppress the status and x-status fields.
#define CH_FROM
Retain the "From " message separator?
#define MUTT_CM_DECODE_PGP
Used for decoding PGP messages.
#define MUTT_CM_DECODE
Decode the message body into text/plain.
#define CH_NONEWLINE
Don't output terminating newline after the header.
#define CH_WEED_DELIVERED
Weed eventual Delivered-To headers.
#define CH_UPDATE_LABEL
Update X-Label: from email->env->x_label?
#define CH_WEED
Weed the headers?
#define CH_REORDER
Re-order output of headers (specified by 'hdr_order')
#define MUTT_CM_CHARCONV
Perform character set conversions.
#define MUTT_CM_DECODE_SMIME
Used for decoding S/MIME messages.
#define CH_MIME
Ignore MIME fields.
#define CH_UPDATE_REFS
Update References:
#define CH_NOQFROM
Ignore ">From " line.
uint32_t CopyHeaderFlags
Flags for mutt_copy_header(), e.g. CH_UPDATE.
#define CH_UPDATE_LEN
Update Lines: and Content-Length:
#define CH_UPDATE_IRT
Update In-Reply-To:
#define MUTT_CM_PRINTING
Printing the message - display light.
#define CH_FORCE_FROM
Give CH_FROM precedence over CH_WEED?
#define MUTT_CM_DECODE_CRYPT
#define MUTT_CM_NOHEADER
Don't copy the message header.
#define CH_TXTPLAIN
Generate text/plain MIME headers.
uint16_t CopyMessageFlags
Flags for mutt_copy_message(), e.g. MUTT_CM_NOHEADER.
#define CH_VIRTUAL
Write virtual header lines too.
#define CH_UPDATE_SUBJECT
Update Subject: protected header update.
#define CH_NOLEN
Don't write Content-Length: and Lines:
#define MUTT_CM_DISPLAY
Output is displayed to the user.
Convenience wrapper for the core headers.
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
@ MUTT_MMDF
'mmdf' Mailbox type
@ MUTT_MBOX
'mbox' Mailbox type
@ MUTT_MAILDIR
'Maildir' Mailbox type
int crypt_pgp_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **b_dec)
Wrapper for CryptModuleSpecs::decrypt_mime()
int crypt_smime_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **b_dec)
Wrapper for CryptModuleSpecs::decrypt_mime()
int mutt_make_string(struct Buffer *buf, size_t max_cols, const struct Expando *exp, struct Mailbox *m, int inpgr, struct Email *e, MuttFormatFlags flags, const char *progress)
Create formatted strings using mailbox expandos.
void mutt_body_free(struct Body **ptr)
Free a Body.
Structs that make up an email.
bool mutt_matches_ignore(const char *s)
Does the string match the ignore list.
#define MUTT_ENV_CHANGED_SUBJECT
Protected header update.
#define MUTT_ENV_CHANGED_XLABEL
X-Label edited.
#define MUTT_ENV_CHANGED_IRT
In-Reply-To changed to link/break threads.
#define MUTT_ENV_CHANGED_REFS
References changed to break thread.
int mutt_file_copy_bytes(FILE *fp_in, FILE *fp_out, size_t size)
Copy some content from one file to another.
bool mutt_file_seek(FILE *fp, LOFF_T offset, int whence)
Wrapper for fseeko with error handling.
#define mutt_file_fclose(FP)
bool is_from(const char *s, char *path, size_t pathlen, time_t *tp)
Is a string a 'From' header line?
struct ListHead HeaderOrderList
List of header fields in the order they should be displayed.
#define mutt_debug(LEVEL,...)
Convenience wrapper for the gui headers.
int mutt_body_handler(struct Body *b, struct State *state)
Handler for the Body of an email.
Decide how to display email content.
GUI manage the main index (list of emails)
struct Mailbox * get_current_mailbox(void)
Get the current Mailbox.
@ LL_DEBUG3
Log at debug level 3.
@ LL_DEBUG2
Log at debug level 2.
@ LL_DEBUG1
Log at debug level 1.
int nm_update_filename(struct Mailbox *m, const char *old_file, const char *new_file, struct Email *e)
Change the filename.
#define MUTT_MEM_REALLOC(pptr, n, type)
const char MimeSpecials[]
Characters that need special treatment in MIME.
@ TYPE_MULTIPART
Type: 'multipart/*'.
@ TYPE_APPLICATION
Type: 'application/*'.
void mutt_ch_canonical_charset(char *buf, size_t buflen, const char *name)
Canonicalise the charset of a string.
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.
#define STATE_PAGER
Output will be displayed in the Pager.
#define STATE_WEED
Weed headers even when not in display mode.
#define STATE_DISPLAY
Output is displayed to the user.
#define STATE_REPLYING
Are we replying?
#define STATE_VERIFY
Perform signature verification.
#define STATE_CHARCONV
Do character set conversions.
#define STATE_PRINTING
Are we printing? - STATE_DISPLAY "light".
char * mutt_str_dup(const char *str)
Copy a string, safely.
int mutt_str_asprintf(char **strp, const char *fmt,...)
char * mutt_strn_copy(char *dest, const char *src, size_t len, size_t dsize)
Copy a sub-string into a buffer.
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_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
bool mutt_istrn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings ignoring case (to a maximum), safely.
Many unsorted constants and some structs.
int mutt_window_wrap_cols(int width, short wrap)
Calculate the wrap column for a given screen width.
Some miscellaneous functions.
int mx_msg_close(struct Mailbox *m, struct Message **ptr)
Close a message.
struct Message * mx_msg_open(struct Mailbox *m, struct Email *e)
Return a stream pointer for a message.
struct Message * mx_msg_open_new(struct Mailbox *m, const struct Email *e, MsgOpenFlags flags)
Open a new message.
int mx_msg_commit(struct Mailbox *m, struct Message *msg)
Commit a message to a folder - Wrapper for MxOps::msg_commit()
#define MUTT_ADD_FROM
add a From_ line
#define MUTT_MSG_NO_FLAGS
No flags are set.
API for encryption/signing of emails.
#define APPLICATION_PGP
Use PGP to encrypt/sign.
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
#define SEC_ENCRYPT
Email is encrypted.
Notmuch virtual mailbox type.
char * nm_email_get_folder(struct Email *e)
Get the folder for a Email.
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)
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
void rfc2047_encode(char **pd, const char *specials, int col, const struct Slist *charsets)
RFC-2047-encode a string.
void rfc2047_decode(char **pd)
Decode any RFC2047-encoded header fields.
void rfc2047_decode_addrlist(struct AddressList *al)
Decode any RFC2047 headers in an Address list.
Convenience wrapper for the send headers.
struct Buffer * personal
Real name of address.
struct Body * parts
parts of a multipart or message/rfc822
LOFF_T offset
offset where the actual data begins
bool deleted
Attachment marked for deletion.
LOFF_T length
length (in bytes) of attachment
struct Body * next
next attachment in the list
long hdr_offset
Offset in stream where the headers begin.
unsigned int type
content-type primary type, ContentType
String manipulation buffer.
char * data
Pointer to data.
The envelope/body of an email.
struct Envelope * env
Envelope information.
int lines
How many lines in the body of this message?
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib....
struct Body * body
List of MIME parts.
bool old
Email is seen, but unread.
LOFF_T offset
Where in the stream does this message begin?
bool attach_del
Has an attachment marked for deletion.
bool flagged
Marked important?
bool replied
Email has been replied to.
struct TagList tags
For drivers that support server tagging.
char *const subject
Email's subject.
unsigned char changed
Changed fields, e.g. MUTT_ENV_CHANGED_SUBJECT.
struct ListHead references
message references (in reverse order)
struct ListHead in_reply_to
in-reply-to header content
enum MailboxType type
Mailbox type.
A local copy of an email.
FILE * fp
pointer to the message data
char * committed_path
the final path generated by mx_msg_commit()
Container for Accounts, Notifications.
struct ConfigSubset * sub
Inherited config items.
Keep track when processing files.
int wraplen
Width to wrap lines to (when flags & STATE_DISPLAY)
StateFlags flags
Flags, e.g. STATE_DISPLAY.
FILE * fp_out
File to write to.
FILE * fp_in
File to read from.
const char * prefix
String to add to the beginning of each output line.