NeoMutt  2024-12-12-14-g7b49f7
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
handler.c File Reference

Decide how to display email content. More...

#include "config.h"
#include <ctype.h>
#include <iconv.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "handler.h"
#include "attach/lib.h"
#include "key/lib.h"
#include "menu/lib.h"
#include "ncrypt/lib.h"
#include "pager/lib.h"
#include "copy.h"
#include "enriched.h"
#include "globals.h"
#include "mailcap.h"
#include "mutt_logging.h"
#include "muttlib.h"
#include "rfc3676.h"
#include <libintl.h>
+ Include dependency graph for handler.c:

Go to the source code of this file.

Macros

#define BUFI_SIZE   1000
 
#define BUFO_SIZE   2000
 
#define TXT_HTML   1
 
#define TXT_PLAIN   2
 
#define TXT_ENRICHED   3
 

Typedefs

typedef int(* handler_t) (struct Body *b_email, struct State *state)
 

Functions

static void print_part_line (struct State *state, struct Body *b_email, int n)
 Print a separator for the Mime part.
 
static void convert_to_state (iconv_t cd, char *bufi, size_t *l, struct State *state)
 Convert text and write it to a file.
 
static void decode_xbit (struct State *state, long len, bool istext, iconv_t cd)
 Decode xbit-encoded text.
 
static int qp_decode_triple (char *s, char *d)
 Decode a quoted-printable triplet.
 
static void qp_decode_line (char *dest, char *src, size_t *l, int last)
 Decode a line of quoted-printable text.
 
static void decode_quoted (struct State *state, long len, bool istext, iconv_t cd)
 Decode an attachment encoded with quoted-printable.
 
static unsigned char decode_byte (char ch)
 Decode a uuencoded byte.
 
static void decode_uuencoded (struct State *state, long len, bool istext, iconv_t cd)
 Decode uuencoded text.
 
static bool is_mmnoask (const char *buf)
 Metamail compatibility: should the attachment be autoviewed?
 
static bool is_autoview (struct Body *b)
 Should email body be filtered by mailcap.
 
static int autoview_handler (struct Body *b_email, struct State *state)
 Handler for autoviewable attachments - Implements handler_t -.
 
static int text_plain_handler (struct Body *b_email, struct State *state)
 Handler for plain text - Implements handler_t -.
 
static int message_handler (struct Body *b_email, struct State *state)
 Handler for message/rfc822 body parts - Implements handler_t -.
 
static int external_body_handler (struct Body *b_email, struct State *state)
 Handler for external-body emails - Implements handler_t -.
 
static int alternative_handler (struct Body *b_email, struct State *state)
 Handler for multipart alternative emails - Implements handler_t -.
 
static int multilingual_handler (struct Body *b_email, struct State *state)
 Handler for multi-lingual emails - Implements handler_t -.
 
static int multipart_handler (struct Body *b_email, struct State *state)
 Handler for multipart emails - Implements handler_t -.
 
static int run_decode_and_handler (struct Body *b, struct State *state, handler_t handler, bool plaintext)
 Run an appropriate decoder for an email.
 
static int valid_pgp_encrypted_handler (struct Body *b_email, struct State *state)
 Handler for valid pgp-encrypted emails - Implements handler_t -.
 
static int malformed_pgp_encrypted_handler (struct Body *b_email, struct State *state)
 Handler for invalid pgp-encrypted emails - Implements handler_t -.
 
void mutt_decode_base64 (struct State *state, size_t len, bool istext, iconv_t cd)
 Decode base64-encoded text.
 
int mutt_body_handler (struct Body *b, struct State *state)
 Handler for the Body of an email.
 
bool mutt_prefer_as_attachment (struct Body *b)
 Do we want this part as an attachment?
 
bool mutt_can_decode (struct Body *b)
 Will decoding the attachment produce any output.
 
void mutt_decode_attachment (const struct Body *b, struct State *state)
 Decode an email's attachment.
 

Detailed Description

Decide how to display email content.

Authors
  • Michael R. Elkins
  • Pietro Cerutti
  • Richard Russon
  • Federico Kircheis
  • Reis Radomil
  • Ian Zimmerman
  • David Purton
  • Dennis Schön

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 handler.c.

Macro Definition Documentation

◆ BUFI_SIZE

#define BUFI_SIZE   1000

Definition at line 68 of file handler.c.

◆ BUFO_SIZE

#define BUFO_SIZE   2000

Definition at line 69 of file handler.c.

◆ TXT_HTML

#define TXT_HTML   1

Definition at line 71 of file handler.c.

◆ TXT_PLAIN

#define TXT_PLAIN   2

Definition at line 72 of file handler.c.

◆ TXT_ENRICHED

#define TXT_ENRICHED   3

Definition at line 73 of file handler.c.

Typedef Documentation

◆ handler_t

typedef int(* handler_t) (struct Body *b_email, struct State *state)

Definition at line 85 of file handler.c.

Function Documentation

◆ print_part_line()

static void print_part_line ( struct State state,
struct Body b_email,
int  n 
)
static

Print a separator for the Mime part.

Parameters
stateState of text being processed
b_emailBody of the email
nPart number for multipart emails (0 otherwise)

Definition at line 93 of file handler.c.

94{
95 char length[5] = { 0 };
96 mutt_str_pretty_size(length, sizeof(length), b_email->length);
97 state_mark_attach(state);
98 char *charset = mutt_param_get(&b_email->parameter, "charset");
99 if (n == 0)
100 {
101 state_printf(state, _("[-- Type: %s/%s%s%s, Encoding: %s, Size: %s --]\n"),
102 TYPE(b_email), b_email->subtype, charset ? "; charset=" : "",
103 charset ? charset : "", ENCODING(b_email->encoding), length);
104 }
105 else
106 {
107 state_printf(state, _("[-- Alternative Type #%d: %s/%s%s%s, Encoding: %s, Size: %s --]\n"),
108 n, TYPE(b_email), b_email->subtype, charset ? "; charset=" : "",
109 charset ? charset : "", ENCODING(b_email->encoding), length);
110 }
111}
#define ENCODING(x)
Definition: mime.h:92
#define TYPE(body)
Definition: mime.h:89
#define _(a)
Definition: message.h:28
void state_mark_attach(struct State *state)
Write a unique marker around content.
Definition: state.c:73
int state_printf(struct State *state, const char *fmt,...)
Write a formatted string to the State.
Definition: state.c:187
void mutt_str_pretty_size(char *buf, size_t buflen, size_t num)
Display an abbreviated size, like 3.4K.
Definition: muttlib.c:1004
char * mutt_param_get(const struct ParameterList *pl, const char *s)
Find a matching Parameter.
Definition: parameter.c:85
LOFF_T length
length (in bytes) of attachment
Definition: body.h:53
struct ParameterList parameter
Parameters of the content-type.
Definition: body.h:63
char * subtype
content-type subtype
Definition: body.h:61
unsigned int encoding
content-transfer-encoding, ContentEncoding
Definition: body.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ convert_to_state()

static void convert_to_state ( iconv_t  cd,
char *  bufi,
size_t *  l,
struct State state 
)
static

Convert text and write it to a file.

Parameters
cdIconv conversion descriptor
bufiBuffer with text to convert
lLength of buffer
stateState to write to

Definition at line 120 of file handler.c.

121{
122 char bufo[BUFO_SIZE] = { 0 };
123 const char *ib = NULL;
124 char *ob = NULL;
125 size_t ibl, obl;
126
127 if (!bufi)
128 {
129 if (iconv_t_valid(cd))
130 {
131 ob = bufo;
132 obl = sizeof(bufo);
133 iconv(cd, NULL, NULL, &ob, &obl);
134 if (ob != bufo)
135 state_prefix_put(state, bufo, ob - bufo);
136 }
137 return;
138 }
139
140 if (!iconv_t_valid(cd))
141 {
142 state_prefix_put(state, bufi, *l);
143 *l = 0;
144 return;
145 }
146
147 ib = bufi;
148 ibl = *l;
149 while (true)
150 {
151 ob = bufo;
152 obl = sizeof(bufo);
153 mutt_ch_iconv(cd, &ib, &ibl, &ob, &obl, 0, "?", NULL);
154 if (ob == bufo)
155 break;
156 state_prefix_put(state, bufo, ob - bufo);
157 }
158 memmove(bufi, ib, ibl);
159 *l = ibl;
160}
#define BUFO_SIZE
Definition: handler.c:69
size_t mutt_ch_iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft, const char **inrepls, const char *outrepl, int *iconverrno)
Change the encoding of a string.
Definition: charset.c:697
static bool iconv_t_valid(const iconv_t cd)
Is the conversion descriptor valid?
Definition: charset.h:105
void state_prefix_put(struct State *state, const char *buf, size_t buflen)
Write a prefixed fixed-string to the State.
Definition: state.c:205
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ decode_xbit()

static void decode_xbit ( struct State state,
long  len,
bool  istext,
iconv_t  cd 
)
static

Decode xbit-encoded text.

Parameters
stateState to work with
lenLength of text to decode
istextMime part is plain text
cdIconv conversion descriptor

Definition at line 169 of file handler.c.

170{
171 if (!istext)
172 {
173 mutt_file_copy_bytes(state->fp_in, state->fp_out, len);
174 return;
175 }
176
177 state_set_prefix(state);
178
179 int c;
180 char bufi[BUFI_SIZE] = { 0 };
181 size_t l = 0;
182 while (((c = fgetc(state->fp_in)) != EOF) && len--)
183 {
184 if ((c == '\r') && len)
185 {
186 const int ch = fgetc(state->fp_in);
187 if (ch == '\n')
188 {
189 c = ch;
190 len--;
191 }
192 else
193 {
194 ungetc(ch, state->fp_in);
195 }
196 }
197
198 bufi[l++] = c;
199 if (l == sizeof(bufi))
200 convert_to_state(cd, bufi, &l, state);
201 }
202
203 convert_to_state(cd, bufi, &l, state);
204 convert_to_state(cd, 0, 0, state);
205
206 state_reset_prefix(state);
207}
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:257
#define BUFI_SIZE
Definition: handler.c:68
static void convert_to_state(iconv_t cd, char *bufi, size_t *l, struct State *state)
Convert text and write it to a file.
Definition: handler.c:120
#define state_set_prefix(state)
Definition: state.h:56
#define state_reset_prefix(state)
Definition: state.h:57
FILE * fp_out
File to write to.
Definition: state.h:50
FILE * fp_in
File to read from.
Definition: state.h:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ qp_decode_triple()

static int qp_decode_triple ( char *  s,
char *  d 
)
static

Decode a quoted-printable triplet.

Parameters
sState to work with
dDecoded character
Return values
0Success
-1Error

Definition at line 216 of file handler.c.

217{
218 /* soft line break */
219 if ((s[0] == '=') && (s[1] == '\0'))
220 return 1;
221
222 /* quoted-printable triple */
223 if ((s[0] == '=') && isxdigit((unsigned char) s[1]) && isxdigit((unsigned char) s[2]))
224 {
225 *d = (hexval(s[1]) << 4) | hexval(s[2]);
226 return 0;
227 }
228
229 /* something else */
230 return -1;
231}
#define hexval(ch)
Definition: mime.h:80
+ Here is the caller graph for this function:

◆ qp_decode_line()

static void qp_decode_line ( char *  dest,
char *  src,
size_t *  l,
int  last 
)
static

Decode a line of quoted-printable text.

Parameters
destBuffer for result
srcText to decode
lBytes written to buffer
lastLast character of the line

Definition at line 240 of file handler.c.

241{
242 char *d = NULL, *s = NULL;
243 char c = 0;
244
245 int kind = -1;
246 bool soft = false;
247
248 /* decode the line */
249
250 for (d = dest, s = src; *s;)
251 {
252 switch ((kind = qp_decode_triple(s, &c)))
253 {
254 case 0:
255 *d++ = c;
256 s += 3;
257 break; /* qp triple */
258 case -1:
259 *d++ = *s++;
260 break; /* single character */
261 case 1:
262 soft = true;
263 s++;
264 break; /* soft line break */
265 }
266 }
267
268 if (!soft && (last == '\n'))
269 {
270 /* neither \r nor \n as part of line-terminating CRLF
271 * may be qp-encoded, so remove \r and \n-terminate;
272 * see RFC2045, sect. 6.7, (1): General 8bit representation */
273 if ((kind == 0) && (c == '\r'))
274 *(d - 1) = '\n';
275 else
276 *d++ = '\n';
277 }
278
279 *d = '\0';
280 *l = d - dest;
281}
static int qp_decode_triple(char *s, char *d)
Decode a quoted-printable triplet.
Definition: handler.c:216
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ decode_quoted()

