From 50eeb3d818c7c36f03d0c195c48528c2cd2731ee Mon Sep 17 00:00:00 2001 From: hiro Date: Wed, 23 Aug 2006 03:55:56 +0000 Subject: added signature information to MsgInfo. git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@1128 ee746299-78ed-0310-b773-934348b2243d --- ChangeLog | 9 +++++++++ ChangeLog.ja | 9 +++++++++ libsylph/procmime.c | 1 - libsylph/procmime.h | 1 - libsylph/procmsg.c | 33 ++++++++++++++++++++++++++------- libsylph/procmsg.h | 14 +++++++++++--- src/mimeview.c | 9 --------- src/rfc2015.c | 49 ++++++++++++++++++++----------------------------- src/textview.c | 40 +++++++++++++++++++++++++--------------- 9 files changed, 100 insertions(+), 65 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0994b593..ec7c6c17 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-08-23 + + * libsylph/procmsg.[ch] + libsylph/procmime.[ch] + src/textview.c + src/mimeview.c + src/rfc2015.c: added signature information to MsgInfo. Removed unused + member from MimeInfo. + 2006-08-17 * src/textview.c diff --git a/ChangeLog.ja b/ChangeLog.ja index 8da1d5b7..8389e912 100644 --- a/ChangeLog.ja +++ b/ChangeLog.ja @@ -1,3 +1,12 @@ +2006-08-23 + + * libsylph/procmsg.[ch] + libsylph/procmime.[ch] + src/textview.c + src/mimeview.c + src/rfc2015.c: 署名情報を MsgInfo に追加。未使用のメンバを MimeInfo + から削除。 + 2006-08-17 * src/textview.c diff --git a/libsylph/procmime.c b/libsylph/procmime.c index 28bb9d1f..193c23e0 100644 --- a/libsylph/procmime.c +++ b/libsylph/procmime.c @@ -68,7 +68,6 @@ void procmime_mimeinfo_free_all(MimeInfo *mimeinfo) g_free(mimeinfo->content_disposition); g_free(mimeinfo->filename); - g_free(mimeinfo->plaintextfile); g_free(mimeinfo->sigstatus); g_free(mimeinfo->sigstatus_full); diff --git a/libsylph/procmime.h b/libsylph/procmime.h index ac86a63c..a4bbd312 100644 --- a/libsylph/procmime.h +++ b/libsylph/procmime.h @@ -118,7 +118,6 @@ struct _MimeInfo MimeInfo *children; MimeInfo *plaintext; - gchar *plaintextfile; gchar *sigstatus; gchar *sigstatus_full; diff --git a/libsylph/procmsg.c b/libsylph/procmsg.c index e212a7cd..13141f50 100644 --- a/libsylph/procmsg.c +++ b/libsylph/procmsg.c @@ -1078,8 +1078,8 @@ gchar *procmsg_get_message_file_path(MsgInfo *msginfo) g_return_val_if_fail(msginfo != NULL, NULL); - if (msginfo->plaintext_file) - file = g_strdup(msginfo->plaintext_file); + if (msginfo->encinfo && msginfo->encinfo->plaintext_file) + file = g_strdup(msginfo->encinfo->plaintext_file); else if (msginfo->file_path) return g_strdup(msginfo->file_path); else { @@ -1473,8 +1473,13 @@ MsgInfo *procmsg_msginfo_copy(MsgInfo *msginfo) MEMBDUP(file_path); - MEMBDUP(plaintext_file); - MEMBCOPY(decryption_failed); + if (msginfo->encinfo) { + newmsginfo->encinfo = g_new0(MsgEncryptInfo, 1); + MEMBDUP(encinfo->plaintext_file); + MEMBDUP(encinfo->sigstatus); + MEMBDUP(encinfo->sigstatus_full); + MEMBCOPY(encinfo->decryption_failed); + } return newmsginfo; } @@ -1504,8 +1509,17 @@ MsgInfo *procmsg_msginfo_get_full_info(MsgInfo *msginfo) full_msginfo->file_path = g_strdup(msginfo->file_path); - full_msginfo->plaintext_file = g_strdup(msginfo->plaintext_file); - full_msginfo->decryption_failed = msginfo->decryption_failed; + if (msginfo->encinfo) { + full_msginfo->encinfo = g_new0(MsgEncryptInfo, 1); + full_msginfo->encinfo->plaintext_file = + g_strdup(msginfo->encinfo->plaintext_file); + full_msginfo->encinfo->sigstatus = + g_strdup(msginfo->encinfo->sigstatus); + full_msginfo->encinfo->sigstatus_full = + g_strdup(msginfo->encinfo->sigstatus_full); + full_msginfo->encinfo->decryption_failed = + msginfo->encinfo->decryption_failed; + } return full_msginfo; } @@ -1549,7 +1563,12 @@ void procmsg_msginfo_free(MsgInfo *msginfo) g_free(msginfo->file_path); - g_free(msginfo->plaintext_file); + if (msginfo->encinfo) { + g_free(msginfo->encinfo->plaintext_file); + g_free(msginfo->encinfo->sigstatus); + g_free(msginfo->encinfo->sigstatus_full); + g_free(msginfo->encinfo); + } g_free(msginfo); } diff --git a/libsylph/procmsg.h b/libsylph/procmsg.h index 3fc7e119..32172142 100644 --- a/libsylph/procmsg.h +++ b/libsylph/procmsg.h @@ -33,6 +33,7 @@ typedef struct _MsgInfo MsgInfo; typedef struct _MsgFlags MsgFlags; typedef struct _MsgFileInfo MsgFileInfo; +typedef struct _MsgEncryptInfo MsgEncryptInfo; #include "folder.h" #include "procmime.h" @@ -195,9 +196,8 @@ struct _MsgInfo /* used only for temporary messages */ gchar *file_path; - /* used only for encrypted messages */ - gchar *plaintext_file; - guint decryption_failed : 1; + /* used only for encrypted (and signed) messages */ + MsgEncryptInfo *encinfo; }; struct _MsgFileInfo @@ -206,6 +206,14 @@ struct _MsgFileInfo MsgFlags *flags; }; +struct _MsgEncryptInfo +{ + gchar *plaintext_file; + gchar *sigstatus; + gchar *sigstatus_full; + gboolean decryption_failed; +}; + typedef FILE * (*DecryptMessageFunc) (MsgInfo *msginfo, MimeInfo **mimeinfo); diff --git a/src/mimeview.c b/src/mimeview.c index 3a79811a..b117d6a9 100644 --- a/src/mimeview.c +++ b/src/mimeview.c @@ -520,19 +520,10 @@ static void mimeview_show_message_part(MimeView *mimeview, MimeInfo *partinfo) { FILE *fp; const gchar *fname; -#if USE_GPGME - MimeInfo *pi; -#endif if (!partinfo) return; -#if USE_GPGME - for (pi = partinfo; pi && !pi->plaintextfile ; pi = pi->parent) - ; - fname = pi ? pi->plaintextfile : mimeview->file; -#else fname = mimeview->file; -#endif /* USE_GPGME */ if (!fname) return; if ((fp = g_fopen(fname, "rb")) == NULL) { diff --git a/src/rfc2015.c b/src/rfc2015.c index bffc3259..4f050d3b 100644 --- a/src/rfc2015.c +++ b/src/rfc2015.c @@ -362,7 +362,7 @@ static gchar *copy_gpgmedata_to_temp(GpgmeData data, guint *length) } #endif -static gpgme_data_t pgp_decrypt(MimeInfo *partinfo, FILE *fp) +static gpgme_data_t pgp_decrypt(MsgInfo *msginfo, MimeInfo *partinfo, FILE *fp) { gpgme_ctx_t ctx = NULL; gpgme_error_t err; @@ -400,11 +400,14 @@ static gpgme_data_t pgp_decrypt(MimeInfo *partinfo, FILE *fp) err = gpgme_op_decrypt_verify(ctx, cipher, plain); + msginfo->encinfo = g_new0(MsgEncryptInfo, 1); + if (err) { gpgmegtk_free_passphrase(); debug_print("decryption failed: %s\n", gpgme_strerror(err)); gpgme_data_release(plain); plain = NULL; + msginfo->encinfo->decryption_failed = TRUE; goto leave; } @@ -412,14 +415,14 @@ static gpgme_data_t pgp_decrypt(MimeInfo *partinfo, FILE *fp) verifyresult = gpgme_op_verify_result(ctx); if (verifyresult && verifyresult->signatures) { - g_free(partinfo->sigstatus_full); - partinfo->sigstatus_full = sig_status_full(ctx, verifyresult); result = gpgmegtk_sig_status_to_string(verifyresult->signatures, FALSE); - g_free(partinfo->sigstatus); - partinfo->sigstatus = g_strdup(result); - debug_print("full status: %s\n", partinfo->sigstatus_full); + msginfo->encinfo->sigstatus = g_strdup(result); + msginfo->encinfo->sigstatus_full = + sig_status_full(ctx, verifyresult); debug_print("verification status: %s\n", result); + debug_print("full status: %s\n", + msginfo->encinfo->sigstatus_full); if (prefs_common.gpg_signature_popup) { GpgmegtkSigStatus statuswindow; statuswindow = gpgmegtk_sig_status_create(); @@ -428,6 +431,7 @@ static gpgme_data_t pgp_decrypt(MimeInfo *partinfo, FILE *fp) } } + leave: gpgme_data_release(cipher); gpgme_release(ctx); @@ -602,7 +606,8 @@ static gint headerp(gchar *p, gchar **names) #define DECRYPTION_ABORT() \ { \ procmime_mimeinfo_free_all(tmpinfo); \ - msginfo->decryption_failed = 1; \ + if (msginfo->encinfo) \ + msginfo->encinfo->decryption_failed = TRUE; \ return; \ } @@ -658,7 +663,7 @@ void rfc2015_decrypt_message(MsgInfo *msginfo, MimeInfo *mimeinfo, FILE *fp) debug_print("** yep, it is pgp encrypted\n"); - plain = pgp_decrypt(partinfo, fp); + plain = pgp_decrypt(msginfo, partinfo, fp); if (!plain) { DECRYPTION_ABORT(); } @@ -708,16 +713,10 @@ void rfc2015_decrypt_message(MsgInfo *msginfo, MimeInfo *mimeinfo, FILE *fp) gpgme_strerror(gpgme_error_from_errno(errno))); } - if (partinfo->sigstatus) { - mimeinfo->sigstatus = g_strdup(partinfo->sigstatus); - mimeinfo->sigstatus_full = g_strdup(partinfo->sigstatus_full); - } - fclose(dstfp); procmime_mimeinfo_free_all(tmpinfo); - msginfo->plaintext_file = fname; - msginfo->decryption_failed = 0; + msginfo->encinfo->plaintext_file = fname; } #undef DECRYPTION_ABORT @@ -746,21 +745,15 @@ FILE *rfc2015_open_message_decrypted(MsgInfo *msginfo, MimeInfo **mimeinfo) } if (MSG_IS_ENCRYPTED(msginfo->flags) && - !msginfo->plaintext_file && - !msginfo->decryption_failed) { + (!msginfo->encinfo || + (!msginfo->encinfo->plaintext_file && + !msginfo->encinfo->decryption_failed))) { fpos = ftell(fp); rfc2015_decrypt_message(msginfo, mimeinfo_, fp); - if (msginfo->plaintext_file && - !msginfo->decryption_failed) { - gchar *sigstatus = NULL, *sigstatus_full = NULL; - + if (msginfo->encinfo && + msginfo->encinfo->plaintext_file && + !msginfo->encinfo->decryption_failed) { fclose(fp); - if (mimeinfo_->sigstatus) { - sigstatus = mimeinfo_->sigstatus; - mimeinfo_->sigstatus = NULL; - sigstatus_full = mimeinfo_->sigstatus_full; - mimeinfo_->sigstatus_full = NULL; - } procmime_mimeinfo_free_all(mimeinfo_); if ((fp = procmsg_open_message(msginfo)) == NULL) @@ -770,8 +763,6 @@ FILE *rfc2015_open_message_decrypted(MsgInfo *msginfo, MimeInfo **mimeinfo) fclose(fp); return NULL; } - mimeinfo_->sigstatus = sigstatus; - mimeinfo_->sigstatus_full = sigstatus_full; } else { if (fseek(fp, fpos, SEEK_SET) < 0) perror("fseek"); diff --git a/src/textview.c b/src/textview.c index 8437c7d1..e9d33d59 100644 --- a/src/textview.c +++ b/src/textview.c @@ -478,8 +478,9 @@ void textview_show_message(TextView *textview, MimeInfo *mimeinfo, textview_add_parts(textview, mimeinfo, fp); #if USE_GPGME - if (mimeinfo->sigstatus) - textview_add_sig_part(textview, mimeinfo); + if (textview->messageview->msginfo->encinfo && + textview->messageview->msginfo->encinfo->sigstatus) + textview_add_sig_part(textview, NULL); #endif fclose(fp); @@ -740,22 +741,32 @@ static void textview_add_sig_part(TextView *textview, MimeInfo *mimeinfo) GtkTextIter iter; gchar buf[BUFFSIZE]; const gchar *color; + const gchar *sigstatus; + const gchar *sigstatus_full; + const gchar *type; + + if (mimeinfo) { + sigstatus = mimeinfo->sigstatus; + sigstatus_full = mimeinfo->sigstatus_full; + type = mimeinfo->content_type; + } else if (textview->messageview->msginfo->encinfo) { + sigstatus = textview->messageview->msginfo->encinfo->sigstatus; + sigstatus_full = + textview->messageview->msginfo->encinfo->sigstatus_full; + type = "signature"; + } else + return; - if (!mimeinfo->sigstatus) + if (!sigstatus) return; - if (mimeinfo->parent) - g_snprintf(buf, sizeof(buf), "\n[%s (%s)]\n", - mimeinfo->content_type, mimeinfo->sigstatus); - else - g_snprintf(buf, sizeof(buf), "\n[%s (%s)]\n", - "signature", mimeinfo->sigstatus); + g_snprintf(buf, sizeof(buf), "\n[%s (%s)]\n", type, sigstatus); - if (!strcmp(mimeinfo->sigstatus, _("Good signature"))) + if (!strcmp(sigstatus, _("Good signature"))) color = "good-signature"; - else if (!strcmp(mimeinfo->sigstatus, _("Valid signature (untrusted key)"))) + else if (!strcmp(sigstatus, _("Valid signature (untrusted key)"))) color = "untrusted-signature"; - else if (!strcmp(mimeinfo->sigstatus, _("BAD signature"))) + else if (!strcmp(sigstatus, _("BAD signature"))) color = "bad-signature"; else color = "nocheck-signature"; @@ -764,10 +775,9 @@ static void textview_add_sig_part(TextView *textview, MimeInfo *mimeinfo) gtk_text_buffer_get_end_iter(buffer, &iter); gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, buf, -1, color, "mimepart", NULL); - if (mimeinfo->sigstatus_full) + if (sigstatus_full) gtk_text_buffer_insert_with_tags_by_name - (buffer, &iter, mimeinfo->sigstatus_full, -1, - "mimepart", NULL); + (buffer, &iter, sigstatus_full, -1, "mimepart", NULL); } #endif -- cgit v1.2.3