NeoMutt  2023-05-17-56-ga67199
Teaching an old dog new tricks
DOXYGEN
encrypted_handler()

Manage a PGP or S/MIME encrypted MIME part. More...

+ Collaboration diagram for encrypted_handler():

Functions

int pgp_gpgme_encrypted_handler (struct Body *a, struct State *state)
 Implements CryptModuleSpecs::encrypted_handler() -. More...
 
int pgp_class_encrypted_handler (struct Body *a, struct State *state)
 Implements CryptModuleSpecs::encrypted_handler() -. More...
 

Detailed Description

Manage a PGP or S/MIME encrypted MIME part.

Parameters
mBody of the email
stateState of text being processed
Return values
0Success
-1Error

Function Documentation

◆ pgp_gpgme_encrypted_handler()

int pgp_gpgme_encrypted_handler ( struct Body a,
struct State state 
)

Implements CryptModuleSpecs::encrypted_handler() -.

This handler is passed the application/octet-stream directly. The caller must propagate a->goodsig to its parent.

Definition at line 2661 of file crypt_gpgme.c.

2662{
2663 int is_signed;
2664 int rc = 0;
2665
2666 mutt_debug(LL_DEBUG2, "Entering handler\n");
2667
2668 FILE *fp_out = mutt_file_mkstemp();
2669 if (!fp_out)
2670 {
2671 mutt_perror(_("Can't create temporary file"));
2672 if (state->flags & STATE_DISPLAY)
2673 {
2674 state_attach_puts(state, _("[-- Error: could not create temporary file --]\n"));
2675 }
2676 return -1;
2677 }
2678
2679 struct Body *tattach = decrypt_part(a, state, fp_out, false, &is_signed);
2680 if (tattach)
2681 {
2682 tattach->goodsig = is_signed > 0;
2683
2684 if (state->flags & STATE_DISPLAY)
2685 {
2686 state_attach_puts(state, is_signed ?
2687 _("[-- The following data is PGP/MIME signed and encrypted --]\n\n") :
2688 _("[-- The following data is PGP/MIME encrypted --]\n\n"));
2689 mutt_protected_headers_handler(tattach, state);
2690 }
2691
2692 /* Store any protected headers in the parent so they can be
2693 * accessed for index updates after the handler recursion is done.
2694 * This is done before the handler to prevent a nested encrypted
2695 * handler from freeing the headers. */
2697 a->mime_headers = tattach->mime_headers;
2698 tattach->mime_headers = NULL;
2699
2700 FILE *fp_save = state->fp_in;
2701 state->fp_in = fp_out;
2702 rc = mutt_body_handler(tattach, state);
2703 state->fp_in = fp_save;
2704
2705 /* Embedded multipart signed protected headers override the
2706 * encrypted headers. We need to do this after the handler so
2707 * they can be printed in the pager. */
2708 if (mutt_is_multipart_signed(tattach) && tattach->parts && tattach->parts->mime_headers)
2709 {
2711 a->mime_headers = tattach->parts->mime_headers;
2712 tattach->parts->mime_headers = NULL;
2713 }
2714
2715 /* if a multipart/signed is the _only_ sub-part of a
2716 * multipart/encrypted, cache signature verification
2717 * status. */
2718 if (mutt_is_multipart_signed(tattach) && !tattach->next)
2719 a->goodsig |= tattach->goodsig;
2720
2721 if (state->flags & STATE_DISPLAY)
2722 {
2723 state_puts(state, "\n");
2724 state_attach_puts(state, is_signed ?
2725 _("[-- End of PGP/MIME signed and encrypted data --]\n") :
2726 _("[-- End of PGP/MIME encrypted data --]\n"));
2727 }
2728
2729 mutt_body_free(&tattach);
2730 mutt_message(_("PGP message successfully decrypted"));
2731 }
2732 else
2733 {
2734#ifdef USE_AUTOCRYPT
2735 if (!OptAutocryptGpgme)
2736#endif
2737 {
2738 mutt_error(_("Could not decrypt PGP message"));
2739 }
2740 rc = -1;
2741 }
2742
2743 mutt_file_fclose(&fp_out);
2744 mutt_debug(LL_DEBUG2, "Leaving handler\n");
2745
2746 return rc;
2747}
SecurityFlags mutt_is_multipart_signed(struct Body *b)
Is a message signed?
Definition: crypt.c:398
static struct Body * decrypt_part(struct Body *a, struct State *state, FILE *fp_out, bool is_smime, int *r_is_signed)
Decrypt a PGP or SMIME message.
Definition: crypt_gpgme.c:1693
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:57
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
Definition: envelope.c:97
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:150
bool OptAutocryptGpgme
(pseudo) use Autocrypt context inside ncrypt/crypt_gpgme.c
Definition: globals.c:68
int mutt_protected_headers_handler(struct Body *b, struct State *state)
Process a protected header - Implements handler_t -.
Definition: crypt.c:1107
#define mutt_error(...)
Definition: logging2.h:90
#define mutt_message(...)
Definition: logging2.h:89
#define mutt_debug(LEVEL,...)
Definition: logging2.h:87
#define mutt_perror(...)
Definition: logging2.h:91
int mutt_body_handler(struct Body *b, struct State *state)
Handler for the Body of an email.
Definition: handler.c:1618
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:44
#define _(a)
Definition: message.h:28
void state_attach_puts(struct State *state, const char *t)
Write a string to the state.
Definition: state.c:102
#define state_puts(STATE, STR)
Definition: state.h:57
#define STATE_DISPLAY
Output is displayed to the user.
Definition: state.h:32
The body of an email.
Definition: body.h:36
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:72
struct Envelope * mime_headers
Memory hole protected headers.
Definition: body.h:75
struct Body * next
next attachment in the list
Definition: body.h:71
bool goodsig
Good cryptographic signature.
Definition: body.h:45
StateFlags flags
Flags, e.g. STATE_DISPLAY.
Definition: state.h:51
FILE * fp_in
File to read from.
Definition: state.h:48
#define mutt_file_mkstemp()
Definition: tmp.h:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_class_encrypted_handler()

int pgp_class_encrypted_handler ( struct Body a,
struct State state 
)

Implements CryptModuleSpecs::encrypted_handler() -.

Definition at line 1249 of file pgp.c.

1250{
1251 FILE *fp_in = NULL;
1252 struct Body *tattach = NULL;
1253 int rc = 0;
1254
1255 FILE *fp_out = mutt_file_mkstemp();
1256 if (!fp_out)
1257 {
1258 mutt_perror(_("Can't create temporary file"));
1259 if (state->flags & STATE_DISPLAY)
1260 {
1261 state_attach_puts(state, _("[-- Error: could not create temporary file --]\n"));
1262 }
1263 return -1;
1264 }
1265
1266 if (state->flags & STATE_DISPLAY)
1267 crypt_current_time(state, "PGP");
1268
1269 tattach = pgp_decrypt_part(a, state, fp_out, a);
1270 if (tattach)
1271 {
1272 if (state->flags & STATE_DISPLAY)
1273 {
1274 state_attach_puts(state, _("[-- The following data is PGP/MIME encrypted --]\n\n"));
1275 mutt_protected_headers_handler(tattach, state);
1276 }
1277
1278 /* Store any protected headers in the parent so they can be
1279 * accessed for index updates after the handler recursion is done.
1280 * This is done before the handler to prevent a nested encrypted
1281 * handler from freeing the headers. */
1283 a->mime_headers = tattach->mime_headers;
1284 tattach->mime_headers = NULL;
1285
1286 fp_in = state->fp_in;
1287 state->fp_in = fp_out;
1288 rc = mutt_body_handler(tattach, state);
1289 state->fp_in = fp_in;
1290
1291 /* Embedded multipart signed protected headers override the
1292 * encrypted headers. We need to do this after the handler so
1293 * they can be printed in the pager. */
1294 if (mutt_is_multipart_signed(tattach) && tattach->parts && tattach->parts->mime_headers)
1295 {
1297 a->mime_headers = tattach->parts->mime_headers;
1298 tattach->parts->mime_headers = NULL;
1299 }
1300
1301 /* if a multipart/signed is the _only_ sub-part of a
1302 * multipart/encrypted, cache signature verification
1303 * status. */
1304 if (mutt_is_multipart_signed(tattach) && !tattach->next)
1305 a->goodsig |= tattach->goodsig;
1306
1307 if (state->flags & STATE_DISPLAY)
1308 {
1309 state_puts(state, "\n");
1310 state_attach_puts(state, _("[-- End of PGP/MIME encrypted data --]\n"));
1311 }
1312
1313 mutt_body_free(&tattach);
1314 /* clear 'Invoking...' message, since there's no error */
1315 mutt_message(_("PGP message successfully decrypted"));
1316 }
1317 else
1318 {
1319 mutt_error(_("Could not decrypt PGP message"));
1320 /* void the passphrase, even if it's not necessarily the problem */
1322 rc = -1;
1323 }
1324
1325 mutt_file_fclose(&fp_out);
1326
1327 return rc;
1328}
void crypt_current_time(struct State *state, const char *app_name)
Print the current time.
Definition: crypt.c:69
void pgp_class_void_passphrase(void)
Implements CryptModuleSpecs::void_passphrase() -.
Definition: pgp.c:76
static struct Body * pgp_decrypt_part(struct Body *a, struct State *state, FILE *fp_out, struct Body *p)
Decrypt part of a PGP message.
Definition: pgp.c:1028
+ Here is the call graph for this function: