NeoMutt  2025-12-11-1009-ga75d9e
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 2779 of file crypt_gpgme.c.

2780{
2781 int is_signed = 0;
2782 int rc = 0;
2783
2784 mutt_debug(LL_DEBUG2, "Entering handler\n");
2785
2786 FILE *fp_out = mutt_file_mkstemp();
2787 if (!fp_out)
2788 {
2789 mutt_perror(_("Can't create temporary file"));
2790 if (state->flags & STATE_DISPLAY)
2791 {
2792 state_attach_puts(state, _("[-- Error: could not create temporary file --]\n"));
2793 }
2794 return -1;
2795 }
2796
2797 struct Body *tattach = decrypt_part(b, state, fp_out, false, &is_signed);
2798 if (tattach)
2799 {
2800 tattach->goodsig = is_signed > 0;
2801
2802 if (state->flags & STATE_DISPLAY)
2803 {
2804 state_attach_puts(state, is_signed ?
2805 _("[-- The following data is PGP/MIME signed and encrypted --]\n") :
2806 _("[-- The following data is PGP/MIME encrypted --]\n"));
2807 mutt_protected_headers_handler(tattach, state);
2808 }
2809
2810 /* Store any protected headers in the parent so they can be
2811 * accessed for index updates after the handler recursion is done.
2812 * This is done before the handler to prevent a nested encrypted
2813 * handler from freeing the headers. */
2815 b->mime_headers = tattach->mime_headers;
2816 tattach->mime_headers = NULL;
2817
2818 FILE *fp_save = state->fp_in;
2819 state->fp_in = fp_out;
2820 rc = mutt_body_handler(tattach, state);
2821 state->fp_in = fp_save;
2822
2823 /* Embedded multipart signed protected headers override the
2824 * encrypted headers. We need to do this after the handler so
2825 * they can be printed in the pager. */
2826 if (mutt_is_multipart_signed(tattach) && tattach->parts && tattach->parts->mime_headers)
2827 {
2829 b->mime_headers = tattach->parts->mime_headers;
2830 tattach->parts->mime_headers = NULL;
2831 }
2832
2833 /* if a multipart/signed is the _only_ sub-part of a
2834 * multipart/encrypted, cache signature verification
2835 * status. */
2836 if (mutt_is_multipart_signed(tattach) && !tattach->next)
2837 b->goodsig |= tattach->goodsig;
2838
2839 if (state->flags & STATE_DISPLAY)
2840 {
2841 state_attach_puts(state, is_signed ?
2842 _("[-- End of PGP/MIME signed and encrypted data --]\n") :
2843 _("[-- End of PGP/MIME encrypted data --]\n"));
2844 }
2845
2846 mutt_body_free(&tattach);
2847 mutt_message(_("PGP message successfully decrypted"));
2848 }
2849 else
2850 {
2851#ifdef USE_AUTOCRYPT
2852 if (!OptAutocryptGpgme)
2853#endif
2854 {
2855 mutt_error(_("Could not decrypt PGP message"));
2856 }
2857 rc = -1;
2858 }
2859
2860 mutt_file_fclose(&fp_out);
2861 mutt_debug(LL_DEBUG2, "Leaving handler\n");
2862
2863 return rc;
2864}
SecurityFlags mutt_is_multipart_signed(struct Body *b)
Is a message signed?
Definition crypt.c:409
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:144
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:1123
#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:1668
@ 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
@ STATE_DISPLAY
Output is displayed to the user.
Definition state.h:37
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:58
FILE * fp_in
File to read from.
Definition state.h:55
#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 1251 of file pgp.c.

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