From: Thomas Roessler Date: Tue, 26 Mar 2002 22:23:57 +0000 (+0000) Subject: More inline PGP changes. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c6f71e22d9b31f2340eaf333562e06341fe9f7de;p=neomutt More inline PGP changes. --- diff --git a/commands.c b/commands.c index 85874b042..5090d1989 100644 --- a/commands.c +++ b/commands.c @@ -201,7 +201,7 @@ int mutt_display_message (HEADER *cur) #endif #ifdef HAVE_PGP - if (cur->security & APPLICATION_PGP && (cmflags & M_CM_VERIFY)) + if ((cur->security & APPLICATION_PGP) && (cmflags & M_CM_VERIFY)) mutt_message ((cur->security & GOODSIGN) ? _("PGP signature successfully verified.") : _("PGP signature could NOT be verified.")); diff --git a/compose.c b/compose.c index f552faff1..7068fb6a0 100644 --- a/compose.c +++ b/compose.c @@ -948,7 +948,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ case OP_COMPOSE_TOGGLE_RECODE: { CHECK_COUNT; - if (!mutt_is_text_type (CURRENT->type, CURRENT->subtype)) + if (!mutt_is_text_part (CURRENT)) { mutt_error (_("Recoding only affects text attachments.")); break; diff --git a/contrib/gpg.rc b/contrib/gpg.rc index 7a6520750..e12a521b7 100644 --- a/contrib/gpg.rc +++ b/contrib/gpg.rc @@ -31,7 +31,7 @@ # breaking PGP/MIME. # decode application/pgp -set pgp_decode_command="/usr/bin/gpg %?p?--passphrase-fd 0? --no-verbose --quiet --batch --output - %f" +set pgp_decode_command="/usr/bin/gpg --charset utf-8 %?p?--passphrase-fd 0? --no-verbose --quiet --batch --output - %f" # verify a pgp/mime signature set pgp_verify_command="/usr/bin/gpg --no-verbose --quiet --batch --output - --verify %s %f" @@ -45,15 +45,15 @@ set pgp_sign_command="/usr/bin/gpg --no-verbose --batch --quiet --output - # create a application/pgp signed (old-style) message # set pgp_clearsign_command="/usr/bin/gpg-2comp --comment '' --no-verbose --batch --output - --passphrase-fd 0 --armor --textmode --clearsign %?a?-u %a? %f" -set pgp_clearsign_command="/usr/bin/gpg --no-verbose --batch --quiet --output - --passphrase-fd 0 --armor --textmode --clearsign %?a?-u %a? %f" +set pgp_clearsign_command="/usr/bin/gpg --charset utf-8 --no-verbose --batch --quiet --output - --passphrase-fd 0 --armor --textmode --clearsign %?a?-u %a? %f" # create a pgp/mime encrypted attachment # set pgp_encrypt_only_command="pgpewrap gpg-2comp -v --batch --output - --encrypt --textmode --armor --always-trust -- -r %r -- %f" -set pgp_encrypt_only_command="pgpewrap /usr/bin/gpg --batch --quiet --no-verbose --output - --encrypt --textmode --armor --always-trust -- -r %r -- %f" +set pgp_encrypt_only_command="pgpewrap /usr/bin/gpg --charset utf-8 --batch --quiet --no-verbose --output - --encrypt --textmode --armor --always-trust -- -r %r -- %f" # create a pgp/mime encrypted and signed attachment # set pgp_encrypt_sign_command="pgpewrap gpg-2comp --passphrase-fd 0 -v --batch --output - --encrypt --sign %?a?-u %a? --armor --always-trust -- -r %r -- %f" -set pgp_encrypt_sign_command="pgpewrap /usr/bin/gpg --passphrase-fd 0 --batch --quiet --no-verbose --textmode --output - --encrypt --sign %?a?-u %a? --armor --always-trust -- -r %r -- %f" +set pgp_encrypt_sign_command="pgpewrap /usr/bin/gpg --charset utf-8 --passphrase-fd 0 --batch --quiet --no-verbose --textmode --output - --encrypt --sign %?a?-u %a? --armor --always-trust -- -r %r -- %f" # import a key into the public key ring set pgp_import_command="/usr/bin/gpg --no-verbose --import -v %f" diff --git a/crypt.c b/crypt.c index ceb23e747..95b1fee91 100644 --- a/crypt.c +++ b/crypt.c @@ -180,10 +180,9 @@ int mutt_protect (HEADER *msg, char *keylist) if (msg->security & APPLICATION_PGP) { if ((msg->content->type == TYPETEXT) && - !ascii_strcasecmp (msg->content->subtype, "plain") && - ((flags & ENCRYPT) || (msg->content->content && msg->content->content->hibin == 0))) + !ascii_strcasecmp (msg->content->subtype, "plain")) { - if ((i = query_quadoption (OPT_PGPTRADITIONAL, _("Create an application/pgp message?"))) == -1) + if ((i = query_quadoption (OPT_PGPTRADITIONAL, _("Create an inline PGP message?"))) == -1) return -1; else if (i == M_YES) traditional = 1; @@ -362,7 +361,11 @@ int crypt_query (BODY *m) } #ifdef HAVE_PGP else if (m->type == TYPETEXT) + { t |= mutt_is_application_pgp (m); + if (t && m->goodsig) + t |= GOODSIGN; + } #endif @@ -761,7 +764,7 @@ void mutt_signed_handler (BODY *a, STATE *s) mutt_unlink (tempfile); b->goodsig = goodsig; - b->badsig = goodsig; + b->badsig = goodsig; /* XXX - WHAT!?!?!? */ /* Now display the signed body */ state_attach_puts (_("[-- The following data is signed --]\n\n"), s); diff --git a/handler.c b/handler.c index 7b8e2df51..eba8eec8f 100644 --- a/handler.c +++ b/handler.c @@ -1720,7 +1720,7 @@ static void external_body_handler (BODY *b, STATE *s) void mutt_decode_attachment (BODY *b, STATE *s) { - int istext = mutt_is_text_type (b->type, b->subtype); + int istext = mutt_is_text_part (b); iconv_t cd = (iconv_t)(-1); if (istext && s->flags & M_CHARCONV) @@ -1879,7 +1879,7 @@ void mutt_body_handler (BODY *b, STATE *s) /* see if we need to decode this part before processing it */ if (b->encoding == ENCBASE64 || b->encoding == ENCQUOTEDPRINTABLE || b->encoding == ENCUUENCODED || plaintext || - mutt_is_text_type (b->type, b->subtype)) /* text subtypes may + mutt_is_text_part (b)) /* text subtypes may * require character * set conversion even * with 8bit encoding. diff --git a/muttlib.c b/muttlib.c index 4c2da9493..23aa16632 100644 --- a/muttlib.c +++ b/muttlib.c @@ -138,7 +138,7 @@ int mutt_copy_body (FILE *fp, BODY **tgt, BODY *src) b->use_disp = use_disp; b->unlink = 1; - if (mutt_is_text_type (b->type, b->subtype)) + if (mutt_is_text_part (b)) b->noconv = 1; b->xtype = safe_strdup (b->xtype); @@ -616,8 +616,16 @@ int mutt_needs_mailcap (BODY *m) return 1; } -int mutt_is_text_type (int t, char *s) +int mutt_is_text_part (BODY *b) { + int t = b->type; + char *s = b->subtype; + + +#ifdef HAVE_PGP + if (mutt_is_application_pgp (b)) + return 0; +#endif if (t == TYPETEXT) return 1; diff --git a/pgp.c b/pgp.c index 32ed90c87..ae9b16043 100644 --- a/pgp.c +++ b/pgp.c @@ -364,18 +364,27 @@ void pgp_application_pgp_handler (BODY *m, STATE *s) state_attach_puts (_("[-- BEGIN PGP SIGNED MESSAGE --]\n\n"), s); } - /* Use PGP's output if there was no clearsig signature. */ - + /* + * Use PGP's output if there was no clearsig signature. + * Assume it's utf-8. + */ + if(!clearsign && pgpout) { + int c; + FGETCONV *fc; + fflush (pgpout); rewind (pgpout); - while (fgets (buf, sizeof (buf) - 1, pgpout) != NULL) + + fc = fgetconv_open (pgpout, "utf-8", Charset, M_ICONV_HOOK_TO); + while ((c = fgetconv (fc)) != EOF) { - if (s->prefix) + state_putc (c, s); + if (c == '\n' && s->prefix) state_puts (s->prefix, s); - state_puts (buf, s); } + fgetconv_close (&fc); } /* Close the temporary files iff they were created. @@ -1280,7 +1289,7 @@ BODY *pgp_traditional_encryptsign (BODY *a, int flags, char *keylist) char pgperrfile[_POSIX_PATH_MAX]; char pgpinfile[_POSIX_PATH_MAX]; - char send_charset[STRING]; + const char *send_charset; FILE *pgpout = NULL, *pgperr = NULL, *pgpin = NULL; FILE *fp; @@ -1311,8 +1320,28 @@ BODY *pgp_traditional_encryptsign (BODY *a, int flags, char *keylist) return NULL; } - mutt_copy_stream (fp, pgpin); - fclose (fp); + if (!mutt_is_us_ascii (Charset)) + { + int c; + FGETCONV *fc; + + if (flags & ENCRYPT) + send_charset = "us-ascii"; + else + send_charset = "utf-8"; + + fc = fgetconv_open (fp, Charset, "utf-8", M_ICONV_HOOK_FROM); + while ((c = fgetconv (fc)) != EOF) + fputc (c, pgpin); + + fgetconv_close (&fc); + } + else + { + send_charset = "us-ascii"; + mutt_copy_stream (fp, pgpin); + } + safe_fclose (&fp); fclose (pgpin); mutt_mktemp (pgpoutfile); @@ -1387,11 +1416,9 @@ BODY *pgp_traditional_encryptsign (BODY *a, int flags, char *keylist) b->type = TYPETEXT; b->subtype = safe_strdup ("plain"); - mutt_set_parameter ("x-mutt-action", flags & ENCRYPT ? "pgp-encrypt" : "pgp-sign", - &b->parameter); - mutt_set_parameter ("charset", mutt_get_body_charset (send_charset, - sizeof (send_charset), a), + mutt_set_parameter ("x-action", flags & ENCRYPT ? "pgp-encrypt" : "pgp-sign", &b->parameter); + mutt_set_parameter ("charset", send_charset, &b->parameter); b->filename = safe_strdup (pgpoutfile); @@ -1404,6 +1431,11 @@ BODY *pgp_traditional_encryptsign (BODY *a, int flags, char *keylist) b->unlink = 1; b->use_disp = 1; + b->noconv = 1; + + if (!(flags & ENCRYPT)) + b->encoding = a->encoding; + return b; } diff --git a/protos.h b/protos.h index 895e66165..33c8bfd59 100644 --- a/protos.h +++ b/protos.h @@ -287,7 +287,7 @@ int mutt_is_message_type(int, const char *); int mutt_is_list_cc (int, ADDRESS *, ADDRESS *); int mutt_is_list_recipient (int, ADDRESS *, ADDRESS *); int mutt_is_subscribed_list (ADDRESS *); -int mutt_is_text_type (int, char *); +int mutt_is_text_part (BODY *); int mutt_is_valid_mailbox (const char *); int mutt_lookup_mime_type (BODY *, const char *); int mutt_messages_in_thread (CONTEXT *, HEADER *, int); diff --git a/recvattach.c b/recvattach.c index ab6479ede..7e2103499 100644 --- a/recvattach.c +++ b/recvattach.c @@ -201,13 +201,13 @@ const char *mutt_attach_fmt (char *dest, case 'C': if (!optional) { - if (mutt_is_text_type (aptr->content->type, aptr->content->subtype) && + if (mutt_is_text_part (aptr->content) && mutt_get_body_charset (charset, sizeof (charset), aptr->content)) mutt_format_s (dest, destlen, prefix, charset); else mutt_format_s (dest, destlen, prefix, ""); } - else if (!mutt_is_text_type (aptr->content->type, aptr->content->subtype) || + else if (!mutt_is_text_part (aptr->content) || !mutt_get_body_charset (charset, sizeof (charset), aptr->content)) optional = 0; break; diff --git a/sendlib.c b/sendlib.c index d5e082c97..1a1051872 100644 --- a/sendlib.c +++ b/sendlib.c @@ -506,11 +506,11 @@ int mutt_write_mime_body (BODY *a, FILE *f) fc = fgetconv_open (fpin, 0, 0, 0); if (a->encoding == ENCQUOTEDPRINTABLE) - encode_quoted (fc, f, mutt_is_text_type (a->type, a->subtype)); + encode_quoted (fc, f, mutt_is_text_part (a)); else if (a->encoding == ENCBASE64) - encode_base64 (fc, f, mutt_is_text_type (a->type, a->subtype)); + encode_base64 (fc, f, mutt_is_text_part (a)); else if (a->type == TYPETEXT && (!a->noconv)) - encode_8bit (fc, f, mutt_is_text_type (a->type, a->subtype)); + encode_8bit (fc, f, mutt_is_text_part (a)); else mutt_copy_stream (fpin, f);