NeoMutt  2025-12-11-769-g906513
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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 *b, struct State *state)
 Manage a PGP or S/MIME encrypted MIME part - Implements CryptModuleSpecs::encrypted_handler() -.
 
int pgp_class_encrypted_handler (struct Body *b, struct State *state)
 Manage a PGP or S/MIME encrypted MIME part - Implements CryptModuleSpecs::encrypted_handler() -.
 

Detailed Description

Manage a PGP or S/MIME encrypted MIME part.

Parameters
bBody 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 * b,
struct State * state )

Manage a PGP or S/MIME encrypted MIME part - Implements CryptModuleSpecs::encrypted_handler() -.

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

Definition at line 2774 of file crypt_gpgme.c.

2775{
2776 int is_signed;
2777 int rc = 0;
2778
2779 mutt_debug(LL_DEBUG2, "Entering handler\n");
2780
2781 FILE *fp_out = mutt_file_mkstemp();
2782 if (!fp_out)
2783 {
2784 mutt_perror(_("Can't create temporary file"));
2785 if (state->flags & STATE_DISPLAY)
2786 {
2787 state_attach_puts(state, _("[-- Error: could not create temporary file --]\n"));
2788 }
2789 return -1;
2790 }
2791
2792 struct Body *tattach = decrypt_part(b, state, fp_out, false, &is_signed);
2793 if (tattach)
2794 {
2795 tattach->goodsig = is_signed > 0;
2796
2797 if (state->flags & STATE_DISPLAY)
2798 {
2799 state_attach_puts(state, is_signed ?
2800 _("[-- The following data is PGP/MIME signed and encrypted --]\n") :
2801 _("[-- The following data is PGP/MIME encrypted --]\n"));
2802 mutt_protected_headers_handler(tattach, state);
2803 }
2804
2805 /* Store any protected headers in the parent so they can be
2806 * accessed for index updates after the handler recursion is done.
2807 * This is done before the handler to prevent a nested encrypted
2808 * handler from freeing the headers. */
2810 b->mime_headers = tattach->mime_headers;
2811 tattach->mime_headers = NULL;
2812
2813 FILE *fp_save = state->fp_in;
2814 state->fp_in = fp_out;
2815 rc = mutt_body_handler(tattach, state);
2816 state->fp_in = fp_save;
2817
2818 /* Embedded multipart signed protected headers override the
2819 * encrypted headers. We need to do this after the handler so
2820 * they can be printed in the pager. */
2821 if (mutt_is_multipart_signed(tattach) && tattach->parts && tattach->parts->mime_headers)
2822 {
2824 b->mime_headers = tattach->parts->mime_headers;
2825 tattach->parts->mime_headers = NULL;
2826 }
2827
2828 /* if a multipart/signed is the _only_ sub-part of a
2829 * multipart/encrypted, cache signature verification
2830 * status. */
2831 if (mutt_is_multipart_signed(tattach) && !tattach->next)
2832 b->goodsig |= tattach->goodsig;
2833
2834 if (state->flags & STATE_DISPLAY)
2835 {
2836 state_attach_puts(state, is_signed ?
2837 _("[-- End of PGP/MIME signed and encrypted data --]\n") :
2838 _("[-- End of PGP/MIME encrypted data --]\n"));
2839 }
2840
2841 mutt_body_free(&tattach);
2842 mutt_message(_("PGP message successfully decrypted"));
2843 }
2844 else
2845 {
2846#ifdef USE_AUTOCRYPT
2847 if (!OptAutocryptGpgme)
2848#endif
2849 {
2850 mutt_error(_("Could not decrypt PGP message"));
2851 }
2852 rc = -1;
2853 }
2854
2855 mutt_file_fclose(&fp_out);
2856 mutt_debug(LL_DEBUG2, "Leaving handler\n");
2857
2858 return rc;
2859}
SecurityFlags mutt_is_multipart_signed(struct Body *b)
Is a message signed?
Definition crypt.c:408
static struct Body * decrypt_part(struct Body *b, struct State *state, FILE *fp_out, bool is_smime, int *r_is_signed)
Decrypt a PGP or SMIME message.
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition body.c:58
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
Definition envelope.c:125
#define mutt_file_fclose(FP)
Definition file.h:139
bool OptAutocryptGpgme
(pseudo) use Autocrypt context inside ncrypt/crypt_gpgme.c
Definition globals.c:44
int mutt_protected_headers_handler(struct Body *b_email, struct State *state)
Handler for protected headers - Implements handler_t -.
Definition crypt.c:1122
#define mutt_error(...)
Definition logging2.h:94
#define mutt_message(...)
Definition logging2.h:93
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
#define mutt_perror(...)
Definition logging2.h:95
int mutt_body_handler(struct Body *b, struct State *state)
Handler for the Body of an email.
Definition handler.c:1664
@ LL_DEBUG2
Log at debug level 2.
Definition logging2.h:46
#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:104
#define STATE_DISPLAY
Output is displayed to the user.
Definition state.h:33
The body of an email.
Definition body.h:36
struct Body * parts
parts of a multipart or message/rfc822
Definition body.h:73
struct Envelope * mime_headers
Memory hole protected headers.
Definition body.h:76
struct Body * next
next attachment in the list
Definition body.h:72
bool goodsig
Good cryptographic signature.
Definition body.h:45
StateFlags flags
Flags, e.g. STATE_DISPLAY.
Definition state.h:52
FILE * fp_in
File to read from.
Definition state.h:49
#define mutt_file_mkstemp()
Definition tmp.h:36
+ 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 * b,
struct State * state )

Manage a PGP or S/MIME encrypted MIME part - Implements CryptModuleSpecs::encrypted_handler() -.

Definition at line 1246 of file pgp.c.

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