From 1ab70c789bb4631a5cbdfd60a8164d66cbdd767e Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Wed, 10 Oct 2012 20:14:37 +0200 Subject: [PATCH 1/6] In case of multiple matching encryption keys, use the most recent one without bothering the user --- src/plugins/pgpcore/select-keys.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/plugins/pgpcore/select-keys.c b/src/plugins/pgpcore/select-keys.c index f558f4a..5ba6b6f 100644 --- a/src/plugins/pgpcore/select-keys.c +++ b/src/plugins/pgpcore/select-keys.c @@ -278,6 +278,7 @@ fill_clist (struct select_keys_s *sk, const char *pattern, gpgme_protocol_t prot cm_return_val_if_fail (sk, NULL); clist = sk->clist; cm_return_val_if_fail (clist, NULL); + static int use_most_recent_key = 1; debug_print ("select_keys:fill_clist: pattern '%s' proto %d\n", pattern, proto); @@ -306,7 +307,6 @@ fill_clist (struct select_keys_s *sk, const char *pattern, gpgme_protocol_t prot if (!key->can_encrypt || key->revoked || key->expired || key->disabled) continue; debug_print ("%% %s:%d: insert\n", __FILE__ ,__LINE__ ); - set_row (clist, key, proto ); for (; uid; uid = uid->next) { gchar *raw_mail = NULL; @@ -322,14 +322,37 @@ fill_clist (struct select_keys_s *sk, const char *pattern, gpgme_protocol_t prot } g_free(raw_mail); } - num_results++; - last_key = key; + if (use_most_recent_key) { + if (last_key == NULL) { + debug_print ("%s:%d: First matching key for %s has fingerprint %s\n", + __FILE__ ,__LINE__, pattern, key->subkeys->fpr); + last_key = key; + } else if (key->subkeys->timestamp > last_key->subkeys->timestamp) { + debug_print ("%s:%d: Ditching key %s in favor of the more recent %s\n", + __FILE__ ,__LINE__, last_key->subkeys->fpr, key->subkeys->fpr); + last_key = key; + } else { + debug_print ("%s:%d: Not chosing key %s as it's older than the current choice\n", + __FILE__ ,__LINE__, key->subkeys->fpr); + } + } else { + set_row (clist, key, proto ); + num_results++; + last_key = key; + } key = NULL; update_progress (sk, ++running, pattern); while (gtk_events_pending ()) gtk_main_iteration (); } - + + if (use_most_recent_key && last_key) { + debug_print ("%s:%d: The final key for %s has fingerprint %s\n", + __FILE__ ,__LINE__, pattern, last_key->subkeys->fpr); + set_row (clist, last_key, proto ); + num_results++; + } + if (exact_match == TRUE && num_results == 1) { if (last_key->uids->validity < GPGME_VALIDITY_FULL && !use_untrusted(last_key, last_uid, proto)) -- 1.8.1.3 From 26578da27c47a0130d6b650c84fcab523553ab48 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Mon, 21 Jan 2013 15:26:19 +0100 Subject: [PATCH 2/6] Fix a segmentation fault in procmime_scan_text_content() in case of conversion failures --- src/procmime.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/procmime.c b/src/procmime.c index b14dfe6..1fa508e 100644 --- a/src/procmime.c +++ b/src/procmime.c @@ -804,8 +804,6 @@ gboolean procmime_scan_text_content(MimeInfo *mimeinfo, g_free(str); } else { conv_fail = TRUE; - if ((scan_ret = scan_callback(str, cb_data)) == TRUE) - break; } } } -- 1.8.1.3 From 2bbd87835c87e44e921bc16eea267685bc74694e Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Mon, 21 Jan 2013 17:56:34 +0100 Subject: [PATCH 3/6] Pauls potential fix --- src/codeconv.h | 1 + src/procmime.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/codeconv.h b/src/codeconv.h index de193d1..d293c9e 100644 --- a/src/codeconv.h +++ b/src/codeconv.h @@ -168,6 +168,7 @@ struct _CodeConverter #define CS_WINDOWS_874 "Windows-874" #define CS_GEORGIAN_PS "GEORGIAN-PS" #define CS_TCVN5712_1 "TCVN5712-1" +#define CS_X_VIET_VPS "X-VIET-VPS" #define C_INTERNAL C_UTF_8 #define CS_INTERNAL CS_UTF_8 diff --git a/src/procmime.c b/src/procmime.c index 1fa508e..5f810b8 100644 --- a/src/procmime.c +++ b/src/procmime.c @@ -768,6 +768,8 @@ gboolean procmime_scan_text_content(MimeInfo *mimeinfo, src_codeset = CS_GB18030; else if (!forced_charset && src_codeset && !strcasecmp(src_codeset, CS_GB2312)) src_codeset = CS_GB18030; + else if (!forced_charset && src_codeset && !strcasecmp(src_codeset, CS_X_VIET_VPS)) + src_codeset = CS_WINDOWS_874; if (mimeinfo->type == MIMETYPE_TEXT && !g_ascii_strcasecmp(mimeinfo->subtype, "html")) { SC_HTMLParser *parser; -- 1.8.1.3 From ad6ff8af60d05d91465d0b5e4e2d6f0d8bab38fe Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Thu, 7 Feb 2013 18:05:24 +0100 Subject: [PATCH 4/6] Ignore stray OpenPGP ASCII armor encryption headers .. that aren't located at the start of the buffer or line. This makes makes it less likely that unencrypted messages are shown as encrypted and trigger decryption errors when being displayed. RFC 4880 6.2. allows trailing but no leading white-space. --- src/plugins/pgpinline/pgpinline.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/plugins/pgpinline/pgpinline.c b/src/plugins/pgpinline/pgpinline.c index 17523a1..73f100a 100644 --- a/src/plugins/pgpinline/pgpinline.c +++ b/src/plugins/pgpinline/pgpinline.c @@ -173,6 +173,22 @@ static gchar *get_part_as_string(MimeInfo *mimeinfo) return textdata; } +static gchar *pgpinline_locate_armor_header(gchar *textdata, const gchar *armor_header) +{ + gchar *pos; + + pos = strstr(textdata, armor_header); + /* + * It's only a valid armor header if it's at the + * beginning of the buffer or a new line. + */ + if (pos != NULL && (pos == textdata || *(pos-1) == '\n')) + { + return pos; + } + return NULL; +} + static gboolean pgpinline_is_signed(MimeInfo *mimeinfo) { PrivacyDataPGP *data = NULL; @@ -364,7 +379,7 @@ static gboolean pgpinline_is_encrypted(MimeInfo *mimeinfo) if (!textdata) return FALSE; - if (!strstr(textdata, enc_indicator)) { + if (!pgpinline_locate_armor_header(textdata, enc_indicator)) { g_free(textdata); return FALSE; } @@ -456,7 +471,7 @@ static MimeInfo *pgpinline_decrypt(MimeInfo *mimeinfo) } /* Store any part before encrypted text */ - pos = strstr(textdata, begin_indicator); + pos = pgpinline_locate_armor_header(textdata, begin_indicator); if (pos != NULL && (pos - textdata) > 0) { if (fwrite(textdata, 1, pos - textdata, dstfp) < pos - textdata) { FILE_OP_ERROR(fname, "fwrite"); @@ -491,7 +506,7 @@ static MimeInfo *pgpinline_decrypt(MimeInfo *mimeinfo) goto FILE_ERROR; } if (pos != NULL) { - pos = strstr(pos, end_indicator); + pos = pgpinline_locate_armor_header(pos, end_indicator); if (pos != NULL && *pos != '\0') { pos += strlen(end_indicator); if (fwrite(pos, 1, strlen(pos), dstfp) < strlen(pos)) { -- 1.8.1.3 From 31528b0b15f8a8473e9ed22fd03c15abf6eec1b6 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Fri, 8 Feb 2013 09:19:30 +0100 Subject: [PATCH 5/6] Slightly simplify pgpinline_is_signed() by using gpinline_locate_armor_header() --- src/plugins/pgpinline/pgpinline.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/plugins/pgpinline/pgpinline.c b/src/plugins/pgpinline/pgpinline.c index 73f100a..260ef83 100644 --- a/src/plugins/pgpinline/pgpinline.c +++ b/src/plugins/pgpinline/pgpinline.c @@ -222,13 +222,9 @@ static gboolean pgpinline_is_signed(MimeInfo *mimeinfo) textdata = get_part_as_string(mimeinfo); if (!textdata) return FALSE; - - if ((sigpos = strstr(textdata, sig_indicator)) == NULL) { - g_free(textdata); - return FALSE; - } - if (!(sigpos == textdata) && !(sigpos[-1] == '\n')) { + sigpos = pgpinline_locate_armor_header(textdata, sig_indicator); + if (sigpos == NULL) { g_free(textdata); return FALSE; } -- 1.8.1.3 From 6c750a8c1e652f107996a2fb8428766fb2b5755a Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Fri, 8 Feb 2013 09:26:12 +0100 Subject: [PATCH 6/6] Move a couple of armor headers from the stack to the data section --- src/plugins/pgpinline/pgpinline.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/plugins/pgpinline/pgpinline.c b/src/plugins/pgpinline/pgpinline.c index 260ef83..5d6fe7c 100644 --- a/src/plugins/pgpinline/pgpinline.c +++ b/src/plugins/pgpinline/pgpinline.c @@ -192,7 +192,7 @@ static gchar *pgpinline_locate_armor_header(gchar *textdata, const gchar *armor_ static gboolean pgpinline_is_signed(MimeInfo *mimeinfo) { PrivacyDataPGP *data = NULL; - const gchar *sig_indicator = "-----BEGIN PGP SIGNED MESSAGE-----"; + static const gchar sig_indicator[] = "-----BEGIN PGP SIGNED MESSAGE-----"; gchar *textdata, *sigpos; cm_return_val_if_fail(mimeinfo != NULL, FALSE); @@ -347,6 +347,6 @@ static gchar *pgpinline_get_sig_info_full(MimeInfo *mimeinfo) static gboolean pgpinline_is_encrypted(MimeInfo *mimeinfo) { - const gchar *enc_indicator = "-----BEGIN PGP MESSAGE-----"; + static const gchar enc_indicator[] = "-----BEGIN PGP MESSAGE-----"; gchar *textdata; cm_return_val_if_fail(mimeinfo != NULL, FALSE); @@ -399,8 +398,8 @@ static MimeInfo *pgpinline_decrypt(MimeInfo *mimeinfo) gpgme_ctx_t ctx; gchar *chars; size_t len; - const gchar *begin_indicator = "-----BEGIN PGP MESSAGE-----"; - const gchar *end_indicator = "-----END PGP MESSAGE-----"; + static const gchar begin_indicator[] = "-----BEGIN PGP MESSAGE-----"; + static const gchar end_indicator[] = "-----END PGP MESSAGE-----"; gchar *pos; if (gpgme_new(&ctx) != GPG_ERR_NO_ERROR) -- 1.8.1.3