72 char *p = NULL, *q = NULL, *ct = NULL;
74 char subtype[256] = { 0 };
75 char xtype[256] = { 0 };
77 bool found_mimetypes =
false;
82 for (
int count = 0; count < 4; count++)
100 snprintf(buf,
sizeof(buf),
"%s/.mime.types",
NONULL(
HomeDir));
107 fp = fopen(buf,
"r");
110 found_mimetypes =
true;
112 while (fgets(buf,
sizeof(buf) - 1, fp))
115 p = strchr(buf,
'#');
124 p = strpbrk(ct,
" \t");
131 while ((p = strtok(p,
" \t\n")))
134 if ((sze > cur_sze) && (szf >= sze) &&
mutt_istr_equal(path + szf - sze, p) &&
135 ((szf == sze) || (path[szf - sze - 1] ==
'.')))
147 for (q = p; *q && !
IS_SPACE(*q); q++)
168 if (!found_mimetypes)
170 mutt_error(
_(
"Could not find any mime.types file"));
191 struct Buffer *buf = NULL;
192 struct State state = { 0 };
193 struct stat st = { 0 };
195 for (; a; a = a->
next)
257 struct stat st = { 0 };
298 fputs(
"MIME-Version: 1.0\n", fp_out);
324 if (fp_in && (fp_in != fp))
348 char send_charset[128] = { 0 };
351 (info->
linemax > 990) || (info->
from && c_encode_from))
355 else if (info->
hibin)
368 if (c_allow_8bit && !info->
lobin)
414 char chsbuf[256] = { 0 };
446 struct Body *body = NULL;
451 const bool c_mime_forward_decode =
cs_subset_bool(sub,
"mime_forward_decode");
452 const bool c_forward_decrypt =
cs_subset_bool(sub,
"forward_decrypt");
495 if (!attach_msg && c_mime_forward_decode)
502 pgp &= ~SMIME_ENCRYPT;
524 pgp &= ~SMIME_ENCRYPT;
557 FILE *
fp = NULL, *fp_err = NULL;
563 const char *
const c_mime_type_query_command =
cs_subset_string(sub,
"mime_type_query_command");
579 if (strchr(buf,
'/'))
598 if (!path || (path[0] ==
'\0'))
604 const char *
const c_mime_type_query_command =
cs_subset_string(sub,
"mime_type_query_command");
605 const bool c_mime_type_query_first =
cs_subset_bool(sub,
"mime_type_query_first");
607 if (c_mime_type_query_command && c_mime_type_query_first)
615 if (!att->
subtype && c_mime_type_query_command && !c_mime_type_query_first)
629 if ((info->
nulbin == 0) &&
667 p = strchr(np->
data,
':');
681 sprintf(np->
data + i + 2,
"%s", tmp);
699 if (!c_hostname || (c_hostname[0] ==
'@'))
702 const char *p = c_hostname;
705 if (may_hide_host && c_hidden_host)
707 p = strchr(c_hostname,
'.');
712 if (!p || !strchr(p,
'.'))
744 const int ID_LEFT_LEN = 50;
745 const int ID_RIGHT_LEN = 12;
746 char rnd_id_left[ID_LEFT_LEN + 1];
747 char rnd_id_right[ID_RIGHT_LEN + 1];
748 char buf[128] = { 0 };
752 rnd_id_left[ID_LEFT_LEN] = 0;
753 rnd_id_right[ID_RIGHT_LEN] = 0;
755 snprintf(buf,
sizeof(buf),
"<%s@%s>", rnd_id_left, rnd_id_right);
783 char buf[1024] = { 0 };
835 struct AddressList *to,
const char *resent_from,
850 const bool c_bounce_delivered =
cs_subset_bool(sub,
"bounce_delivered");
851 if (!c_bounce_delivered)
859 fprintf(fp_tmp,
"Resent-From: %s\n", resent_from);
867 fprintf(fp_tmp,
"Resent-Message-ID: %s\n", msgid_str);
937 mutt_error(
_(
"Bad IDN %s while preparing resent-from"), err);
970 for (; b; b = b->
next)
1000 char fcc_expanded[
PATH_MAX] = { 0 };
1004 char *tok = strtok(fcc_tok,
",");
1010 int status =
mutt_write_fcc(tok, e, msgid, post, fcc, finalpath, sub);
1014 while ((tok = strtok(NULL,
",")))
1024 status =
mutt_write_fcc(fcc_expanded, e, msgid, post, fcc, finalpath, sub);
1045 const char *fcc,
char **finalpath,
struct ConfigSubset *sub)
1048 struct Buffer *tempfile = NULL;
1049 FILE *fp_tmp = NULL;
1051 bool need_mailbox_cleanup =
false;
1052 struct stat st = { 0 };
1058#ifdef RECORD_FOLDER_HOOK
1062 bool old_append = m_fcc->
append;
1083 need_mailbox_cleanup =
true;
1099 const bool c_crypt_protected_headers_read =
cs_subset_bool(
sub,
"crypt_protected_headers_read");
1105 c_crypt_protected_headers_read &&
1115 fprintf(msg->
fp,
"Mutt-References: %s\n", msgid);
1120 fprintf(msg->
fp,
"Mutt-Fcc: %s\n", fcc);
1123 fprintf(msg->
fp,
"Status: RO\n");
1128 fputs(
"Mutt-PGP: ", msg->
fp);
1130 fputc(
'E', msg->
fp);
1132 fputc(
'O', msg->
fp);
1135 fputc(
'S', msg->
fp);
1139 fprintf(msg->
fp,
"<%s>", c_pgp_sign_as);
1142 fputc(
'I', msg->
fp);
1145 fputc(
'A', msg->
fp);
1147 fputc(
'Z', msg->
fp);
1149 fputc(
'\n', msg->
fp);
1155 fputs(
"Mutt-SMIME: ", msg->
fp);
1158 fputc(
'E', msg->
fp);
1161 if (c_smime_encrypt_with)
1162 fprintf(msg->
fp,
"C<%s>", c_smime_encrypt_with);
1165 fputc(
'O', msg->
fp);
1168 fputc(
'S', msg->
fp);
1171 if (c_smime_sign_as)
1172 fprintf(msg->
fp,
"<%s>", c_smime_sign_as);
1175 fputc(
'I', msg->
fp);
1176 fputc(
'\n', msg->
fp);
1185 fputs(
"Mutt-Mix:", msg->
fp);
1189 fprintf(msg->
fp,
" %s", (
char *) p->
data);
1192 fputc(
'\n', msg->
fp);
1202 if (
mutt_file_seek(fp_tmp, -1, SEEK_END) && (fgetc(fp_tmp) !=
'\n') &&
1205 fputc(
'\n', fp_tmp);
1222 char line_buf[1024] = { 0 };
1224 while (fgets(line_buf,
sizeof(line_buf), fp_tmp))
1226 fprintf(msg->
fp,
"Content-Length: " OFF_T_FMT
"\n", (LOFF_T) ftello(fp_tmp));
1227 fprintf(msg->
fp,
"Lines: %d\n\n", lines);
1243 fputc(
'\n', msg->
fp);
1254 if (!post && need_mailbox_cleanup)
1261 m_fcc->
append = old_append;
1264#ifdef RECORD_FOLDER_HOOK
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
void mutt_addrlist_qualify(struct AddressList *al, const char *host)
Expand local names in an Address list using a hostname.
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.
void mutt_addrlist_append(struct AddressList *al, struct Address *a)
Append an Address to an AddressList.
struct Address * mutt_addr_new(void)
Create a new Address.
size_t mutt_addrlist_write(const struct AddressList *al, struct Buffer *buf, bool display)
Write an Address to a buffer.
const char AddressSpecials[]
Characters with special meaning for email addresses.
void mutt_addrlist_write_file(const struct AddressList *al, FILE *fp, const char *header)
Wrapper for mutt_write_address()
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
GUI display the mailboxes in a side panel.
void mutt_parse_mime_message(struct Email *e, FILE *fp)
Parse a MIME email.
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
char * mutt_buffer_strdup(const struct Buffer *buf)
Copy a Buffer's string.
static const char * mutt_buffer_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.
const struct Slist * cs_subset_slist(const struct ConfigSubset *sub, const char *name)
Get a string-list 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.
char * HomeDir
User's home directory.
struct Content * mutt_get_content_info(const char *fname, struct Body *b, struct ConfigSubset *sub)
Analyze file to determine MIME encoding to use.
Conversion between different character encodings.
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_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.
Duplicate the structure of an entire email.
#define CH_XMIT
Transmitting this message? (Ignore Lines: and Content-Length:)
#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 MUTT_CM_CHARCONV
Perform character set conversions.
#define CH_MIME
Ignore MIME fields.
#define CH_NOQFROM
Ignore ">From " line.
uint32_t CopyHeaderFlags
Flags for mutt_copy_header(), e.g. CH_UPDATE.
#define MUTT_CM_NO_FLAGS
No flags are set.
#define CH_TXTPLAIN
Generate text/plain MIME headers.
uint16_t CopyMessageFlags
Flags for mutt_copy_message(), e.g. MUTT_CM_NOHEADER.
Convenience wrapper for the core headers.
SecurityFlags mutt_is_application_pgp(struct Body *b)
Does the message use PGP?
SecurityFlags mutt_is_application_smime(struct Body *b)
Does the message use S/MIME?
bool crypt_valid_passphrase(SecurityFlags flags)
Check that we have a usable passphrase, ask if not.
bool mutt_should_hide_protected_subject(struct Email *e)
Should NeoMutt hide the protected subject?
SecurityFlags mutt_is_multipart_encrypted(struct Body *b)
Does the message have encrypted parts?
void mutt_date_make_date(struct Buffer *buf, bool local)
Write a date in RFC822 format to a buffer.
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
void mutt_body_free(struct Body **ptr)
Free a Body.
struct Body * mutt_body_new(void)
Create a new Body.
char * mutt_body_get_charset(struct Body *b, char *buf, size_t buflen)
Get a body's character set.
struct Email * email_new(void)
Create a new Email.
Structs that make up an email.
int mutt_file_copy_stream(FILE *fp_in, FILE *fp_out)
Copy the contents of one file into another.
char * mutt_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, ReadLineFlags flags)
Read a line from a file.
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
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.
void mutt_file_unlink(const char *s)
Delete a file, carefully.
void mutt_buffer_file_expand_fmt_quote(struct Buffer *dest, const char *fmt, const char *src)
Replace s in a string with a filename.
#define MUTT_RL_NO_FLAGS
No flags are set.
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
pid_t filter_create(const char *cmd, FILE **fp_in, FILE **fp_out, FILE **fp_err)
Set up filter program.
bool OptNewsSend
(pseudo) used to change behavior when posting
#define mutt_debug(LEVEL,...)
void mutt_decode_attachment(struct Body *b, struct State *state)
Decode an email's attachment.
Decide how to display email content.
void mutt_folder_hook(const char *path, const char *desc)
Perform a folder hook.
struct Mailbox * get_current_mailbox(void)
Get the current Mailbox.
@ LL_DEBUG1
Log at debug level 1.
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
@ MUTT_MMDF
'mmdf' Mailbox type
@ MUTT_MBOX
'mbox' Mailbox type
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
@ ENC_BASE64
Base-64 encoded text.
@ ENC_QUOTED_PRINTABLE
Quoted-printable text.
@ TYPE_OTHER
Unknown Content-Type.
@ TYPE_MESSAGE
Type: 'message/*'.
@ TYPE_MULTIPART
Type: 'multipart/*'.
@ TYPE_APPLICATION
Type: 'application/*'.
@ TYPE_TEXT
Type: 'text/*'.
@ DISP_INLINE
Content is inline.
#define mutt_ch_is_us_ascii(str)
Convenience wrapper for the library headers.
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.
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_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.
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Many unsorted constants and some structs.
void mutt_mailbox_cleanup(const char *path, struct stat *st)
Restore the timestamp of a mailbox.
Mailbox helper functions.
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
Some miscellaneous functions.
#define mutt_buffer_mktemp(buf)
int mx_msg_close(struct Mailbox *m, struct Message **msg)
Close a message.
bool mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags)
Open a mailbox and parse it.
struct Message * mx_msg_open(struct Mailbox *m, int msgno)
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()
struct Mailbox * mx_path_resolve(const char *path)
Get a Mailbox for a path.
enum MxStatus mx_mbox_close(struct Mailbox *m)
Save changes and close mailbox.
uint8_t MsgOpenFlags
Flags for mx_msg_open_new(), e.g. MUTT_ADD_FROM.
#define MUTT_ADD_FROM
add a From_ line
#define MUTT_SET_DRAFT
set the message draft flag
#define MUTT_APPEND
Open mailbox for appending messages.
#define MUTT_QUIET
Do not print any messages.
API for encryption/signing of emails.
#define SEC_INLINE
Email has an inline signature.
#define SEC_AUTOCRYPT
(Autocrypt) Message will be, or was Autocrypt encrypt+signed
uint16_t SecurityFlags
Flags, e.g. SEC_ENCRYPT.
#define SEC_OPPENCRYPT
Opportunistic encrypt mode.
#define APPLICATION_PGP
Use PGP to encrypt/sign.
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
#define SEC_NO_FLAGS
No flags are set.
#define SEC_ENCRYPT
Email is encrypted.
#define SEC_AUTOCRYPT_OVERRIDE
(Autocrypt) Indicates manual set/unset of encryption
#define SEC_SIGN
Email is signed.
void mutt_param_delete(struct ParameterList *pl, const char *attribute)
Delete a matching Parameter.
void mutt_param_set(struct ParameterList *pl, const char *attribute, const char *value)
Set a Parameter.
void mutt_parse_content_type(const char *s, struct Body *ct)
Parse a content type.
enum ContentType mutt_check_mime_type(const char *s)
Check a MIME type string.
struct Envelope * mutt_rfc822_read_header(FILE *fp, struct Email *e, bool user_hdrs, bool weed)
Parses an RFC822 header.
struct Body * mutt_rfc822_parse_message(FILE *fp, struct Body *parent)
Parse a Message/RFC822 body.
bool mutt_is_message_type(int type, const char *subtype)
Determine if a mime type matches a message or not.
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
#define STAILQ_FOREACH(var, head, field)
#define STAILQ_EMPTY(head)
#define TAILQ_HEAD_INITIALIZER(head)
#define TAILQ_EMPTY(head)
void mutt_rand_base32(char *buf, size_t buflen)
Fill a buffer with a base32-encoded random string.
void rfc2047_encode_addrlist(struct AddressList *al, const char *tag)
Encode any RFC2047 headers, where required, in an Address list.
void rfc2047_encode(char **pd, const char *specials, int col, const struct Slist *charsets)
RFC-2047-encode a string.
void rfc2047_decode_envelope(struct Envelope *env)
Decode the fields of an Envelope.
void rfc2047_decode(char **pd)
Decode any RFC2047-encoded header fields.
void rfc2047_encode_envelope(struct Envelope *env)
Encode the fields of an Envelope.
int mutt_write_mime_body(struct Body *a, FILE *fp, struct ConfigSubset *sub)
Write a MIME part.
struct Address * mutt_default_from(struct ConfigSubset *sub)
Get a default 'from' Address.
void mutt_set_followup_to(struct Envelope *env, struct ConfigSubset *sub)
Set followup-to field.
void mutt_stamp_attachment(struct Body *a)
Timestamp an Attachment.
enum ContentType mutt_lookup_mime_type(struct Body *att, const char *path)
Find the MIME type for an attachment.
static char * gen_msgid(void)
Generate a random Message ID.
static void set_noconv_flags(struct Body *b, bool flag)
Set/reset the "x-mutt-noconv" flag.
const char * mutt_fqdn(bool may_hide_host, const struct ConfigSubset *sub)
Get the Fully-Qualified Domain Name.
int mutt_bounce_message(FILE *fp, struct Mailbox *m, struct Email *e, struct AddressList *to, struct ConfigSubset *sub)
Bounce an email message.
struct Body * mutt_make_file_attach(const char *path, struct ConfigSubset *sub)
Create a file attachment.
int mutt_write_multiple_fcc(const char *path, struct Email *e, const char *msgid, bool post, char *fcc, char **finalpath, struct ConfigSubset *sub)
Handle FCC with multiple, comma separated entries.
void mutt_message_to_7bit(struct Body *a, FILE *fp, struct ConfigSubset *sub)
Convert an email's MIME parts to 7-bit.
void mutt_unprepare_envelope(struct Envelope *env)
Undo the encodings of mutt_prepare_envelope()
static void encode_headers(struct ListHead *h, struct ConfigSubset *sub)
RFC2047-encode a list of headers.
static void set_encoding(struct Body *b, struct Content *info, struct ConfigSubset *sub)
Determine which Content-Transfer-Encoding to use.
void mutt_prepare_envelope(struct Envelope *env, bool final, struct ConfigSubset *sub)
Prepare an email header.
struct Body * mutt_make_message_attach(struct Mailbox *m, struct Email *e, bool attach_msg, struct ConfigSubset *sub)
Create a message attachment.
static void transform_to_7bit(struct Body *a, FILE *fp_in, struct ConfigSubset *sub)
Convert MIME parts to 7-bit.
int mutt_write_fcc(const char *path, struct Email *e, const char *msgid, bool post, const char *fcc, char **finalpath, struct ConfigSubset *sub)
Write email to FCC mailbox.
void mutt_update_encoding(struct Body *a, struct ConfigSubset *sub)
Update the encoding type.
static int bounce_message(FILE *fp, struct Mailbox *m, struct Email *e, struct AddressList *to, const char *resent_from, struct AddressList *env_from, struct ConfigSubset *sub)
Bounce an email message.
static void run_mime_type_query(struct Body *att, struct ConfigSubset *sub)
Run an external command to determine the MIME type.
Miscellaneous functions for sending an email.
int mutt_invoke_sendmail(struct Mailbox *m, struct AddressList *from, struct AddressList *to, struct AddressList *cc, struct AddressList *bcc, const char *msg, bool eightbit, struct ConfigSubset *sub)
Run sendmail.
int mutt_smtp_send(const struct AddressList *from, const struct AddressList *to, const struct AddressList *cc, const struct AddressList *bcc, const char *msgfile, bool eightbit, struct ConfigSubset *sub)
Send a message using SMTP.
char * mailbox
Mailbox and host address.
char * personal
Real name of address.
char * d_filename
filename to be used for the content-disposition header If NULL, filename is used instead.
struct Body * parts
parts of a multipart or message/rfc822
LOFF_T offset
offset where the actual data begins
char * xtype
content-type if x-unknown
bool noconv
Don't do character set conversion.
bool unlink
If true, filename should be unlink()ed before free()ing this structure.
time_t stamp
Time stamp of last encoding update.
LOFF_T length
length (in bytes) of attachment
struct ParameterList parameter
Parameters of the content-type.
bool use_disp
Content-Disposition uses filename= ?
struct Email * email
header information for message/rfc822
unsigned int disposition
content-disposition, ContentDisposition
struct Content * content
Detailed info about the content of the attachment.
struct Body * next
next attachment in the list
bool force_charset
Send mode: don't adjust the character set when in send-mode.
char * subtype
content-type subtype
unsigned int encoding
content-transfer-encoding, ContentEncoding
unsigned int type
content-type primary type, ContentType
char * filename
When sending a message, this is the file to which this structure refers.
String manipulation buffer.
A set of inherited config items.
Info about an attachment.
long hibin
8-bit characters
long ascii
Number of ascii chars.
bool from
Has a line beginning with "From "?
long nulbin
Null characters (0x0)
long linemax
Length of the longest line in the file.
long lobin
Unprintable 7-bit chars (eg., control chars)
The envelope/body of an email.
struct Envelope * env
Envelope information.
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.
LOFF_T offset
Where in the stream does this message begin?
struct ListHead chain
Mixmaster chain.
int msgno
Number displayed to the user.
struct ListHead userhdrs
user defined headers
struct AddressList to
Email's 'To' list.
char * message_id
Message ID.
struct AddressList mail_followup_to
Email's 'mail-followup-to'.
struct AddressList cc
Email's 'Cc' list.
struct AddressList bcc
Email's 'Bcc' list.
bool append
Mailbox is opened in append mode.
enum MailboxType type
Mailbox type.
struct ConfigSubset * sub
Inherited config items.
A local copy of an email.
FILE * fp
pointer to the message data
char * committed_path
the final path generated by mx_msg_commit()
Keep track when processing files.
FILE * fp_out
File to write to.
FILE * fp_in
File to read from.