NeoMutt  2021-10-29-220-g2b1eec
Teaching an old dog new tricks
DOXYGEN
copy.h File Reference

Duplicate the structure of an entire email. More...

#include "config.h"
#include <stdint.h>
#include <stdio.h>
+ Include dependency graph for copy.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MUTT_CM_NO_FLAGS   0
 No flags are set. More...
 
#define MUTT_CM_NOHEADER   (1 << 0)
 Don't copy the message header. More...
 
#define MUTT_CM_PREFIX   (1 << 1)
 Quote the header and body. More...
 
#define MUTT_CM_DECODE   (1 << 2)
 Decode the message body into text/plain. More...
 
#define MUTT_CM_DISPLAY   (1 << 3)
 Output is displayed to the user. More...
 
#define MUTT_CM_UPDATE   (1 << 4)
 Update structs on sync. More...
 
#define MUTT_CM_WEED   (1 << 5)
 Weed message/rfc822 attachment headers. More...
 
#define MUTT_CM_CHARCONV   (1 << 6)
 Perform character set conversions. More...
 
#define MUTT_CM_PRINTING   (1 << 7)
 Printing the message - display light. More...
 
#define MUTT_CM_REPLYING   (1 << 8)
 Replying the message. More...
 
#define MUTT_CM_DECODE_PGP   (1 << 9)
 Used for decoding PGP messages. More...
 
#define MUTT_CM_DECODE_SMIME   (1 << 10)
 Used for decoding S/MIME messages. More...
 
#define MUTT_CM_VERIFY   (1 << 11)
 Do signature verification. More...
 
#define MUTT_CM_DECODE_CRYPT   (MUTT_CM_DECODE_PGP | MUTT_CM_DECODE_SMIME)
 
#define CH_NO_FLAGS   0
 No flags are set. More...
 
#define CH_UPDATE   (1 << 0)
 Update the status and x-status fields? More...
 
#define CH_WEED   (1 << 1)
 Weed the headers? More...
 
#define CH_DECODE   (1 << 2)
 Do RFC2047 header decoding. More...
 
#define CH_XMIT   (1 << 3)
 Transmitting this message? (Ignore Lines: and Content-Length:) More...
 
#define CH_FROM   (1 << 4)
 Retain the "From " message separator? More...
 
#define CH_PREFIX   (1 << 5)
 Quote header using $indent_string string? More...
 
#define CH_NOSTATUS   (1 << 6)
 Suppress the status and x-status fields. More...
 
#define CH_REORDER   (1 << 7)
 Re-order output of headers (specified by 'hdr_order') More...
 
#define CH_NONEWLINE   (1 << 8)
 Don't output terminating newline after the header. More...
 
#define CH_MIME   (1 << 9)
 Ignore MIME fields. More...
 
#define CH_UPDATE_LEN   (1 << 10)
 Update Lines: and Content-Length: More...
 
#define CH_TXTPLAIN   (1 << 11)
 Generate text/plain MIME headers. More...
 
#define CH_NOLEN   (1 << 12)
 Don't write Content-Length: and Lines: More...
 
#define CH_WEED_DELIVERED   (1 << 13)
 Weed eventual Delivered-To headers. More...
 
#define CH_FORCE_FROM   (1 << 14)
 Give CH_FROM precedence over CH_WEED? More...
 
#define CH_NOQFROM   (1 << 15)
 Ignore ">From " line. More...
 
#define CH_UPDATE_IRT   (1 << 16)
 Update In-Reply-To: More...
 
#define CH_UPDATE_REFS   (1 << 17)
 Update References: More...
 
#define CH_DISPLAY   (1 << 18)
 Display result to user. More...
 
#define CH_UPDATE_LABEL   (1 << 19)
 Update X-Label: from email->env->x_label? More...
 
#define CH_UPDATE_SUBJECT   (1 << 20)
 Update Subject: protected header update. More...
 
#define CH_VIRTUAL   (1 << 21)
 Write virtual header lines too. More...
 

Typedefs

typedef uint16_t CopyMessageFlags
 Flags for mutt_copy_message(), e.g. MUTT_CM_NOHEADER. More...
 
typedef uint32_t CopyHeaderFlags
 Flags for mutt_copy_header(), e.g. CH_UPDATE. More...
 

Functions

int mutt_copy_hdr (FILE *fp_in, FILE *fp_out, LOFF_T off_start, LOFF_T off_end, CopyHeaderFlags chflags, const char *prefix, int wraplen)
 Copy header from one file to another. More...
 
int mutt_copy_header (FILE *fp_in, struct Email *e, FILE *fp_out, CopyHeaderFlags chflags, const char *prefix, int wraplen)
 Copy Email header. More...
 
int mutt_copy_message_fp (FILE *fp_out, FILE *fp_in, struct Email *e, CopyMessageFlags cmflags, CopyHeaderFlags chflags, int wraplen)
 Make a copy of a message from a FILE pointer. More...
 
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. More...
 
int mutt_append_message (struct Mailbox *m_dst, struct Mailbox *m_src, struct Email *e, struct Message *msg, CopyMessageFlags cmflags, CopyHeaderFlags chflags)
 Append a message. More...
 

Detailed Description

Duplicate the structure of an entire email.

Authors
  • Michael R. Elkins

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 copy.h.

Macro Definition Documentation

◆ MUTT_CM_NO_FLAGS

#define MUTT_CM_NO_FLAGS   0

No flags are set.

Definition at line 35 of file copy.h.

◆ MUTT_CM_NOHEADER

#define MUTT_CM_NOHEADER   (1 << 0)

Don't copy the message header.

Definition at line 36 of file copy.h.

◆ MUTT_CM_PREFIX

#define MUTT_CM_PREFIX   (1 << 1)

Quote the header and body.

Definition at line 37 of file copy.h.

◆ MUTT_CM_DECODE

#define MUTT_CM_DECODE   (1 << 2)

Decode the message body into text/plain.

Definition at line 38 of file copy.h.

◆ MUTT_CM_DISPLAY

#define MUTT_CM_DISPLAY   (1 << 3)

Output is displayed to the user.

Definition at line 39 of file copy.h.

◆ MUTT_CM_UPDATE

#define MUTT_CM_UPDATE   (1 << 4)

Update structs on sync.

Definition at line 40 of file copy.h.

◆ MUTT_CM_WEED

#define MUTT_CM_WEED   (1 << 5)

Weed message/rfc822 attachment headers.

Definition at line 41 of file copy.h.

◆ MUTT_CM_CHARCONV

#define MUTT_CM_CHARCONV   (1 << 6)

Perform character set conversions.

Definition at line 42 of file copy.h.

◆ MUTT_CM_PRINTING

#define MUTT_CM_PRINTING   (1 << 7)

Printing the message - display light.

Definition at line 43 of file copy.h.

◆ MUTT_CM_REPLYING

#define MUTT_CM_REPLYING   (1 << 8)

Replying the message.

Definition at line 44 of file copy.h.

◆ MUTT_CM_DECODE_PGP

#define MUTT_CM_DECODE_PGP   (1 << 9)

Used for decoding PGP messages.

Definition at line 45 of file copy.h.

◆ MUTT_CM_DECODE_SMIME

#define MUTT_CM_DECODE_SMIME   (1 << 10)

Used for decoding S/MIME messages.

Definition at line 46 of file copy.h.

◆ MUTT_CM_VERIFY

#define MUTT_CM_VERIFY   (1 << 11)

Do signature verification.

Definition at line 47 of file copy.h.

◆ MUTT_CM_DECODE_CRYPT

#define MUTT_CM_DECODE_CRYPT   (MUTT_CM_DECODE_PGP | MUTT_CM_DECODE_SMIME)

Definition at line 48 of file copy.h.

◆ CH_NO_FLAGS

#define CH_NO_FLAGS   0

No flags are set.

Definition at line 51 of file copy.h.

◆ CH_UPDATE

#define CH_UPDATE   (1 << 0)

Update the status and x-status fields?

Definition at line 52 of file copy.h.

◆ CH_WEED

#define CH_WEED   (1 << 1)

Weed the headers?

Definition at line 53 of file copy.h.

◆ CH_DECODE

#define CH_DECODE   (1 << 2)

Do RFC2047 header decoding.

Definition at line 54 of file copy.h.

◆ CH_XMIT

#define CH_XMIT   (1 << 3)

Transmitting this message? (Ignore Lines: and Content-Length:)

Definition at line 55 of file copy.h.

◆ CH_FROM

#define CH_FROM   (1 << 4)

Retain the "From " message separator?

Definition at line 56 of file copy.h.

◆ CH_PREFIX

#define CH_PREFIX   (1 << 5)

Quote header using $indent_string string?

Definition at line 57 of file copy.h.

◆ CH_NOSTATUS

#define CH_NOSTATUS   (1 << 6)

Suppress the status and x-status fields.

Definition at line 58 of file copy.h.

◆ CH_REORDER

#define CH_REORDER   (1 << 7)

Re-order output of headers (specified by 'hdr_order')

Definition at line 59 of file copy.h.

◆ CH_NONEWLINE

#define CH_NONEWLINE   (1 << 8)

Don't output terminating newline after the header.

Definition at line 60 of file copy.h.

◆ CH_MIME

#define CH_MIME   (1 << 9)

Ignore MIME fields.

Definition at line 61 of file copy.h.

◆ CH_UPDATE_LEN

#define CH_UPDATE_LEN   (1 << 10)

Update Lines: and Content-Length:

Definition at line 62 of file copy.h.

◆ CH_TXTPLAIN

#define CH_TXTPLAIN   (1 << 11)

Generate text/plain MIME headers.

Definition at line 63 of file copy.h.

◆ CH_NOLEN

#define CH_NOLEN   (1 << 12)

Don't write Content-Length: and Lines:

Definition at line 64 of file copy.h.

◆ CH_WEED_DELIVERED

#define CH_WEED_DELIVERED   (1 << 13)

Weed eventual Delivered-To headers.

Definition at line 65 of file copy.h.

◆ CH_FORCE_FROM

#define CH_FORCE_FROM   (1 << 14)

Give CH_FROM precedence over CH_WEED?

Definition at line 66 of file copy.h.

◆ CH_NOQFROM

#define CH_NOQFROM   (1 << 15)

Ignore ">From " line.

Definition at line 67 of file copy.h.

◆ CH_UPDATE_IRT

#define CH_UPDATE_IRT   (1 << 16)

Update In-Reply-To:

Definition at line 68 of file copy.h.

◆ CH_UPDATE_REFS

#define CH_UPDATE_REFS   (1 << 17)

Update References:

Definition at line 69 of file copy.h.

◆ CH_DISPLAY

#define CH_DISPLAY   (1 << 18)

Display result to user.

Definition at line 70 of file copy.h.

◆ CH_UPDATE_LABEL

#define CH_UPDATE_LABEL   (1 << 19)

Update X-Label: from email->env->x_label?

Definition at line 71 of file copy.h.

◆ CH_UPDATE_SUBJECT

#define CH_UPDATE_SUBJECT   (1 << 20)

Update Subject: protected header update.

Definition at line 72 of file copy.h.

◆ CH_VIRTUAL

#define CH_VIRTUAL   (1 << 21)

Write virtual header lines too.

Definition at line 73 of file copy.h.

Typedef Documentation

◆ CopyMessageFlags

typedef uint16_t CopyMessageFlags

Flags for mutt_copy_message(), e.g. MUTT_CM_NOHEADER.

Definition at line 34 of file copy.h.

◆ CopyHeaderFlags

typedef uint32_t CopyHeaderFlags

Flags for mutt_copy_header(), e.g. CH_UPDATE.

Definition at line 50 of file copy.h.

Function Documentation

◆ mutt_copy_hdr()

int mutt_copy_hdr ( FILE *  fp_in,
FILE *  fp_out,
LOFF_T  off_start,
LOFF_T  off_end,
CopyHeaderFlags  chflags,
const char *  prefix,
int  wraplen 
)

Copy header from one file to another.

Parameters
fp_inFILE pointer to read from
fp_outFILE pointer to write to
off_startOffset to start from
off_endOffset to finish at
chflagsFlags, see CopyHeaderFlags
prefixPrefix for quoting headers
wraplenWidth to wrap at (when chflags & CH_DISPLAY)
Return values
0Success
-1Failure

Ok, the only reason for not merging this with mutt_copy_header() below is to avoid creating a Email structure in message_handler(). Also, this one will wrap headers much more aggressively than the other one.

Definition at line 105 of file copy.c.

107 {
108  bool from = false;
109  bool this_is_from = false;
110  bool ignore = false;
111  char buf[1024]; /* should be long enough to get most fields in one pass */
112  char *nl = NULL;
113  struct Headers headers = ARRAY_HEAD_INITIALIZER;
114  int hdr_count;
115  int x;
116  char *this_one = NULL;
117  size_t this_one_len = 0;
118 
119  if (off_start < 0)
120  return -1;
121 
122  if (ftello(fp_in) != off_start)
123  if (!mutt_file_seek(fp_in, off_start, SEEK_SET))
124  return -1;
125 
126  buf[0] = '\n';
127  buf[1] = '\0';
128 
129  if ((chflags & (CH_REORDER | CH_WEED | CH_MIME | CH_DECODE | CH_PREFIX | CH_WEED_DELIVERED)) == 0)
130  {
131  /* Without these flags to complicate things
132  * we can do a more efficient line to line copying */
133  while (ftello(fp_in) < off_end)
134  {
135  nl = strchr(buf, '\n');
136 
137  if (!fgets(buf, sizeof(buf), fp_in))
138  break;
139 
140  /* Is it the beginning of a header? */
141  if (nl && (buf[0] != ' ') && (buf[0] != '\t'))
142  {
143  ignore = true;
144  if (!from && mutt_str_startswith(buf, "From "))
145  {
146  if ((chflags & CH_FROM) == 0)
147  continue;
148  from = true;
149  }
150  else if ((chflags & CH_NOQFROM) && mutt_istr_startswith(buf, ">From "))
151  continue;
152  else if ((buf[0] == '\n') || ((buf[0] == '\r') && (buf[1] == '\n')))
153  break; /* end of header */
154 
155  if ((chflags & (CH_UPDATE | CH_XMIT | CH_NOSTATUS)) &&
156  (mutt_istr_startswith(buf, "Status:") || mutt_istr_startswith(buf, "X-Status:")))
157  {
158  continue;
159  }
160  if ((chflags & (CH_UPDATE_LEN | CH_XMIT | CH_NOLEN)) &&
161  (mutt_istr_startswith(buf, "Content-Length:") ||
162  mutt_istr_startswith(buf, "Lines:")))
163  {
164  continue;
165  }
166  if ((chflags & CH_UPDATE_REFS) &&
167  mutt_istr_startswith(buf, "References:"))
168  {
169  continue;
170  }
171  if ((chflags & CH_UPDATE_IRT) &&
172  mutt_istr_startswith(buf, "In-Reply-To:"))
173  {
174  continue;
175  }
176  if (chflags & CH_UPDATE_LABEL && mutt_istr_startswith(buf, "X-Label:"))
177  continue;
178  if ((chflags & CH_UPDATE_SUBJECT) &&
179  mutt_istr_startswith(buf, "Subject:"))
180  {
181  continue;
182  }
183 
184  ignore = false;
185  }
186 
187  if (!ignore && (fputs(buf, fp_out) == EOF))
188  return -1;
189  }
190  return 0;
191  }
192 
193  hdr_count = 1;
194  x = 0;
195 
196  /* We are going to read and collect the headers in an array
197  * so we are able to do re-ordering.
198  * First count the number of entries in the array */
199  if (chflags & CH_REORDER)
200  {
201  struct ListNode *np = NULL;
202  STAILQ_FOREACH(np, &HeaderOrderList, entries)
203  {
204  mutt_debug(LL_DEBUG3, "Reorder list: %s\n", np->data);
205  hdr_count++;
206  }
207  }
208 
209  mutt_debug(LL_DEBUG1, "WEED is %sset\n", (chflags & CH_WEED) ? "" : "not ");
210 
211  ARRAY_RESERVE(&headers, hdr_count);
212 
213  /* Read all the headers into the array */
214  while (ftello(fp_in) < off_end)
215  {
216  nl = strchr(buf, '\n');
217 
218  /* Read a line */
219  if (!fgets(buf, sizeof(buf), fp_in))
220  break;
221 
222  /* Is it the beginning of a header? */
223  if (nl && (buf[0] != ' ') && (buf[0] != '\t'))
224  {
225  /* Do we have anything pending? */
226  if (this_one)
227  {
228  if (chflags & CH_DECODE)
229  {
230  if (address_header_decode(&this_one) == 0)
231  rfc2047_decode(&this_one);
232  this_one_len = mutt_str_len(this_one);
233 
234  /* Convert CRLF line endings to LF */
235  if ((this_one_len > 2) && (this_one[this_one_len - 2] == '\r') &&
236  (this_one[this_one_len - 1] == '\n'))
237  {
238  this_one[this_one_len - 2] = '\n';
239  this_one[this_one_len - 1] = '\0';
240  }
241  }
242 
243  add_one_header(&headers, x, this_one);
244  this_one = NULL;
245  }
246 
247  ignore = true;
248  this_is_from = false;
249  if (!from && mutt_str_startswith(buf, "From "))
250  {
251  if ((chflags & CH_FROM) == 0)
252  continue;
253  this_is_from = true;
254  from = true;
255  }
256  else if ((buf[0] == '\n') || ((buf[0] == '\r') && (buf[1] == '\n')))
257  break; /* end of header */
258 
259  /* note: CH_FROM takes precedence over header weeding. */
260  if (!((chflags & CH_FROM) && (chflags & CH_FORCE_FROM) && this_is_from) &&
261  (chflags & CH_WEED) && mutt_matches_ignore(buf))
262  {
263  continue;
264  }
265  if ((chflags & CH_WEED_DELIVERED) &&
266  mutt_istr_startswith(buf, "Delivered-To:"))
267  {
268  continue;
269  }
270  if ((chflags & (CH_UPDATE | CH_XMIT | CH_NOSTATUS)) &&
271  (mutt_istr_startswith(buf, "Status:") ||
272  mutt_istr_startswith(buf, "X-Status:")))
273  {
274  continue;
275  }
276  if ((chflags & (CH_UPDATE_LEN | CH_XMIT | CH_NOLEN)) &&
277  (mutt_istr_startswith(buf, "Content-Length:") || mutt_istr_startswith(buf, "Lines:")))
278  {
279  continue;
280  }
281  if ((chflags & CH_MIME))
282  {
283  if (mutt_istr_startswith(buf, "mime-version:"))
284  {
285  continue;
286  }
287  size_t plen = mutt_istr_startswith(buf, "content-");
288  if ((plen != 0) &&
289  (mutt_istr_startswith(buf + plen, "transfer-encoding:") ||
290  mutt_istr_startswith(buf + plen, "type:")))
291  {
292  continue;
293  }
294  }
295  if ((chflags & CH_UPDATE_REFS) &&
296  mutt_istr_startswith(buf, "References:"))
297  {
298  continue;
299  }
300  if ((chflags & CH_UPDATE_IRT) &&
301  mutt_istr_startswith(buf, "In-Reply-To:"))
302  {
303  continue;
304  }
305  if ((chflags & CH_UPDATE_LABEL) && mutt_istr_startswith(buf, "X-Label:"))
306  continue;
307  if ((chflags & CH_UPDATE_SUBJECT) &&
308  mutt_istr_startswith(buf, "Subject:"))
309  {
310  continue;
311  }
312 
313  /* Find x -- the array entry where this header is to be saved */
314  if (chflags & CH_REORDER)
315  {
316  struct ListNode *np = NULL;
317  x = 0;
318  int match = -1;
319  size_t match_len = 0, hdr_order_len;
320 
321  STAILQ_FOREACH(np, &HeaderOrderList, entries)
322  {
323  x++;
324  hdr_order_len = mutt_str_len(np->data);
325  if (mutt_istrn_equal(buf, np->data, hdr_order_len))
326  {
327  if ((match == -1) || (hdr_order_len > match_len))
328  {
329  match = x;
330  match_len = hdr_order_len;
331  }
332  mutt_debug(LL_DEBUG2, "Reorder: %s matches %s", np->data, buf);
333  }
334  }
335  if (match != -1)
336  x = match;
337  }
338 
339  ignore = false;
340  } /* If beginning of header */
341 
342  if (!ignore)
343  {
344  mutt_debug(LL_DEBUG2, "Reorder: x = %d; hdr_count = %d\n", x, hdr_count);
345  if (this_one)
346  {
347  size_t blen = mutt_str_len(buf);
348 
349  mutt_mem_realloc(&this_one, this_one_len + blen + sizeof(char));
350  strcat(this_one + this_one_len, buf);
351  this_one_len += blen;
352  }
353  else
354  {
355  this_one = mutt_str_dup(buf);
356  this_one_len = mutt_str_len(this_one);
357  }
358  }
359  } /* while (ftello (fp_in) < off_end) */
360 
361  /* Do we have anything pending? -- XXX, same code as in above in the loop. */
362  if (this_one)
363  {
364  if (chflags & CH_DECODE)
365  {
366  if (address_header_decode(&this_one) == 0)
367  rfc2047_decode(&this_one);
368  this_one_len = mutt_str_len(this_one);
369  }
370 
371  add_one_header(&headers, x, this_one);
372  this_one = NULL;
373  }
374 
375  /* Now output the headers in order */
376  bool error = false;
377  char **hp = NULL;
378  ARRAY_FOREACH(hp, &headers)
379  {
380  if (!error && hp && *hp)
381  {
382  /* We couldn't do the prefixing when reading because RFC2047
383  * decoding may have concatenated lines. */
384  if (chflags & (CH_DECODE | CH_PREFIX))
385  {
386  const char *pre = (chflags & CH_PREFIX) ? prefix : NULL;
387  const short c_wrap = cs_subset_number(NeoMutt->sub, "wrap");
388  wraplen = mutt_window_wrap_cols(wraplen, c_wrap);
389 
390  if (mutt_write_one_header(fp_out, 0, *hp, pre, wraplen, chflags, NeoMutt->sub) == -1)
391  {
392  error = true;
393  }
394  }
395  else
396  {
397  if (fputs(*hp, fp_out) == EOF)
398  {
399  error = true;
400  }
401  }
402  }
403 
404  FREE(hp);
405  }
406  ARRAY_FREE(&headers);
407 
408  if (error)
409  return -1;
410  return 0;
411 }
#define ARRAY_RESERVE(head, num)
Reserve memory for the array.
Definition: array.h:185
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:208
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:200
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition: array.h:54
static int address_header_decode(char **h)
Parse an email's headers.
Definition: copy.c:1117
static void add_one_header(struct Headers *headers, size_t pos, char *value)
Add a header to a Headers array.
Definition: copy.c:75
#define CH_DECODE
Do RFC2047 header decoding.
Definition: copy.h:54
#define CH_XMIT
Transmitting this message? (Ignore Lines: and Content-Length:)
Definition: copy.h:55
#define CH_PREFIX
Quote header using $indent_string string?
Definition: copy.h:57
#define CH_UPDATE
Update the status and x-status fields?
Definition: copy.h:52
#define CH_NOSTATUS
Suppress the status and x-status fields.
Definition: copy.h:58
#define CH_FROM
Retain the "From " message separator?
Definition: copy.h:56
#define CH_WEED_DELIVERED
Weed eventual Delivered-To headers.
Definition: copy.h:65
#define CH_UPDATE_LABEL
Update X-Label: from email->env->x_label?
Definition: copy.h:71
#define CH_WEED
Weed the headers?
Definition: copy.h:53
#define CH_REORDER
Re-order output of headers (specified by 'hdr_order')
Definition: copy.h:59
#define CH_MIME
Ignore MIME fields.
Definition: copy.h:61
#define CH_UPDATE_REFS
Update References:
Definition: copy.h:69
#define CH_NOQFROM
Ignore ">From " line.
Definition: copy.h:67
#define CH_UPDATE_LEN
Update Lines: and Content-Length:
Definition: copy.h:62
#define CH_UPDATE_IRT
Update In-Reply-To:
Definition: copy.h:68
#define CH_FORCE_FROM
Give CH_FROM precedence over CH_WEED?
Definition: copy.h:66
#define CH_UPDATE_SUBJECT
Update Subject: protected header update.
Definition: copy.h:72
#define CH_NOLEN
Don't write Content-Length: and Lines:
Definition: copy.h:64
bool mutt_file_seek(FILE *fp, LOFF_T offset, int whence)
Wrapper for fseeko with error handling.
Definition: file.c:665
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
int mutt_write_one_header(FILE *fp, const char *tag, const char *value, const char *pfx, int wraplen, CopyHeaderFlags chflags, struct ConfigSubset *sub)
Write one header line to a file.
Definition: header.c:420
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
@ LL_DEBUG3
Log at debug level 3.
Definition: logging.h:42
@ LL_DEBUG2
Log at debug level 2.
Definition: logging.h:41
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
#define FREE(x)
Definition: memory.h:40
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:181
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:158
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:475
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:170
bool mutt_istrn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings ignoring case (to a maximum), safely.
Definition: string.c:432
struct ListHead HeaderOrderList
List of header fields in the order they should be displayed.
Definition: mutt_globals.h:64
int mutt_window_wrap_cols(int width, short wrap)
Calculate the wrap column for a given screen width.
Definition: mutt_window.c:364
bool mutt_matches_ignore(const char *s)
Does the string match the ignore list.
Definition: parse.c:314
static size_t plen
Length of cached packet.
Definition: pgppacket.c:39
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
void rfc2047_decode(char **pd)
Decode any RFC2047-encoded header fields.
Definition: rfc2047.c:644
A List node for strings.
Definition: list.h:35
char * data
String.
Definition: list.h:36
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_copy_header()

int mutt_copy_header ( FILE *  fp_in,
struct Email e,
FILE *  fp_out,
CopyHeaderFlags  chflags,
const char *  prefix,
int  wraplen 
)

Copy Email header.

Parameters
fp_inFILE pointer to read from
eEmail
fp_outFILE pointer to write to
chflagsSee CopyHeaderFlags
prefixPrefix for quoting headers (if CH_PREFIX is set)
wraplenWidth to wrap at (when chflags & CH_DISPLAY)
Return values
0Success
-1Failure

Definition at line 424 of file copy.c.

426 {
427  char *temp_hdr = NULL;
428 
429  if (e->env)
430  {
431  chflags |= ((e->env->changed & MUTT_ENV_CHANGED_IRT) ? CH_UPDATE_IRT : 0) |
435  }
436 
437  if (mutt_copy_hdr(fp_in, fp_out, e->offset, e->body->offset, chflags, prefix, wraplen) == -1)
438  return -1;
439 
440  if (chflags & CH_TXTPLAIN)
441  {
442  char chsbuf[128];
443  char buf[128];
444  fputs("MIME-Version: 1.0\n", fp_out);
445  fputs("Content-Transfer-Encoding: 8bit\n", fp_out);
446  fputs("Content-Type: text/plain; charset=", fp_out);
447  const char *const c_charset = cs_subset_string(NeoMutt->sub, "charset");
448  mutt_ch_canonical_charset(chsbuf, sizeof(chsbuf), c_charset ? c_charset : "us-ascii");
449  mutt_addr_cat(buf, sizeof(buf), chsbuf, MimeSpecials);
450  fputs(buf, fp_out);
451  fputc('\n', fp_out);
452  }
453 
454  if ((chflags & CH_UPDATE_IRT) && !STAILQ_EMPTY(&e->env->in_reply_to))
455  {
456  fputs("In-Reply-To:", fp_out);
457  struct ListNode *np = NULL;
458  STAILQ_FOREACH(np, &e->env->in_reply_to, entries)
459  {
460  fputc(' ', fp_out);
461  fputs(np->data, fp_out);
462  }
463  fputc('\n', fp_out);
464  }
465 
466  if ((chflags & CH_UPDATE_REFS) && !STAILQ_EMPTY(&e->env->references))
467  {
468  fputs("References:", fp_out);
469  mutt_write_references(&e->env->references, fp_out, 0);
470  fputc('\n', fp_out);
471  }
472 
473  if ((chflags & CH_UPDATE) && ((chflags & CH_NOSTATUS) == 0))
474  {
475  if (e->old || e->read)
476  {
477  fputs("Status: ", fp_out);
478  if (e->read)
479  fputs("RO", fp_out);
480  else if (e->old)
481  fputc('O', fp_out);
482  fputc('\n', fp_out);
483  }
484 
485  if (e->flagged || e->replied)
486  {
487  fputs("X-Status: ", fp_out);
488  if (e->replied)
489  fputc('A', fp_out);
490  if (e->flagged)
491  fputc('F', fp_out);
492  fputc('\n', fp_out);
493  }
494  }
495 
496  if (chflags & CH_UPDATE_LEN && ((chflags & CH_NOLEN) == 0))
497  {
498  fprintf(fp_out, "Content-Length: " OFF_T_FMT "\n", e->body->length);
499  if ((e->lines != 0) || (e->body->length == 0))
500  fprintf(fp_out, "Lines: %d\n", e->lines);
501  }
502 
503  const bool c_weed = cs_subset_bool(NeoMutt->sub, "weed");
504 #ifdef USE_NOTMUCH
505  if (chflags & CH_VIRTUAL)
506  {
507  /* Add some fake headers based on notmuch data */
508  char *folder = nm_email_get_folder(e);
509  if (folder && !(c_weed && mutt_matches_ignore("folder")))
510  {
511  char buf[1024];
512  mutt_str_copy(buf, folder, sizeof(buf));
513  mutt_pretty_mailbox(buf, sizeof(buf));
514 
515  fputs("Folder: ", fp_out);
516  fputs(buf, fp_out);
517  fputc('\n', fp_out);
518  }
519  }
520 #endif
521  char *tags = driver_tags_get(&e->tags);
522  if (tags && !(c_weed && mutt_matches_ignore("tags")))
523  {
524  fputs("Tags: ", fp_out);
525  fputs(tags, fp_out);
526  fputc('\n', fp_out);
527  }
528  FREE(&tags);
529 
530  const char *const c_send_charset =
531  cs_subset_string(NeoMutt->sub, "send_charset");
532  const short c_wrap = cs_subset_number(NeoMutt->sub, "wrap");
533  if ((chflags & CH_UPDATE_LABEL) && e->env->x_label)
534  {
535  temp_hdr = e->env->x_label;
536  /* env->x_label isn't currently stored with direct references elsewhere.
537  * Mailbox->label_hash strdups the keys. But to be safe, encode a copy */
538  if (!(chflags & CH_DECODE))
539  {
540  temp_hdr = mutt_str_dup(temp_hdr);
541  rfc2047_encode(&temp_hdr, NULL, sizeof("X-Label:"), c_send_charset);
542  }
544  fp_out, "X-Label", temp_hdr, (chflags & CH_PREFIX) ? prefix : 0,
545  mutt_window_wrap_cols(wraplen, c_wrap), chflags, NeoMutt->sub) == -1)
546  {
547  return -1;
548  }
549  if (!(chflags & CH_DECODE))
550  FREE(&temp_hdr);
551  }
552 
553  if ((chflags & CH_UPDATE_SUBJECT) && e->env->subject)
554  {
555  temp_hdr = e->env->subject;
556  /* env->subject is directly referenced in Mailbox->subj_hash, so we
557  * have to be careful not to encode (and thus free) that memory. */
558  if (!(chflags & CH_DECODE))
559  {
560  temp_hdr = mutt_str_dup(temp_hdr);
561  rfc2047_encode(&temp_hdr, NULL, sizeof("Subject:"), c_send_charset);
562  }
564  fp_out, "Subject", temp_hdr, (chflags & CH_PREFIX) ? prefix : 0,
565  mutt_window_wrap_cols(wraplen, c_wrap), chflags, NeoMutt->sub) == -1)
566  {
567  return -1;
568  }
569  if (!(chflags & CH_DECODE))
570  FREE(&temp_hdr);
571  }
572 
573  if ((chflags & CH_NONEWLINE) == 0)
574  {
575  if (chflags & CH_PREFIX)
576  fputs(prefix, fp_out);
577  fputc('\n', fp_out); /* add header terminator */
578  }
579 
580  if (ferror(fp_out) || feof(fp_out))
581  return -1;
582 
583  return 0;
584 }
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:681
int mutt_copy_hdr(FILE *fp_in, FILE *fp_out, LOFF_T off_start, LOFF_T off_end, CopyHeaderFlags chflags, const char *prefix, int wraplen)
Copy header from one file to another.
Definition: copy.c:105
#define CH_NONEWLINE
Don't output terminating newline after the header.
Definition: copy.h:60
#define CH_TXTPLAIN
Generate text/plain MIME headers.
Definition: copy.h:63
#define CH_VIRTUAL
Write virtual header lines too.
Definition: copy.h:73
void mutt_pretty_mailbox(char *buf, size_t buflen)
Shorten a mailbox path using '~' or '='.
Definition: muttlib.c:526
#define MUTT_ENV_CHANGED_SUBJECT
Protected header update.
Definition: envelope.h:35
#define MUTT_ENV_CHANGED_XLABEL
X-Label edited.
Definition: envelope.h:34
#define MUTT_ENV_CHANGED_IRT
In-Reply-To changed to link/break threads.
Definition: envelope.h:32
#define MUTT_ENV_CHANGED_REFS
References changed to break thread.
Definition: envelope.h:33
void mutt_write_references(const struct ListHead *r, FILE *fp, size_t trim)
Add the message references to a list.
Definition: header.c:514
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
const char MimeSpecials[]
Characters that need special treatment in MIME.
Definition: mime.c:67
void mutt_ch_canonical_charset(char *buf, size_t buflen, const char *name)
Canonicalise the charset of a string.
Definition: charset.c:355
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:560
char * nm_email_get_folder(struct Email *e)
Get the folder for a Email.
Definition: notmuch.c:1463
#define STAILQ_EMPTY(head)
Definition: queue.h:348
void rfc2047_encode(char **pd, const char *specials, int col, const char *charsets)
RFC-2047-encode a string.
Definition: rfc2047.c:619
LOFF_T offset
offset where the actual data begins
Definition: body.h:51
LOFF_T length
length (in bytes) of attachment
Definition: body.h:52
bool read
Email is read.
Definition: email.h:48
struct Envelope * env
Envelope information.
Definition: email.h:66
int lines
How many lines in the body of this message?
Definition: email.h:60
struct Body * body
List of MIME parts.
Definition: email.h:67
bool old
Email is seen, but unread.
Definition: email.h:47
LOFF_T offset
Where in the stream does this message begin?
Definition: email.h:69
bool flagged
Marked important?
Definition: email.h:45
bool replied
Email has been replied to.
Definition: email.h:49
struct TagList tags
For drivers that support server tagging.
Definition: email.h:70
unsigned char changed
Changed fields, e.g. MUTT_ENV_CHANGED_SUBJECT.
Definition: envelope.h:90
struct ListHead references
message references (in reverse order)
Definition: envelope.h:83
struct ListHead in_reply_to
in-reply-to header content
Definition: envelope.h:84
char * subject
Email's subject.
Definition: envelope.h:68
char * x_label
X-Label.
Definition: envelope.h:74
char * driver_tags_get(struct TagList *list)
Get tags.
Definition: tags.c:144
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_copy_message_fp()

int mutt_copy_message_fp ( FILE *  fp_out,
FILE *  fp_in,
struct Email e,
CopyMessageFlags  cmflags,
CopyHeaderFlags  chflags,
int  wraplen 
)

Make a copy of a message from a FILE pointer.

Parameters
fp_outWhere to write output
fp_inWhere to get input
eEmail being copied
cmflagsFlags, see CopyMessageFlags
chflagsFlags, see CopyHeaderFlags
wraplenWidth to wrap at (when chflags & CH_DISPLAY)
Return values
0Success
-1Failure

Definition at line 651 of file copy.c.

653 {
654  struct Body *body = e->body;
655  char prefix[128];
656  LOFF_T new_offset = -1;
657  int rc = 0;
658 
659  if (cmflags & MUTT_CM_PREFIX)
660  {
661  const bool c_text_flowed = cs_subset_bool(NeoMutt->sub, "text_flowed");
662  if (c_text_flowed)
663  mutt_str_copy(prefix, ">", sizeof(prefix));
664  else
665  {
666  const char *const c_indent_string =
667  cs_subset_string(NeoMutt->sub, "indent_string");
668  struct Mailbox *m_cur = get_current_mailbox();
669  mutt_make_string(prefix, sizeof(prefix), wraplen, NONULL(c_indent_string),
670  m_cur, -1, e, MUTT_FORMAT_NO_FLAGS, NULL);
671  }
672  }
673 
674  if ((cmflags & MUTT_CM_NOHEADER) == 0)
675  {
676  if (cmflags & MUTT_CM_PREFIX)
677  chflags |= CH_PREFIX;
678  else if (e->attach_del && (chflags & CH_UPDATE_LEN))
679  {
680  int new_lines;
681  int rc_attach_del = -1;
682  LOFF_T new_length = body->length;
683  struct Buffer *quoted_date = NULL;
684 
685  quoted_date = mutt_buffer_pool_get();
686  mutt_buffer_addch(quoted_date, '"');
687  mutt_date_make_date(quoted_date,
688  cs_subset_bool(NeoMutt->sub, "local_date_header"));
689  mutt_buffer_addch(quoted_date, '"');
690 
691  /* Count the number of lines and bytes to be deleted */
692  if (!mutt_file_seek(fp_in, body->offset, SEEK_SET))
693  {
694  goto attach_del_cleanup;
695  }
696  const int del =
697  count_delete_lines(fp_in, body, &new_length, mutt_buffer_len(quoted_date));
698  if (del == -1)
699  {
700  goto attach_del_cleanup;
701  }
702  new_lines = e->lines - del;
703 
704  /* Copy the headers */
705  if (mutt_copy_header(fp_in, e, fp_out, chflags | CH_NOLEN | CH_NONEWLINE, NULL, wraplen))
706  goto attach_del_cleanup;
707  fprintf(fp_out, "Content-Length: " OFF_T_FMT "\n", new_length);
708  if (new_lines <= 0)
709  new_lines = 0;
710  else
711  fprintf(fp_out, "Lines: %d\n", new_lines);
712 
713  putc('\n', fp_out);
714  if (ferror(fp_out) || feof(fp_out))
715  goto attach_del_cleanup;
716  new_offset = ftello(fp_out);
717 
718  /* Copy the body */
719  if (!mutt_file_seek(fp_in, body->offset, SEEK_SET))
720  goto attach_del_cleanup;
721  if (copy_delete_attach(body, fp_in, fp_out, mutt_buffer_string(quoted_date)))
722  goto attach_del_cleanup;
723 
724  mutt_buffer_pool_release(&quoted_date);
725 
726  LOFF_T fail = ((ftello(fp_out) - new_offset) - new_length);
727  if (fail)
728  {
729  mutt_error(ngettext("The length calculation was wrong by %ld byte",
730  "The length calculation was wrong by %ld bytes", fail),
731  fail);
732  new_length += fail;
733  }
734 
735  /* Update original message if we are sync'ing a mailfolder */
736  if (cmflags & MUTT_CM_UPDATE)
737  {
738  e->attach_del = false;
739  e->lines = new_lines;
740  body->offset = new_offset;
741 
742  body->length = new_length;
743  mutt_body_free(&body->parts);
744  }
745 
746  rc_attach_del = 0;
747 
748  attach_del_cleanup:
749  mutt_buffer_pool_release(&quoted_date);
750  return rc_attach_del;
751  }
752 
753  if (mutt_copy_header(fp_in, e, fp_out, chflags,
754  (chflags & CH_PREFIX) ? prefix : NULL, wraplen) == -1)
755  {
756  return -1;
757  }
758 
759  new_offset = ftello(fp_out);
760  }
761 
762  if (cmflags & MUTT_CM_DECODE)
763  {
764  /* now make a text/plain version of the message */
765  struct State s = { 0 };
766  s.fp_in = fp_in;
767  s.fp_out = fp_out;
768  if (cmflags & MUTT_CM_PREFIX)
769  s.prefix = prefix;
770  if (cmflags & MUTT_CM_DISPLAY)
771  {
772  s.flags |= MUTT_DISPLAY;
773  s.wraplen = wraplen;
774  }
775  if (cmflags & MUTT_CM_PRINTING)
776  s.flags |= MUTT_PRINTING;
777  if (cmflags & MUTT_CM_WEED)
778  s.flags |= MUTT_WEED;
779  if (cmflags & MUTT_CM_CHARCONV)
780  s.flags |= MUTT_CHARCONV;
781  if (cmflags & MUTT_CM_REPLYING)
782  s.flags |= MUTT_REPLYING;
783 
784  if ((WithCrypto != 0) && cmflags & MUTT_CM_VERIFY)
785  s.flags |= MUTT_VERIFY;
786 
787  rc = mutt_body_handler(body, &s);
788  }
789  else if ((WithCrypto != 0) && (cmflags & MUTT_CM_DECODE_CRYPT) && (e->security & SEC_ENCRYPT))
790  {
791  struct Body *cur = NULL;
792  FILE *fp = NULL;
793 
794  if (((WithCrypto & APPLICATION_PGP) != 0) && (cmflags & MUTT_CM_DECODE_PGP) &&
795  (e->security & APPLICATION_PGP) && (e->body->type == TYPE_MULTIPART))
796  {
797  if (crypt_pgp_decrypt_mime(fp_in, &fp, e->body, &cur))
798  return -1;
799  fputs("MIME-Version: 1.0\n", fp_out);
800  }
801 
802  if (((WithCrypto & APPLICATION_SMIME) != 0) && (cmflags & MUTT_CM_DECODE_SMIME) &&
804  {
805  if (crypt_smime_decrypt_mime(fp_in, &fp, e->body, &cur))
806  return -1;
807  }
808 
809  if (!cur)
810  {
811  mutt_error(_("No decryption engine available for message"));
812  return -1;
813  }
814 
815  mutt_write_mime_header(cur, fp_out, NeoMutt->sub);
816  fputc('\n', fp_out);
817 
818  if (!mutt_file_seek(fp, cur->offset, SEEK_SET))
819  return -1;
820  if (mutt_file_copy_bytes(fp, fp_out, cur->length) == -1)
821  {
822  mutt_file_fclose(&fp);
823  mutt_body_free(&cur);
824  return -1;
825  }
826  mutt_body_free(&cur);
827  mutt_file_fclose(&fp);
828  }
829  else
830  {
831  if (!mutt_file_seek(fp_in, body->offset, SEEK_SET))
832  return -1;
833  if (cmflags & MUTT_CM_PREFIX)
834  {
835  int c;
836  size_t bytes = body->length;
837 
838  fputs(prefix, fp_out);
839 
840  while (((c = fgetc(fp_in)) != EOF) && bytes--)
841  {
842  fputc(c, fp_out);
843  if (c == '\n')
844  {
845  fputs(prefix, fp_out);
846  }
847  }
848  }
849  else if (mutt_file_copy_bytes(fp_in, fp_out, body->length) == -1)
850  return -1;
851  }
852 
853  if ((cmflags & MUTT_CM_UPDATE) && ((cmflags & MUTT_CM_NOHEADER) == 0) &&
854  (new_offset != -1))
855  {
856  body->offset = new_offset;
857  mutt_body_free(&body->parts);
858  }
859 
860  return rc;
861 }
size_t mutt_buffer_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:356
size_t mutt_buffer_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:240
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
int mutt_copy_header(FILE *fp_in, struct Email *e, FILE *fp_out, CopyHeaderFlags chflags, const char *prefix, int wraplen)
Copy Email header.
Definition: copy.c:424
static int count_delete_lines(FILE *fp, struct Body *b, LOFF_T *length, size_t datelen)
Count lines to be deleted in this email body.
Definition: copy.c:597
static int copy_delete_attach(struct Body *b, FILE *fp_in, FILE *fp_out, const char *quoted_date)
Copy a message, deleting marked attachments.
Definition: copy.c:983
#define MUTT_CM_WEED
Weed message/rfc822 attachment headers.
Definition: copy.h:41
#define MUTT_CM_REPLYING
Replying the message.
Definition: copy.h:44
#define MUTT_CM_PREFIX
Quote the header and body.
Definition: copy.h:37
#define MUTT_CM_UPDATE
Update structs on sync.
Definition: copy.h:40
#define MUTT_CM_VERIFY
Do signature verification.
Definition: copy.h:47
#define MUTT_CM_DECODE_PGP
Used for decoding PGP messages.
Definition: copy.h:45
#define MUTT_CM_DECODE
Decode the message body into text/plain.
Definition: copy.h:38
#define MUTT_CM_CHARCONV
Perform character set conversions.
Definition: copy.h:42
#define MUTT_CM_DECODE_SMIME
Used for decoding S/MIME messages.
Definition: copy.h:46
#define MUTT_CM_PRINTING
Printing the message - display light.
Definition: copy.h:43
#define MUTT_CM_DECODE_CRYPT
Definition: copy.h:48
#define MUTT_CM_NOHEADER
Don't copy the message header.
Definition: copy.h:36
#define MUTT_CM_DISPLAY
Output is displayed to the user.
Definition: copy.h:39
int crypt_smime_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur)
Wrapper for CryptModuleSpecs::decrypt_mime()
Definition: cryptglue.c:434
int crypt_pgp_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur)
Wrapper for CryptModuleSpecs::decrypt_mime()
Definition: cryptglue.c:212
void mutt_date_make_date(struct Buffer *buf, bool local)
Write a date in RFC822 format to a buffer.
Definition: date.c:378
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:57
int mutt_file_copy_bytes(FILE *fp_in, FILE *fp_out, size_t size)
Copy some content from one file to another.
Definition: file.c:241
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:153
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: format_flags.h:30
#define mutt_error(...)
Definition: logging.h:87
int mutt_body_handler(struct Body *b, struct State *s)
Handler for the Body of an email.
Definition: handler.c:1607
void mutt_make_string(char *buf, size_t buflen, int cols, const char *s, struct Mailbox *m, int inpgr, struct Email *e, MuttFormatFlags flags, const char *progress)
Create formatted strings using mailbox expandos.
Definition: hdrline.c:1410
int mutt_write_mime_header(struct Body *a, FILE *fp, struct ConfigSubset *sub)
Create a MIME header.
Definition: header.c:761
struct Mailbox * get_current_mailbox(void)
Get the current Mailbox.
Definition: index.c:474
@ TYPE_MULTIPART
Type: 'multipart/*'.
Definition: mime.h:37
@ TYPE_APPLICATION
Type: 'application/*'.
Definition: mime.h:33
#define _(a)
Definition: message.h:28
#define MUTT_WEED
Weed headers even when not in display mode.
Definition: state.h:35
#define MUTT_VERIFY
Perform signature verification.
Definition: state.h:33
#define MUTT_CHARCONV
Do character set conversions.
Definition: state.h:36
#define MUTT_DISPLAY
Output is displayed to the user.
Definition: state.h:32
#define MUTT_REPLYING
Are we replying?
Definition: state.h:38
#define MUTT_PRINTING
Are we printing? - MUTT_DISPLAY "light".
Definition: state.h:37
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:87
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:88
#define SEC_ENCRYPT
Email is encrypted.
Definition: lib.h:75
#define WithCrypto
Definition: lib.h:113
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
#define NONULL(x)
Definition: string2.h:37
The body of an email.
Definition: body.h:35
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:71
unsigned int type
content-type primary type, ContentType
Definition: body.h:39
String manipulation buffer.
Definition: buffer.h:34
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib....
Definition: email.h:41
bool attach_del
Has an attachment marked for deletion.
Definition: email.h:99
A mailbox.
Definition: mailbox.h:82
Keep track when processing files.
Definition: state.h:45
int wraplen
Width to wrap lines to (when flags & MUTT_DISPLAY)
Definition: state.h:50
StateFlags flags
Flags, e.g. MUTT_DISPLAY.
Definition: state.h:49
FILE * fp_out
File to write to.
Definition: state.h:47
char * prefix
String to add to the beginning of each output line.
Definition: state.h:48
FILE * fp_in
File to read from.
Definition: state.h:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_copy_message()

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.

Parameters
fp_outFILE pointer to write to
eEmail
msgMessage
cmflagsFlags, see CopyMessageFlags
chflagsFlags, see CopyHeaderFlags
wraplenWidth to wrap at (when chflags & CH_DISPLAY)
Return values
0Success
-1Failure

should be made to return -1 on fatal errors, and 1 on non-fatal errors like partial decode, where it is worth displaying as much as possible

Definition at line 877 of file copy.c.

879 {
880  if (!msg || !e->body)
881  {
882  return -1;
883  }
884  if (fp_out == msg->fp)
885  {
886  mutt_debug(LL_DEBUG1, "trying to read/write from/to the same FILE*!\n");
887  return -1;
888  }
889 
890  int rc = mutt_copy_message_fp(fp_out, msg->fp, e, cmflags, chflags, wraplen);
891  if ((rc == 0) && (ferror(fp_out) || feof(fp_out)))
892  {
893  mutt_debug(LL_DEBUG1, "failed to detect EOF!\n");
894  rc = -1;
895  }
896  return rc;
897 }
int mutt_copy_message_fp(FILE *fp_out, FILE *fp_in, struct Email *e, CopyMessageFlags cmflags, CopyHeaderFlags chflags, int wraplen)
Make a copy of a message from a FILE pointer.
Definition: copy.c:651
FILE * fp
pointer to the message data
Definition: mxapi.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_append_message()

int mutt_append_message ( struct Mailbox m_dst,
struct Mailbox m_src,
struct Email e,
struct Message msg,
CopyMessageFlags  cmflags,
CopyHeaderFlags  chflags 
)

Append a message.

Parameters
m_dstDestination Mailbox
m_srcSource Mailbox
eEmail
msgMessage
cmflagsFlags, see CopyMessageFlags
chflagsFlags, see CopyHeaderFlags
Return values
0Success
-1Failure

Definition at line 952 of file copy.c.

955 {
956  const bool own_msg = !msg;
957  if (own_msg && !(msg = mx_msg_open(m_src, e->msgno)))
958  {
959  return -1;
960  }
961 
962  int rc = append_message(m_dst, msg->fp, m_src, e, cmflags, chflags);
963  if (own_msg)
964  {
965  mx_msg_close(m_src, &msg);
966  }
967  return rc;
968 }
static int append_message(struct Mailbox *dest, FILE *fp_in, struct Mailbox *src, struct Email *e, CopyMessageFlags cmflags, CopyHeaderFlags chflags)
Appends a copy of the given message to a mailbox.
Definition: copy.c:910
int mx_msg_close(struct Mailbox *m, struct Message **msg)
Close a message.
Definition: mx.c:1192
struct Message * mx_msg_open(struct Mailbox *m, int msgno)
Return a stream pointer for a message.
Definition: mx.c:1146
int msgno
Number displayed to the user.
Definition: email.h:111
+ Here is the call graph for this function:
+ Here is the caller graph for this function: