63 const char *quoted_date);
76static void add_one_header(
struct HeaderArray *headers,
size_t pos,
char *value)
81 char *new_value = NULL;
106int mutt_copy_hdr(FILE *fp_in, FILE *fp_out, LOFF_T off_start, LOFF_T off_end,
110 bool this_is_from =
false;
112 char buf[1024] = { 0 };
117 char *this_one = NULL;
118 size_t this_one_len = 0;
123 if (ftello(fp_in) != off_start)
134 while (ftello(fp_in) < off_end)
136 nl = strchr(buf,
'\n');
138 if (!fgets(buf,
sizeof(buf), fp_in))
142 if (nl && (buf[0] !=
' ') && (buf[0] !=
'\t'))
155 else if ((buf[0] ==
'\n') || ((buf[0] ==
'\r') && (buf[1] ==
'\n')))
189 if (!ignore && (fputs(buf, fp_out) == EOF))
216 while (ftello(fp_in) < off_end)
218 nl = strchr(buf,
'\n');
221 if (!fgets(buf,
sizeof(buf), fp_in))
225 if (nl && (buf[0] !=
' ') && (buf[0] !=
'\t'))
237 if ((this_one_len > 2) && (this_one[this_one_len - 2] ==
'\r') &&
238 (this_one[this_one_len - 1] ==
'\n'))
240 this_one[this_one_len - 2] =
'\n';
241 this_one[this_one_len - 1] =
'\0';
250 this_is_from =
false;
258 else if ((buf[0] ==
'\n') || ((buf[0] ==
'\r') && (buf[1] ==
'\n')))
317 size_t match_len = 0;
324 if ((match == -1) || (hdr_order_len > match_len))
327 match_len = hdr_order_len;
349 this_one_len += blen;
380 if (!error && hp && *hp)
386 const char *pre = (chflags &
CH_PREFIX) ? prefix : NULL;
396 if (fputs(*hp, fp_out) == EOF)
426 char *temp_hdr = NULL;
441 char chsbuf[128] = { 0 };
442 char buf[128] = { 0 };
443 fputs(
"MIME-Version: 1.0\n", fp_out);
444 fputs(
"Content-Transfer-Encoding: 8bit\n", fp_out);
445 fputs(
"Content-Type: text/plain; charset=", fp_out);
455 fputs(
"In-Reply-To:", fp_out);
460 fputs(np->
data, fp_out);
467 fputs(
"References:", fp_out);
476 fputs(
"Status: ", fp_out);
486 fputs(
"X-Status: ", fp_out);
497 fprintf(fp_out,
"Content-Length: " OFF_T_FMT
"\n", e->
body->
length);
499 fprintf(fp_out,
"Lines: %d\n", e->
lines);
510 char buf[1024] = { 0 };
514 fputs(
"Folder: ", fp_out);
523 fputs(
"Tags: ", fp_out);
539 rfc2047_encode(&temp_hdr, NULL,
sizeof(
"X-Label:"), c_send_charset);
559 rfc2047_encode(&temp_hdr, NULL,
sizeof(
"Subject:"), c_send_charset);
574 fputs(prefix, fp_out);
578 if (ferror(fp_out) || feof(fp_out))
605 for (
long l = b->
length; l; l--)
607 const int ch = getc(fp);
618 *length -= b->
length - (89 + datelen);
620 for (
long l = 10; b->
length >= l; l *= 10)
653 char prefix[128] = { 0 };
654 LOFF_T new_offset = -1;
669 setlocale(LC_TIME,
NONULL(c_attribution_locale));
672 setlocale(LC_TIME,
"");
685 int rc_attach_del = -1;
686 LOFF_T new_length = body->
length;
687 struct Buffer *quoted_date = NULL;
697 goto attach_del_cleanup;
702 goto attach_del_cleanup;
704 new_lines = e->
lines - del;
708 goto attach_del_cleanup;
709 fprintf(fp_out,
"Content-Length: " OFF_T_FMT
"\n", new_length);
713 fprintf(fp_out,
"Lines: %d\n", new_lines);
716 if (ferror(fp_out) || feof(fp_out))
717 goto attach_del_cleanup;
718 new_offset = ftello(fp_out);
722 goto attach_del_cleanup;
724 goto attach_del_cleanup;
728 LOFF_T fail = ((ftello(fp_out) - new_offset) - new_length);
731 mutt_error(ngettext(
"The length calculation was wrong by %ld byte",
732 "The length calculation was wrong by %ld bytes", fail),
741 e->
lines = new_lines;
742 body->
offset = new_offset;
744 body->
length = new_length;
752 return rc_attach_del;
756 (chflags &
CH_PREFIX) ? prefix : NULL, wraplen) == -1)
761 new_offset = ftello(fp_out);
767 struct State state = { 0 };
796 struct Body *cur = NULL;
804 fputs(
"MIME-Version: 1.0\n", fp_out);
816 mutt_error(
_(
"No decryption engine available for message"));
841 size_t bytes = body->
length;
843 fputs(prefix, fp_out);
845 while (((c = fgetc(fp_in)) != EOF) && bytes--)
850 fputs(prefix, fp_out);
863 body->
offset = new_offset;
887 if (!msg || !e->
body)
891 if (fp_out == msg->
fp)
898 if ((rc == 0) && (ferror(fp_out) || feof(fp_out)))
920 char buf[256] = { 0 };
926 if (!fgets(buf,
sizeof(buf), fp_in))
966 const bool own_msg = !msg;
995 struct Body *part = NULL;
997 for (part = b->
parts; part; part = part->
next)
1011 "Content-Type: message/external-body; access-type=x-mutt-deleted;\n"
1012 "\texpiration=%s; length=" OFF_T_FMT
"\n"
1014 quoted_date, part->
length);
1061 switch (tolower((
unsigned char) *s))
1140 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.
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.
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.
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.
int crypt_smime_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur)
Wrapper for CryptModuleSpecs::decrypt_mime()
int crypt_pgp_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur)
Wrapper for CryptModuleSpecs::decrypt_mime()
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.
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
bool mutt_file_seek(FILE *fp, LOFF_T offset, int whence)
Wrapper for fseeko with error handling.
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.
void mutt_make_string(char *buf, size_t buflen, int cols, const char *s, struct Mailbox *m, int inpgr, struct Email *e, MuttFormatFlags flags, const char *progress)
Create formatted strings using mailbox expandos.
String processing routines to generate the mail index.
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.
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
@ MUTT_MMDF
'mmdf' Mailbox type
@ MUTT_MBOX
'mbox' Mailbox type
@ MUTT_MAILDIR
'Maildir' Mailbox type
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
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.
int nm_update_filename(struct Mailbox *m, const char *old_file, const char *new_file, struct Email *e)
Change the filename.
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)
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.
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
char * subject
Email's subject.
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.
char * prefix
String to add to the beginning of each output line.
FILE * fp_in
File to read from.