NeoMutt  2019-11-11
Teaching an old dog new tricks
DOXYGEN
commands.c File Reference

Manage where the email is piped to external commands. More...

#include "config.h"
#include <errno.h>
#include <limits.h>
#include <regex.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "mutt/mutt.h"
#include "address/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "mutt.h"
#include "alias.h"
#include "context.h"
#include "copy.h"
#include "curs_lib.h"
#include "filter.h"
#include "format_flags.h"
#include "globals.h"
#include "hdrline.h"
#include "hook.h"
#include "icommands.h"
#include "keymap.h"
#include "mutt_commands.h"
#include "mutt_curses.h"
#include "mutt_logging.h"
#include "mutt_mailbox.h"
#include "mutt_menu.h"
#include "mutt_parse.h"
#include "mutt_window.h"
#include "muttlib.h"
#include "mx.h"
#include "ncrypt/ncrypt.h"
#include "options.h"
#include "pager.h"
#include "protos.h"
#include "sendlib.h"
#include "sort.h"
#include "imap/imap.h"
#include "notmuch/mutt_notmuch.h"
#include <libintl.h>
#include "autocrypt/autocrypt.h"
+ Include dependency graph for commands.c:

Go to the source code of this file.

Macros

#define EXTRA_SPACE   (15 + 7 + 2)
 

Functions

static void process_protected_headers (struct Email *e)
 Get the protected header and update the index. More...
 
int mutt_display_message (struct MuttWindow *win, struct Mailbox *m, struct Email *e)
 Display a message in the pager. More...
 
void ci_bounce_message (struct Mailbox *m, struct EmailList *el)
 Bounce an email. More...
 
static void pipe_set_flags (bool decode, bool print, CopyMessageFlags *cmflags, CopyHeaderFlags *chflags)
 Generate flags for copy header/message. More...
 
static void pipe_msg (struct Mailbox *m, struct Email *e, FILE *fp, bool decode, bool print)
 Pipe a message. More...
 
static int pipe_message (struct Mailbox *m, struct EmailList *el, char *cmd, bool decode, bool print, bool split, const char *sep)
 Pipe message to a command. More...
 
void mutt_pipe_message (struct Mailbox *m, struct EmailList *el)
 Pipe a message. More...
 
void mutt_print_message (struct Mailbox *m, struct EmailList *el)
 Print a message. More...
 
int mutt_select_sort (bool reverse)
 Ask the user for a sort method. More...
 
void mutt_shell_escape (void)
 invoke a command in a subshell More...
 
void mutt_enter_command (void)
 enter a neomutt command More...
 
void mutt_display_address (struct Envelope *env)
 Display the address of a message. More...
 
static void set_copy_flags (struct Email *e, bool decode, bool decrypt, CopyMessageFlags *cmflags, CopyHeaderFlags *chflags)
 Set the flags for a message copy. More...
 
int mutt_save_message_ctx (struct Email *e, bool delete_original, bool decode, bool decrypt, struct Mailbox *m)
 Save a message to a given mailbox. More...
 
int mutt_save_message (struct Mailbox *m, struct EmailList *el, bool delete_original, bool decode, bool decrypt)
 Save an email. More...
 
bool mutt_edit_content_type (struct Email *e, struct Body *b, FILE *fp)
 Edit the content type of an attachment. More...
 
static bool check_traditional_pgp (struct Email *e, MuttRedrawFlags *redraw)
 Check for an inline PGP content. More...
 
bool mutt_check_traditional_pgp (struct EmailList *el, MuttRedrawFlags *redraw)
 Check if a message has inline PGP content. More...
 
void mutt_check_stats (void)
 Forcibly update mailbox stats. More...
 

Variables

unsigned char C_CryptVerifySig
 Config: Verify PGP or SMIME signatures. More...
 
char * C_DisplayFilter
 Config: External command to pre-process an email before display. More...
 
bool C_PipeDecode
 Config: Decode the message when piping it. More...
 
char * C_PipeSep
 Config: Separator to add between multiple piped messages. More...
 
bool C_PipeSplit
 Config: Run the pipe command on each message separately. More...
 
bool C_PrintDecode
 Config: Decode message before printing it. More...
 
bool C_PrintSplit
 Config: Print multiple messages separately. More...
 
bool C_PromptAfter
 Config: Pause after running an external pager. More...
 
static const char * ExtPagerProgress = "all"
 
static char LastSaveFolder [PATH_MAX] = ""
 The folder the user last saved to. More...
 

Detailed Description

Manage where the email is piped to external commands.

Authors
  • Michael R. Elkins
  • Thomas Roessler
  • Pietro Cerutti

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file commands.c.

Macro Definition Documentation

◆ EXTRA_SPACE

#define EXTRA_SPACE   (15 + 7 + 2)

Function Documentation

◆ process_protected_headers()

static void process_protected_headers ( struct Email e)
static

Get the protected header and update the index.

Parameters
eEmail to update

Definition at line 104 of file commands.c.

105 {
106  struct Envelope *prot_headers = NULL;
107  regmatch_t pmatch[1];
108 
109 #ifdef USE_AUTOCRYPT
111  return;
112 #else
114  return;
115 #endif
116 
117  /* Grab protected headers to update in the index */
118  if (e->security & SEC_SIGN)
119  {
120  /* Don't update on a bad signature.
121  *
122  * This is a simplification. It's possible the headers are in the
123  * encrypted part of a nested encrypt/signed. But properly handling that
124  * case would require more complexity in the decryption handlers, which
125  * I'm not sure is worth it. */
126  if (!(e->security & SEC_GOODSIGN))
127  return;
128 
130  {
131  prot_headers = e->content->parts->mime_headers;
132  }
134  {
135  prot_headers = e->content->mime_headers;
136  }
137  }
138  if (!prot_headers && (e->security & SEC_ENCRYPT))
139  {
140  if (((WithCrypto & APPLICATION_PGP) != 0) &&
143  {
144  prot_headers = e->content->mime_headers;
145  }
146  else if (((WithCrypto & APPLICATION_SMIME) != 0) && mutt_is_application_smime(e->content))
147  {
148  prot_headers = e->content->mime_headers;
149  }
150  }
151 
152  /* Update protected headers in the index and header cache. */
153  if (C_CryptProtectedHeadersRead && prot_headers && prot_headers->subject &&
154  mutt_str_strcmp(e->env->subject, prot_headers->subject))
155  {
156  if (Context->mailbox->subj_hash && e->env->real_subj)
158 
159  mutt_str_replace(&e->env->subject, prot_headers->subject);
160  FREE(&e->env->disp_subj);
161  if (mutt_regex_capture(C_ReplyRegex, e->env->subject, 1, pmatch))
162  e->env->real_subj = e->env->subject + pmatch[0].rm_eo;
163  else
164  e->env->real_subj = e->env->subject;
165 
166  if (Context->mailbox->subj_hash)
168 
170 
171  /* Also persist back to the message headers if this is set */
173  {
175  e->changed = 1;
176  Context->mailbox->changed = 1;
177  }
178  }
179 
180 #ifdef USE_AUTOCRYPT
181  if (C_Autocrypt && (e->security & SEC_ENCRYPT) && prot_headers && prot_headers->autocrypt_gossip)
182  {
183  mutt_autocrypt_process_gossip_header(e, prot_headers);
184  }
185 #endif
186 }
The "current" mailbox.
Definition: context.h:36
void mutt_hash_delete(struct Hash *table, const char *strkey, const void *data)
Remove an element from a Hash table.
Definition: hash.c:443
WHERE bool C_Autocrypt
Config: Enables the Autocrypt feature.
Definition: globals.h:203
struct Envelope * mime_headers
Memory hole protected headers.
Definition: body.h:63
struct AutocryptHeader * autocrypt_gossip
Definition: envelope.h:86
char * disp_subj
Display subject (modified copy of subject)
Definition: envelope.h:68
struct Body * content
List of MIME parts.
Definition: email.h:90
int mutt_autocrypt_process_gossip_header(struct Email *e, struct Envelope *prot_headers)
Parse an Autocrypt email gossip header.
Definition: autocrypt.c:406
int mutt_is_valid_multipart_pgp_encrypted(struct Body *b)
Is this a valid multi-part encrypted message?
Definition: crypt.c:477
char * real_subj
Offset of the real subject.
Definition: envelope.h:67
bool changed
Email has been edited.
Definition: email.h:48
int mx_save_hcache(struct Mailbox *m, struct Email *e)
Save message to the header cache - Wrapper for MxOps::msg_save_hcache()
Definition: mx.c:1623
#define SEC_ENCRYPT
Email is encrypted.
Definition: ncrypt.h:122
#define MUTT_ENV_CHANGED_SUBJECT
Protected header update.
Definition: envelope.h:35
unsigned char changed
Changed fields, e.g. MUTT_ENV_CHANGED_SUBJECT.
Definition: envelope.h:88
struct Mailbox * mailbox
Definition: context.h:50
#define SEC_GOODSIGN
Email has a valid signature.
Definition: ncrypt.h:124
struct Envelope * env
Envelope information.
Definition: email.h:89
SecurityFlags mutt_is_multipart_signed(struct Body *b)
Is a message signed?
Definition: crypt.c:412
struct Regex * C_ReplyRegex
Config: Regex to match message reply subjects like "re: ".
Definition: email_globals.c:37
#define SEC_SIGN
Email is signed.
Definition: ncrypt.h:123
WHERE bool C_CryptProtectedHeadersSave
Config: Save the cleartext Subject with the headers.
Definition: globals.h:280
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:54
SecurityFlags mutt_is_malformed_multipart_pgp_encrypted(struct Body *b)
Check for malformed layout.
Definition: crypt.c:514
SecurityFlags mutt_is_application_smime(struct Body *m)
Does the message use S/MIME?
Definition: crypt.c:618
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/ncrypt.h pgplib.h, smime.h
Definition: email.h:39
WHERE bool C_CryptProtectedHeadersRead
Config: Display protected headers (Memory Hole) in the pager.
Definition: globals.h:279
void mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:453
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: ncrypt.h:134
bool mutt_regex_capture(const struct Regex *regex, const char *str, size_t nmatch, regmatch_t matches[])
match a regex against a string, with provided options
Definition: regex.c:594
char * subject
Email&#39;s subject.
Definition: envelope.h:66
struct Hash * subj_hash
Hash table by subject.
Definition: mailbox.h:139
#define FREE(x)
Definition: memory.h:40
bool changed
Mailbox has been modified.
Definition: mailbox.h:125
struct HashElem * mutt_hash_insert(struct Hash *table, const char *strkey, void *data)
Add a new element to the Hash table (with string keys)
Definition: hash.c:351
#define WithCrypto
Definition: ncrypt.h:160
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
The header of an Email.
Definition: envelope.h:54
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: ncrypt.h:135
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_display_message()

int mutt_display_message ( struct MuttWindow win,
struct Mailbox m,
struct Email e 
)

Display a message in the pager.

Parameters
winWindow
mMailbox
eEmail to display
Return values
0Success
-1Error

Definition at line 196 of file commands.c.

197 {
198  int rc = 0;
199  bool builtin = false;
201  CopyHeaderFlags chflags;
202  pid_t filterpid = -1;
203  struct Buffer *tempfile = NULL;
204  int res;
205 
208 
209  char columns[16];
210  snprintf(columns, sizeof(columns), "%d", win->cols);
211  mutt_envlist_set("COLUMNS", columns, true);
212 
213  /* see if crypto is needed for this message. if so, we should exit curses */
214  if ((WithCrypto != 0) && e->security)
215  {
216  if (e->security & SEC_ENCRYPT)
217  {
218  if (e->security & APPLICATION_SMIME)
221  goto cleanup;
222 
223  cmflags |= MUTT_CM_VERIFY;
224  }
225  else if (e->security & SEC_SIGN)
226  {
227  /* find out whether or not the verify signature */
228  /* L10N: Used for the $crypt_verify_sig prompt */
229  if (query_quadoption(C_CryptVerifySig, _("Verify signature?")) == MUTT_YES)
230  {
231  cmflags |= MUTT_CM_VERIFY;
232  }
233  }
234  }
235 
236  if (cmflags & MUTT_CM_VERIFY || e->security & SEC_ENCRYPT)
237  {
238  if (e->security & APPLICATION_PGP)
239  {
240  if (!TAILQ_EMPTY(&e->env->from))
242 
244  }
245 
246  if (e->security & APPLICATION_SMIME)
248  }
249 
250  FILE *fp_filter_out = NULL;
251  tempfile = mutt_buffer_pool_get();
252  mutt_buffer_mktemp(tempfile);
253  FILE *fp_out = mutt_file_fopen(mutt_b2s(tempfile), "w");
254  if (!fp_out)
255  {
256  mutt_error(_("Could not create temporary file"));
257  goto cleanup;
258  }
259 
260  if (C_DisplayFilter)
261  {
262  fp_filter_out = fp_out;
263  fp_out = NULL;
264  filterpid = mutt_create_filter_fd(C_DisplayFilter, &fp_out, NULL, NULL, -1,
265  fileno(fp_filter_out), -1);
266  if (filterpid < 0)
267  {
268  mutt_error(_("Can't create display filter"));
269  mutt_file_fclose(&fp_filter_out);
270  unlink(mutt_b2s(tempfile));
271  goto cleanup;
272  }
273  }
274 
275  if (!C_Pager || (mutt_str_strcmp(C_Pager, "builtin") == 0))
276  builtin = true;
277  else
278  {
279  char buf[1024];
280  struct HdrFormatInfo hfi;
281 
282  hfi.ctx = Context;
283  hfi.mailbox = m;
284  hfi.pager_progress = ExtPagerProgress;
285  hfi.email = e;
286  mutt_make_string_info(buf, sizeof(buf), win->cols, NONULL(C_PagerFormat),
287  &hfi, MUTT_FORMAT_NO_FLAGS);
288  fputs(buf, fp_out);
289  fputs("\n\n", fp_out);
290  }
291 
292  chflags = (C_Weed ? (CH_WEED | CH_REORDER) : CH_NO_FLAGS) | CH_DECODE | CH_FROM | CH_DISPLAY;
293 #ifdef USE_NOTMUCH
294  if (m->magic == MUTT_NOTMUCH)
295  chflags |= CH_VIRTUAL;
296 #endif
297  res = mutt_copy_message(fp_out, m, e, cmflags, chflags, win->cols);
298 
299  if (((mutt_file_fclose(&fp_out) != 0) && (errno != EPIPE)) || (res < 0))
300  {
301  mutt_error(_("Could not copy message"));
302  if (fp_filter_out)
303  {
304  mutt_wait_filter(filterpid);
305  mutt_file_fclose(&fp_filter_out);
306  }
307  mutt_file_unlink(mutt_b2s(tempfile));
308  goto cleanup;
309  }
310 
311  if (fp_filter_out && (mutt_wait_filter(filterpid) != 0))
313 
314  mutt_file_fclose(&fp_filter_out); /* XXX - check result? */
315 
316  if (WithCrypto)
317  {
318  /* update crypto information for this message */
319  e->security &= ~(SEC_GOODSIGN | SEC_BADSIGN);
320  e->security |= crypt_query(e->content);
321 
322  /* Remove color cache for this message, in case there
323  * are color patterns for both ~g and ~V */
324  e->pair = 0;
325 
326  /* Process protected headers and autocrypt gossip headers */
328  }
329 
330  if (builtin)
331  {
332  if ((WithCrypto != 0) && (e->security & APPLICATION_SMIME) && (cmflags & MUTT_CM_VERIFY))
333  {
334  if (e->security & SEC_GOODSIGN)
335  {
336  if (crypt_smime_verify_sender(m, e) == 0)
337  mutt_message(_("S/MIME signature successfully verified"));
338  else
339  mutt_error(_("S/MIME certificate owner does not match sender"));
340  }
341  else if (e->security & SEC_PARTSIGN)
342  mutt_message(_("Warning: Part of this message has not been signed"));
343  else if (e->security & SEC_SIGN || e->security & SEC_BADSIGN)
344  mutt_error(_("S/MIME signature could NOT be verified"));
345  }
346 
347  if ((WithCrypto != 0) && (e->security & APPLICATION_PGP) && (cmflags & MUTT_CM_VERIFY))
348  {
349  if (e->security & SEC_GOODSIGN)
350  mutt_message(_("PGP signature successfully verified"));
351  else if (e->security & SEC_PARTSIGN)
352  mutt_message(_("Warning: Part of this message has not been signed"));
353  else if (e->security & SEC_SIGN)
354  mutt_message(_("PGP signature could NOT be verified"));
355  }
356 
357  struct Pager info = { 0 };
358  /* Invoke the builtin pager */
359  info.email = e;
360  info.ctx = Context;
361  rc = mutt_pager(NULL, mutt_b2s(tempfile), MUTT_PAGER_MESSAGE, &info);
362  }
363  else
364  {
365  mutt_endwin();
366 
367  struct Buffer *cmd = mutt_buffer_pool_get();
368  mutt_buffer_printf(cmd, "%s %s", NONULL(C_Pager), mutt_b2s(tempfile));
369  int r = mutt_system(mutt_b2s(cmd));
370  if (r == -1)
371  mutt_error(_("Error running \"%s\""), mutt_b2s(cmd));
372  unlink(mutt_b2s(tempfile));
374 
375  if (!OptNoCurses)
376  keypad(stdscr, true);
377  if (r != -1)
378  mutt_set_flag(m, e, MUTT_READ, true);
379  if ((r != -1) && C_PromptAfter)
380  {
381  mutt_unget_event(mutt_any_key_to_continue(_("Command: ")), 0);
382  rc = km_dokey(MENU_PAGER);
383  }
384  else
385  rc = 0;
386  }
387 
388 cleanup:
389  mutt_envlist_unset("COLUMNS");
390  mutt_buffer_pool_release(&tempfile);
391  return rc;
392 }
int km_dokey(enum MenuType menu)
Determine what a keypress should do.
Definition: keymap.c:619
struct Context * ctx
Definition: hdrline.h:47
#define mutt_buffer_mktemp(buf)
Definition: muttlib.h:79
#define NONULL(x)
Definition: string2.h:37
#define mutt_set_flag(m, e, flag, bf)
Definition: protos.h:69
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:100
#define TAILQ_FIRST(head)
Definition: queue.h:717
enum QuadOption query_quadoption(enum QuadOption opt, const char *prompt)
Ask the user a quad-question.
Definition: init.c:3340
#define mutt_message(...)
Definition: logging.h:83
#define MUTT_PAGER_MESSAGE
Definition: pager.h:58
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:39
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:111
struct Body * content
List of MIME parts.
Definition: email.h:90
void mutt_file_unlink(const char *s)
Delete a file, carefully.
Definition: file.c:194
String manipulation buffer.
Definition: buffer.h:33
void mutt_parse_mime_message(struct Mailbox *m, struct Email *e)
Parse a MIME email.
Definition: mutt_parse.c:49
int mutt_copy_message(FILE *fp_out, struct Mailbox *m, struct Email *e, CopyMessageFlags cmflags, CopyHeaderFlags chflags, int wraplen)
Copy a message from a Mailbox.
Definition: copy.c:810
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:763
#define CH_FROM
Retain the "From " message separator?
Definition: copy.h:55
#define _(a)
Definition: message.h:28
static const char * ExtPagerProgress
Definition: commands.c:95
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:46
#define MUTT_MESSAGE_HOOK
message-hook: run before displaying a message
Definition: hook.h:52
uint16_t CopyMessageFlags
Flags for mutt_copy_message(), e.g. MUTT_CM_NOHEADER.
Definition: copy.h:31
int crypt_smime_verify_sender(struct Mailbox *m, struct Email *e)
Wrapper for CryptModuleSpecs::smime_verify_sender()
Definition: cryptglue.c:465
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
An email being displayed.
Definition: pager.h:65
unsigned char C_CryptVerifySig
Config: Verify PGP or SMIME signatures.
Definition: commands.c:86
#define SEC_ENCRYPT
Email is encrypted.
Definition: ncrypt.h:122
#define SEC_PARTSIGN
Not all parts of the email is signed.
Definition: ncrypt.h:126
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: format_flags.h:30
#define SEC_BADSIGN
Email has a bad signature.
Definition: ncrypt.h:125
Pager pager (email viewer)
Definition: keymap.h:78
bool crypt_valid_passphrase(SecurityFlags flags)
Check that we have a usable passphrase, ask if not.
Definition: crypt.c:147
struct Mailbox * mailbox
Definition: context.h:50
#define MUTT_CM_DISPLAY
Output is displayed to the user.
Definition: copy.h:38
Data passed to index_format_str()
Definition: hdrline.h:45
#define SEC_GOODSIGN
Email has a valid signature.
Definition: ncrypt.h:124
struct AddressList from
Email&#39;s &#39;From&#39; list.
Definition: envelope.h:57
enum MailboxType magic
Mailbox type.
Definition: mailbox.h:116
#define CH_WEED
Weed the headers?
Definition: copy.h:52
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:152
struct Envelope * env
Envelope information.
Definition: email.h:89
#define CH_VIRTUAL
Write virtual header lines too.
Definition: copy.h:72
void mutt_make_string_info(char *buf, size_t buflen, int cols, const char *s, struct HdrFormatInfo *hfi, MuttFormatFlags flags)
Create pager status bar string.
Definition: hdrline.c:1521
void crypt_invoke_message(SecurityFlags type)
Display an informative message.
Definition: cryptglue.c:146
#define mutt_b2s(buf)
Definition: buffer.h:41
struct Context * ctx
Current mailbox.
Definition: pager.h:67
#define SEC_SIGN
Email is signed.
Definition: ncrypt.h:123
WHERE struct Context * Context
Definition: globals.h:44
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:544
bool mutt_envlist_unset(const char *name)
Unset an environment variable.
Definition: envlist.c:131
#define CH_NO_FLAGS
No flags are set.
Definition: copy.h:50
#define MUTT_CM_DECODE
Decode the message body into text/plain.
Definition: copy.h:37
#define CH_REORDER
Re-order output of headers (specified by &#39;hdr_order&#39;)
Definition: copy.h:58
#define MUTT_CM_CHARCONV
Perform character set conversions.
Definition: copy.h:41
void crypt_smime_getkeys(struct Envelope *env)
Wrapper for CryptModuleSpecs::smime_getkeys()
Definition: cryptglue.c:456
#define CH_DECODE
Do RFC2047 header decoding.
Definition: copy.h:53
pid_t mutt_create_filter_fd(const char *cmd, FILE **fp_in, FILE **fp_out, FILE **fp_err, int fdin, int fdout, int fderr)
Run a command on a pipe (optionally connect stdin/stdout)
Definition: filter.c:65
void crypt_pgp_invoke_getkeys(struct Address *addr)
Wrapper for CryptModuleSpecs::pgp_invoke_getkeys()
Definition: cryptglue.c:265
#define CH_DISPLAY
Display result to user.
Definition: copy.h:69
Messages that have been read.
Definition: mutt.h:100
#define MUTT_CM_VERIFY
Do signature verification.
Definition: copy.h:46
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/ncrypt.h pgplib.h, smime.h
Definition: email.h:39
&#39;Notmuch&#39; (virtual) Mailbox type
Definition: mailbox.h:53
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: ncrypt.h:134
int mutt_any_key_to_continue(const char *s)
Prompt the user to &#39;press any key&#39; and wait.
Definition: curs_lib.c:577
bool C_PromptAfter
Config: Pause after running an external pager.
Definition: commands.c:93
struct Email * email
Current message.
Definition: pager.h:68
char * C_DisplayFilter
Config: External command to pre-process an email before display.
Definition: commands.c:87
uint32_t CopyHeaderFlags
Flags for mutt_copy_header(), e.g. CH_UPDATE.
Definition: copy.h:49
#define mutt_error(...)
Definition: logging.h:84
static void process_protected_headers(struct Email *e)
Get the protected header and update the index.
Definition: commands.c:104
bool mutt_envlist_set(const char *name, const char *value, bool overwrite)
Set an environment variable.
Definition: envlist.c:84
WHERE char * C_Pager
Config: External command for viewing messages, or &#39;builtin&#39; to use NeoMutt&#39;s.
Definition: globals.h:134
void mutt_message_hook(struct Mailbox *m, struct Email *e, HookFlags type)
Perform a message hook.
Definition: hook.c:573
#define TAILQ_EMPTY(head)
Definition: queue.h:715
int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct Pager *extra)
Display a file, or help, in a window.
Definition: pager.c:2244
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:585
int mutt_wait_filter(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:221
#define WithCrypto
Definition: ncrypt.h:160
SecurityFlags crypt_query(struct Body *m)
Check out the type of encryption used.
Definition: crypt.c:694
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
int pair
Color-pair to use when displaying in the index.
Definition: email.h:79
int mutt_system(const char *cmd)
Run an external command.
Definition: system.c:51
WHERE char * C_PagerFormat
Config: printf-like format string for the pager&#39;s status bar.
Definition: globals.h:135
bool C_Weed
Config: Filter headers when displaying/forwarding/printing/replying.
Definition: email_globals.c:40
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: ncrypt.h:135
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ci_bounce_message()

void ci_bounce_message ( struct Mailbox m,
struct EmailList *  el 
)

Bounce an email.

Parameters
mMailbox
elList of Emails to bounce

Definition at line 399 of file commands.c.

400 {
401  if (!m || !el || STAILQ_EMPTY(el))
402  return;
403 
404  char prompt[129];
405  char scratch[128];
406  char buf[8192] = { 0 };
407  struct AddressList al = TAILQ_HEAD_INITIALIZER(al);
408  char *err = NULL;
409  int rc;
410  int msg_count = 0;
411 
412  struct EmailNode *en = NULL;
413  STAILQ_FOREACH(en, el, entries)
414  {
415  /* RFC5322 mandates a From: header,
416  * so warn before bouncing messages without one */
417  if (!TAILQ_EMPTY(&en->email->env->from))
418  mutt_error(_("Warning: message contains no From: header"));
419 
420  msg_count++;
421  }
422 
423  if (msg_count == 1)
424  mutt_str_strfcpy(prompt, _("Bounce message to: "), sizeof(prompt));
425  else
426  mutt_str_strfcpy(prompt, _("Bounce tagged messages to: "), sizeof(prompt));
427 
428  rc = mutt_get_field(prompt, buf, sizeof(buf), MUTT_ALIAS);
429  if (rc || !buf[0])
430  return;
431 
432  mutt_addrlist_parse2(&al, buf);
433  if (TAILQ_EMPTY(&al))
434  {
435  mutt_error(_("Error parsing address"));
436  return;
437  }
438 
439  mutt_expand_aliases(&al);
440 
441  if (mutt_addrlist_to_intl(&al, &err) < 0)
442  {
443  mutt_error(_("Bad IDN: '%s'"), err);
444  FREE(&err);
445  mutt_addrlist_clear(&al);
446  return;
447  }
448 
449  buf[0] = '\0';
450  mutt_addrlist_write(buf, sizeof(buf), &al, true);
451 
452 #define EXTRA_SPACE (15 + 7 + 2)
453  snprintf(scratch, sizeof(scratch),
454  ngettext("Bounce message to %s?", "Bounce messages to %s?", msg_count), buf);
455 
457  {
458  mutt_simple_format(prompt, sizeof(prompt), 0, MuttMessageWindow->cols - EXTRA_SPACE,
459  JUSTIFY_LEFT, 0, scratch, sizeof(scratch), false);
460  mutt_str_strcat(prompt, sizeof(prompt), "...?");
461  }
462  else
463  snprintf(prompt, sizeof(prompt), "%s?", scratch);
464 
465  if (query_quadoption(C_Bounce, prompt) != MUTT_YES)
466  {
467  mutt_addrlist_clear(&al);
469  mutt_message(ngettext("Message not bounced", "Messages not bounced", msg_count));
470  return;
471  }
472 
474 
475  struct Message *msg = NULL;
476  STAILQ_FOREACH(en, el, entries)
477  {
478  msg = mx_msg_open(m, en->email->msgno);
479  if (!msg)
480  {
481  rc = -1;
482  break;
483  }
484 
485  rc = mutt_bounce_message(msg->fp, en->email, &al);
486  mx_msg_close(m, &msg);
487 
488  if (rc < 0)
489  break;
490  }
491 
492  mutt_addrlist_clear(&al);
493  /* If no error, or background, display message. */
494  if ((rc == 0) || (rc == S_BKG))
495  mutt_message(ngettext("Message bounced", "Messages bounced", msg_count));
496 }
WHERE unsigned char C_Bounce
Config: Confirm before bouncing a message.
Definition: globals.h:183
void mutt_expand_aliases(struct AddressList *al)
Expand aliases in a List of Addresses.
Definition: alias.c:303
Left justify the text.
Definition: curs_lib.h:47
#define MUTT_ALIAS
Do alias "completion" by calling up the alias-menu.
Definition: mutt.h:63
enum QuadOption query_quadoption(enum QuadOption opt, const char *prompt)
Ask the user a quad-question.
Definition: init.c:3340
#define mutt_message(...)
Definition: logging.h:83
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:39
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1381
#define _(a)
Definition: message.h:28
#define S_BKG
Definition: string2.h:43
size_t mutt_addrlist_write(char *buf, size_t buflen, const struct AddressList *al, bool display)
Write an Address to a buffer.
Definition: address.c:1137
int mutt_addrlist_parse2(struct AddressList *al, const char *s)
Parse a list of email addresses.
Definition: address.c:606
#define mutt_get_field(field, buf, buflen, complete)
Definition: curs_lib.h:91
int mx_msg_close(struct Mailbox *m, struct Message **msg)
Close a message.
Definition: mx.c:1101
struct AddressList from
Email&#39;s &#39;From&#39; list.
Definition: envelope.h:57
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:95
struct Envelope * env
Envelope information.
Definition: email.h:89
int mutt_bounce_message(FILE *fp, struct Email *e, struct AddressList *to)
Bounce an email message.
Definition: sendlib.c:3128
A local copy of an email.
Definition: mx.h:81
int mutt_strwidth(const char *s)
Measure a string&#39;s width in screen cells.
Definition: curs_lib.c:1287
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
char * mutt_str_strcat(char *buf, size_t buflen, const char *s)
Concatenate two strings.
Definition: string.c:395
int mutt_addrlist_to_intl(struct AddressList *al, char **err)
Convert an Address list to Punycode.
Definition: address.c:1216
struct Email * email
Email in the list.
Definition: email.h:116
#define mutt_error(...)
Definition: logging.h:84
FILE * fp
pointer to the message data
Definition: mx.h:83
#define FREE(x)
Definition: memory.h:40
#define STAILQ_EMPTY(head)
Definition: queue.h:346
List of Emails.
Definition: email.h:114
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:42
#define TAILQ_EMPTY(head)
Definition: queue.h:715
#define EXTRA_SPACE
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:631
struct Message * mx_msg_open(struct Mailbox *m, int msgno)
return a stream pointer for a message
Definition: mx.c:1053
int msgno
Number displayed to the user.
Definition: email.h:86
void mutt_simple_format(char *buf, size_t buflen, int min_width, int max_width, enum FormatJustify justify, char pad_char, const char *s, size_t n, bool arboreal)
Format a string, like snprintf()
Definition: curs_lib.c:1021
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pipe_set_flags()

static void pipe_set_flags ( bool  decode,
bool  print,
CopyMessageFlags cmflags,
CopyHeaderFlags chflags 
)
static

Generate flags for copy header/message.

Parameters
[in]decodeIf true decode the message
[in]printIf true, mark the message for printing
[out]cmflagsFlags, see CopyMessageFlags
[out]chflagsFlags, see CopyHeaderFlags

Definition at line 505 of file commands.c.

507 {
508  if (decode)
509  {
510  *chflags |= CH_DECODE | CH_REORDER;
511  *cmflags |= MUTT_CM_DECODE | MUTT_CM_CHARCONV;
512 
513  if (C_Weed)
514  {
515  *chflags |= CH_WEED;
516  *cmflags |= MUTT_CM_WEED;
517  }
518 
519  /* Just as with copy-decode, we need to update the mime fields to avoid
520  * confusing programs that may process the email. However, we don't want
521  * to force those fields to appear in printouts. */
522  if (!print)
523  *chflags |= CH_MIME | CH_TXTPLAIN;
524  }
525 
526  if (print)
527  *cmflags |= MUTT_CM_PRINTING;
528 }
#define CH_MIME
Ignore MIME fields.
Definition: copy.h:60
#define MUTT_CM_WEED
Weed message/rfc822 attachment headers.
Definition: copy.h:40
#define MUTT_CM_PRINTING
Printing the message - display light.
Definition: copy.h:42
#define CH_WEED
Weed the headers?
Definition: copy.h:52
#define CH_TXTPLAIN
Generate text/plain MIME headers.
Definition: copy.h:62
#define MUTT_CM_DECODE
Decode the message body into text/plain.
Definition: copy.h:37
#define CH_REORDER
Re-order output of headers (specified by &#39;hdr_order&#39;)
Definition: copy.h:58
#define MUTT_CM_CHARCONV
Perform character set conversions.
Definition: copy.h:41
#define CH_DECODE
Do RFC2047 header decoding.
Definition: copy.h:53
bool C_Weed
Config: Filter headers when displaying/forwarding/printing/replying.
Definition: email_globals.c:40
+ Here is the caller graph for this function:

◆ pipe_msg()

static void pipe_msg ( struct Mailbox m,
struct Email e,
FILE *  fp,
bool  decode,
bool  print 
)
static

Pipe a message.

Parameters
mMailbox
eEmail to pipe
fpFile to write to
decodeIf true, decode the message
printIf true, message is for printing

Definition at line 538 of file commands.c.

539 {
541  CopyHeaderFlags chflags = CH_FROM;
542 
543  pipe_set_flags(decode, print, &cmflags, &chflags);
544 
545  if ((WithCrypto != 0) && decode && e->security & SEC_ENCRYPT)
546  {
548  return;
549  endwin();
550  }
551 
552  if (decode)
554 
555  mutt_copy_message(fp, m, e, cmflags, chflags, 0);
556 }
void mutt_parse_mime_message(struct Mailbox *m, struct Email *e)
Parse a MIME email.
Definition: mutt_parse.c:49
int mutt_copy_message(FILE *fp_out, struct Mailbox *m, struct Email *e, CopyMessageFlags cmflags, CopyHeaderFlags chflags, int wraplen)
Copy a message from a Mailbox.
Definition: copy.c:810
#define CH_FROM
Retain the "From " message separator?
Definition: copy.h:55
uint16_t CopyMessageFlags
Flags for mutt_copy_message(), e.g. MUTT_CM_NOHEADER.
Definition: copy.h:31
#define SEC_ENCRYPT
Email is encrypted.
Definition: ncrypt.h:122
#define MUTT_CM_NO_FLAGS
No flags are set.
Definition: copy.h:34
bool crypt_valid_passphrase(SecurityFlags flags)
Check that we have a usable passphrase, ask if not.
Definition: crypt.c:147
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/ncrypt.h pgplib.h, smime.h
Definition: email.h:39
uint32_t CopyHeaderFlags
Flags for mutt_copy_header(), e.g. CH_UPDATE.
Definition: copy.h:49
FILE * fp
pointer to the message data
Definition: mx.h:83
#define WithCrypto
Definition: ncrypt.h:160
static void pipe_set_flags(bool decode, bool print, CopyMessageFlags *cmflags, CopyHeaderFlags *chflags)
Generate flags for copy header/message.
Definition: commands.c:505
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pipe_message()

static int pipe_message ( struct Mailbox m,
struct EmailList *  el,
char *  cmd,
bool  decode,
bool  print,
bool  split,
const char *  sep 
)
static

Pipe message to a command.

Parameters
mMailbox
elList of Emails to pipe
cmdCommand to pipe to
decodeShould the message be decrypted
printTrue if this is a print job
splitShould a separator be sent between messages?
sepSeparator string
Return values
0Success
1Error

The following code is shared between printing and piping.

Definition at line 572 of file commands.c.

574 {
575  if (!m || !el)
576  return 1;
577 
578  struct EmailNode *en = STAILQ_FIRST(el);
579  if (!en)
580  return 1;
581 
582  int rc = 0;
583  pid_t pid;
584  FILE *fp_out = NULL;
585 
586  if (!STAILQ_NEXT(en, entries))
587  {
588  /* handle a single message */
590 
591  if ((WithCrypto != 0) && decode)
592  {
594  if ((en->email->security & SEC_ENCRYPT) &&
596  {
597  return 1;
598  }
599  }
600  mutt_endwin();
601 
602  pid = mutt_create_filter(cmd, &fp_out, NULL, NULL);
603  if (pid < 0)
604  {
605  mutt_perror(_("Can't create filter process"));
606  return 1;
607  }
608 
609  OptKeepQuiet = true;
610  pipe_msg(m, en->email, fp_out, decode, print);
611  mutt_file_fclose(&fp_out);
612  rc = mutt_wait_filter(pid);
613  OptKeepQuiet = false;
614  }
615  else
616  {
617  /* handle tagged messages */
618  if ((WithCrypto != 0) && decode)
619  {
620  STAILQ_FOREACH(en, el, entries)
621  {
624  if ((en->email->security & SEC_ENCRYPT) &&
626  {
627  return 1;
628  }
629  }
630  }
631 
632  if (split)
633  {
634  STAILQ_FOREACH(en, el, entries)
635  {
637  mutt_endwin();
638  pid = mutt_create_filter(cmd, &fp_out, NULL, NULL);
639  if (pid < 0)
640  {
641  mutt_perror(_("Can't create filter process"));
642  return 1;
643  }
644  OptKeepQuiet = true;
645  pipe_msg(m, en->email, fp_out, decode, print);
646  /* add the message separator */
647  if (sep)
648  fputs(sep, fp_out);
649  mutt_file_fclose(&fp_out);
650  if (mutt_wait_filter(pid) != 0)
651  rc = 1;
652  OptKeepQuiet = false;
653  }
654  }
655  else
656  {
657  mutt_endwin();
658  pid = mutt_create_filter(cmd, &fp_out, NULL, NULL);
659  if (pid < 0)
660  {
661  mutt_perror(_("Can't create filter process"));
662  return 1;
663  }
664  OptKeepQuiet = true;
665  STAILQ_FOREACH(en, el, entries)
666  {
668  pipe_msg(m, en->email, fp_out, decode, print);
669  /* add the message separator */
670  if (sep)
671  fputs(sep, fp_out);
672  }
673  mutt_file_fclose(&fp_out);
674  if (mutt_wait_filter(pid) != 0)
675  rc = 1;
676  OptKeepQuiet = false;
677  }
678  }
679 
680  if ((rc != 0) || C_WaitKey)
682  return rc;
683 }
pid_t mutt_create_filter(const char *s, FILE **fp_in, FILE **fp_out, FILE **fp_err)
Set up filter program.
Definition: filter.c:210
#define mutt_perror(...)
Definition: logging.h:85
void mutt_parse_mime_message(struct Mailbox *m, struct Email *e)
Parse a MIME email.
Definition: mutt_parse.c:49
#define _(a)
Definition: message.h:28
#define MUTT_MESSAGE_HOOK
message-hook: run before displaying a message
Definition: hook.h:52
#define SEC_ENCRYPT
Email is encrypted.
Definition: ncrypt.h:122
static void pipe_msg(struct Mailbox *m, struct Email *e, FILE *fp, bool decode, bool print)
Pipe a message.
Definition: commands.c:538
bool crypt_valid_passphrase(SecurityFlags flags)
Check that we have a usable passphrase, ask if not.
Definition: crypt.c:147
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:152
WHERE bool C_WaitKey
Config: Prompt to press a key after running external commands.
Definition: globals.h:269
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:544
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
#define STAILQ_NEXT(elm, field)
Definition: queue.h:398
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/ncrypt.h pgplib.h, smime.h
Definition: email.h:39
int mutt_any_key_to_continue(const char *s)
Prompt the user to &#39;press any key&#39; and wait.
Definition: curs_lib.c:577
struct Email * email
Email in the list.
Definition: email.h:116
List of Emails.
Definition: email.h:114
void mutt_message_hook(struct Mailbox *m, struct Email *e, HookFlags type)
Perform a message hook.
Definition: hook.c:573
int mutt_wait_filter(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:221
WHERE bool OptKeepQuiet
(pseudo) shut up the message and refresh functions while we are executing an external program...
Definition: options.h:37
#define STAILQ_FIRST(head)
Definition: queue.h:348
#define WithCrypto
Definition: ncrypt.h:160
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_pipe_message()

void mutt_pipe_message ( struct Mailbox m,
struct EmailList *  el 
)

Pipe a message.

Parameters
mMailbox
elList of Emails to pipe

Definition at line 690 of file commands.c.

691 {
692  if (!m || !el)
693  return;
694 
695  char buf[1024] = { 0 };
696 
697  if ((mutt_get_field(_("Pipe to command: "), buf, sizeof(buf), MUTT_CMD) != 0) ||
698  (buf[0] == '\0'))
699  {
700  return;
701  }
702 
703  mutt_expand_path(buf, sizeof(buf));
704  pipe_message(m, el, buf, C_PipeDecode, false, C_PipeSplit, C_PipeSep);
705 }
#define _(a)
Definition: message.h:28
char * C_PipeSep
Config: Separator to add between multiple piped messages.
Definition: commands.c:89
bool C_PipeDecode
Config: Decode the message when piping it.
Definition: commands.c:88
#define mutt_get_field(field, buf, buflen, complete)
Definition: curs_lib.h:91
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
Definition: muttlib.c:134
bool C_PipeSplit
Config: Run the pipe command on each message separately.
Definition: commands.c:90
#define MUTT_CMD
Do completion on previous word.
Definition: mutt.h:66
static int pipe_message(struct Mailbox *m, struct EmailList *el, char *cmd, bool decode, bool print, bool split, const char *sep)
Pipe message to a command.
Definition: commands.c:572
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_print_message()

void mutt_print_message ( struct Mailbox m,
struct EmailList *  el 
)

Print a message.

Parameters
mMailbox
elList of Emails to print

Definition at line 712 of file commands.c.

713 {
714  if (!m || !el)
715  return;
716 
717  if (C_Print && !C_PrintCommand)
718  {
719  mutt_message(_("No printing command has been defined"));
720  return;
721  }
722 
723  int msg_count = 0;
724  struct EmailNode *en = NULL;
725  STAILQ_FOREACH(en, el, entries)
726  {
727  msg_count++;
728  }
729 
730  if (query_quadoption(C_Print, (msg_count == 1) ?
731  _("Print message?") :
732  _("Print tagged messages?")) != MUTT_YES)
733  {
734  return;
735  }
736 
737  if (pipe_message(m, el, C_PrintCommand, C_PrintDecode, true, C_PrintSplit, "\f") == 0)
738  mutt_message(ngettext("Message printed", "Messages printed", msg_count));
739  else
740  {
741  mutt_message(ngettext("Message could not be printed",
742  "Messages could not be printed", msg_count));
743  }
744 }
WHERE unsigned char C_Print
Config: Confirm before printing a message.
Definition: globals.h:188
enum QuadOption query_quadoption(enum QuadOption opt, const char *prompt)
Ask the user a quad-question.
Definition: init.c:3340
#define mutt_message(...)
Definition: logging.h:83
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:39
bool C_PrintSplit
Config: Print multiple messages separately.
Definition: commands.c:92
#define _(a)
Definition: message.h:28
bool C_PrintDecode
Config: Decode message before printing it.
Definition: commands.c:91
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
WHERE char * C_PrintCommand
Config: External command to print a message.
Definition: globals.h:138
List of Emails.
Definition: email.h:114
static int pipe_message(struct Mailbox *m, struct EmailList *el, char *cmd, bool decode, bool print, bool split, const char *sep)
Pipe message to a command.
Definition: commands.c:572
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_select_sort()

int mutt_select_sort ( bool  reverse)

Ask the user for a sort method.

Parameters
reverseIf true make it a reverse sort
Return values
numSort type, see SortType

Definition at line 751 of file commands.c.

752 {
753  enum SortType method = C_Sort; /* save the current method in case of abort */
754  enum SortType new_sort = C_Sort;
755 
756  switch (mutt_multi_choice(reverse ?
757  /* L10N: The highlighted letters must match the "Sort" options */
758  _("Rev-Sort "
759  "(d)ate/(f)rm/(r)ecv/(s)ubj/t(o)/(t)hread/"
760  "(u)nsort/si(z)e/s(c)ore/s(p)am/(l)abel?") :
761  /* L10N: The highlighted letters must match the "Rev-Sort" options */
762  _("Sort "
763  "(d)ate/(f)rm/(r)ecv/(s)ubj/t(o)/(t)hread/"
764  "(u)nsort/si(z)e/s(c)ore/s(p)am/(l)abel?"),
765  /* L10N: These must match the highlighted letters from "Sort" and "Rev-Sort" */
766  _("dfrsotuzcpl")))
767  {
768  case -1: /* abort - don't resort */
769  return -1;
770 
771  case 1: /* (d)ate */
772  new_sort = SORT_DATE;
773  break;
774 
775  case 2: /* (f)rm */
776  new_sort = SORT_FROM;
777  break;
778 
779  case 3: /* (r)ecv */
780  new_sort = SORT_RECEIVED;
781  break;
782 
783  case 4: /* (s)ubj */
784  new_sort = SORT_SUBJECT;
785  break;
786 
787  case 5: /* t(o) */
788  new_sort = SORT_TO;
789  break;
790 
791  case 6: /* (t)hread */
792  new_sort = SORT_THREADS;
793  break;
794 
795  case 7: /* (u)nsort */
796  new_sort = SORT_ORDER;
797  break;
798 
799  case 8: /* si(z)e */
800  new_sort = SORT_SIZE;
801  break;
802 
803  case 9: /* s(c)ore */
804  new_sort = SORT_SCORE;
805  break;
806 
807  case 10: /* s(p)am */
808  new_sort = SORT_SPAM;
809  break;
810 
811  case 11: /* (l)abel */
812  new_sort = SORT_LABEL;
813  break;
814  }
815  if (reverse)
816  new_sort |= SORT_REVERSE;
817 
818  cs_str_native_set(Config, "sort", new_sort, NULL);
819  return (C_Sort != method) ? 0 : -1; /* no need to resort if it's the same */
820 }
SortType
Methods for sorting.
Definition: sort2.h:48
Sort by the email&#39;s From field.
Definition: sort2.h:54
#define _(a)
Definition: message.h:28
WHERE struct ConfigSet * Config
Wrapper around the user&#39;s config settings.
Definition: globals.h:41
Sort by the email&#39;s score.
Definition: sort2.h:59
Sort by the emails label.
Definition: sort2.h:69
Sort by the size of the email.
Definition: sort2.h:51
Sort by the order the messages appear in the mailbox.
Definition: sort2.h:55
WHERE short C_Sort
Config: Sort method for the index.
Definition: sort.h:58
int mutt_multi_choice(const char *prompt, const char *letters)
Offer the user a multiple choice question.
Definition: curs_lib.c:862
Sort by email threads.
Definition: sort2.h:56
Sort by the email&#39;s spam score.
Definition: sort2.h:64
Sort by the email&#39;s To field.
Definition: sort2.h:58
Sort by when the message were delivered locally.
Definition: sort2.h:57
Sort by the date the email was sent.
Definition: sort2.h:50
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:86
Sort by the email&#39;s subject.
Definition: sort2.h:53
int cs_str_native_set(const struct ConfigSet *cs, const char *name, intptr_t value, struct Buffer *err)
Natively set the value of a string config item.
Definition: set.c:772
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_shell_escape()

void mutt_shell_escape ( void  )

invoke a command in a subshell

Definition at line 825 of file commands.c.

826 {
827  char buf[1024];
828 
829  buf[0] = '\0';
830  if (mutt_get_field(_("Shell command: "), buf, sizeof(buf), MUTT_CMD) != 0)
831  return;
832 
833  if ((buf[0] == '\0') && C_Shell)
834  mutt_str_strfcpy(buf, C_Shell, sizeof(buf));
835  if (buf[0] == '\0')
836  return;
837 
839  mutt_endwin();
840  fflush(stdout);
841  int rc = mutt_system(buf);
842  if (rc == -1)
843  mutt_debug(LL_DEBUG1, "Error running \"%s\"", buf);
844 
845  if ((rc != 0) || C_WaitKey)
848 }
The "current" mailbox.
Definition: context.h:36
#define _(a)
Definition: message.h:28
WHERE char * C_Shell
Config: External command to run subshells in.
Definition: globals.h:141
#define mutt_get_field(field, buf, buflen, complete)
Definition: curs_lib.h:91
struct Mailbox * mailbox
Definition: context.h:50
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:95
#define MUTT_CMD
Do completion on previous word.
Definition: mutt.h:66
WHERE bool C_WaitKey
Config: Prompt to press a key after running external commands.
Definition: globals.h:269
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:544
int mutt_mailbox_check(struct Mailbox *m_cur, int force)
Check all all Mailboxes for new mail.
Definition: mutt_mailbox.c:127
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
#define MUTT_MAILBOX_CHECK_FORCE
Definition: mutt_mailbox.h:17
int mutt_any_key_to_continue(const char *s)
Prompt the user to &#39;press any key&#39; and wait.
Definition: curs_lib.c:577
Log at debug level 1.
Definition: logging.h:56
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:42
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
int mutt_system(const char *cmd)
Run an external command.
Definition: system.c:51
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_enter_command()

void mutt_enter_command ( void  )

enter a neomutt command

Definition at line 853 of file commands.c.

854 {
855  char buf[1024] = { 0 };
856 
857  /* if enter is pressed after : with no command, just return */
858  if ((mutt_get_field(":", buf, sizeof(buf), MUTT_COMMAND) != 0) || !buf[0])
859  return;
860 
861  struct Buffer err = mutt_buffer_make(256);
862  struct Buffer token = mutt_buffer_make(256);
863 
864  /* check if buf is a valid icommand, else fall back quietly to parse_rc_lines */
865  enum CommandResult rc = mutt_parse_icommand(buf, &err);
866  if (!mutt_buffer_is_empty(&err))
867  {
868  /* since errbuf could potentially contain printf() sequences in it,
869  * we must call mutt_error() in this fashion so that vsprintf()
870  * doesn't expect more arguments that we passed */
871  if (rc == MUTT_CMD_ERROR)
872  mutt_error("%s", err.data);
873  else
874  mutt_warning("%s", err.data);
875  }
876  else if (rc != MUTT_CMD_SUCCESS)
877  {
878  rc = mutt_parse_rc_line(buf, &token, &err);
879  if (!mutt_buffer_is_empty(&err))
880  {
881  if (rc == MUTT_CMD_SUCCESS) /* command succeeded with message */
882  mutt_message("%s", err.data);
883  else if (rc == MUTT_CMD_ERROR)
884  mutt_error("%s", err.data);
885  else if (rc == MUTT_CMD_WARNING)
886  mutt_warning("%s", err.data);
887  }
888  }
889  /* else successful command */
890 
891  mutt_buffer_dealloc(&token);
892  mutt_buffer_dealloc(&err);
893 }
#define mutt_warning(...)
Definition: logging.h:82
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:33
Error: Can&#39;t help the user.
Definition: mutt_commands.h:35
#define mutt_message(...)
Definition: logging.h:83
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
String manipulation buffer.
Definition: buffer.h:33
enum CommandResult mutt_parse_icommand(char *line, struct Buffer *err)
Parse an informational command.
Definition: icommands.c:75
#define mutt_get_field(field, buf, buflen, complete)
Definition: curs_lib.h:91
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:294
#define MUTT_COMMAND
Do command completion.
Definition: mutt.h:69
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:37
Warning: Help given to the user.
Definition: mutt_commands.h:36
#define mutt_error(...)
Definition: logging.h:84
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:252
enum CommandResult mutt_parse_rc_line(char *line, struct Buffer *token, struct Buffer *err)
Parse a line of user config.
Definition: init.c:3232
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_display_address()

void mutt_display_address ( struct Envelope env)

Display the address of a message.

Parameters
envEnvelope containing address

Definition at line 899 of file commands.c.

900 {
901  const char *pfx = NULL;
902  char buf[128];
903 
904  struct AddressList *al = mutt_get_address(env, &pfx);
905  if (!al)
906  return;
907 
908  /* Note: We don't convert IDNA to local representation this time.
909  * That is intentional, so the user has an opportunity to copy &
910  * paste the on-the-wire form of the address to other, IDN-unable
911  * software. */
912  buf[0] = '\0';
913  mutt_addrlist_write(buf, sizeof(buf), al, false);
914  mutt_message("%s: %s", pfx, buf);
915 }
#define mutt_message(...)
Definition: logging.h:83
struct AddressList * mutt_get_address(struct Envelope *env, const char **pfxp)
Get an Address from an Envelope.
Definition: alias.c:335
size_t mutt_addrlist_write(char *buf, size_t buflen, const struct AddressList *al, bool display)
Write an Address to a buffer.
Definition: address.c:1137
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_copy_flags()

static void set_copy_flags ( struct Email e,
bool  decode,
bool  decrypt,
CopyMessageFlags cmflags,
CopyHeaderFlags chflags 
)
static

Set the flags for a message copy.

Parameters
[in]eEmail
[in]decodeIf true, decode the message
[in]decryptIf true, decrypt the message
[out]cmflagsFlags, see CopyMessageFlags
[out]chflagsFlags, see CopyHeaderFlags

Definition at line 925 of file commands.c.

927 {
928  *cmflags = MUTT_CM_NO_FLAGS;
929  *chflags = CH_UPDATE_LEN;
930 
931  if ((WithCrypto != 0) && !decode && decrypt && (e->security & SEC_ENCRYPT))
932  {
934  {
935  *chflags = CH_NONEWLINE | CH_XMIT | CH_MIME;
936  *cmflags = MUTT_CM_DECODE_PGP;
937  }
938  else if (((WithCrypto & APPLICATION_PGP) != 0) &&
940  {
941  decode = 1;
942  }
943  else if (((WithCrypto & APPLICATION_SMIME) != 0) &&
945  {
946  *chflags = CH_NONEWLINE | CH_XMIT | CH_MIME;
947  *cmflags = MUTT_CM_DECODE_SMIME;
948  }
949  }
950 
951  if (decode)
952  {
953  *chflags = CH_XMIT | CH_MIME | CH_TXTPLAIN;
954  *cmflags = MUTT_CM_DECODE | MUTT_CM_CHARCONV;
955 
956  if (!decrypt) /* If decode doesn't kick in for decrypt, */
957  {
958  *chflags |= CH_DECODE; /* then decode RFC2047 headers, */
959 
960  if (C_Weed)
961  {
962  *chflags |= CH_WEED; /* and respect $weed. */
963  *cmflags |= MUTT_CM_WEED;
964  }
965  }
966  }
967 }
#define CH_MIME
Ignore MIME fields.
Definition: copy.h:60
struct Body * content
List of MIME parts.
Definition: email.h:90
#define MUTT_CM_WEED
Weed message/rfc822 attachment headers.
Definition: copy.h:40
#define SEC_ENCRYPT
Email is encrypted.
Definition: ncrypt.h:122
#define MUTT_CM_NO_FLAGS
No flags are set.
Definition: copy.h:34
SecurityFlags mutt_is_multipart_encrypted(struct Body *b)
Does the message have encrypted parts?
Definition: crypt.c:453
#define CH_WEED
Weed the headers?
Definition: copy.h:52
#define CH_TXTPLAIN
Generate text/plain MIME headers.
Definition: copy.h:62
SecurityFlags mutt_is_application_pgp(struct Body *m)
Does the message use PGP?
Definition: crypt.c:559
#define MUTT_CM_DECODE
Decode the message body into text/plain.
Definition: copy.h:37
#define MUTT_CM_CHARCONV
Perform character set conversions.
Definition: copy.h:41
#define CH_DECODE
Do RFC2047 header decoding.
Definition: copy.h:53
#define CH_XMIT
Transmitting this message? (Ignore Lines: and Content-Length:)
Definition: copy.h:54
#define CH_UPDATE_LEN
Update Lines: and Content-Length:
Definition: copy.h:61
SecurityFlags mutt_is_application_smime(struct Body *m)
Does the message use S/MIME?
Definition: crypt.c:618
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/ncrypt.h pgplib.h, smime.h
Definition: email.h:39
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: ncrypt.h:134
#define MUTT_CM_DECODE_SMIME
Used for decoding S/MIME messages.
Definition: copy.h:45
#define MUTT_CM_DECODE_PGP
Used for decoding PGP messages.
Definition: copy.h:44
#define WithCrypto
Definition: ncrypt.h:160
#define CH_NONEWLINE
Don&#39;t output terminating newline after the header.
Definition: copy.h:59
bool C_Weed
Config: Filter headers when displaying/forwarding/printing/replying.
Definition: email_globals.c:40
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: ncrypt.h:135
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_save_message_ctx()

int mutt_save_message_ctx ( struct Email e,
bool  delete_original,
bool  decode,
bool  decrypt,
struct Mailbox m 
)

Save a message to a given mailbox.

Parameters
eEmail
delete_originalIf true, delete the original
decodeIf true, decode the message
decryptIf true, decrypt the message
mMailbox to save to
Return values
0Success
-1Error

Definition at line 979 of file commands.c.

981 {
983  CopyHeaderFlags chflags = CH_NO_FLAGS;
984  int rc;
985 
986  set_copy_flags(e, decode, decrypt, &cmflags, &chflags);
987 
988  if (decode || decrypt)
990 
991  rc = mutt_append_message(m, Context->mailbox, e, cmflags, chflags);
992  if (rc != 0)
993  return rc;
994 
995  if (delete_original)
996  {
999  if (C_DeleteUntag)
1000  mutt_set_flag(Context->mailbox, e, MUTT_TAG, false);
1001  }
1002 
1003  return 0;
1004 }
The "current" mailbox.
Definition: context.h:36
#define mutt_set_flag(m, e, flag, bf)
Definition: protos.h:69
static void set_copy_flags(struct Email *e, bool decode, bool decrypt, CopyMessageFlags *cmflags, CopyHeaderFlags *chflags)
Set the flags for a message copy.
Definition: commands.c:925
void mutt_parse_mime_message(struct Mailbox *m, struct Email *e)
Parse a MIME email.
Definition: mutt_parse.c:49
Messages to be purged (bypass trash)
Definition: mutt.h:104
uint16_t CopyMessageFlags
Flags for mutt_copy_message(), e.g. MUTT_CM_NOHEADER.
Definition: copy.h:31
#define MUTT_CM_NO_FLAGS
No flags are set.
Definition: copy.h:34
struct Mailbox * mailbox
Definition: context.h:50
Messages to be deleted.
Definition: mutt.h:102
#define CH_NO_FLAGS
No flags are set.
Definition: copy.h:50
Tagged messages.
Definition: mutt.h:107
WHERE bool C_DeleteUntag
Config: Untag messages when they are marked for deletion.
Definition: globals.h:214
uint32_t CopyHeaderFlags
Flags for mutt_copy_header(), e.g. CH_UPDATE.
Definition: copy.h:49
int mutt_append_message(struct Mailbox *dest, struct Mailbox *src, struct Email *e, CopyMessageFlags cmflags, CopyHeaderFlags chflags)
Append a message.
Definition: copy.c:880
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_save_message()

int mutt_save_message ( struct Mailbox m,
struct EmailList *  el,
bool  delete_original,
bool  decode,
bool  decrypt 
)

Save an email.

Parameters
mMailbox
elList of Emails to save
delete_originalIf true, delete the original (save)
decodeIf true, decode the message
decryptIf true, decrypt the message
Return values
0Copy/save was successful
-1Error/abort

Definition at line 1016 of file commands.c.

1018 {
1019  if (!el || STAILQ_EMPTY(el))
1020  return -1;
1021 
1022  bool need_passphrase = false;
1023  int app = 0;
1024  int rc = -1;
1025  const char *prompt = NULL;
1026  struct stat st;
1027  struct EmailNode *en = STAILQ_FIRST(el);
1028  bool single = !STAILQ_NEXT(en, entries);
1029 
1030  struct Buffer *buf = mutt_buffer_pool_get();
1031 
1032  if (delete_original)
1033  {
1034  if (decode)
1035  prompt = single ? _("Decode-save to mailbox") : _("Decode-save tagged to mailbox");
1036  else if (decrypt)
1037  prompt = single ? _("Decrypt-save to mailbox") : _("Decrypt-save tagged to mailbox");
1038  else
1039  prompt = single ? _("Save to mailbox") : _("Save tagged to mailbox");
1040  }
1041  else
1042  {
1043  if (decode)
1044  prompt = single ? _("Decode-copy to mailbox") : _("Decode-copy tagged to mailbox");
1045  else if (decrypt)
1046  prompt = single ? _("Decrypt-copy to mailbox") : _("Decrypt-copy tagged to mailbox");
1047  else
1048  prompt = single ? _("Copy to mailbox") : _("Copy tagged to mailbox");
1049  }
1050 
1051  if (WithCrypto)
1052  {
1053  need_passphrase = (en->email->security & SEC_ENCRYPT);
1054  app = en->email->security;
1055  }
1057  mutt_default_save(buf->data, buf->dsize, en->email);
1058  mutt_buffer_fix_dptr(buf);
1059 
1061  if (mutt_buffer_enter_fname(prompt, buf, 0) == -1)
1062  goto cleanup;
1063 
1064  size_t pathlen = mutt_buffer_len(buf);
1065  if (pathlen == 0)
1066  goto cleanup;
1067 
1068  /* Trim any trailing '/' */
1069  if (buf->data[pathlen - 1] == '/')
1070  buf->data[pathlen - 1] = '\0';
1071 
1072  /* This is an undocumented feature of ELM pointed out to me by Felix von
1073  * Leitner <leitner@prz.fu-berlin.de> */
1074  if (mutt_str_strcmp(mutt_b2s(buf), ".") == 0)
1076  else
1078 
1080 
1081  /* check to make sure that this file is really the one the user wants */
1082  if (mutt_save_confirm(mutt_b2s(buf), &st) != 0)
1083  goto cleanup;
1084 
1085  if ((WithCrypto != 0) && need_passphrase && (decode || decrypt) &&
1086  !crypt_valid_passphrase(app))
1087  {
1088  goto cleanup;
1089  }
1090 
1091  mutt_message(_("Copying to %s..."), mutt_b2s(buf));
1092 
1093 #ifdef USE_IMAP
1094  if ((m->magic == MUTT_IMAP) && !(decode || decrypt) &&
1095  (imap_path_probe(mutt_b2s(buf), NULL) == MUTT_IMAP))
1096  {
1097  switch (imap_copy_messages(m, el, mutt_b2s(buf), delete_original))
1098  {
1099  /* success */
1100  case 0:
1101  mutt_clear_error();
1102  rc = 0;
1103  goto cleanup;
1104  /* non-fatal error: continue to fetch/append */
1105  case 1:
1106  break;
1107  /* fatal error, abort */
1108  case -1:
1109  goto cleanup;
1110  }
1111  }
1112 #endif
1113 
1114  struct Mailbox *m_save = mx_path_resolve(mutt_b2s(buf));
1115  struct Context *ctx_save = mx_mbox_open(m_save, MUTT_NEWFOLDER);
1116  if (!ctx_save)
1117  {
1118  mailbox_free(&m_save);
1119  goto cleanup;
1120  }
1121  bool old_append = m_save->append;
1122  m_save->append = true;
1123 
1124 #ifdef USE_COMPRESSED
1125  /* If we're saving to a compressed mailbox, the stats won't be updated
1126  * until the next open. Until then, improvise. */
1127  struct Mailbox *m_comp = NULL;
1128  if (ctx_save->mailbox->compress_info)
1129  {
1130  m_comp = mailbox_find(ctx_save->mailbox->realpath);
1131  }
1132  /* We probably haven't been opened yet */
1133  if (m_comp && (m_comp->msg_count == 0))
1134  m_comp = NULL;
1135 #endif
1136  if (single)
1137  {
1138  if (mutt_save_message_ctx(en->email, delete_original, decode, decrypt,
1139  ctx_save->mailbox) != 0)
1140  {
1141  m_save->append = old_append;
1142  mx_mbox_close(&ctx_save);
1143  goto cleanup;
1144  }
1145 #ifdef USE_COMPRESSED
1146  if (m_comp)
1147  {
1148  m_comp->msg_count++;
1149  if (!en->email->read)
1150  {
1151  m_comp->msg_unread++;
1152  if (!en->email->old)
1153  m_comp->msg_new++;
1154  }
1155  if (en->email->flagged)
1156  m_comp->msg_flagged++;
1157  }
1158 #endif
1159  }
1160  else
1161  {
1162  rc = 0;
1163 
1164 #ifdef USE_NOTMUCH
1165  if (m->magic == MUTT_NOTMUCH)
1166  nm_db_longrun_init(m, true);
1167 #endif
1168  STAILQ_FOREACH(en, el, entries)
1169  {
1171  rc = mutt_save_message_ctx(en->email, delete_original, decode, decrypt,
1172  ctx_save->mailbox);
1173  if (rc != 0)
1174  break;
1175 #ifdef USE_COMPRESSED
1176  if (m_comp)
1177  {
1178  struct Email *e2 = en->email;
1179  m_comp->msg_count++;
1180  if (!e2->read)
1181  {
1182  m_comp->msg_unread++;
1183  if (!e2->old)
1184  m_comp->msg_new++;
1185  }
1186  if (e2->flagged)
1187  m_comp->msg_flagged++;
1188  }
1189 #endif
1190  }
1191 #ifdef USE_NOTMUCH
1192  if (m->magic == MUTT_NOTMUCH)
1193  nm_db_longrun_done(m);
1194 #endif
1195  if (rc != 0)
1196  {
1197  m_save->append = old_append;
1198  mx_mbox_close(&ctx_save);
1199  goto cleanup;
1200  }
1201  }
1202 
1203  const bool need_mailbox_cleanup = ((ctx_save->mailbox->magic == MUTT_MBOX) ||
1204  (ctx_save->mailbox->magic == MUTT_MMDF));
1205 
1206  m_save->append = old_append;
1207  mx_mbox_close(&ctx_save);
1208 
1209  if (need_mailbox_cleanup)
1210  mutt_mailbox_cleanup(mutt_b2s(buf), &st);
1211 
1212  mutt_clear_error();
1213  rc = 0;
1214 
1215 cleanup:
1217  return rc;
1218 }
int mutt_save_message_ctx(struct Email *e, bool delete_original, bool decode, bool decrypt, struct Mailbox *m)
Save a message to a given mailbox.
Definition: commands.c:979
The "current" mailbox.
Definition: context.h:36
int msg_count
Total number of messages.
Definition: mailbox.h:102
The envelope/body of an email.
Definition: email.h:37
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:100
enum MailboxType imap_path_probe(const char *path, const struct stat *st)
Is this an IMAP Mailbox? - Implements MxOps::path_probe()
Definition: imap.c:2430
int msg_unread
Number of unread messages.
Definition: mailbox.h:103
int mx_mbox_close(struct Context **ptr)
Save changes and close mailbox.
Definition: mx.c:561
void mutt_mailbox_cleanup(const char *path, struct stat *st)
Restore the timestamp of a mailbox.
Definition: mutt_mailbox.c:353
#define mutt_message(...)
Definition: logging.h:83
int msg_flagged
Number of flagged messages.
Definition: mailbox.h:104
struct Mailbox * mailbox_find(const char *path)
Find the mailbox with a given path.
Definition: mailbox.c:79
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:95
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:111
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
struct Context * mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags)
Open a mailbox and parse it.
Definition: mx.c:253
#define MUTT_MESSAGE_HOOK
message-hook: run before displaying a message
Definition: hook.h:52
#define SEC_ENCRYPT
Email is encrypted.
Definition: ncrypt.h:122
void mutt_default_save(char *path, size_t pathlen, struct Email *e)
Find the default save path for an email.
Definition: hook.c:656
void mutt_buffer_pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using &#39;~&#39; or &#39;=&#39;.
Definition: muttlib.c:704
int mutt_save_confirm(const char *s, struct stat *st)
Ask the user to save.
Definition: muttlib.c:1449
bool crypt_valid_passphrase(SecurityFlags flags)
Check that we have a usable passphrase, ask if not.
Definition: crypt.c:147
size_t dsize
Length of data.
Definition: buffer.h:37
bool read
Email is read.
Definition: email.h:51
struct Mailbox * mailbox
Definition: context.h:50
bool old
Email is seen, but unread.
Definition: email.h:50
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition: mailbox.c:55
enum MailboxType magic
Mailbox type.
Definition: mailbox.h:116
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:115
void mutt_buffer_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
Definition: buffer.c:181
#define mutt_b2s(buf)
Definition: buffer.h:41
void nm_db_longrun_done(struct Mailbox *m)
Finish a long transaction.
Definition: nm_db.c:304
size_t mutt_buffer_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:356
A mailbox.
Definition: mailbox.h:92
char * data
Pointer to data.
Definition: buffer.h:35
&#39;mmdf&#39; Mailbox type
Definition: mailbox.h:48
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
bool append
Mailbox is opened in append mode.
Definition: mailbox.h:124
int imap_copy_messages(struct Mailbox *m, struct EmailList *el, const char *dest, bool delete_original)
Server COPY messages to another folder.
Definition: message.c:1583
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
#define STAILQ_NEXT(elm, field)
Definition: queue.h:398
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/ncrypt.h pgplib.h, smime.h
Definition: email.h:39
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
&#39;Notmuch&#39; (virtual) Mailbox type
Definition: mailbox.h:53
&#39;mbox&#39; Mailbox type
Definition: mailbox.h:47
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:343
bool flagged
Marked important?
Definition: email.h:43
int msg_new
Number of new messages.
Definition: mailbox.h:106
struct Email * email
Email in the list.
Definition: email.h:116
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:135
struct Mailbox * mx_path_resolve(const char *path)
XXX.
Definition: mx.c:1552
#define STAILQ_EMPTY(head)
Definition: queue.h:346
List of Emails.
Definition: email.h:114
void nm_db_longrun_init(struct Mailbox *m, bool writable)
Start a long transaction.
Definition: nm_db.c:289
void mutt_message_hook(struct Mailbox *m, struct Email *e, HookFlags type)
Perform a message hook.
Definition: hook.c:573
#define MUTT_NEWFOLDER
Create a new folder - same as MUTT_APPEND,.
Definition: mx.h:55
&#39;IMAP&#39; Mailbox type
Definition: mailbox.h:52
#define STAILQ_FIRST(head)
Definition: queue.h:348
#define WithCrypto
Definition: ncrypt.h:160
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
#define mutt_buffer_enter_fname(prompt, fname, mailbox)
Definition: curs_lib.h:87
static char LastSaveFolder[PATH_MAX]
The folder the user last saved to.
Definition: commands.c:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_edit_content_type()

bool mutt_edit_content_type ( struct Email e,
struct Body b,
FILE *  fp 
)

Edit the content type of an attachment.

Parameters
eEmail
bAttachment
fpFile handle to the attachment
Return values
booltrue if a structural change is made

recvattach requires the return code to know when to regenerate the actx.

Definition at line 1229 of file commands.c.

1230 {
1231  char buf[1024];
1232  char obuf[1024];
1233  char tmp[256];
1234  char charset[256];
1235 
1236  bool charset_changed = false;
1237  bool type_changed = false;
1238  bool structure_changed = false;
1239 
1240  char *cp = mutt_param_get(&b->parameter, "charset");
1241  mutt_str_strfcpy(charset, cp, sizeof(charset));
1242 
1243  snprintf(buf, sizeof(buf), "%s/%s", TYPE(b), b->subtype);
1244  mutt_str_strfcpy(obuf, buf, sizeof(obuf));
1245  if (!TAILQ_EMPTY(&b->parameter))
1246  {
1247  size_t l = strlen(buf);
1248  struct Parameter *np = NULL;
1249  TAILQ_FOREACH(np, &b->parameter, entries)
1250  {
1251  mutt_addr_cat(tmp, sizeof(tmp), np->value, MimeSpecials);
1252  l += snprintf(buf + l, sizeof(buf) - l, "; %s=%s", np->attribute, tmp);
1253  if (l >= sizeof(buf))
1254  {
1255  // L10N: e.g. "text/plain; charset=UTF-8; ..."
1256  mutt_error(_("Content type is too long"));
1257  return false;
1258  }
1259  }
1260  }
1261 
1262  if ((mutt_get_field("Content-Type: ", buf, sizeof(buf), 0) != 0) || (buf[0] == '\0'))
1263  return false;
1264 
1265  /* clean up previous junk */
1267  FREE(&b->subtype);
1268 
1269  mutt_parse_content_type(buf, b);
1270 
1271  snprintf(tmp, sizeof(tmp), "%s/%s", TYPE(b), NONULL(b->subtype));
1272  type_changed = (mutt_str_strcasecmp(tmp, obuf) != 0);
1273  charset_changed =
1274  (mutt_str_strcasecmp(charset, mutt_param_get(&b->parameter, "charset")) != 0);
1275 
1276  /* if in send mode, check for conversion - current setting is default. */
1277 
1278  if (!e && (b->type == TYPE_TEXT) && charset_changed)
1279  {
1280  snprintf(tmp, sizeof(tmp), _("Convert to %s upon sending?"),
1281  mutt_param_get(&b->parameter, "charset"));
1282  int ans = mutt_yesorno(tmp, b->noconv ? MUTT_NO : MUTT_YES);
1283  if (ans != MUTT_ABORT)
1284  b->noconv = (ans == MUTT_NO);
1285  }
1286 
1287  /* inform the user */
1288 
1289  snprintf(tmp, sizeof(tmp), "%s/%s", TYPE(b), NONULL(b->subtype));
1290  if (type_changed)
1291  mutt_message(_("Content-Type changed to %s"), tmp);
1292  if ((b->type == TYPE_TEXT) && charset_changed)
1293  {
1294  if (type_changed)
1295  mutt_sleep(1);
1296  mutt_message(b->noconv ? _("Character set changed to %s; not converting") :
1297  _("Character set changed to %s; converting"),
1298  mutt_param_get(&b->parameter, "charset"));
1299  }
1300 
1301  b->force_charset |= charset_changed;
1302 
1303  if (!is_multipart(b) && b->parts)
1304  {
1305  structure_changed = true;
1306  mutt_body_free(&b->parts);
1307  }
1308  if (!mutt_is_message_type(b->type, b->subtype) && b->email)
1309  {
1310  structure_changed = true;
1311  b->email->content = NULL;
1312  email_free(&b->email);
1313  }
1314 
1315  if (fp && !b->parts && (is_multipart(b) || mutt_is_message_type(b->type, b->subtype)))
1316  {
1317  structure_changed = true;
1318  mutt_parse_part(fp, b);
1319  }
1320 
1321  if ((WithCrypto != 0) && e)
1322  {
1323  if (e->content == b)
1324  e->security = SEC_NO_FLAGS;
1325 
1326  e->security |= crypt_query(b);
1327  }
1328 
1329  return structure_changed;
1330 }
char * attribute
Parameter name.
Definition: parameter.h:34
#define NONULL(x)
Definition: string2.h:37
bool mutt_is_message_type(int type, const char *subtype)
Determine if a mime type matches a message or not.
Definition: parse.c:1389
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:719
#define is_multipart(body)
Definition: mime.h:77
User aborted the question (with Ctrl-G)
Definition: quad.h:37
#define mutt_message(...)
Definition: logging.h:83
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:39
#define SEC_NO_FLAGS
No flags are set.
Definition: ncrypt.h:121
struct Body * content
List of MIME parts.
Definition: email.h:90
bool noconv
Don&#39;t do character set conversion.
Definition: body.h:73
#define _(a)
Definition: message.h:28
#define mutt_get_field(field, buf, buflen, complete)
Definition: curs_lib.h:91
void mutt_sleep(short s)
Sleep for a while.
Definition: muttlib.c:1546
enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def)
Ask the user a Yes/No question.
Definition: curs_lib.c:375
bool force_charset
Send mode: don&#39;t adjust the character set when in send-mode.
Definition: body.h:74
void mutt_param_free(struct ParameterList *pl)
Free a ParameterList.
Definition: parameter.c:61
char * subtype
content-type subtype
Definition: body.h:37
User answered &#39;No&#39;, or assume &#39;No&#39;.
Definition: quad.h:38
Type: &#39;text/*&#39;.
Definition: mime.h:38
const char MimeSpecials[]
Characters that need special treatment in MIME.
Definition: mime.c:67
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:54
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/ncrypt.h pgplib.h, smime.h
Definition: email.h:39
unsigned int type
content-type primary type
Definition: body.h:65
#define TYPE(body)
Definition: mime.h:83
void mutt_parse_content_type(const char *s, struct Body *ct)
Parse a content type.
Definition: parse.c:454
void mutt_parse_part(FILE *fp, struct Body *b)
Parse a MIME part.
Definition: parse.c:1404
char * value
Parameter value.
Definition: parameter.h:35
#define mutt_error(...)
Definition: logging.h:84
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
Attribute associated with a MIME part.
Definition: parameter.h:32
#define FREE(x)
Definition: memory.h:40
char * mutt_param_get(const struct ParameterList *pl, const char *s)
Find a matching Parameter.
Definition: parameter.c:84
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:57
#define TAILQ_EMPTY(head)
Definition: queue.h:715
void email_free(struct Email **ptr)
Free an Email.
Definition: email.c:41
struct ParameterList parameter
parameters of the content-type
Definition: body.h:39
struct Email * email
header information for message/rfc822
Definition: body.h:55
#define WithCrypto
Definition: ncrypt.h:160
SecurityFlags crypt_query(struct Body *m)
Check out the type of encryption used.
Definition: crypt.c:694
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.
Definition: address.c:671
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ check_traditional_pgp()

static bool check_traditional_pgp ( struct Email e,
MuttRedrawFlags redraw 
)
static

Check for an inline PGP content.

Parameters
[in]eEmail to check
[out]redrawFlags if the screen needs redrawing, see MuttRedrawFlags
Return values
trueIf message contains inline PGP content

Definition at line 1338 of file commands.c.

1339 {
1340  bool rc = false;
1341 
1343 
1345  struct Message *msg = mx_msg_open(Context->mailbox, e->msgno);
1346  if (!msg)
1347  return 0;
1348  if (crypt_pgp_check_traditional(msg->fp, e->content, false))
1349  {
1350  e->security = crypt_query(e->content);
1351  *redraw |= REDRAW_FULL;
1352  rc = true;
1353  }
1354 
1356  mx_msg_close(Context->mailbox, &msg);
1357  return rc;
1358 }
The "current" mailbox.
Definition: context.h:36
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:47
struct Body * content
List of MIME parts.
Definition: email.h:90
void mutt_parse_mime_message(struct Mailbox *m, struct Email *e)
Parse a MIME email.
Definition: mutt_parse.c:49
#define PGP_TRADITIONAL_CHECKED
Email has a traditional (inline) signature.
Definition: ncrypt.h:136
int mx_msg_close(struct Mailbox *m, struct Message **msg)
Close a message.
Definition: mx.c:1101
struct Mailbox * mailbox
Definition: context.h:50
A local copy of an email.
Definition: mx.h:81
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/ncrypt.h pgplib.h, smime.h
Definition: email.h:39
int crypt_pgp_check_traditional(FILE *fp, struct Body *b, bool just_one)
Wrapper for CryptModuleSpecs::pgp_check_traditional()
Definition: cryptglue.c:274
FILE * fp
pointer to the message data
Definition: mx.h:83
SecurityFlags crypt_query(struct Body *m)
Check out the type of encryption used.
Definition: crypt.c:694
struct Message * mx_msg_open(struct Mailbox *m, int msgno)
return a stream pointer for a message
Definition: mx.c:1053
int msgno
Number displayed to the user.
Definition: email.h:86
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_check_traditional_pgp()

bool mutt_check_traditional_pgp ( struct EmailList *  el,
MuttRedrawFlags redraw 
)

Check if a message has inline PGP content.

Parameters
[in]elList of Emails to check
[out]redrawFlags if the screen needs redrawing, see MuttRedrawFlags
Return values
trueIf message contains inline PGP content

Definition at line 1366 of file commands.c.

1367 {
1368  bool rc = false;
1369  struct EmailNode *en = NULL;
1370  STAILQ_FOREACH(en, el, entries)
1371  {
1372  if (!(en->email->security & PGP_TRADITIONAL_CHECKED))
1373  rc = check_traditional_pgp(en->email, redraw) || rc;
1374  }
1375 
1376  return rc;
1377 }
#define PGP_TRADITIONAL_CHECKED
Email has a traditional (inline) signature.
Definition: ncrypt.h:136
static bool check_traditional_pgp(struct Email *e, MuttRedrawFlags *redraw)
Check for an inline PGP content.
Definition: commands.c:1338
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/ncrypt.h pgplib.h, smime.h
Definition: email.h:39
struct Email * email
Email in the list.
Definition: email.h:116
List of Emails.
Definition: email.h:114
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_check_stats()

void mutt_check_stats ( void  )

Forcibly update mailbox stats.

Definition at line 1382 of file commands.c.

1383 {
1385 }
The "current" mailbox.
Definition: context.h:36
struct Mailbox * mailbox
Definition: context.h:50
int mutt_mailbox_check(struct Mailbox *m_cur, int force)
Check all all Mailboxes for new mail.
Definition: mutt_mailbox.c:127
#define MUTT_MAILBOX_CHECK_FORCE
Definition: mutt_mailbox.h:17
#define MUTT_MAILBOX_CHECK_FORCE_STATS
Definition: mutt_mailbox.h:18
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ C_CryptVerifySig

unsigned char C_CryptVerifySig

Config: Verify PGP or SMIME signatures.

Definition at line 86 of file commands.c.

◆ C_DisplayFilter

char* C_DisplayFilter

Config: External command to pre-process an email before display.

Definition at line 87 of file commands.c.

◆ C_PipeDecode

bool C_PipeDecode

Config: Decode the message when piping it.

Definition at line 88 of file commands.c.

◆ C_PipeSep

char* C_PipeSep

Config: Separator to add between multiple piped messages.

Definition at line 89 of file commands.c.

◆ C_PipeSplit

bool C_PipeSplit

Config: Run the pipe command on each message separately.

Definition at line 90 of file commands.c.

◆ C_PrintDecode

bool C_PrintDecode

Config: Decode message before printing it.

Definition at line 91 of file commands.c.

◆ C_PrintSplit

bool C_PrintSplit

Config: Print multiple messages separately.

Definition at line 92 of file commands.c.

◆ C_PromptAfter

bool C_PromptAfter

Config: Pause after running an external pager.

Definition at line 93 of file commands.c.

◆ ExtPagerProgress

const char* ExtPagerProgress = "all"
static

Definition at line 95 of file commands.c.

◆ LastSaveFolder

char LastSaveFolder[PATH_MAX] = ""
static

The folder the user last saved to.

Used by ci_save_message()

Definition at line 98 of file commands.c.