changeset: 6466:e5fe2f80e797
user:      Kevin McCarthy <ke...@8t8.us>
date:      Tue Jul 21 12:34:49 2015 -0700
link:      http://dev.mutt.org/hg/mutt/rev/e5fe2f80e797

Imap: Fix flag caching after sync.

The flags cached in IMAP_HEADER_DATA were not updated to match the
HEADER flags after a sync.  This means if a flag were toggled and synced
twice, the second sync was not sending the flag update.

Thanks to Noah Misch for the patch.

changeset: 6467:704e0622cc67
user:      Kevin McCarthy <ke...@8t8.us>
date:      Tue Jul 21 12:41:13 2015 -0700
link:      http://dev.mutt.org/hg/mutt/rev/704e0622cc67

merge stable

diffs (truncated from 11833 to 950 lines):

diff -r 70b85d8b232b -r 704e0622cc67 .hgignore
--- a/.hgignore Tue Feb 10 18:29:24 2015 +0100
+++ b/.hgignore Tue Jul 21 12:41:13 2015 -0700
@@ -17,6 +17,7 @@
 ^depcomp$
 ^install-sh$
 ^missing$
+^mkinstalldirs$
 
 # built objects
 ^flea$
@@ -37,6 +38,8 @@
 ^doc/manual\.(txt|xml|aux|log|out|tex|pdf)$
 ^doc/mutt\.1$
 ^doc/muttrc\.man$
+^doc/pgpewrap\.1$
+^doc/pgpring\.1$
 ^doc/.*\.html$
 ^doc/stamp-
 ^doc/smime_keys\.1$
@@ -53,6 +56,9 @@
 syntax: glob
 .deps
 Makefile
+GPATH
+GRTAGS
+GTAGS
 TAGS
 cscope.*
 *.swp
diff -r 70b85d8b232b -r 704e0622cc67 INSTALL
--- a/INSTALL   Tue Feb 10 18:29:24 2015 +0100
+++ b/INSTALL   Tue Jul 21 12:41:13 2015 -0700
@@ -280,7 +280,7 @@
        For the real fix, applying Sun patches # 105490-05 (linker
        patch) and # 105210-17 (libc and malloc patch) from
        sunsolve.sun.com has been reported to stop these problems
-       from occuring.
+       from occurring.
 
 Linux
 
diff -r 70b85d8b232b -r 704e0622cc67 Makefile.am
--- a/Makefile.am       Tue Feb 10 18:29:24 2015 +0100
+++ b/Makefile.am       Tue Jul 21 12:41:13 2015 -0700
@@ -1,5 +1,6 @@
 ## Process this file with automake to produce Makefile.in
 ## Use aclocal -I m4; automake --foreign
+include $(top_srcdir)/flymake.am
 
 AUTOMAKE_OPTIONS = 1.6 foreign
 EXTRA_PROGRAMS = mutt_dotlock pgpring pgpewrap mutt_md5
@@ -11,7 +12,7 @@
 
 SUBDIRS = m4 po intl doc contrib $(IMAP_SUBDIR)
 
-bin_SCRIPTS = muttbug flea @SMIMEAUX_TARGET@
+bin_SCRIPTS = muttbug flea $(SMIMEAUX_TARGET)
 
 if BUILD_HCACHE
 HCVERSION = hcversion.h
@@ -19,7 +20,7 @@
 
 BUILT_SOURCES = keymap_defs.h patchlist.c reldate.h conststrings.c $(HCVERSION)
 
-bin_PROGRAMS = mutt @DOTLOCK_TARGET@ @PGPAUX_TARGET@
+bin_PROGRAMS = mutt $(DOTLOCK_TARGET) $(PGPAUX_TARGET)
 mutt_SOURCES = \
        addrbook.c alias.c attach.c base64.c browser.c buffy.c color.c \
        crypt.c cryptglue.c \
@@ -37,10 +38,10 @@
 
 nodist_mutt_SOURCES = $(BUILT_SOURCES)
 
-mutt_LDADD = @MUTT_LIB_OBJECTS@ @LIBOBJS@ $(LIBIMAP) $(MUTTLIBS) \
+mutt_LDADD = $(MUTT_LIB_OBJECTS) $(LIBOBJS) $(LIBIMAP) $(MUTTLIBS) \
        $(INTLLIBS) $(LIBICONV)  $(GPGME_LIBS)
 
-mutt_DEPENDENCIES = @MUTT_LIB_OBJECTS@ @LIBOBJS@ $(LIBIMAPDEPS) \
+mutt_DEPENDENCIES = $(MUTT_LIB_OBJECTS) $(LIBOBJS) $(LIBIMAPDEPS) \
        $(INTLDEPS)
 
 DEFS=-DPKGDATADIR=\"$(pkgdatadir)\" -DSYSCONFDIR=\"$(sysconfdir)\" \
@@ -49,8 +50,6 @@
 
 AM_CPPFLAGS=-I. -I$(top_srcdir) $(IMAP_INCLUDES) $(GPGME_CFLAGS) -Iintl
 
-CPPFLAGS=@CPPFLAGS@
-
 EXTRA_mutt_SOURCES = account.c bcache.c crypt-gpgme.c crypt-mod-pgp-classic.c \
        crypt-mod-pgp-gpgme.c crypt-mod-smime-classic.c \
        crypt-mod-smime-gpgme.c dotlock.c gnupgparse.c hcache.c md5.c \
@@ -79,12 +78,12 @@
 EXTRA_SCRIPTS = smime_keys
 
 mutt_dotlock_SOURCES = mutt_dotlock.c
-mutt_dotlock_LDADD = @LIBOBJS@
-mutt_dotlock_DEPENDENCIES = @LIBOBJS@
+mutt_dotlock_LDADD = $(LIBOBJS)
+mutt_dotlock_DEPENDENCIES = $(LIBOBJS)
 
 pgpring_SOURCES = pgppubring.c pgplib.c lib.c extlib.c sha1.c md5.c 
pgppacket.c ascii.c
-pgpring_LDADD = @LIBOBJS@ $(INTLLIBS) 
-pgpring_DEPENDENCIES = @LIBOBJS@ $(INTLDEPS)
+pgpring_LDADD = $(LIBOBJS) $(INTLLIBS)
+pgpring_DEPENDENCIES = $(LIBOBJS) $(INTLDEPS)
 
 mutt_md5_SOURCES = md5.c
 mutt_md5_CFLAGS = -DMD5UTIL
@@ -118,7 +117,7 @@
 
 ACLOCAL_AMFLAGS = -I m4
 
-LDADD = @LIBOBJS@ @INTLLIBS@
+LDADD = $(LIBOBJS) $(INTLLIBS)
 
 flea:  muttbug.sh
        cp muttbug.sh flea
@@ -154,14 +153,14 @@
                rm -f $(DESTDIR)$(bindir)/mutt.dotlock ;                \
                ln -sf $(DESTDIR)$(bindir)/mutt_dotlock 
$(DESTDIR)$(bindir)/mutt.dotlock ; \
        fi
-       if test -f $(DESTDIR)$(bindir)/mutt_dotlock && test x@DOTLOCK_GROUP@ != 
x ; then \
-               chgrp @DOTLOCK_GROUP@ $(DESTDIR)$(bindir)/mutt_dotlock && \
-               chmod @DOTLOCK_PERMISSION@ $(DESTDIR)$(bindir)/mutt_dotlock || \
+       if test -f $(DESTDIR)$(bindir)/mutt_dotlock && test x$(DOTLOCK_GROUP) 
!= x ; then \
+               chgrp $(DOTLOCK_GROUP) $(DESTDIR)$(bindir)/mutt_dotlock && \
+               chmod $(DOTLOCK_PERMISSION) $(DESTDIR)$(bindir)/mutt_dotlock || 
\
                { echo "Can't fix mutt_dotlock's permissions!  This is required 
to lock mailboxes in the mail spool directory." >&2 ; exit 1 ; } \
        fi
 
 install-data-local:
-       $(srcdir)/mkinstalldirs $(DESTDIR)$(sysconfdir)
+       $(MKDIR_P) $(DESTDIR)$(sysconfdir)
        $(INSTALL) -m 644 $(srcdir)/mime.types 
$(DESTDIR)$(sysconfdir)/mime.types.dist
        -if [ ! -f $(DESTDIR)$(sysconfdir)/mime.types ]; then \
                $(INSTALL) -m 644 $(srcdir)/mime.types $(DESTDIR)$(sysconfdir); 
\
diff -r 70b85d8b232b -r 704e0622cc67 README.SECURITY
--- a/README.SECURITY   Tue Feb 10 18:29:24 2015 +0100
+++ b/README.SECURITY   Tue Jul 21 12:41:13 2015 -0700
@@ -19,7 +19,7 @@
 
 - Backticks are handled specially when preparing % expandos for
   mailcap entries.  This fix will keep the current problem from
-  occuring, but we are sure there are other possible mailcap entries
+  occurring, but we are sure there are other possible mailcap entries
   where this doesn't help.
 
 - We have added a configuration variable named $mailcap_sanitize,
diff -r 70b85d8b232b -r 704e0622cc67 README.SSL
--- a/README.SSL        Tue Feb 10 18:29:24 2015 +0100
+++ b/README.SSL        Tue Jul 21 12:41:13 2015 -0700
@@ -97,7 +97,7 @@
     openssl s_client -host <imap server> -port <port> -verify -debug -no_ssl2
     openssl s_client -host <imap server> -port <port> -verify -debug -no_ssl3
 
-You can also combine the options until you get a successfull connect.  Once
+You can also combine the options until you get a successful connect.  Once
 you know which options do not work, you can set the variables for non-working
 protocols to know.  The variables for the protocols are ssl_use_tlsv1, 
 ssl_use_sslv2, and ssl_use_sslv3.
diff -r 70b85d8b232b -r 704e0622cc67 TODO
--- a/TODO      Tue Feb 10 18:29:24 2015 +0100
+++ b/TODO      Tue Jul 21 12:41:13 2015 -0700
@@ -50,7 +50,7 @@
   Note: This still requires some thought, since we'd have to store
   per-entry data in the menu structure.  As an alternative, we could
   extend the tag method to do something to more general flags. The
-  latter approach would make the implementation of propper
+  latter approach would make the implementation of proper
   tag-prefix behaviour more simple: Functions should only be applied
   when a message is tagged and visible.  Additionally, we must not
   access a menu's max field directly any more: Adding an entry to a
diff -r 70b85d8b232b -r 704e0622cc67 UPDATING
--- a/UPDATING  Tue Feb 10 18:29:24 2015 +0100
+++ b/UPDATING  Tue Jul 21 12:41:13 2015 -0700
@@ -9,6 +9,8 @@
   ! FCC is now preserved when postponing a message.
   ! Mail-Followup-To is now preserved when recalling a postponed message.
   ! Allow filename prompt when saving multiple attachments to a directory.
+  + terminal status-line (TS) support, a.k.a. xterm title. see the
+    following variables: $ts_enabled, $ts_icon_format, $ts_status_format
 
 1.5.22 (2013-10-18):
 
diff -r 70b85d8b232b -r 704e0622cc67 build-release
--- a/build-release     Tue Feb 10 18:29:24 2015 +0100
+++ b/build-release     Tue Jul 21 12:41:13 2015 -0700
@@ -53,7 +53,7 @@
 
 # now, prepare the distribution tar balls
 
-automake
+automake --add-missing --copy --force-missing
 touch configure.ac
 make config.status
 ./config.status
diff -r 70b85d8b232b -r 704e0622cc67 color.c
--- a/color.c   Tue Feb 10 18:29:24 2015 +0100
+++ b/color.c   Tue Jul 21 12:41:13 2015 -0700
@@ -93,6 +93,7 @@
   { "bold",            MT_COLOR_BOLD },
   { "underline",       MT_COLOR_UNDERLINE },
   { "index",           MT_COLOR_INDEX },
+  { "prompt",          MT_COLOR_PROMPT },
   { NULL,              0 }
 };
 
diff -r 70b85d8b232b -r 704e0622cc67 commands.c
--- a/commands.c        Tue Feb 10 18:29:24 2015 +0100
+++ b/commands.c        Tue Jul 21 12:41:13 2015 -0700
@@ -286,7 +286,7 @@
   if (rc || !buf[0])
     return;
 
-  if (!(adr = rfc822_parse_adrlist (adr, buf)))
+  if (!(adr = mutt_parse_adrlist (adr, buf)))
   {
     mutt_error _("Error parsing address!");
     return;
diff -r 70b85d8b232b -r 704e0622cc67 compose.c
--- a/compose.c Tue Feb 10 18:29:24 2015 +0100
+++ b/compose.c Tue Jul 21 12:41:13 2015 -0700
@@ -141,6 +141,9 @@
       addstr (_(" (S/MIME)"));
   }
 
+  if (option (OPTCRYPTOPPORTUNISTICENCRYPT) && (msg->security & OPPENCRYPT))
+      addstr (_(" (OppEnc mode)"));
+
   clrtoeol ();
   move (HDR_CRYPTINFO, 0);
   clrtoeol ();
@@ -526,14 +529,29 @@
        break;
       case OP_COMPOSE_EDIT_TO:
        menu->redraw = edit_address_list (HDR_TO, &msg->env->to);
+       if (option (OPTCRYPTOPPORTUNISTICENCRYPT))
+       {
+         crypt_opportunistic_encrypt (msg);
+         redraw_crypt_lines (msg);
+       }
         mutt_message_hook (NULL, msg, M_SEND2HOOK);
         break;
       case OP_COMPOSE_EDIT_BCC:
        menu->redraw = edit_address_list (HDR_BCC, &msg->env->bcc);
+       if (option (OPTCRYPTOPPORTUNISTICENCRYPT))
+       {
+         crypt_opportunistic_encrypt (msg);
+         redraw_crypt_lines (msg);
+       }
         mutt_message_hook (NULL, msg, M_SEND2HOOK);
        break;
       case OP_COMPOSE_EDIT_CC:
        menu->redraw = edit_address_list (HDR_CC, &msg->env->cc);
+       if (option (OPTCRYPTOPPORTUNISTICENCRYPT))
+       {
+         crypt_opportunistic_encrypt (msg);
+         redraw_crypt_lines (msg);
+       }
         mutt_message_hook (NULL, msg, M_SEND2HOOK);    
         break;
       case OP_COMPOSE_EDIT_SUBJECT:
@@ -593,6 +611,8 @@
            mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err);
            FREE (&err);
          }
+         if (option (OPTCRYPTOPPORTUNISTICENCRYPT))
+           crypt_opportunistic_encrypt (msg);
        }
        else
        {
@@ -1220,7 +1240,8 @@
            mutt_clear_error ();
            break;
          }
-         msg->security = 0;
+         msg->security &= ~APPLICATION_SMIME;
+         msg->security |= APPLICATION_PGP;
        }
        msg->security = crypt_pgp_send_menu (msg, &menu->redraw);
        redraw_crypt_lines (msg);
@@ -1246,7 +1267,8 @@
             mutt_clear_error ();
             break;
          }
-         msg->security = 0;
+         msg->security &= ~APPLICATION_PGP;
+         msg->security |= APPLICATION_SMIME;
        }
        msg->security = crypt_smime_send_menu(msg, &menu->redraw);
        redraw_crypt_lines (msg);
diff -r 70b85d8b232b -r 704e0622cc67 configure.ac
--- a/configure.ac      Tue Feb 10 18:29:24 2015 +0100
+++ b/configure.ac      Tue Jul 21 12:41:13 2015 -0700
@@ -35,6 +35,7 @@
 AC_PROG_CPP
 AC_PROG_MAKE_SET
 AC_PROG_INSTALL
+AC_PROG_MKDIR_P
 AC_PROG_RANLIB
 AC_CHECK_TOOL(AR, ar, ar)
 
@@ -138,6 +139,11 @@
       #needed to get GPGME_LIBS and al correctly
       AM_PATH_GPGME(1.0.0, AC_DEFINE(CRYPT_BACKEND_GPGME, 1,
                     [Define if you use GPGME to support OpenPGP]))
+      dnl AC_CHECK_FUNCS([gpgme_op_export_keys])
+      saved_LIBS="$LIBS"
+      LIBS="$LIBS $GPGME_LIBS"
+      AC_CHECK_FUNCS([gpgme_op_export_keys])
+      LIBS="$saved_LIBS"
       MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS crypt-gpgme.o crypt-mod-pgp-gpgme.o 
crypt-mod-smime-gpgme.o"
    fi
 else
@@ -163,7 +169,7 @@
 ])
  
 if test x$have_smime != xno ; then
-       AC_DEFINE(CRYPT_BACKEND_CLASSIC_SMIME, 1, [Define if you want clasic 
S/MIME support.])
+       AC_DEFINE(CRYPT_BACKEND_CLASSIC_SMIME, 1, [Define if you want classic 
S/MIME support.])
        MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS smime.o crypt-mod-smime-classic.o"
        SMIMEAUX_TARGET="smime_keys"
 fi
@@ -295,6 +301,7 @@
         if test "$ac_cv_func_decl_resizeterm" = yes; then
                 MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS resize.o"
         fi
+        AC_CHECK_FUNCS([use_extended_names])
         LIBS="$old_LIBS"
         ])
 
@@ -706,6 +713,16 @@
       AC_CHECK_DECLS([GNUTLS_VERIFY_DISABLE_TIME_CHECKS], [], [],
                     [[#include <gnutls/x509.h>]])
 
+      LIBS="$LIBS -lgnutls"
+      AC_CHECK_FUNCS(gnutls_priority_set_direct)
+      AC_CHECK_TYPES([gnutls_certificate_credentials_t,
+                      gnutls_certificate_status_t,
+                      gnutls_datum_t,
+                      gnutls_digest_algorithm_t,
+                      gnutls_session_t,
+                      gnutls_transport_ptr_t,
+                      gnutls_x509_crt_t], [], [], [[#include 
<gnutls/gnutls.h>]])
+
       LIBS="$saved_LIBS"
       MUTTLIBS="$MUTTLIBS -lgnutls"
 
diff -r 70b85d8b232b -r 704e0622cc67 contrib/Makefile.am
--- a/contrib/Makefile.am       Tue Feb 10 18:29:24 2015 +0100
+++ b/contrib/Makefile.am       Tue Jul 21 12:41:13 2015 -0700
@@ -14,7 +14,7 @@
        iconv/make.sh
 
 install-data-local:
-       $(top_srcdir)/mkinstalldirs $(DESTDIR)$(docdir)/samples 
$(DESTDIR)$(docdir)/samples/iconv
+       $(MKDIR_P) $(DESTDIR)$(docdir)/samples $(DESTDIR)$(docdir)/samples/iconv
        for f in $(SAMPLES) ; do \
                $(INSTALL) -m 644 $(srcdir)/$$f $(DESTDIR)$(docdir)/samples ;   
\
        done
diff -r 70b85d8b232b -r 704e0622cc67 contrib/colors.default
--- a/contrib/colors.default    Tue Feb 10 18:29:24 2015 +0100
+++ b/contrib/colors.default    Tue Jul 21 12:41:13 2015 -0700
@@ -6,6 +6,7 @@
 color quoted blue white
 color signature red white
 color attachment red white
+color prompt brightmagenta white
 color message brightred white
 color error brightred white
 color indicator brightyellow red
diff -r 70b85d8b232b -r 704e0622cc67 contrib/colors.linux
--- a/contrib/colors.linux      Tue Feb 10 18:29:24 2015 +0100
+++ b/contrib/colors.linux      Tue Jul 21 12:41:13 2015 -0700
@@ -6,6 +6,7 @@
 color quoted blue black
 color signature blue black
 color attachment red black
+color prompt brightmagenta black
 color message brightred black
 color error brightred black
 color indicator black red
diff -r 70b85d8b232b -r 704e0622cc67 contrib/gpg.rc
--- a/contrib/gpg.rc    Tue Feb 10 18:29:24 2015 +0100
+++ b/contrib/gpg.rc    Tue Jul 21 12:41:13 2015 -0700
@@ -65,10 +65,10 @@
 set pgp_verify_key_command="gpg --verbose --batch --fingerprint --check-sigs 
%r"
 
 # read in the public key ring
-set pgp_list_pubring_command="gpg --no-verbose --batch --quiet --with-colons 
--list-keys %r" 
+set pgp_list_pubring_command="gpg --no-verbose --batch --quiet --with-colons 
--with-fingerprint --with-fingerprint --list-keys %r"
 
 # read in the secret key ring
-set pgp_list_secring_command="gpg --no-verbose --batch --quiet --with-colons 
--list-secret-keys %r" 
+set pgp_list_secring_command="gpg --no-verbose --batch --quiet --with-colons 
--with-fingerprint --with-fingerprint --list-secret-keys %r"
 
 # fetch keys
 # set pgp_getkeys_command="pkspxycwrap %r"
diff -r 70b85d8b232b -r 704e0622cc67 contrib/smime.rc
--- a/contrib/smime.rc  Tue Feb 10 18:29:24 2015 +0100
+++ b/contrib/smime.rc  Tue Jul 21 12:41:13 2015 -0700
@@ -6,7 +6,7 @@
 # will be the default method unless the following option is set
 set smime_is_default
 
-# Uncoment this if you don't want to set labels for certificates you add.
+# Uncomment this if you don't want to set labels for certificates you add.
 # unset smime_ask_cert_label
 
 # Passphrase expiration
@@ -25,7 +25,7 @@
 # line and replace the keyid with your own.
 set smime_default_key="12345678.0"
 
-# Uncommen to make mutt ask what key to use when trying to decrypt a message.
+# Uncomment to make mutt ask what key to use when trying to decrypt a message.
 # It will use the default key above (if that was set) else.
 # unset smime_decrypt_use_default_key
 
@@ -49,7 +49,7 @@
 set smime_get_signer_cert_command="openssl smime -verify -in %f -noverify 
-signer %c -out /dev/null"
 
 # This is used to get the email address the certificate was issued to.
-set smime_get_cert_email_command="openssl x509 -in  %f -noout -email"
+set smime_get_cert_email_command="openssl x509 -in %f -noout -email"
 
 # Add a certificate to the database using smime_keys.
 set smime_import_cert_command="smime_keys add_cert %f"
@@ -59,10 +59,10 @@
 # Sction B: Outgoing messages
 
 # Algorithm to use for encryption.
-# valid choices are rc2-40, rc2-64, rc2-128, des, des3
-set smime_encrypt_with="des3"
+# valid choices are aes128, aes192, aes256, rc2-40, rc2-64, rc2-128, des, des3
+set smime_encrypt_with="aes256"
 
-# Encrypt a message. Input file is a MIME entity.
+# Encrypt a message.  Input file is a MIME entity.
 set smime_encrypt_command="openssl smime -encrypt -%a -outform DER -in %f %c"
 
 # Sign.
@@ -72,8 +72,8 @@
 
 #Section C: Incoming messages
 
-# Decrypt a message. Output is a MIME entity.
-set smime_decrypt_command="openssl smime -decrypt  -passin stdin -inform DER 
-in %f -inkey %k -recip %c"
+# Decrypt a message.  Output is a MIME entity.
+set smime_decrypt_command="openssl smime -decrypt -passin stdin -inform DER 
-in %f -inkey %k -recip %c"
 
 # Verify a signature of type multipart/signed
 set smime_verify_command="openssl smime -verify -inform DER -in %s %C -content 
%f"
@@ -91,7 +91,7 @@
 # your public key, use this command instead.
 # set smime_sign_command="openssl smime -sign -signer %c -inkey %k -passin 
stdin -in %f -outform DER"
 #
-# In order to verify the signature only and skip checking the certificate  
chain:
+# In order to verify the signature only and skip checking the certificate 
chain:
 #
 # set smime_verify_command="openssl smime -verify -inform DER -in %s -content 
%f -noverify"
 # set smime_verify_opaque_command="openssl smime -verify -inform DER -in %s 
-noverify"
diff -r 70b85d8b232b -r 704e0622cc67 crypt-gpgme.c
--- a/crypt-gpgme.c     Tue Feb 10 18:29:24 2015 +0100
+++ b/crypt-gpgme.c     Tue Jul 21 12:41:13 2015 -0700
@@ -110,6 +110,7 @@
   int idx;             /* and the user ID at this index */
   const char *uid;     /* and for convenience point to this user ID */
   unsigned int flags;  /* global and per uid flags (for convenience)*/
+  gpgme_validity_t validity;  /* uid validity (cached for convenience) */
 } crypt_key_t;
 
 typedef struct crypt_entry
@@ -179,6 +180,34 @@
   return s;
 }
 
+/* Return the long keyID for the key K. */
+static const char *crypt_long_keyid (crypt_key_t *k)
+{
+  const char *s = "????????????????";
+
+  if (k->kobj && k->kobj->subkeys)
+    {
+      s = k->kobj->subkeys->keyid;
+    }
+
+  return s;
+}
+
+/* Return the short keyID for the key K. */
+static const char *crypt_short_keyid (crypt_key_t *k)
+{
+  const char *s = "????????";
+
+  if (k->kobj && k->kobj->subkeys)
+    {
+      s = k->kobj->subkeys->keyid;
+      if (strlen (s) == 16)
+        s += 8;
+    }
+
+  return s;
+}
+
 /* Return the hexstring fingerprint from the key K. */
 static const char *crypt_fpr (crypt_key_t *k)
 {
@@ -190,6 +219,24 @@
   return s;
 }
 
+/* Returns the fingerprint if available, otherwise
+ * returns the long keyid.
+ */
+static const char *crypt_fpr_or_lkeyid(crypt_key_t *k)
+{
+  const char *s = "????????????????";
+
+  if (k->kobj && k->kobj->subkeys)
+  {
+    if (k->kobj->subkeys->fpr)
+      s = k->kobj->subkeys->fpr;
+    else
+      s = k->kobj->subkeys->keyid;
+  }
+
+  return s;
+}
+
 /* Parse FLAGS and return a statically allocated(!) string with them. */
 static char *crypt_key_abilities (int flags)
 {
@@ -240,6 +287,7 @@
   k->idx = key->idx;
   k->uid = key->uid;
   k->flags = key->flags;
+  k->validity = key->validity;
 
   return k;
 }
@@ -248,12 +296,19 @@
    to NULL. */
 static void crypt_free_key (crypt_key_t **keylist)
 {
+  crypt_key_t *k;
+
+  if (!keylist)
+    return;
+
   while (*keylist)
-    {
-      crypt_key_t *k = (*keylist)->next;
-      FREE (&k);
-      *keylist = k;
-    }
+  {
+    k = *keylist;
+    *keylist = (*keylist)->next;
+
+    gpgme_key_unref (k->kobj);
+    FREE (&k);
+  }
 }
 
 /* Return trute when key K is valid. */
@@ -267,21 +322,12 @@
 /* Return true whe validity of KEY is sufficient. */
 static int crypt_id_is_strong (crypt_key_t *key)
 {
-  gpgme_validity_t val = GPGME_VALIDITY_UNKNOWN;
-  gpgme_user_id_t uid = NULL;
   unsigned int is_strong = 0;
-  unsigned int i = 0;
 
   if ((key->flags & KEYFLAG_ISX509))
     return 1;
 
-  for (i = 0, uid = key->kobj->uids; (i < key->idx) && uid;
-       i++, uid = uid->next)
-    ;
-  if (uid)
-    val = uid->validity;
-
-  switch (val)
+  switch (key->validity)
     {
     case GPGME_VALIDITY_UNKNOWN:
     case GPGME_VALIDITY_UNDEFINED:
@@ -504,21 +550,27 @@
   return 0;
 }
 
-/* Copy a data object to a newly created temporay file and return that
-   filename. Caller must free.  With RET_FP not NULL, don't close the
-   stream but return it there. */
-static char *data_object_to_tempfile (gpgme_data_t data, FILE **ret_fp)
+/* Copy a data object to a temporary file.
+ * The tempfile name may be optionally passed in.
+ * If ret_fp is passed in, the file will be rewound, left open, and returned
+ * via that parameter.
+ * The tempfile name is returned, and must be freed.
+ */
+static char *data_object_to_tempfile (gpgme_data_t data, char *tempf, FILE 
**ret_fp)
 {
   int err;
-  char tempfile[_POSIX_PATH_MAX];
+  char tempfb[_POSIX_PATH_MAX];
   FILE *fp;
   size_t nread = 0;
 
-  mutt_mktemp (tempfile, sizeof (tempfile));
-  fp = safe_fopen (tempfile, "w+");
-  if (!fp)
+  if (!tempf)
     {
-      mutt_perror (tempfile);
+      mutt_mktemp (tempfb, sizeof (tempfb));
+      tempf = tempfb;
+    }
+  if ((fp = safe_fopen (tempf, tempf == tempfb ? "w+" : "a+")) == NULL)
+    {
+      mutt_perror _("Can't create temporary file");
       return NULL;
     }
 
@@ -532,9 +584,9 @@
         {
           if (fwrite (buf, nread, 1, fp) != 1)
             {
-              mutt_perror (tempfile);
+              mutt_perror (tempf);
               safe_fclose (&fp);
-              unlink (tempfile);
+              unlink (tempf);
               return NULL;
             }
         }
@@ -546,13 +598,35 @@
   if (nread == -1)
     {
       mutt_error (_("error reading data object: %s\n"), gpgme_strerror (err));
-      unlink (tempfile);
+      unlink (tempf);
       safe_fclose (&fp);
       return NULL;
     }
   if (ret_fp)
     *ret_fp = fp;
-  return safe_strdup (tempfile);
+  return safe_strdup (tempf);
+}
+
+
+static void free_recipient_set (gpgme_key_t **p_rset)
+{
+  gpgme_key_t *rset, k;
+
+  if (!p_rset)
+    return;
+
+  rset = *p_rset;
+  if (!rset)
+    return;
+
+  while (*rset)
+  {
+    k = *rset;
+    gpgme_key_unref (k);
+    rset++;
+  }
+
+  FREE (p_rset);       /* __FREE_CHECKED__ */
 }
 
 
@@ -608,7 +682,9 @@
              {
                mutt_error (_("error adding recipient `%s': %s\n"),
                            buf, gpgme_strerror (err));
-               FREE (&rset);
+               rset[rset_n] = NULL;
+               free_recipient_set (&rset);
+               gpgme_release (context);
                return NULL;
              }
          }
@@ -651,8 +727,8 @@
   err = gpgme_op_keylist_next (listctx, &key2);
   if (!err)
     {
-      gpgme_key_release (key);
-      gpgme_key_release (key2);
+      gpgme_key_unref (key);
+      gpgme_key_unref (key2);
       gpgme_release (listctx);
       mutt_error (_("ambiguous specification of secret key `%s'\n"),
                   signid);
@@ -663,7 +739,7 @@
 
   gpgme_signers_clear (ctx);
   err = gpgme_signers_add (ctx, key);
-  gpgme_key_release (key);
+  gpgme_key_unref (key);
   if (err)
     {
       mutt_error (_("error setting secret key `%s': %s\n"),
@@ -747,7 +823,7 @@
 
   gpgme_release (ctx);
 
-  outfile = data_object_to_tempfile (ciphertext, NULL);
+  outfile = data_object_to_tempfile (ciphertext, NULL, NULL);
   gpgme_data_release (ciphertext);
   return outfile;
 }
@@ -834,6 +910,7 @@
   if (set_signer (ctx, use_smime))
     {
       gpgme_data_release (signature);
+      gpgme_data_release (message);
       gpgme_release (ctx);
       return NULL;
     }
@@ -872,7 +949,7 @@
       return NULL;
   }
 
-  sigfile = data_object_to_tempfile (signature, NULL);
+  sigfile = data_object_to_tempfile (signature, NULL, NULL);
   gpgme_data_release (signature);
   if (!sigfile)
     {
@@ -918,6 +995,7 @@
   else
     {
       t->subtype = safe_strdup ("pgp-signature");
+      mutt_set_parameter ("name", "signature.asc", &t->parameter);
       t->use_disp = 0;
       t->disposition = DISPNONE;
       t->encoding = ENC7BIT;
@@ -961,13 +1039,13 @@
   plaintext = body_to_data_object (a, 0);
   if (!plaintext)
     {
-      FREE (&rset);
+      free_recipient_set (&rset);
       return NULL;
     }
   
   outfile = encrypt_gpgme_object (plaintext, rset, 0, sign);
   gpgme_data_release (plaintext);
-  FREE (&rset);
+  free_recipient_set (&rset);
   if (!outfile)
       return NULL;
 
@@ -1020,13 +1098,13 @@
   plaintext = body_to_data_object (a, 0);
   if (!plaintext)
     {
-      FREE (&rset);
+      free_recipient_set (&rset);
       return NULL;
     }
 
   outfile = encrypt_gpgme_object (plaintext, rset, 1, 0);
   gpgme_data_release (plaintext);
-  FREE (&rset);
+  free_recipient_set (&rset);
   if (!outfile) 
       return NULL;
 
@@ -1342,7 +1420,7 @@
 
       if (signature_key)
        {
-         gpgme_key_release (signature_key);
+         gpgme_key_unref (signature_key);
          signature_key = NULL;
        }
       
@@ -1420,7 +1498,7 @@
       }
 
       if (key != signature_key)
-       gpgme_key_release (key);
+       gpgme_key_unref (key);
     }
 
   return anybad ? 1 : anywarn ? 2 : 0;
@@ -1461,6 +1539,9 @@
   state_attach_puts (_("[-- Begin signature information --]\n"), s);
 
   err = gpgme_op_verify (ctx, signature, message, NULL);
+  gpgme_data_release (message);
+  gpgme_data_release (signature);
+
   mutt_need_hard_redraw ();
   if (err)
     {
@@ -1478,7 +1559,7 @@
 
       if (signature_key)
        {
-         gpgme_key_release (signature_key);
+         gpgme_key_unref (signature_key);
          signature_key = NULL;
        }
 
@@ -1966,7 +2047,7 @@
       subkey = subkey->next;
       more = 1;
     }
-    gpgme_key_release (key);
+    gpgme_key_unref (key);
   }
   if (gpg_err_code (err) != GPG_ERR_EOF)
   {
@@ -2148,7 +2229,7 @@
   char *fname;
   FILE *fp;
 
-  fname = data_object_to_tempfile (data, &fp);
+  fname = data_object_to_tempfile (data, NULL, &fp);
   if (!fname)
     return;
   unlink (fname);
@@ -2341,7 +2422,7 @@
                                            "information --]\n\n"), s);
                     }
 
-                  tmpfname = data_object_to_tempfile (plaintext, &pgpout);
+                  tmpfname = data_object_to_tempfile (plaintext, NULL, 
&pgpout);
                   if (!tmpfname)
                     {
                       pgpout = NULL;
@@ -2353,6 +2434,7 @@
                       FREE (&tmpfname);
                     }
                 }
+              gpgme_data_release (plaintext);
               gpgme_release (ctx);
             }
       
@@ -2404,6 +2486,7 @@
                 state_attach_puts (_("[-- END PGP SIGNED MESSAGE --]\n"), s);
             }
           
+          gpgme_data_release (armored_data);
           if (pgpout)
             {
               safe_fclose (&pgpout);
@@ -2769,35 +2852,28 @@
         s = "x";
       else
        {
-         gpgme_user_id_t uid = NULL;
-         unsigned int i = 0;
-
-         for (i = 0, uid = key->kobj->uids; uid && (i < key->idx);
-               i++, uid = uid->next)
-            ;
-         if (uid)
-           switch (uid->validity)
-             {
-             case GPGME_VALIDITY_UNDEFINED:
-               s = "q";
-               break;
-             case GPGME_VALIDITY_NEVER:
-               s = "n";
-               break;
-             case GPGME_VALIDITY_MARGINAL:
-               s = "m";
-               break;
-             case GPGME_VALIDITY_FULL:
-               s = "f";
-               break;
-             case GPGME_VALIDITY_ULTIMATE:
-               s = "u";
-               break;
-             case GPGME_VALIDITY_UNKNOWN:
-             default:
-               s = "?";
-               break;
-             }
+          switch (key->validity)
+            {
+            case GPGME_VALIDITY_UNDEFINED:
+              s = "q";
+              break;
+            case GPGME_VALIDITY_NEVER:
+              s = "n";
+              break;
+            case GPGME_VALIDITY_MARGINAL:
+              s = "m";
+              break;
+            case GPGME_VALIDITY_FULL:
+              s = "f";
+              break;
+            case GPGME_VALIDITY_ULTIMATE:
+              s = "u";
+              break;
+            case GPGME_VALIDITY_UNKNOWN:
+            default:
+              s = "?";
+              break;
+            }
        }
       snprintf (fmt, sizeof (fmt), "%%%sc", prefix);
       snprintf (dest, destlen, fmt, s? *s: 'B');
@@ -2842,7 +2918,7 @@
   if ((r = mutt_strcasecmp ((*s)->uid, (*t)->uid)))
     return r > 0;
   else
-    return mutt_strcasecmp (crypt_keyid (*s), crypt_keyid (*t)) > 0;
+    return mutt_strcasecmp (crypt_fpr_or_lkeyid (*s), crypt_fpr_or_lkeyid 
(*t)) > 0;
 }
 
 static int crypt_compare_address (const void *a, const void *b)
@@ -2859,7 +2935,7 @@
   crypt_key_t **t = (crypt_key_t **) b;
   int r;
 
-  if ((r = mutt_strcasecmp (crypt_keyid (*s), crypt_keyid (*t))))
+  if ((r = mutt_strcasecmp (crypt_fpr_or_lkeyid (*s), crypt_fpr_or_lkeyid 
(*t))))
     return r > 0;
   else
     return mutt_strcasecmp ((*s)->uid, (*t)->uid) > 0;
@@ -2910,10 +2986,8 @@
            - ((*t)->flags & (KEYFLAG_RESTRICTIONS)))))
     return r > 0;
 
-  if ((*s)->kobj->uids)
-    ts = (*s)->kobj->uids->validity;
-  if ((*t)->kobj->uids)
-    tt = (*t)->kobj->uids->validity;
+  ts = (*s)->validity;
+  tt = (*t)->validity;
   if ((r = (tt - ts)))
     return r < 0;
 
@@ -2935,7 +3009,7 @@
 
   if ((r = mutt_strcasecmp ((*s)->uid, (*t)->uid)))
     return r > 0;
-  return (mutt_strcasecmp (crypt_keyid ((*s)), crypt_keyid ((*t)))) > 0;
+  return (mutt_strcasecmp (crypt_fpr_or_lkeyid ((*s)), crypt_fpr_or_lkeyid 
((*t)))) > 0;
 }

Reply via email to