79 char *p = NULL, *q = NULL, *ct = NULL;
81 char subtype[256] = { 0 };
82 char xtype[256] = { 0 };
84 bool found_mimetypes =
false;
89 for (
int count = 0; count < 4; count++)
107 snprintf(buf,
sizeof(buf),
"%s/.mime.types",
NONULL(
HomeDir));
117 found_mimetypes =
true;
119 while (fgets(buf,
sizeof(buf) - 1, fp))
122 p = strchr(buf,
'#');
131 p = strpbrk(ct,
" \t");
138 while ((p = strtok(p,
" \t\n")))
141 if ((sze > cur_sze) && (szf >= sze) &&
mutt_istr_equal(path + szf - sze, p) &&
142 ((szf == sze) || (path[szf - sze - 1] ==
'.')))
154 for (q = p; *q && !isspace(*q); q++)
175 if (!found_mimetypes)
177 mutt_error(
_(
"Could not find any mime.types file"));
198 struct Buffer *buf = NULL;
199 struct State state = { 0 };
200 struct stat st = { 0 };
202 for (; b; b = b->
next)
264 struct stat st = { 0 };
307 fputs(
"MIME-Version: 1.0\n", fp_out);
333 if (fp_in && (fp_in != fp))
357 char send_charset[128] = { 0 };
360 (info->
linemax > 990) || (info->
from && c_encode_from))
364 else if (info->
hibin)
377 if (c_allow_8bit && !info->
lobin)
425 char chsbuf[256] = { 0 };
457 struct Body *body = NULL;
462 const bool c_mime_forward_decode =
cs_subset_bool(sub,
"mime_forward_decode");
463 const bool c_forward_decrypt =
cs_subset_bool(sub,
"forward_decrypt");
506 if (!attach_msg && c_mime_forward_decode)
513 pgp &= ~SMIME_ENCRYPT;
535 pgp &= ~SMIME_ENCRYPT;
568 FILE *
fp = NULL, *fp_err = NULL;
574 const char *
const c_mime_type_query_command =
cs_subset_string(sub,
"mime_type_query_command");
590 if (strchr(buf,
'/'))
609 if (!path || (path[0] ==
'\0'))
615 const char *
const c_mime_type_query_command =
cs_subset_string(sub,
"mime_type_query_command");
616 const bool c_mime_type_query_first =
cs_subset_bool(sub,
"mime_type_query_first");
618 if (c_mime_type_query_command && c_mime_type_query_first)
626 if (!b->
subtype && c_mime_type_query_command && !c_mime_type_query_first)
640 if ((info->
nulbin == 0) &&
692 sprintf(np->
data + i + 2,
"%s", tmp);
710 if (!c_hostname || (c_hostname[0] ==
'@'))
713 const char *p = c_hostname;
716 if (may_hide_host && c_hidden_host)
718 p = strchr(c_hostname,
'.');
723 if (!p || !strchr(p,
'.'))
755 const int ID_LEFT_LEN = 50;
756 const int ID_RIGHT_LEN = 12;
757 char rnd_id_left[ID_LEFT_LEN + 1];
758 char rnd_id_right[ID_RIGHT_LEN + 1];
759 char buf[128] = { 0 };
763 rnd_id_left[ID_LEFT_LEN] = 0;
764 rnd_id_right[ID_RIGHT_LEN] = 0;
766 snprintf(buf,
sizeof(buf),
"<%s@%s>", rnd_id_left, rnd_id_right);
794 char buf[1024] = { 0 };
846 struct AddressList *to,
const char *resent_from,
861 const bool c_bounce_delivered =
cs_subset_bool(sub,
"bounce_delivered");
862 if (!c_bounce_delivered)
870 fprintf(fp_tmp,
"Resent-From: %s\n", resent_from);
874 fprintf(fp_tmp,
"Resent-Date: %s\n",
buf_string(date));
878 fprintf(fp_tmp,
"Resent-Message-ID: %s\n", msgid_str);
947 mutt_error(
_(
"Bad IDN %s while preparing resent-from"), err);
977 for (; b; b = b->
next)
1012 char *tok = strtok(fcc_tok,
",");
1018 int status =
mutt_write_fcc(tok, e, msgid, post, fcc, finalpath, sub);
1023 while ((tok = strtok(NULL,
",")))
1059 const char *fcc,
char **finalpath,
struct ConfigSubset *sub)
1062 struct Buffer *tempfile = NULL;
1063 FILE *fp_tmp = NULL;
1065 bool need_mailbox_cleanup =
false;
1066 struct stat st = { 0 };
1072#ifdef RECORD_FOLDER_HOOK
1076 bool old_append = m_fcc->
append;
1097 need_mailbox_cleanup =
true;
1113 const bool c_crypt_protected_headers_read =
cs_subset_bool(
sub,
"crypt_protected_headers_read");
1119 c_crypt_protected_headers_read &&
1129 fprintf(msg->
fp,
"Mutt-References: %s\n", msgid);
1134 fprintf(msg->
fp,
"Mutt-Fcc: %s\n", fcc);
1137 fprintf(msg->
fp,
"Status: RO\n");
1142 fputs(
"Mutt-PGP: ", msg->
fp);
1144 fputc(
'E', msg->
fp);
1146 fputc(
'O', msg->
fp);
1149 fputc(
'S', msg->
fp);
1153 fprintf(msg->
fp,
"<%s>", c_pgp_sign_as);
1156 fputc(
'I', msg->
fp);
1159 fputc(
'A', msg->
fp);
1161 fputc(
'Z', msg->
fp);
1163 fputc(
'\n', msg->
fp);
1169 fputs(
"Mutt-SMIME: ", msg->
fp);
1172 fputc(
'E', msg->
fp);
1175 if (c_smime_encrypt_with)
1176 fprintf(msg->
fp,
"C<%s>", c_smime_encrypt_with);
1179 fputc(
'O', msg->
fp);
1182 fputc(
'S', msg->
fp);
1185 if (c_smime_sign_as)
1186 fprintf(msg->
fp,
"<%s>", c_smime_sign_as);
1189 fputc(
'I', msg->
fp);
1190 fputc(
'\n', msg->
fp);
1199 if (
mutt_file_seek(fp_tmp, -1, SEEK_END) && (fgetc(fp_tmp) !=
'\n') &&
1202 fputc(
'\n', fp_tmp);
1219 char line_buf[1024] = { 0 };
1221 while (fgets(line_buf,
sizeof(line_buf), fp_tmp))
1223 fprintf(msg->
fp,
"Content-Length: " OFF_T_FMT
"\n", (LOFF_T) ftello(fp_tmp));
1224 fprintf(msg->
fp,
"Lines: %d\n\n", lines);
1240 fputc(
'\n', msg->
fp);
1251 if (!post && need_mailbox_cleanup)
1258 m_fcc->
append = old_append;
1261#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 * buf_new(const char *str)
Allocate a new Buffer.
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
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.
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 MUTT_CM_DECODE_SMIME
Used for decoding S/MIME messages.
#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.
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
@ MUTT_MMDF
'mmdf' Mailbox type
@ MUTT_MBOX
'mbox' Mailbox type
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?
SecurityFlags mutt_is_application_pgp(const struct Body *b)
Does the message use PGP?
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.
struct Body * mutt_rfc822_parse_message(FILE *fp, struct Body *b)
Parse a Message/RFC822 body.
void mutt_parse_content_type(const char *s, struct Body *b)
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.
bool mutt_is_message_type(int type, const char *subtype)
Determine if a mime type matches a message or not.
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.
int mutt_file_copy_bytes(FILE *fp_in, FILE *fp_out, size_t size)
Copy some content from one file to another.
void buf_file_expand_fmt_quote(struct Buffer *dest, const char *fmt, const char *src)
Replace s in a string with a filename.
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.
#define mutt_file_fclose(FP)
#define mutt_file_fopen(PATH, MODE)
#define MUTT_RL_NO_FLAGS
No flags are set.
bool OptNewsSend
(pseudo) used to change behavior when posting
char ** EnvList
Private copy of the environment variables.
#define mutt_debug(LEVEL,...)
void mutt_decode_attachment(const 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.
#define MUTT_MEM_REALLOC(pptr, n, type)
@ 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)
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.
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, char **envlist)
Set up filter program.
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 mailbox_restore_timestamp(const char *path, struct stat *st)
Restore the timestamp of a mailbox.
Mailbox helper functions.
void buf_expand_path(struct Buffer *buf)
Create the canonical path.
Some miscellaneous functions.
int mx_msg_close(struct Mailbox *m, struct Message **ptr)
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, 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()
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.
#define mutt_file_fopen_masked(PATH, MODE)
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.
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 STAILQ_FOREACH(var, head, field)
#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 *b, FILE *fp, struct ConfigSubset *sub)
Write a MIME part.
Convenience wrapper for the send headers.
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.
Prepare and send an email.
static void set_noconv_flags(struct Body *b, bool flag)
Set/reset the "x-mutt-noconv" flag.
void mutt_update_encoding(struct Body *b, struct ConfigSubset *sub)
Update the encoding type.
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.
enum ContentType mutt_lookup_mime_type(struct Body *b, const char *path)
Find the MIME type for an attachment.
struct Body * mutt_make_file_attach(const char *path, struct ConfigSubset *sub)
Create a file attachment.
char * mutt_gen_msgid(void)
Generate a random Message ID.
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_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.
static void run_mime_type_query(struct Body *b, struct ConfigSubset *sub)
Run an external command to determine the MIME type.
static void transform_to_7bit(struct Body *b, FILE *fp_in, struct ConfigSubset *sub)
Convert MIME parts to 7-bit.
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.
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_message_to_7bit(struct Body *b, FILE *fp, struct ConfigSubset *sub)
Convert an email's MIME parts to 7-bit.
void mutt_stamp_attachment(struct Body *b)
Timestamp an Attachment.
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.
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.
Send email using 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.
Send email to an SMTP server.
struct Buffer * personal
Real name of address.
struct Buffer * mailbox
Mailbox and host 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 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.