71 char p[256], tmp[256];
77 if (c_crypt_timestamp)
84 snprintf(tmp,
sizeof(tmp),
_(
"[-- %s output follows%s --]\n"),
NONULL(app_name), p);
110#include <sys/resource.h>
114static void disable_coredumps(
void)
116 struct rlimit rl = { 0, 0 };
117 static bool done =
false;
121 setrlimit(RLIMIT_CORE, &rl);
160 struct Body *pbody = NULL, *tmp_pbody = NULL;
161 struct Body *tmp_smime_pbody = NULL;
162 struct Body *tmp_pgp_pbody = NULL;
163 bool has_retainable_sig =
false;
173 security &= ~SEC_SIGN;
188 if (
query_quadoption(c_pgp_mime_auto,
_(
"Inline PGP can't be used with attachments. Revert to PGP/MIME?")) !=
191 mutt_error(
_(
"Mail not sent: inline PGP can't be used with attachments"));
197 if ((
query_quadoption(c_pgp_mime_auto,
_(
"Inline PGP can't be used with format=flowed. Revert to PGP/MIME?"))) !=
200 mutt_error(
_(
"Mail not sent: inline PGP can't be used with format=flowed"));
210 puts(
_(
"Invoking PGP..."));
221 _(
"Message can't be sent inline. Revert to using PGP/MIME?")) !=
MUTT_YES)
235 tmp_smime_pbody = e->
body;
237 tmp_pgp_pbody = e->
body;
239#ifdef CRYPT_BACKEND_GPGME
241 if (sign && c_crypt_use_pka)
247 const char *mailbox = NULL;
249 bool free_from =
false;
259 if (!
mailbox && c_envelope_from_address)
272 if (c_crypt_protected_headers_write)
312 tmp_smime_pbody = tmp_pbody;
323 has_retainable_sig =
true;
326 tmp_pgp_pbody = tmp_pbody;
346 if ((tmp_smime_pbody != e->
body) && (tmp_smime_pbody != tmp_pbody))
363 if (has_retainable_sig)
375 if (has_retainable_sig)
607 bool complain =
false;
640 mutt_message(
_(
"S/MIME messages with no hints on content are unsupported"));
648 if ((len > 0) && (*(t + len) ==
'.'))
725 rc |= u | (w & ~SEC_GOODSIGN);
765 const int c = fgetc(state->
fp_in);
777 if ((c ==
'\n') && !hadcr)
877 puts(
_(
"Trying to extract PGP keys...\n"));
904 puts(
_(
"Trying to extract S/MIME certificates..."));
947 const char *self_encrypt = NULL;
986 if (c_pgp_self_encrypt || (c_pgp_encrypt_self ==
MUTT_YES))
987 self_encrypt = c_pgp_default_key;
1000 if (c_smime_self_encrypt || (c_smime_encrypt_self ==
MUTT_YES))
1001 self_encrypt = c_smime_default_key;
1005 if (!oppenc_mode && self_encrypt)
1009 sprintf(*keylist + keylist_size,
" %s", self_encrypt);
1033 char *pgpkeylist = NULL;
1058 for (; a; a = a->
next)
1069 (*signatures)[(*n)++] = a;
1082 const char *
const c_crypt_protected_headers_subject =
1131 bool inconsistent =
false;
1132 struct Body *top = b;
1133 struct Body **signatures = NULL;
1136 struct Buffer *tempfile = NULL;
1143 state_printf(state,
_(
"[-- Error: Unknown multipart/signed protocol %s --]\n\n"),
1148 if (!(b && b->
next))
1150 inconsistent =
true;
1154 switch (signed_type)
1159 inconsistent =
true;
1166 inconsistent =
true;
1174 inconsistent =
true;
1178 inconsistent =
true;
1183 state_attach_puts(state,
_(
"[-- Error: Missing or bad-format multipart/signed signature --]\n\n"));
1195 bool goodsig =
true;
1198 for (
int i = 0; i < sigcnt; i++)
1221 state_printf(state,
_(
"[-- Warning: We can't verify %s/%s signatures. --]\n\n"),
1222 TYPE(signatures[i]), signatures[i]->subtype);
1268 const char **ppl,
const char **pps)
1270 const char *ps = NULL, *pl = NULL, *phint = NULL;
1271 char *pfcopy = NULL, *s1 = NULL, *s2 = NULL;
1295 if (((
'0' <= c) && (c <=
'9')) || ((
'A' <= c) && (c <=
'F')) ||
1296 ((
'a' <= c) && (c <=
'f')))
1305 if ((c ==
' ') && ((hexdigits % 4) == 0))
1313 pfcopy = (!c && ((hexdigits == 40) || (hexdigits == 32)) ?
mutt_str_dup(pf) : NULL);
1364 if (!strchr(
"0123456789ABCDEFabcdef", *s++))
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_free(struct Address **ptr)
Free a single Address.
void mutt_addrlist_dedupe(struct AddressList *al)
Remove duplicate addresses.
void mutt_expand_aliases(struct AddressList *al)
Expand aliases in a List of Addresses.
GUI display the mailboxes in a side panel.
void mutt_parse_mime_message(struct Email *e, FILE *fp)
Parse a MIME email.
Autocrypt end-to-end encryption.
@ AUTOCRYPT_REC_NO
Do no use Autocrypt.
int mutt_autocrypt_generate_gossip_list(struct Email *e)
Create the gossip list headers.
enum AutocryptRec mutt_autocrypt_ui_recommendation(const struct Email *e, char **keylist)
Get the recommended action for an Email.
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.
enum QuadOption cs_subset_quad(const struct ConfigSubset *sub, const char *name)
Get a quad-value config item by name.
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
const struct Address * cs_subset_address(const struct ConfigSubset *sub, const char *name)
Get an Address 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.
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 MUTT_CM_DECODE
Decode the message body into text/plain.
#define MUTT_CM_CHARCONV
Perform character set conversions.
#define MUTT_CM_DECODE_SMIME
Used for decoding S/MIME messages.
#define CH_DISPLAY
Display result to user.
#define MUTT_CM_NO_FLAGS
No flags are set.
#define MUTT_CM_DECODE_CRYPT
#define MUTT_CM_NOHEADER
Don't copy the message header.
#define CH_NO_FLAGS
No flags are set.
Convenience wrapper for the core headers.
SecurityFlags mutt_is_application_pgp(struct Body *b)
Does the message use PGP?
void crypt_opportunistic_encrypt(struct Email *e)
Can all recipients be determined.
bool crypt_is_numerical_keyid(const char *s)
Is this a numerical keyid.
SecurityFlags mutt_is_multipart_signed(struct Body *b)
Is a message signed?
static void crypt_fetch_signatures(struct Body ***signatures, struct Body *a, int *n)
Create an array of an emails parts.
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.
int mutt_is_valid_multipart_pgp_encrypted(struct Body *b)
Is this a valid multi-part encrypted message?
bool mutt_should_hide_protected_subject(struct Email *e)
Should NeoMutt hide the protected subject?
void crypt_convert_to_7bit(struct Body *a)
Convert an email to 7bit encoding.
SecurityFlags mutt_is_multipart_encrypted(struct Body *b)
Does the message have encrypted parts?
int mutt_protect(struct Email *e, char *keylist, bool postpone)
Encrypt and/or sign a message.
void crypt_forget_passphrase(void)
Forget a passphrase and display a message.
const char * crypt_get_fingerprint_or_id(const char *p, const char **pphint, const char **ppl, const char **pps)
Get the fingerprint or long key ID.
SecurityFlags mutt_is_malformed_multipart_pgp_encrypted(struct Body *b)
Check for malformed layout.
int crypt_write_signed(struct Body *a, struct State *state, const char *tempfile)
Write the message body/part.
int crypt_get_keys(struct Email *e, char **keylist, bool oppenc_mode)
Check we have all the keys we need.
void crypt_current_time(struct State *state, const char *app_name)
Print the current time.
void crypt_extract_keys_from_messages(struct Mailbox *m, struct EmailList *el)
Extract keys from a message.
SecurityFlags crypt_query(struct Body *b)
Check out the type of encryption used.
Signing/encryption multiplexor.
char * crypt_smime_find_keys(struct AddressList *addrlist, bool oppenc_mode)
Wrapper for CryptModuleSpecs::find_keys()
struct Body * crypt_pgp_sign_message(struct Body *a, const struct AddressList *from)
Wrapper for CryptModuleSpecs::sign_message()
char * crypt_pgp_find_keys(struct AddressList *addrlist, bool oppenc_mode)
Wrapper for CryptModuleSpecs::find_keys()
struct Body * crypt_smime_build_smime_entity(struct Body *a, char *certlist)
Wrapper for CryptModuleSpecs::smime_build_smime_entity()
bool crypt_smime_valid_passphrase(void)
Wrapper for CryptModuleSpecs::valid_passphrase()
void crypt_pgp_invoke_import(const char *fname)
Wrapper for CryptModuleSpecs::pgp_invoke_import()
void crypt_smime_void_passphrase(void)
Wrapper for CryptModuleSpecs::void_passphrase()
int crypt_pgp_verify_one(struct Body *sigbdy, struct State *state, const char *tempf)
Wrapper for CryptModuleSpecs::verify_one()
int crypt_smime_verify_one(struct Body *sigbdy, struct State *state, const char *tempf)
Wrapper for CryptModuleSpecs::verify_one()
void crypt_smime_invoke_import(const char *infile, const char *mailbox)
Wrapper for CryptModuleSpecs::smime_invoke_import()
void crypt_pgp_set_sender(const char *sender)
Wrapper for CryptModuleSpecs::set_sender()
void crypt_smime_set_sender(const char *sender)
Wrapper for CryptModuleSpecs::set_sender()
void crypt_pgp_void_passphrase(void)
Wrapper for CryptModuleSpecs::void_passphrase()
bool crypt_pgp_valid_passphrase(void)
Wrapper for CryptModuleSpecs::valid_passphrase()
struct Body * crypt_pgp_encrypt_message(struct Email *e, struct Body *a, char *keylist, int sign, const struct AddressList *from)
Wrapper for CryptModuleSpecs::pgp_encrypt_message()
struct Body * crypt_pgp_traditional_encryptsign(struct Body *a, SecurityFlags flags, char *keylist)
Wrapper for CryptModuleSpecs::pgp_traditional_encryptsign()
struct Body * crypt_smime_sign_message(struct Body *a, const struct AddressList *from)
Wrapper for CryptModuleSpecs::sign_message()
Wrapper around crypto functions.
int mutt_any_key_to_continue(const char *s)
Prompt the user to 'press any key' and wait.
void mutt_endwin(void)
Shutdown curses.
size_t mutt_date_localtime_format(char *buf, size_t buflen, const char *format, time_t t)
Format localtime.
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.
Structs that make up an email.
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
struct Envelope * mutt_env_new(void)
Create a new Envelope.
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
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.
bool OptDontHandlePgpKeys
(pseudo) used to extract PGP keys
bool OptPgpCheckTrust
(pseudo) used by dlg_select_pgp_key()
int mutt_protected_headers_handler(struct Body *b, struct State *state)
Process a protected header - Implements handler_t -.
int mutt_signed_handler(struct Body *b, struct State *state)
Verify a "multipart/signed" body - Implements handler_t -.
#define mutt_message(...)
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_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_MESSAGE
Type: 'message/*'.
@ TYPE_MULTIPART
Type: 'multipart/*'.
@ TYPE_APPLICATION
Type: 'application/*'.
@ TYPE_TEXT
Type: 'text/*'.
struct Body * mutt_remove_multipart(struct Body *b)
Extract the multipart body if it exists.
Convenience wrapper for the library headers.
void state_attach_puts(struct State *state, const char *t)
Write a string to the state.
int state_printf(struct State *state, const char *fmt,...)
Write a formatted string to the State.
void state_mark_protected_header(struct State *state)
Write a unique marker around protected headers.
#define state_puts(STATE, STR)
#define STATE_DISPLAY
Output is displayed to the user.
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.
bool mutt_strn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings (to a maximum), safely.
char * mutt_str_skip_whitespace(const char *p)
Find the first non-whitespace character in a string.
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.
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Many unsorted constants and some structs.
int mutt_window_wrap_cols(int width, short wrap)
Calculate the wrap column for a given screen width.
int mx_msg_close(struct Mailbox *m, struct Message **msg)
Close a message.
struct Message * mx_msg_open(struct Mailbox *m, int msgno)
Return a stream pointer for a message.
#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 SEC_GOODSIGN
Email has a valid signature.
#define APPLICATION_PGP
Use PGP to encrypt/sign.
#define SEC_BADSIGN
Email has a bad signature.
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
#define SEC_NO_FLAGS
No flags are set.
#define SEC_PARTSIGN
Not all parts of the email is signed.
#define SEC_ENCRYPT
Email is encrypted.
#define SEC_SIGN
Email is signed.
char * mutt_param_get(const struct ParameterList *pl, const char *s)
Find a matching Parameter.
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.
bool mutt_matches_ignore(const char *s)
Does the string match the ignore list.
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.
QuadOption
Possible values for a quad-option.
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
enum QuadOption query_quadoption(enum QuadOption opt, const char *prompt)
Ask the user a quad-question.
#define STAILQ_FOREACH(var, head, field)
#define TAILQ_FIRST(head)
#define TAILQ_HEAD_INITIALIZER(head)
#define TAILQ_EMPTY(head)
Convenience wrapper for the send headers.
struct Address * mutt_default_from(struct ConfigSubset *sub)
Get a default 'from' Address.
const char * mutt_fqdn(bool may_hide_host, const struct ConfigSubset *sub)
Get the Fully-Qualified Domain Name.
void mutt_message_to_7bit(struct Body *a, FILE *fp, struct ConfigSubset *sub)
Convert an email's MIME parts to 7-bit.
void mutt_prepare_envelope(struct Envelope *env, bool final, struct ConfigSubset *sub)
Prepare an email header.
char * 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
bool badsig
Bad cryptographic signature (needed to check encrypted s/mime-signatures)
struct Envelope * mime_headers
Memory hole protected headers.
bool is_autocrypt
Flag autocrypt-decrypted messages for replying.
LOFF_T length
length (in bytes) of attachment
struct ParameterList parameter
Parameters of the content-type.
char * description
content-description
struct Content * content
Detailed info about the content of the attachment.
struct Body * next
next attachment in the list
char * subtype
content-type subtype
unsigned int encoding
content-transfer-encoding, ContentEncoding
bool goodsig
Good cryptographic signature.
long hdr_offset
Offset in stream where the headers begin.
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.
bool space
Whitespace at the end of lines?
bool from
Has a line beginning with "From "?
struct Email * email
Email in the list.
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.
int msgno
Number displayed to the user.
struct AddressList to
Email's 'To' list.
struct AddressList cc
Email's 'Cc' list.
struct AddressList sender
Email's sender.
char * subject
Email's subject.
struct AddressList bcc
Email's 'Bcc' list.
struct AddressList from
Email's 'From' list.
A local copy of an email.
FILE * fp
pointer to the message data
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.
#define mutt_buffer_mktemp(buf)