static void decode_quoted ( struct State state,
long  len,
bool  istext,
iconv_t  cd 
)
static

Decode an attachment encoded with quoted-printable.

Parameters
stateState to work with
lenLength of text to decode
istextMime part is plain text
cdIconv conversion descriptor

Why doesn't this overflow any buffers? First, it's guaranteed that the length of a line grows when you en-code it to quoted-printable. That means that we always can store the result in a buffer of at most the same size.

Now, we don't special-case if the line we read with fgets() isn't terminated. We don't care about this, since 256 > 78, so corrupted input will just be corrupted a bit more. That implies that 256+1 bytes are always sufficient to store the result of qp_decode_line.

Finally, at soft line breaks, some part of a multibyte character may have been left over by convert_to_state(). This shouldn't be more than 6 characters, so 256+7 should be sufficient memory to store the decoded data.

Just to make sure that I didn't make some off-by-one error above, we just use 512 for the target buffer's size.

Definition at line 308 of file handler.c.

309{
310 char line[256] = { 0 };
311 char decline[512] = { 0 };
312 size_t l = 0;
313 size_t l3;
314
315 if (istext)
316 state_set_prefix(state);
317
318 while (len > 0)
319 {
320 /* It's ok to use a fixed size buffer for input, even if the line turns
321 * out to be longer than this. Just process the line in chunks. This
322 * really shouldn't happen according the MIME spec, since Q-P encoded
323 * lines are at most 76 characters, but we should be liberal about what
324 * we accept. */
325 if (!fgets(line, MIN((ssize_t) sizeof(line), len + 1), state->fp_in))
326 break;
327
328 size_t linelen = strlen(line);
329 len -= linelen;
330
331 /* inspect the last character we read so we can tell if we got the
332 * entire line. */
333 const int last = (linelen != 0) ? line[linelen - 1] : 0;
334
335 /* chop trailing whitespace if we got the full line */
336 if (last == '\n')
337 {
338 while ((linelen > 0) && isspace(line[linelen - 1]))
339 linelen--;
340 line[linelen] = '\0';
341 }
342
343 /* decode and do character set conversion */
344 qp_decode_line(decline + l, line, &l3, last);
345 l += l3;
346 convert_to_state(cd, decline, &l, state);
347 }
348
349 convert_to_state(cd, 0, 0, state);
350 state_reset_prefix(state);
351}
static void qp_decode_line(char *dest, char *src, size_t *l, int last)
Decode a line of quoted-printable text.
Definition: handler.c:240
#define MIN(a, b)
Definition: memory.h:32
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ decode_byte()

static unsigned char decode_byte ( char  ch)
static

Decode a uuencoded byte.

Parameters
chCharacter to decode
Return values
numDecoded value

Definition at line 358 of file handler.c.

359{
360 if ((ch < 32) || (ch > 95))
361 return 0;
362 return ch - 32;
363}
+ Here is the caller graph for this function:

◆ decode_uuencoded()

static void decode_uuencoded ( struct State state,
long  len,
bool  istext,
iconv_t  cd 
)
static

Decode uuencoded text.

Parameters
stateState to work with
lenLength of text to decode
istextMime part is plain text
cdIconv conversion descriptor

Definition at line 372 of file handler.c.

373{
374 char tmps[128] = { 0 };
375 char *pt = NULL;
376 char bufi[BUFI_SIZE] = { 0 };
377 size_t k = 0;
378
379 if (istext)
380 state_set_prefix(state);
381
382 while (len > 0)
383 {
384 if (!fgets(tmps, sizeof(tmps), state->fp_in))
385 goto cleanup;
386 len -= mutt_str_len(tmps);
387 if (mutt_str_startswith(tmps, "begin "))
388 break;
389 }
390 while (len > 0)
391 {
392 if (!fgets(tmps, sizeof(tmps), state->fp_in))
393 goto cleanup;
394 len -= mutt_str_len(tmps);
395 if (mutt_str_startswith(tmps, "end"))
396 break;
397 pt = tmps;
398 const unsigned char linelen = decode_byte(*pt);
399 pt++;
400 for (unsigned char c = 0; (c < linelen) && *pt;)
401 {
402 for (char l = 2; (l <= 6) && pt[0] && pt[1]; l += 2)
403 {
404 char out = decode_byte(*pt) << l;
405 pt++;
406 out |= (decode_byte(*pt) >> (6 - l));
407 bufi[k++] = out;
408 c++;
409 if (c == linelen)
410 break;
411 }
412 convert_to_state(cd, bufi, &k, state);
413 pt++;
414 }
415 }
416
417cleanup:
418 convert_to_state(cd, bufi, &k, state);
419 convert_to_state(cd, 0, 0, state);
420
421 state_reset_prefix(state);
422}
static unsigned char decode_byte(char ch)
Decode a uuencoded byte.
Definition: handler.c:358
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:230
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:496
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_mmnoask()

static bool is_mmnoask ( const char *  buf)
static

Metamail compatibility: should the attachment be autoviewed?

Parameters
bufMime type, e.g. 'text/plain'
Return values
trueMetamail "no ask" is true

Test if the MM_NOASK environment variable should allow autoviewing of the attachment.

Note
If MM_NOASK=1 then the function will automatically return true.

Definition at line 434 of file handler.c.

435{
436 const char *val = mutt_str_getenv("MM_NOASK");
437 if (!val)
438 return false;
439
440 char *p = NULL;
441 char tmp[1024] = { 0 };
442 char *q = NULL;
443
444 if (mutt_str_equal(val, "1"))
445 return true;
446
447 mutt_str_copy(tmp, val, sizeof(tmp));
448 p = tmp;
449
450 while ((p = strtok(p, ",")))
451 {
452 q = strrchr(p, '/');
453 if (q)
454 {
455 if (q[1] == '*')
456 {
457 if (mutt_istrn_equal(buf, p, q - p))
458 return true;
459 }
460 else
461 {
462 if (mutt_istr_equal(buf, p))
463 return true;
464 }
465 }
466 else
467 {
468 const size_t plen = mutt_istr_startswith(buf, p);
469 if ((plen != 0) && (buf[plen] == '/'))
470 return true;
471 }
472
473 p = NULL;
474 }
475
476 return false;
477}
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:672
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
const char * mutt_str_getenv(const char *name)
Get an environment variable.
Definition: string.c:726
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:581
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:242
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:453
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_autoview()

