0.9.6claws32
authorChristoph Hohmann <reboot@gmx.ch>
Fri, 17 Oct 2003 22:01:16 +0000 (22:01 +0000)
committerChristoph Hohmann <reboot@gmx.ch>
Fri, 17 Oct 2003 22:01:16 +0000 (22:01 +0000)
* src/Makefile.am
* src/main.c
* src/mimeview.c
* src/noticeview.c
* src/pgpmime.[ch]                              ** NEW **
* src/privacy.[ch]
* src/rfc2015.c
* src/sgpgme.c                                  ** NEW **
        reimplement PGP/Mime signature checking (unfinished)

13 files changed:
ChangeLog.claws
configure.ac
src/Makefile.am
src/main.c
src/mimeview.c
src/noticeview.c
src/pgpmime.c [new file with mode: 0644]
src/pgpmime.h [new file with mode: 0644]
src/privacy.c
src/privacy.h
src/rfc2015.c
src/sgpgme.c [new file with mode: 0644]
src/sgpgme.h [new file with mode: 0644]

index 44a05ef3a089fea27e4d76e64708299cd7262f35..eb12e24c9db4383553f6cac03ad03578b8a90082 100644 (file)
@@ -1,3 +1,15 @@
+2003-10-17 [christoph]  0.9.6claws32
+
+       * src/Makefile.am
+       * src/main.c
+       * src/mimeview.c
+       * src/noticeview.c
+       * src/pgpmime.[ch]                              ** NEW **
+       * src/privacy.[ch]
+       * src/rfc2015.c
+       * src/sgpgme.c                                  ** NEW **
+               reimplement PGP/Mime signature checking (unfinished)
+
 2003-10-15 [christoph]  0.9.6claws31
 
        * src/procmime.[ch]
index 28fdcfd969ac046af5cc842d007989c7c7ce2f47..6f8395f1185d9d1959fefcbdf8a84dee1fab1e3d 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=6
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=31
+EXTRA_VERSION=32
 if test $EXTRA_VERSION -eq 0; then
     VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}claws
 else
index 80a93c1b2fb98ce29e073547a75eb0127f3ada70..f0cce846bcdc827c36a69a32a6452090a94bf723 100644 (file)
@@ -5,10 +5,10 @@ bin_PROGRAMS = sylpheed
 sylpheed_SOURCES = \
        account.c \
        action.c \
-       addr_compl.c \
        addrbook.c \
        addrcache.c \
        addrclip.c \
+       addr_compl.c \
        addressadd.c \
        addressbook.c \
        addrgather.c \
@@ -27,8 +27,8 @@ sylpheed_SOURCES = \
        editbook.c \
        editgroup.c \
        editjpilot.c \
-       editldap.c \
        editldap_basedn.c \
+       editldap.c \
        editvcard.c \
        enriched.c \
        exphtmldlg.c \
@@ -74,6 +74,7 @@ sylpheed_SOURCES = \
        news.c \
        noticeview.c \
        passphrase.c \
+       pgpmime.c \
        pine.c \
        pop.c \
        prefs_account.c \
@@ -81,8 +82,8 @@ sylpheed_SOURCES = \
        prefs_common.c \
        prefs_customheader.c \
        prefs_display_header.c \
-       prefs_filtering.c \
        prefs_filtering_action.c \
+       prefs_filtering.c \
        prefs_folder_item.c \
        prefs_fonts.c \
        prefs_gtk.c \
@@ -105,6 +106,7 @@ sylpheed_SOURCES = \
        select-keys.c \
        send_message.c \
        setup.c \
+       sgpgme.c \
        sigstatus.c \
        simple-gettext.c \
        sourcewindow.c \
@@ -125,10 +127,10 @@ sylpheedinclude_HEADERS = \
        account.h \
        action.h \
        adbookbase.h \
-       addr_compl.h \
        addrbook.h \
        addrcache.h \
        addrclip.h \
+       addr_compl.h \
        addressadd.h \
        addressbook.h \
        addressitem.h \
@@ -148,8 +150,8 @@ sylpheedinclude_HEADERS = \
        editbook.h \
        editgroup.h \
        editjpilot.h \
-       editldap.h \
        editldap_basedn.h \
+       editldap.h \
        editvcard.h \
        enriched.h \
        exphtmldlg.h \
@@ -185,8 +187,8 @@ sylpheedinclude_HEADERS = \
        matcher_parser.h \
        matcher_parser_lex.h \
        matcher_parser_parse.h \
-       mbox.h \
        mbox_folder.h \
+       mbox.h \
        message_search.h \
        messageview.h \
        mh.h \
@@ -196,6 +198,7 @@ sylpheedinclude_HEADERS = \
        news.h \
        noticeview.h \
        passphrase.h \
+       pgpmime.h \
        pine.h \
        pop.h \
        prefs_account.h \
@@ -203,8 +206,8 @@ sylpheedinclude_HEADERS = \
        prefs_common.h \
        prefs_customheader.h \
        prefs_display_header.h \
-       prefs_filtering.h \
        prefs_filtering_action.h \
+       prefs_filtering.h \
        prefs_folder_item.h \
        prefs_fonts.h \
        prefs_gtk.h \
@@ -227,6 +230,7 @@ sylpheedinclude_HEADERS = \
        select-keys.h \
        send_message.h \
        setup.h \
+       sgpgme.h \
        sigstatus.h \
        sourcewindow.h \
        ssl_manager.h \
index 1d43ed3e5810fbe14f77a2ddcfda90b506c39d8f..272f0aaf942d3c7d6f1b1ff52c6103c82f960627 100644 (file)
@@ -74,7 +74,8 @@
 #include "plugin.h"
 
 #if USE_GPGME
-#  include "rfc2015.h"
+#  include "sgpgme.h"
+#  include "pgpmime.h"
 #endif
 #if USE_OPENSSL
 #  include "ssl.h"
@@ -246,7 +247,8 @@ int main(int argc, char *argv[])
        prefs_common_read_config();
 
 #if USE_GPGME
-       rfc2015_init();
+       sgpgme_init();
+       pgpmime_init();
 #endif
 
        prefs_fonts_init();
@@ -359,7 +361,8 @@ int main(int argc, char *argv[])
        addressbook_destroy();
 
 #ifdef USE_GPGME
-       rfc2015_done();
+       pgpmime_done();
+       sgpgme_done();
 #endif
 
        prefs_fonts_done();
index 24e9cb1c4d7cb23f540d96c22bde928d5d8a5d9d..e796c756a5ec4cddc6e0b6bd85874feb276483dd 100644 (file)
@@ -616,6 +616,55 @@ void mimeview_clear(MimeView *mimeview)
        icon_list_clear(mimeview);
 }
 
+static void check_signature_cb(GtkWidget *widget, gpointer user_data);
+
+static void update_signature_noticeview(MimeView *mimeview, MimeInfo *mimeinfo)
+{
+       if (privacy_mimeinfo_is_signed(mimeinfo)) {
+               gchar *text = NULL, *button_text = NULL;
+               GtkSignalFunc func = NULL;
+
+               switch (privacy_mimeinfo_get_sig_status(mimeinfo)) {
+               case SIGNATURE_UNCHECKED:
+                       text = _("This part of the message has been signed");
+                       button_text = _("Check");
+                       func = check_signature_cb;
+                       break;
+               case SIGNATURE_OK:
+               case SIGNATURE_WARN:
+                       text = _("Signature is ok");
+                       break;
+               case SIGNATURE_INVALID:
+                       text = _("The signature of this part is invalid");
+                       break;
+               case SIGNATURE_CHECK_FAILED:
+                       text = _("Checking the signature failed");
+                       button_text = _("Check again");
+                       func = check_signature_cb;
+               default:
+                       break;
+               }
+               noticeview_set_text(mimeview->siginfoview, text);
+               noticeview_set_button_text(mimeview->siginfoview, button_text);
+               noticeview_set_button_press_callback(
+                       mimeview->siginfoview,
+                       func,
+                       (gpointer) mimeview);
+               noticeview_show(mimeview->siginfoview);
+       } else {
+               noticeview_hide(mimeview->siginfoview);
+       }
+}
+
+static void check_signature_cb(GtkWidget *widget, gpointer user_data)
+{
+       MimeView *mimeview = (MimeView *) user_data;
+       MimeInfo *mimeinfo = mimeview_get_selected_part(mimeview);
+       
+       privacy_mimeinfo_check_signature(mimeinfo);
+       update_signature_noticeview(mimeview, mimeinfo);
+}
+
 static void mimeview_selected(GtkCTree *ctree, GtkCTreeNode *node, gint column,
                              MimeView *mimeview)
 {
@@ -637,12 +686,7 @@ static void mimeview_selected(GtkCTree *ctree, GtkCTreeNode *node, gint column,
        
        mimeview->textview->default_text = FALSE;
 
-       if (privacy_mimeinfo_is_signed(partinfo)) {
-               noticeview_set_text(mimeview->siginfoview, "Signed Part");
-               noticeview_show(mimeview->siginfoview);
-       } else {
-               noticeview_hide(mimeview->siginfoview);
-       }
+       update_signature_noticeview(mimeview, partinfo);
 
        if (!mimeview_show_part(mimeview, partinfo)) {
                switch (partinfo->type) {
index 94a0c3b1467661149f8aec7ad8c54aadd397ca79..7c95e6a3b8d63eb4c24cf5c6689a3bbd538a2f9e 100644 (file)
@@ -86,7 +86,6 @@ NoticeView *noticeview_create(MainWindow *mainwin)
        gtk_signal_connect(GTK_OBJECT(widget), "clicked", 
                           GTK_SIGNAL_FUNC(noticeview_button_pressed),
                           (gpointer) noticeview);
-       gtk_widget_show(widget);
        gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, FALSE, 4);
        
        noticeview->vbox   = vbox;
@@ -136,8 +135,13 @@ void noticeview_set_text(NoticeView *noticeview, const char *text)
 void noticeview_set_button_text(NoticeView *noticeview, const char *text)
 {
        g_return_if_fail(noticeview);
-       gtk_label_set_text
-               (GTK_LABEL(GTK_BIN(noticeview->button)->child), text);
+
+       if (text != NULL) {
+               gtk_label_set_text
+                       (GTK_LABEL(GTK_BIN(noticeview->button)->child), text);
+               gtk_widget_show(noticeview->button);
+       } else
+               gtk_widget_hide(noticeview->button);
 }
 
 void noticeview_set_button_press_callback(NoticeView   *noticeview,
@@ -154,4 +158,3 @@ static void noticeview_button_pressed(GtkButton *button, NoticeView *noticeview)
                noticeview->press(noticeview, noticeview->user_data);
        }
 }
-
diff --git a/src/pgpmime.c b/src/pgpmime.c
new file mode 100644 (file)
index 0000000..07a3f7d
--- /dev/null
@@ -0,0 +1,214 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2003 Hiroyuki Yamamoto & the Sylpheed-Claws team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#ifdef USE_GPGME
+
+#include <glib.h>
+#include <gpgme.h>
+
+#include "defs.h"
+#include "utils.h"
+#include "privacy.h"
+#include "procmime.h"
+#include "pgpmime.h"
+#include "sgpgme.h"
+
+typedef struct _PrivacyDataPGP PrivacyDataPGP;
+
+struct _PrivacyDataPGP
+{
+       PrivacyData     data;
+       
+       gboolean        done_sigtest;
+       gboolean        is_signed;
+       GpgmeSigStat    sigstatus;
+       GpgmeCtx        ctx;
+};
+
+static PrivacySystem pgpmime_system;
+
+static PrivacyDataPGP *pgpmime_new_privacydata()
+{
+       PrivacyDataPGP *data;
+
+       data = g_new0(PrivacyDataPGP, 1);
+       data->data.system = &pgpmime_system;
+       data->done_sigtest = FALSE;
+       data->is_signed = FALSE;
+       data->sigstatus = GPGME_SIG_STAT_NONE;
+       gpgme_new(&data->ctx);
+       
+       return data;
+}
+
+static void pgpmime_free_privacydata(PrivacyData *_data)
+{
+       PrivacyDataPGP *data = (PrivacyDataPGP *) _data;
+       
+       g_free(data);
+}
+
+static gboolean pgpmime_is_signed(MimeInfo *mimeinfo)
+{
+       MimeInfo *parent;
+       MimeInfo *signature;
+       gchar *protocol;
+       PrivacyDataPGP *data = NULL;
+       
+       g_return_val_if_fail(mimeinfo != NULL, FALSE);
+       if (mimeinfo->privacy != NULL) {
+               data = (PrivacyDataPGP *) mimeinfo->privacy;
+               if (data->done_sigtest)
+                       return data->is_signed;
+       }
+       
+       /* check parent */
+       parent = procmime_mimeinfo_parent(mimeinfo);
+       if (parent == NULL)
+               return FALSE;
+       if ((parent->type != MIMETYPE_MULTIPART) ||
+           g_strcasecmp(parent->subtype, "signed"))
+               return FALSE;
+       protocol = g_hash_table_lookup(parent->parameters, "protocol");
+       if ((protocol == NULL) || g_strcasecmp(protocol, "application/pgp-signature"))
+               return FALSE;
+
+       /* check if mimeinfo is the first child */
+       if (parent->node->children->data != mimeinfo)
+               return FALSE;
+
+       /* check signature */
+       signature = parent->node->children->next != NULL ? 
+           (MimeInfo *) parent->node->children->next->data : NULL;
+       if (signature == NULL)
+               return FALSE;
+       if ((signature->type != MIMETYPE_APPLICATION) ||
+           g_strcasecmp(signature->subtype, "pgp-signature"))
+               return FALSE;
+
+       if (data == NULL) {
+               data = pgpmime_new_privacydata();
+               mimeinfo->privacy = (PrivacyData *) data;
+       }
+       data->done_sigtest = TRUE;
+       data->is_signed = TRUE;
+       
+       return TRUE;
+}
+
+static gint pgpmime_check_signature(MimeInfo *mimeinfo)
+{
+       PrivacyDataPGP *data;
+       MimeInfo *parent, *signature;
+       FILE *fp;
+       gchar buf[BUFFSIZE];
+       gchar *boundary;
+       GString *textstr;
+       gint boundary_len;
+       GpgmeData sigdata, textdata;
+       
+       g_return_val_if_fail(mimeinfo != NULL, -1);
+       g_return_val_if_fail(mimeinfo->privacy != NULL, -1);
+       data = (PrivacyDataPGP *) mimeinfo->privacy;
+       
+       debug_print("Checking PGP/MIME signature\n");
+       parent = procmime_mimeinfo_parent(mimeinfo);
+
+       fp = fopen(parent->filename, "rb");
+       g_return_val_if_fail(fp != NULL, SIGNATURE_INVALID);
+       
+       boundary = g_hash_table_lookup(parent->parameters, "boundary");
+       boundary_len = strlen(boundary);
+       while (fgets(buf, sizeof(buf), fp) != NULL)
+               if (IS_BOUNDARY(buf, boundary, boundary_len))
+                       break;
+
+       textstr = g_string_new("");
+       while (fgets(buf, sizeof(buf), fp) != NULL) {
+               if (IS_BOUNDARY(buf, boundary, boundary_len))
+                       break;
+               gchar *buf2;
+               
+               buf2 = canonicalize_str(buf);
+               g_string_append(textstr, buf2);
+               g_free(buf2);
+       }
+       g_string_truncate(textstr, textstr->len - 2);
+       
+       
+       gpgme_data_new_from_mem(&textdata, textstr->str, textstr->len, 0);
+       signature = (MimeInfo *) mimeinfo->node->next->data;
+       gpgme_data_new_from_filepart(&sigdata,
+               signature->filename,
+               NULL,
+               signature->offset,
+               signature->length);
+
+       data->sigstatus =
+               sgpgme_verify_signature (data->ctx, sigdata, textdata);
+       
+       gpgme_data_release(sigdata);
+       gpgme_data_release(textdata);
+       g_string_free(textstr, TRUE);
+       
+       printf("result: %d\n", data->sigstatus);
+       
+       return 0;
+}
+
+static SignatureStatus pgpmime_get_sig_status(MimeInfo *mimeinfo)
+{
+       PrivacyDataPGP *data = (PrivacyDataPGP *) mimeinfo->privacy;
+       
+       g_return_val_if_fail(data != NULL, SIGNATURE_INVALID);
+
+       return sgpgme_sigstat_gpgme_to_privacy(data->sigstatus);
+}
+
+static PrivacySystem pgpmime_system = {
+       "PGP/Mime",                     /* name */
+
+       pgpmime_free_privacydata,       /* free_privacydata */
+
+       pgpmime_is_signed,              /* is_signed(MimeInfo *) */
+       pgpmime_check_signature,        /* check_signature(MimeInfo *) */
+       pgpmime_get_sig_status,         /* get_sig_status(MimeInfo *) */
+       NULL,                           /* get_sig_info_short(MimeInfo *) */
+       NULL,                           /* get_sig_info_full(MimeInfo *) */
+
+       /* NOT YET */
+       NULL,                           /* is_encrypted(MimeInfo *) */
+       NULL,                           /* decrypt(MimeInfo *) */
+};
+
+void pgpmime_init()
+{
+       privacy_register_system(&pgpmime_system);
+}
+
+void pgpmime_done()
+{
+       privacy_unregister_system(&pgpmime_system);
+}
+
+#endif /* USE_GPGME */
diff --git a/src/pgpmime.h b/src/pgpmime.h
new file mode 100644 (file)
index 0000000..a6ce4ce
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2003 Hiroyuki Yamamoto & the Sylpheed-Claws team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef PGPMIME_H
+#define PGPMIME_H 1
+
+void pgpmime_init(void);
+void pgpmime_done(void);
+
+#endif /* PGPMIME_H */
index dbd6bede05faf5d8a0650419ee5523fc157969f2..13fbaf894bf854851c0fb281522324d1cc1c3e8a 100644 (file)
@@ -59,17 +59,48 @@ gboolean privacy_mimeinfo_is_signed(MimeInfo *mimeinfo)
                PrivacySystem *system = (PrivacySystem *) cur->data;
 
                if(system->is_signed != NULL && system->is_signed(mimeinfo))
-                       return TRUE;                    
+                       return TRUE;
        }
 
        return FALSE;
 }
 
-const gchar *privacy_get_signer(MimeInfo *mimeinfo)
+gint privacy_mimeinfo_check_signature(MimeInfo *mimeinfo)
 {
-       g_return_val_if_fail(mimeinfo != NULL, NULL);
+       PrivacySystem *system;
+
+       g_return_val_if_fail(mimeinfo != NULL, -1);
+
+       if (mimeinfo->privacy == NULL)
+               privacy_mimeinfo_is_signed(mimeinfo);
+       
+       if (mimeinfo->privacy == NULL)
+               return -1;
+       
+       system = mimeinfo->privacy->system;
+       if (system->check_signature == NULL)
+               return -1;
+       
+       return system->check_signature(mimeinfo);
+}
 
-       return "Dummy";
+SignatureStatus privacy_mimeinfo_get_sig_status(MimeInfo *mimeinfo)
+{
+       PrivacySystem *system;
+
+       g_return_val_if_fail(mimeinfo != NULL, -1);
+
+       if (mimeinfo->privacy == NULL)
+               privacy_mimeinfo_is_signed(mimeinfo);
+       
+       if (mimeinfo->privacy == NULL)
+               return SIGNATURE_UNCHECKED;
+       
+       system = mimeinfo->privacy->system;
+       if (system->get_sig_status == NULL)
+               return SIGNATURE_UNCHECKED;
+       
+       return system->get_sig_status(mimeinfo);
 }
 
 gboolean privacy_mimeinfo_is_encrypted(MimeInfo *mimeinfo)
index 0885b51942bfd1de27fdf96fa5a3a6e0d24484d9..f339f605ad47e6243e9b5c610963c41ab779521c 100644 (file)
@@ -26,25 +26,27 @@ typedef struct _PrivacyData PrivacyData;
 typedef enum {
        SIGNATURE_UNCHECKED,
        SIGNATURE_OK,
+       SIGNATURE_WARN,
        SIGNATURE_INVALID,
+       SIGNATURE_CHECK_FAILED,
 } SignatureStatus;
 
 #include <glib.h>
 
 #include "procmime.h"
 
-void privacy_register_system           (PrivacySystem *system);
-void privacy_unregister_system         (PrivacySystem *system);
+void privacy_register_system                   (PrivacySystem *system);
+void privacy_unregister_system                 (PrivacySystem *system);
 
-void privacy_free_privacydata          (PrivacyData *);
+void privacy_free_privacydata                  (PrivacyData *);
 
-gboolean privacy_mimeinfo_is_signed    (MimeInfo *);
-const gchar *privacy_get_signer                (MimeInfo *);
-SignatureStatus privacy_check_signature        (MimeInfo *);
+gboolean privacy_mimeinfo_is_signed            (MimeInfo *);
+gint privacy_mimeinfo_check_signature          (MimeInfo *);
+SignatureStatus privacy_mimeinfo_get_sig_status        (MimeInfo *);
 
 #if 0 /* NOT YET */
-gboolean privacy_mimeinfo_is_encrypted (MimeInfo *);
-gint privacy_decrypt                   (MimeInfo *);
+gboolean privacy_mimeinfo_is_encrypted         (MimeInfo *);
+gint privacy_decrypt                           (MimeInfo *);
 #endif
 
 struct _PrivacySystem {
@@ -53,8 +55,10 @@ struct _PrivacySystem {
        void             (*free_privacydata)    (PrivacyData *);
 
        gboolean         (*is_signed)           (MimeInfo *);
-       const gchar     *(*get_signer)          (MimeInfo *);
-       SignatureStatus  (*check_signature)     (MimeInfo *);
+       gint             (*check_signature)     (MimeInfo *);
+       SignatureStatus  (*get_sig_status)      (MimeInfo *);
+       const gchar     *(*get_sig_info_short)  (MimeInfo *);
+       const gchar     *(*get_sig_info_full)   (MimeInfo *);
 
        /* NOT YET */
        gboolean         (*is_encrypted)        (MimeInfo *);
index 120fc27d9e9883ec6f769a35cc5d6af06cebbd4d..cbe5351cb56460c7fcb9fab7209775751ccf927d 100644 (file)
@@ -116,14 +116,6 @@ static void dump_part ( MimeInfo *mimeinfo, FILE *fp )
 }
 #endif
 
-void
-rfc2015_disable_all (void)
-{
-    /* FIXME: set a flag, so that we don't bother the user with failed
-     * gpgme messages */
-}
-
-
 void
 rfc2015_secure_remove (const char *fname)
 {
@@ -524,55 +516,6 @@ leave:
     return plain;
 }
 
-#if 0 /* UNUSED */
-MimeInfo * rfc2015_find_signature (MimeInfo *mimeinfo)
-{
-    MimeInfo *partinfo;
-    int n = 0;
-
-    if (!mimeinfo)
-        return NULL;
-    if (!((mimeinfo->type == MIMETYPE_MULTIPART) && !g_strcasecmp(mimeinfo->subtype, "signed")))
-        return NULL;
-
-    debug_print ("** multipart/signed encountered\n");
-
-    /* check that we have at least 2 parts of the correct type */
-    for (partinfo = mimeinfo->children;
-         partinfo != NULL; partinfo = partinfo->next) {
-        if (++n > 1 && (partinfo->type == MIMETYPE_APPLICATION && 
-               !g_strcasecmp (partinfo->subtype, "pgp-signature")))
-            break;
-    }
-
-    return partinfo;
-}
-
-gboolean rfc2015_has_signature (MimeInfo *mimeinfo)
-{
-    return rfc2015_find_signature (mimeinfo) != NULL;
-}
-
-void rfc2015_check_signature (MimeInfo *mimeinfo, FILE *fp)
-{
-    MimeInfo *partinfo;
-
-    partinfo = rfc2015_find_signature (mimeinfo);
-    if (!partinfo)
-        return;
-
-#if 0
-    g_message ("** yep, it is a pgp signature");
-    dump_mimeinfo ("gpg-signature", partinfo );
-    dump_part (partinfo, fp );
-    dump_mimeinfo ("signed text", mimeinfo->children );
-    dump_part (mimeinfo->children, fp);
-#endif
-
-    check_signature (mimeinfo, partinfo, fp);
-}
-#endif
-
 int rfc2015_is_encrypted (MimeInfo *mimeinfo)
 {
     if (!mimeinfo || mimeinfo->type != MIMETYPE_MULTIPART)
@@ -1465,89 +1408,4 @@ failure:
     return -1;
 }
 
-static gboolean rfc2015_is_signed(MimeInfo *mimeinfo)
-{
-       MimeInfo *parent;
-       MimeInfo *signature;
-       gchar *protocol;
-
-       g_return_val_if_fail(mimeinfo != NULL, FALSE);
-       
-       /* check parent */
-       parent = procmime_mimeinfo_parent(mimeinfo);
-       if (parent == NULL)
-               return FALSE;
-       if ((parent->type != MIMETYPE_MULTIPART) ||
-           g_strcasecmp(parent->subtype, "signed"))
-               return FALSE;
-       protocol = g_hash_table_lookup(parent->parameters, "protocol");
-       if ((protocol == NULL) || g_strcasecmp(protocol, "application/pgp-signature"))
-               return FALSE;
-
-       /* check if mimeinfo is the first child */
-       if (parent->node->children->data != mimeinfo)
-               return FALSE;
-
-       /* check signature */
-       signature = parent->node->children->next != NULL ? 
-           (MimeInfo *) parent->node->children->next->data : NULL;
-       if (signature == NULL)
-               return FALSE;
-       if ((signature->type != MIMETYPE_APPLICATION) ||
-           g_strcasecmp(signature->subtype, "pgp-signature"))
-               return FALSE;
-
-       return TRUE;
-}
-
-static void idle_function_for_gpgme(void)
-{
-       while (gtk_events_pending())
-               gtk_main_iteration();
-}
-
-static PrivacySystem rfc2015_system = {
-       "PGP/Mime",             /* name */
-
-       g_free,                 /* free_privacydata */
-
-       rfc2015_is_signed,      /* is_signed(MimeInfo *) */
-       NULL,                   /* get_signer(MimeInfo *) */
-       NULL,                   /* check_signature(MimeInfo *) */
-
-       /* NOT YET */
-       NULL,                   /* is_encrypted(MimeInfo *) */
-       NULL,                   /* decrypt(MimeInfo *) */
-};
-
-void rfc2015_init()
-{
-       if (gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP) != 
-                       GPGME_No_Error) {  /* Also does some gpgme init */
-               rfc2015_disable_all();
-               debug_print("gpgme_engine_version:\n%s\n",
-                           gpgme_get_engine_info());
-
-               if (prefs_common.gpg_warning) {
-                       AlertValue val;
-
-                       val = alertpanel_message_with_disable
-                               (_("Warning"),
-                                _("GnuPG is not installed properly, or needs to be upgraded.\n"
-                                  "OpenPGP support disabled."));
-                       if (val & G_ALERTDISABLE)
-                               prefs_common.gpg_warning = FALSE;
-               }
-       } else
-               privacy_register_system(&rfc2015_system);
-
-       gpgme_register_idle(idle_function_for_gpgme);
-}
-
-void rfc2015_done()
-{
-       privacy_unregister_system(&rfc2015_system);
-        gpgmegtk_free_passphrase();
-}
-
 #endif /* USE_GPGME */
diff --git a/src/sgpgme.c b/src/sgpgme.c
new file mode 100644 (file)
index 0000000..1863c4c
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2003 Hiroyuki Yamamoto & the Sylpheed-Claws team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+#ifdef USE_GPGME
+
+#include <gtk/gtk.h>
+#include <gpgme.h>
+
+#include "sgpgme.h"
+#include "privacy.h"
+#include "prefs_common.h"
+#include "utils.h"
+#include "alertpanel.h"
+#include "passphrase.h"
+#include "intl.h"
+
+static void idle_function_for_gpgme(void)
+{
+       while (gtk_events_pending())
+               gtk_main_iteration();
+}
+
+static void sgpgme_disable_all(void)
+{
+    /* FIXME: set a flag, so that we don't bother the user with failed
+     * gpgme messages */
+}
+
+GpgmeSigStat sgpgme_verify_signature(GpgmeCtx ctx, GpgmeData sig, 
+                                       GpgmeData plain)
+{
+       GpgmeSigStat status;
+
+       if (gpgme_op_verify(ctx, sig, plain, &status) != GPGME_No_Error)
+               return GPGME_SIG_STAT_ERROR;
+
+       return status;
+}
+
+SignatureStatus sgpgme_sigstat_gpgme_to_privacy(GpgmeSigStat status)
+{
+       switch (status) {
+       case GPGME_SIG_STAT_GOOD:
+               return SIGNATURE_OK;
+       case GPGME_SIG_STAT_GOOD_EXP:
+       case GPGME_SIG_STAT_GOOD_EXPKEY:
+       case GPGME_SIG_STAT_DIFF:
+               return SIGNATURE_WARN;
+       case GPGME_SIG_STAT_BAD:
+               return SIGNATURE_INVALID;
+       case GPGME_SIG_STAT_NOKEY:
+       case GPGME_SIG_STAT_NOSIG:
+       case GPGME_SIG_STAT_ERROR:
+               return SIGNATURE_CHECK_FAILED;
+       case GPGME_SIG_STAT_NONE:
+               return SIGNATURE_UNCHECKED;
+       }
+       return SIGNATURE_CHECK_FAILED;
+}
+
+void sgpgme_init()
+{
+       if (gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP) != 
+                       GPGME_No_Error) {  /* Also does some gpgme init */
+               sgpgme_disable_all();
+               debug_print("gpgme_engine_version:\n%s\n",
+                           gpgme_get_engine_info());
+
+               if (prefs_common.gpg_warning) {
+                       AlertValue val;
+
+                       val = alertpanel_message_with_disable
+                               (_("Warning"),
+                                _("GnuPG is not installed properly, or needs to be upgraded.\n"
+                                  "OpenPGP support disabled."));
+                       if (val & G_ALERTDISABLE)
+                               prefs_common.gpg_warning = FALSE;
+               }
+       }
+
+       gpgme_register_idle(idle_function_for_gpgme);
+}
+
+void sgpgme_done()
+{
+        gpgmegtk_free_passphrase();
+}
+
+#endif /* USE_GPGME */
diff --git a/src/sgpgme.h b/src/sgpgme.h
new file mode 100644 (file)
index 0000000..3be85cd
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2003 Hiroyuki Yamamoto & the Sylpheed-Claws team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef SGPGME_H
+#define SGPGME_H 1
+
+#include <gpgme.h>
+
+#include "privacy.h"
+
+void sgpgme_init(void);
+void sgpgme_done(void);
+
+GpgmeSigStat sgpgme_verify_signature(GpgmeCtx ctx,
+                                    GpgmeData sig,
+                                    GpgmeData plain);
+SignatureStatus sgpgme_sigstat_gpgme_to_privacy(GpgmeSigStat status);
+
+#endif /* SGPGME_H */