static bool is_autoview ( struct Body b)
static

Should email body be filtered by mailcap.

Parameters
bBody of the email
Return values
1body part should be filtered by a mailcap entry prior to viewing inline
0otherwise

Definition at line 485 of file handler.c.

486{
487 char type[256] = { 0 };
488 bool is_av = false;
489
490 snprintf(type, sizeof(type), "%s/%s", TYPE(b), b->subtype);
491
492 const bool c_implicit_auto_view = cs_subset_bool(NeoMutt->sub, "implicit_auto_view");
493 if (c_implicit_auto_view)
494 {
495 /* $implicit_auto_view is essentially the same as "auto_view *" */
496 is_av = true;
497 }
498 else
499 {
500 /* determine if this type is on the user's auto_view list */
501 mutt_check_lookup_list(b, type, sizeof(type));
502 struct ListNode *np = NULL;
503 STAILQ_FOREACH(np, &AutoViewList, entries)
504 {
505 int i = mutt_str_len(np->data);
506 i--;
507 if (((i > 0) && (np->data[i - 1] == '/') && (np->data[i] == '*') &&
508 mutt_istrn_equal(type, np->data, i)) ||
509 mutt_istr_equal(type, np->data))
510 {
511 is_av = true;
512 break;
513 }
514 }
515
516 if (is_mmnoask(type))
517 is_av = true;
518 }
519
520 /* determine if there is a mailcap entry suitable for auto_view
521 *
522 * @warning type is altered by this call as a result of 'mime_lookup' support */
523 if (is_av)
524 return mailcap_lookup(b, type, sizeof(type), NULL, MUTT_MC_AUTOVIEW);
525
526 return false;
527}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
struct ListHead AutoViewList
List of mime types to auto view.
Definition: globals.c:48
static bool is_mmnoask(const char *buf)
Metamail compatibility: should the attachment be autoviewed?
Definition: handler.c:434
bool mailcap_lookup(struct Body *b, char *type, size_t typelen, struct MailcapEntry *entry, enum MailcapLookup opt)
Find given type in the list of mailcap files.
Definition: mailcap.c:483
@ MUTT_MC_AUTOVIEW
Mailcap autoview field.
Definition: mailcap.h:61
void mutt_check_lookup_list(struct Body *b, char *type, size_t len)
Update the mime type.
Definition: mutt_attach.c:343
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
A List node for strings.
Definition: list.h:37
char * data
String.
Definition: list.h:38
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ run_decode_and_handler()

static int run_decode_and_handler ( struct Body b,
struct State state,
handler_t  handler,
bool  plaintext 
)
static

Run an appropriate decoder for an email.

Parameters
bBody of the email
stateState to work with
handlerCallback function to process the content - Implements handler_t
plaintextIs the content in plain text
Return values
0Success
-1Error

Definition at line 1327 of file handler.c.

1329{
1330 const char *save_prefix = NULL;
1331 FILE *fp = NULL;
1332 size_t tmplength = 0;
1333 LOFF_T tmpoffset = 0;
1334 int decode = 0;
1335 int rc = 0;
1336#ifndef USE_FMEMOPEN
1337 struct Buffer *tempfile = NULL;
1338#endif
1339
1340 if (!mutt_file_seek(state->fp_in, b->offset, SEEK_SET))
1341 {
1342 return -1;
1343 }
1344
1345#ifdef USE_FMEMOPEN
1346 char *temp = NULL;
1347 size_t tempsize = 0;
1348#endif
1349
1350 /* see if we need to decode this part before processing it */
1351 if ((b->encoding == ENC_BASE64) || (b->encoding == ENC_QUOTED_PRINTABLE) ||
1352 (b->encoding == ENC_UUENCODED) || (plaintext || mutt_is_text_part(b)))
1353 /* text subtypes may require character set conversion even with 8bit encoding */
1354 {
1355 const int orig_type = b->type;
1356 if (plaintext)
1357 {
1358 b->type = TYPE_TEXT;
1359 }
1360 else
1361 {
1362 /* decode to a tempfile, saving the original destination */
1363 fp = state->fp_out;
1364#ifdef USE_FMEMOPEN
1365 state->fp_out = open_memstream(&temp, &tempsize);
1366 if (!state->fp_out)
1367 {
1368 mutt_error(_("Unable to open 'memory stream'"));
1369 mutt_debug(LL_DEBUG1, "Can't open 'memory stream'\n");
1370 return -1;
1371 }
1372#else
1373 tempfile = buf_pool_get();
1374 buf_mktemp(tempfile);
1375 state->fp_out = mutt_file_fopen(buf_string(tempfile), "w");
1376 if (!state->fp_out)
1377 {
1378 mutt_error(_("Unable to open temporary file"));
1379 mutt_debug(LL_DEBUG1, "Can't open %s\n", buf_string(tempfile));
1380 buf_pool_release(&tempfile);
1381 return -1;
1382 }
1383#endif
1384 /* decoding the attachment changes the size and offset, so save a copy
1385 * of the "real" values now, and restore them after processing */
1386 tmplength = b->length;
1387 tmpoffset = b->offset;
1388
1389 /* if we are decoding binary bodies, we don't want to prefix each
1390 * line with the prefix or else the data will get corrupted. */
1391 save_prefix = state->prefix;
1392 state->prefix = NULL;
1393
1394 decode = 1;
1395 }
1396
1397 mutt_decode_attachment(b, state);
1398
1399 if (decode)
1400 {
1401 b->length = ftello(state->fp_out);
1402 b->offset = 0;
1403#ifdef USE_FMEMOPEN
1404 /* When running under torify, mutt_file_fclose(&state->fp_out) does not seem to
1405 * update tempsize. On the other hand, fflush does. See
1406 * https://github.com/neomutt/neomutt/issues/440 */
1407 fflush(state->fp_out);
1408#endif
1409 mutt_file_fclose(&state->fp_out);
1410
1411 /* restore final destination and substitute the tempfile for input */
1412 state->fp_out = fp;
1413 fp = state->fp_in;
1414#ifdef USE_FMEMOPEN
1415 if (tempsize)
1416 {
1417 state->fp_in = fmemopen(temp, tempsize, "r");
1418 }
1419 else
1420 { /* fmemopen can't handle zero-length buffers */
1421 state->fp_in = mutt_file_fopen("/dev/null", "r");
1422 }
1423 if (!state->fp_in)
1424 {
1425 mutt_perror(_("failed to re-open 'memory stream'"));
1426 FREE(&temp);
1427 return -1;
1428 }
1429#else
1430 state->fp_in = mutt_file_fopen(buf_string(tempfile), "r");
1431 unlink(buf_string(tempfile));
1432 buf_pool_release(&tempfile);
1433#endif
1434 /* restore the prefix */
1435 state->prefix = save_prefix;
1436 }
1437
1438 b->type = orig_type;
1439 }
1440
1441 /* process the (decoded) body part */
1442 if (handler)
1443 {
1444 rc = handler(b, state);
1445 if (rc != 0)
1446 {
1447 mutt_debug(LL_DEBUG1, "Failed on attachment of type %s/%s\n", TYPE(b),
1448 NONULL(b->subtype));
1449 }
1450
1451 if (decode)
1452 {
1453 b->length = tmplength;
1454 b->offset = tmpoffset;
1455
1456 /* restore the original source stream */
1457 mutt_file_fclose(&state->fp_in);
1458 state->fp_in = fp;
1459 }
1460 }
1461 state->flags |= STATE_FIRSTDONE;
1462#ifdef USE_FMEMOPEN
1463 FREE(&temp);
1464#endif
1465
1466 return rc;
1467}
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
bool mutt_file_seek(FILE *fp, LOFF_T offset, int whence)
Wrapper for fseeko with error handling.
Definition: file.c:778
#define mutt_file_fclose(FP)
Definition: file.h:138
#define mutt_file_fopen(PATH, MODE)
Definition: file.h:137
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
#define mutt_perror(...)
Definition: logging2.h:93
void mutt_decode_attachment(const struct Body *b, struct State *state)
Decode an email's attachment.
Definition: handler.c:1906
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
#define FREE(x)
Definition: memory.h:55
@ ENC_UUENCODED
UUEncoded text.
Definition: mime.h:54
@ ENC_BASE64
Base-64 encoded text.
Definition: mime.h:52
@ ENC_QUOTED_PRINTABLE
Quoted-printable text.
Definition: mime.h:51
@ TYPE_TEXT
Type: 'text/*'.
Definition: mime.h:38
#define STATE_FIRSTDONE
The first attachment has been done.
Definition: state.h:40
bool mutt_is_text_part(const struct Body *b)
Is this part of an email in plain text?
Definition: muttlib.c:407
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:96
#define NONULL(x)
Definition: string2.h:37
LOFF_T offset
offset where the actual data begins
Definition: body.h:52
unsigned int type
content-type primary type, ContentType
Definition: body.h:40
String manipulation buffer.
Definition: buffer.h:36
StateFlags flags
Flags, e.g. STATE_DISPLAY.
Definition: state.h:52
const char * prefix
String to add to the beginning of each output line.
Definition: state.h:51
#define buf_mktemp(buf)
Definition: tmp.h:33
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_decode_base64()

void mutt_decode_base64 ( struct State state,
size_t  len,
bool  istext,
iconv_t  cd 
)

Decode base64-encoded text.

Parameters
stateState to work with
lenLength of text to decode
istextMime part is plain text
cdIconv conversion descriptor

Definition at line 1533 of file handler.c.

1534{
1535 char buf[5] = { 0 };
1536 int ch, i;
1537 bool cr = false;
1538 char bufi[BUFI_SIZE] = { 0 };
1539 size_t l = 0;
1540
1541 buf[4] = '\0';
1542
1543 if (istext)
1544 state_set_prefix(state);
1545
1546 while (len > 0)
1547 {
1548 for (i = 0; (i < 4) && (len > 0); len--)
1549 {
1550 ch = fgetc(state->fp_in);
1551 if (ch == EOF)
1552 break;
1553 if ((ch >= 0) && (ch < 128) && ((base64val(ch) != -1) || (ch == '=')))
1554 buf[i++] = ch;
1555 }
1556 if (i != 4)
1557 {
1558 /* "i" may be zero if there is trailing whitespace, which is not an error */
1559 if (i != 0)
1560 mutt_debug(LL_DEBUG2, "didn't get a multiple of 4 chars\n");
1561 break;
1562 }
1563
1564 const int c1 = base64val(buf[0]);
1565 const int c2 = base64val(buf[1]);
1566
1567 /* first char */
1568 ch = (c1 << 2) | (c2 >> 4);
1569
1570 if (cr && (ch != '\n'))
1571 bufi[l++] = '\r';
1572
1573 cr = false;
1574
1575 if (istext && (ch == '\r'))
1576 cr = true;
1577 else
1578 bufi[l++] = ch;
1579
1580 /* second char */
1581 if (buf[2] == '=')
1582 break;
1583 const int c3 = base64val(buf[2]);
1584 ch = ((c2 & 0xf) << 4) | (c3 >> 2);
1585
1586 if (cr && (ch != '\n'))
1587 bufi[l++] = '\r';
1588
1589 cr = false;
1590
1591 if (istext && (ch == '\r'))
1592 cr = true;
1593 else
1594 bufi[l++] = ch;
1595
1596 /* third char */
1597 if (buf[3] == '=')
1598 break;
1599 const int c4 = base64val(buf[3]);
1600 ch = ((c3 & 0x3) << 6) | c4;
1601
1602 if (cr && (ch != '\n'))
1603 bufi[l++] = '\r';
1604
1605 cr = false;
1606
1607 if (istext && (ch == '\r'))
1608 cr = true;
1609 else
1610 bufi[l++] = ch;
1611
1612 if ((l + 8) >= sizeof(bufi))
1613 convert_to_state(cd, bufi, &l, state);
1614 }
1615
1616 if (cr)
1617 bufi[l++] = '\r';
1618
1619 convert_to_state(cd, bufi, &l, state);
1620 convert_to_state(cd, 0, 0, state);
1621
1622 state_reset_prefix(state);
1623}
#define base64val(ch)
Definition: base64.h:32
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_body_handler()

int mutt_body_handler ( struct Body b,
struct State state 
)

Handler for the Body of an email.

Parameters
bBody of the email
stateState to work with
Return values
0Success
-1Error

Definition at line 1632 of file handler.c.

1633{
1634 if (!b || !state)
1635 return -1;
1636
1637 bool plaintext = false;
1638 handler_t handler = NULL;
1639 handler_t encrypted_handler = NULL;
1640 int rc = 0;
1641 static unsigned short recurse_level = 0;
1642
1643 const int oflags = state->flags;
1644 const bool is_attachment_display = (oflags & STATE_DISPLAY_ATTACH);
1645
1646 if (recurse_level >= MUTT_MIME_MAX_DEPTH)
1647 {
1648 mutt_debug(LL_DEBUG1, "recurse level too deep. giving up\n");
1649 return 1;
1650 }
1651 recurse_level++;
1652
1653 /* first determine which handler to use to process this part */
1654
1655 if (is_autoview(b))
1656 {
1657 handler = autoview_handler;
1658 state->flags &= ~STATE_CHARCONV;
1659 }
1660 else if (b->type == TYPE_TEXT)
1661 {
1662 if (mutt_istr_equal("plain", b->subtype))
1663 {
1664 const bool c_reflow_text = cs_subset_bool(NeoMutt->sub, "reflow_text");
1665 /* avoid copying this part twice since removing the transfer-encoding is
1666 * the only operation needed. */
1668 {
1669 encrypted_handler = crypt_pgp_application_handler;
1670 handler = encrypted_handler;
1671 }
1672 else if (c_reflow_text &&
1673 mutt_istr_equal("flowed", mutt_param_get(&b->parameter, "format")))
1674 {
1675 handler = rfc3676_handler;
1676 }
1677 else
1678 {
1679 handler = text_plain_handler;
1680 }
1681 }
1682 else if (mutt_istr_equal("enriched", b->subtype))
1683 {
1684 handler = text_enriched_handler;
1685 }
1686 else /* text body type without a handler */
1687 {
1688 plaintext = false;
1689 }
1690 }
1691 else if (b->type == TYPE_MESSAGE)
1692 {
1693 if (mutt_is_message_type(b->type, b->subtype))
1694 handler = message_handler;
1695 else if (mutt_istr_equal("delivery-status", b->subtype))
1696 plaintext = true;
1697 else if (mutt_istr_equal("external-body", b->subtype))
1698 handler = external_body_handler;
1699 }
1700 else if (b->type == TYPE_MULTIPART)
1701 {
1702 const char *const c_show_multipart_alternative = cs_subset_string(NeoMutt->sub, "show_multipart_alternative");
1703 if (!mutt_str_equal("inline", c_show_multipart_alternative) &&
1704 mutt_istr_equal("alternative", b->subtype))
1705 {
1706 handler = alternative_handler;
1707 }
1708 else if (!mutt_str_equal("inline", c_show_multipart_alternative) &&
1709 mutt_istr_equal("multilingual", b->subtype))
1710 {
1711 handler = multilingual_handler;
1712 }
1713 else if ((WithCrypto != 0) && mutt_istr_equal("signed", b->subtype))
1714 {
1715 if (!mutt_param_get(&b->parameter, "protocol"))
1716 mutt_error(_("Error: multipart/signed has no protocol"));
1717 else if (state->flags & STATE_VERIFY)
1718 handler = mutt_signed_handler;
1719 }
1721 {
1722 encrypted_handler = valid_pgp_encrypted_handler;
1723 handler = encrypted_handler;
1724 }
1726 {
1727 encrypted_handler = malformed_pgp_encrypted_handler;
1728 handler = encrypted_handler;
1729 }
1730
1731 if (!handler)
1732 handler = multipart_handler;
1733
1734 if ((b->encoding != ENC_7BIT) && (b->encoding != ENC_8BIT) && (b->encoding != ENC_BINARY))
1735 {
1736 mutt_debug(LL_DEBUG1, "Bad encoding type %d for multipart entity, assuming 7 bit\n",
1737 b->encoding);
1738 b->encoding = ENC_7BIT;
1739 }
1740 }
1741 else if ((WithCrypto != 0) && (b->type == TYPE_APPLICATION))
1742 {
1743 if (OptDontHandlePgpKeys && mutt_istr_equal("pgp-keys", b->subtype))
1744 {
1745 /* pass raw part through for key extraction */
1746 plaintext = true;
1747 }
1748 else if (((WithCrypto & APPLICATION_PGP) != 0) && mutt_is_application_pgp(b))
1749 {
1750 encrypted_handler = crypt_pgp_application_handler;
1751 handler = encrypted_handler;
1752 }
1753 else if (((WithCrypto & APPLICATION_SMIME) != 0) && mutt_is_application_smime(b))
1754 {
1755 encrypted_handler = crypt_smime_application_handler;
1756 handler = encrypted_handler;
1757 }
1758 }
1759
1760 if ((plaintext || handler) && (is_attachment_display || !mutt_prefer_as_attachment(b)))
1761 {
1762 /* only respect disposition == attachment if we're not
1763 * displaying from the attachment menu (i.e. pager) */
1764 /* Prevent encrypted attachments from being included in replies
1765 * unless $include_encrypted is set. */
1766 const bool c_include_encrypted = cs_subset_bool(NeoMutt->sub, "include_encrypted");
1767 if ((state->flags & STATE_REPLYING) && (state->flags & STATE_FIRSTDONE) &&
1768 encrypted_handler && !c_include_encrypted)
1769 {
1770 goto cleanup;
1771 }
1772
1773 rc = run_decode_and_handler(b, state, handler, plaintext);
1774 }
1775 else if (state->flags & STATE_DISPLAY)
1776 {
1777 /* print hint to use attachment menu for disposition == attachment
1778 * if we're not already being called from there */
1779 const bool c_honor_disposition = cs_subset_bool(NeoMutt->sub, "honor_disposition");
1780 struct Buffer *msg = buf_pool_get();
1781
1782 if (is_attachment_display)
1783 {
1784 if (c_honor_disposition && (b->disposition == DISP_ATTACH))
1785 {
1786 buf_strcpy(msg, _("[-- This is an attachment --]\n"));
1787 }
1788 else
1789 {
1790 /* L10N: %s/%s is a MIME type, e.g. "text/plain". */
1791 buf_printf(msg, _("[-- %s/%s is unsupported --]\n"), TYPE(b), b->subtype);
1792 }
1793 }
1794 else
1795 {
1796 char keystroke[128] = { 0 };
1797 if (km_expand_key(keystroke, sizeof(keystroke),
1798 km_find_func(MENU_PAGER, OP_VIEW_ATTACHMENTS)))
1799 {
1800 if (c_honor_disposition && (b->disposition == DISP_ATTACH))
1801 {
1802 /* L10N: %s expands to a keystroke/key binding, e.g. 'v'. */
1803 buf_printf(msg, _("[-- This is an attachment (use '%s' to view this part) --]\n"),
1804 keystroke);
1805 }
1806 else
1807 {
1808 /* L10N: %s/%s is a MIME type, e.g. "text/plain".
1809 The last %s expands to a keystroke/key binding, e.g. 'v'. */
1810 buf_printf(msg, _("[-- %s/%s is unsupported (use '%s' to view this part) --]\n"),
1811 TYPE(b), b->subtype, keystroke);
1812 }
1813 }
1814 else
1815 {
1816 if (c_honor_disposition && (b->disposition == DISP_ATTACH))
1817 {
1818 buf_strcpy(msg, _("[-- This is an attachment (need 'view-attachments' bound to key) --]\n"));
1819 }
1820 else
1821 {
1822 /* L10N: %s/%s is a MIME type, e.g. "text/plain". */
1823 buf_printf(msg, _("[-- %s/%s is unsupported (need 'view-attachments' bound to key) --]\n"),
1824 TYPE(b), b->subtype);
1825 }
1826 }
1827 }
1828 state_mark_attach(state);
1829 state_printf(state, "%s", buf_string(msg));
1830 buf_pool_release(&msg);
1831 }
1832
1833cleanup:
1834 recurse_level--;
1835 state->flags = oflags | (state->flags & STATE_FIRSTDONE);
1836 if (rc != 0)
1837 {
1838 mutt_debug(LL_DEBUG1, "Bailing on attachment of type %s/%s\n", TYPE(b),
1839 NONULL(b->subtype));
1840 }
1841
1842 return rc;
1843}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:161
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:395
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:291
SecurityFlags mutt_is_application_smime(struct Body *b)
Does the message use S/MIME?
Definition: crypt.c:609
int mutt_is_valid_multipart_pgp_encrypted(struct Body *b)
Is this a valid multi-part encrypted message?
Definition: crypt.c:467
SecurityFlags mutt_is_malformed_multipart_pgp_encrypted(struct Body *b)
Check for malformed layout.
Definition: crypt.c:504
SecurityFlags mutt_is_application_pgp(const struct Body *b)
Does the message use PGP?
Definition: crypt.c:548
bool mutt_is_message_type(int type, const char *subtype)
Determine if a mime type matches a message or not.
Definition: parse.c:1498
bool OptDontHandlePgpKeys
(pseudo) used to extract PGP keys
Definition: globals.c:61
int crypt_pgp_application_handler(struct Body *b_email, struct State *state)
Wrapper for CryptModuleSpecs::application_handler() - Implements handler_t -.
Definition: cryptglue.c:236
static int alternative_handler(struct Body *b_email, struct State *state)
Handler for multipart alternative emails - Implements handler_t -.
Definition: handler.c:942
int text_enriched_handler(struct Body *b_email, struct State *state)
Handler for enriched text - Implements handler_t -.
Definition: enriched.c:469
static int text_plain_handler(struct Body *b_email, struct State *state)
Handler for plain text - Implements handler_t -.
Definition: handler.c:685
int crypt_smime_application_handler(struct Body *b_email, struct State *state)
Wrapper for CryptModuleSpecs::application_handler() - Implements handler_t -.
Definition: cryptglue.c:443
static int autoview_handler(struct Body *b_email, struct State *state)
Handler for autoviewable attachments - Implements handler_t -.
Definition: handler.c:532
static int external_body_handler(struct Body *b_email, struct State *state)
Handler for external-body emails - Implements handler_t -.
Definition: handler.c:770
int rfc3676_handler(struct Body *b_email, struct State *state)
Handler for format=flowed - Implements handler_t -.
Definition: rfc3676.c:323
static int malformed_pgp_encrypted_handler(struct Body *b_email, struct State *state)
Handler for invalid pgp-encrypted emails - Implements handler_t -.
Definition: handler.c:1501
static int valid_pgp_encrypted_handler(struct Body *b_email, struct State *state)
Handler for valid pgp-encrypted emails - Implements handler_t -.
Definition: handler.c:1472
static int message_handler(struct Body *b_email, struct State *state)
Handler for message/rfc822 body parts - Implements handler_t -.
Definition: handler.c:712
static int multipart_handler(struct Body *b_email, struct State *state)
Handler for multipart emails - Implements handler_t -.
Definition: handler.c:1238
static int multilingual_handler(struct Body *b_email, struct State *state)
Handler for multi-lingual emails - Implements handler_t -.
Definition: handler.c:1130
int mutt_signed_handler(struct Body *b_email, struct State *state)
Handler for "multipart/signed" - Implements handler_t -.
Definition: crypt.c:1243
static bool is_autoview(struct Body *b)
Should email body be filtered by mailcap.
Definition: handler.c:485
bool mutt_prefer_as_attachment(struct Body *b)
Do we want this part as an attachment?
Definition: handler.c:1850
int(* handler_t)(struct Body *b_email, struct State *state)
Definition: handler.c:85
static int run_decode_and_handler(struct Body *b, struct State *state, handler_t handler, bool plaintext)
Run an appropriate decoder for an email.
Definition: handler.c:1327
struct Keymap * km_find_func(enum MenuType mtype, int func)
Find a function's mapping in a Menu.
Definition: lib.c:509
int km_expand_key(char *s, size_t len, struct Keymap *map)
Get the key string bound to a Keymap.
Definition: lib.c:457
@ ENC_7BIT
7-bit text
Definition: mime.h:49
@ ENC_BINARY
Binary.
Definition: mime.h:53
@ ENC_8BIT
8-bit text
Definition: mime.h:50
#define MUTT_MIME_MAX_DEPTH
Definition: mime.h:69
@ TYPE_MESSAGE
Type: 'message/*'.
Definition: mime.h:35
@ TYPE_MULTIPART
Type: 'multipart/*'.
Definition: mime.h:37
@ TYPE_APPLICATION
Type: 'application/*'.
Definition: mime.h:33
@ DISP_ATTACH
Content is attached.
Definition: mime.h:63
#define STATE_DISPLAY
Output is displayed to the user.
Definition: state.h:33
#define STATE_DISPLAY_ATTACH
We are displaying an attachment.
Definition: state.h:41
#define STATE_REPLYING
Are we replying?
Definition: state.h:39
#define STATE_VERIFY
Perform signature verification.
Definition: state.h:34
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:96
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:97
#define WithCrypto
Definition: lib.h:122
unsigned int disposition
content-disposition, ContentDisposition
Definition: body.h:42
@ MENU_PAGER
Pager pager (email viewer)
Definition: type.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_prefer_as_attachment()

bool mutt_prefer_as_attachment ( struct Body b)

Do we want this part as an attachment?

Parameters
bBody of email to test
Return values
trueWe want this part as an attachment

Definition at line 1850 of file handler.c.

1851{
1852 if (!mutt_can_decode(b))
1853 return true;
1854
1855 if (b->disposition != DISP_ATTACH)
1856 return false;
1857
1858 return cs_subset_bool(NeoMutt->sub, "honor_disposition");
1859}
bool mutt_can_decode(struct Body *b)
Will decoding the attachment produce any output.
Definition: handler.c:1866
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_can_decode()

bool mutt_can_decode ( struct Body b)

Will decoding the attachment produce any output.

Parameters
bBody of email to test
Return values
trueDecoding the attachment will produce output

Definition at line 1866 of file handler.c.

1867{
1868 if (is_autoview(b))
1869 return true;
1870 if (b->type == TYPE_TEXT)
1871 return true;
1872 if (b->type == TYPE_MESSAGE)
1873 return true;
1874 if (b->type == TYPE_MULTIPART)
1875 {
1876 if (WithCrypto)
1877 {
1878 if (mutt_istr_equal(b->subtype, "signed") || mutt_istr_equal(b->subtype, "encrypted"))
1879 {
1880 return true;
1881 }
1882 }
1883
1884 for (struct Body *part = b->parts; part; part = part->next)
1885 {
1886 if (mutt_can_decode(part))
1887 return true;
1888 }
1889 }
1890 else if ((WithCrypto != 0) && (b->type == TYPE_APPLICATION))
1891 {
1893 return true;
1895 return true;
1896 }
1897
1898 return false;
1899}
The body of an email.
Definition: body.h:36
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:73
struct Body * next
next attachment in the list
Definition: body.h:72
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_decode_attachment()

void mutt_decode_attachment ( const struct Body b,
struct State state 
)

Decode an email's attachment.

Parameters
bBody of the email
stateState of text being processed

Definition at line 1906 of file handler.c.

1907{
1908 int istext = mutt_is_text_part(b) && (b->disposition == DISP_INLINE);
1909 iconv_t cd = ICONV_T_INVALID;
1910
1911 if (!mutt_file_seek(state->fp_in, b->offset, SEEK_SET))
1912 {
1913 return;
1914 }
1915
1916 if (istext && (b->charset || (state->flags & STATE_CHARCONV)))
1917 {
1918 const char *charset = b->charset;
1919 if (!charset)
1920 {
1921 charset = mutt_param_get(&b->parameter, "charset");
1922 if (!charset && !slist_is_empty(cc_assumed_charset()))
1924 }
1925 if (charset && cc_charset())
1927 }
1928
1929 switch (b->encoding)
1930 {
1932 decode_quoted(state, b->length,
1933 istext || (((WithCrypto & APPLICATION_PGP) != 0) &&
1935 cd);
1936 break;
1937 case ENC_BASE64:
1938 mutt_decode_base64(state, b->length,
1939 istext || (((WithCrypto & APPLICATION_PGP) != 0) &&
1941 cd);
1942 break;
1943 case ENC_UUENCODED:
1944 decode_uuencoded(state, b->length,
1945 istext || (((WithCrypto & APPLICATION_PGP) != 0) &&
1947 cd);
1948 break;
1949 default:
1950 decode_xbit(state, b->length,
1951 istext || (((WithCrypto & APPLICATION_PGP) != 0) &&
1953 cd);
1954 break;
1955 }
1956}
const char * cc_charset(void)
Get the cached value of $charset.
Definition: config_cache.c:116
const struct Slist * cc_assumed_charset(void)
Get the cached value of $assumed_charset.
Definition: config_cache.c:101
static void decode_uuencoded(struct State *state, long len, bool istext, iconv_t cd)
Decode uuencoded text.
Definition: handler.c:372
void mutt_decode_base64(struct State *state, size_t len, bool istext, iconv_t cd)
Decode base64-encoded text.
Definition: handler.c:1533
static void decode_quoted(struct State *state, long len, bool istext, iconv_t cd)
Decode an attachment encoded with quoted-printable.
Definition: handler.c:308
static void decode_xbit(struct State *state, long len, bool istext, iconv_t cd)
Decode xbit-encoded text.
Definition: handler.c:169
@ DISP_INLINE
Content is inline.
Definition: mime.h:62
iconv_t mutt_ch_iconv_open(const char *tocode, const char *fromcode, uint8_t flags)
Set up iconv for conversions.
Definition: charset.c:594
const char * mutt_ch_get_default_charset(const struct Slist *const assumed_charset)
Get the default character set.
Definition: charset.c:465
#define MUTT_ICONV_HOOK_FROM
apply charset-hooks to fromcode
Definition: charset.h:65
#define ICONV_T_INVALID
Error value for iconv functions.
Definition: charset.h:93
bool slist_is_empty(const struct Slist *list)
Is the slist empty?
Definition: slist.c:138
#define STATE_CHARCONV
Do character set conversions.
Definition: state.h:37
char * charset
Send mode: charset of attached file as stored on disk.
Definition: body.h:79
+ Here is the call graph for this function:
+ Here is the caller graph for this function: