2005-07-19 [colin] 1.9.12cvs84
authorColin Leroy <colin@colino.net>
Tue, 19 Jul 2005 16:10:13 +0000 (16:10 +0000)
committerColin Leroy <colin@colino.net>
Tue, 19 Jul 2005 16:10:13 +0000 (16:10 +0000)
* configure.ac
* src/plugins/Makefile.am
* src/plugins/pgpinline/.cvsignore
* src/plugins/pgpinline/Makefile.am
* src/plugins/pgpinline/pgpinline.c
* src/plugins/pgpinline/pgpinline.deps
* src/plugins/pgpinline/pgpinline.h
* src/plugins/pgpinline/plugin.c
Put pgpinline in the main tree

ChangeLog-gtk2.claws
PATCHSETS
configure.ac
src/plugins/Makefile.am
src/plugins/pgpinline/.cvsignore [new file with mode: 0644]
src/plugins/pgpinline/Makefile.am [new file with mode: 0644]
src/plugins/pgpinline/pgpinline.c [new file with mode: 0644]
src/plugins/pgpinline/pgpinline.deps [new file with mode: 0644]
src/plugins/pgpinline/pgpinline.h [new file with mode: 0644]
src/plugins/pgpinline/plugin.c [new file with mode: 0644]

index 7674de0705a5b514797dab85528974d311193c8f..4455946b3d2029e81606f49fc2a4115d6ed23f61 100644 (file)
@@ -1,3 +1,15 @@
+2005-07-19 [colin]     1.9.12cvs84
+
+       * configure.ac
+       * src/plugins/Makefile.am
+       * src/plugins/pgpinline/.cvsignore
+       * src/plugins/pgpinline/Makefile.am
+       * src/plugins/pgpinline/pgpinline.c
+       * src/plugins/pgpinline/pgpinline.deps
+       * src/plugins/pgpinline/pgpinline.h
+       * src/plugins/pgpinline/plugin.c
+               Put pgpinline in the main tree
+
 2005-07-19 [paul]      1.9.12cvs83
 
        * src/prefs_actions.c
 2005-07-19 [paul]      1.9.12cvs83
 
        * src/prefs_actions.c
index 8cce8dc9da20d99a84bf730f8dde4bbe27f639ab..ddba55a67858ba303dce72390d863580aa631744 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.395.2.95 -r 1.395.2.96 src/summaryview.c;  ) > 1.9.12cvs81.patchset
 ( cvs diff -u -r 1.654.2.716 -r 1.654.2.717 configure.ac;  cvs diff -u -r 1.1.2.3 -r 1.1.2.4 src/plugins/pgpcore/sgpgme.c;  ) > 1.9.12cvs82.patchset
 ( cvs diff -u -r 1.60.2.18 -r 1.60.2.19 src/prefs_actions.c;  ) > 1.9.12cvs83.patchset
 ( cvs diff -u -r 1.395.2.95 -r 1.395.2.96 src/summaryview.c;  ) > 1.9.12cvs81.patchset
 ( cvs diff -u -r 1.654.2.716 -r 1.654.2.717 configure.ac;  cvs diff -u -r 1.1.2.3 -r 1.1.2.4 src/plugins/pgpcore/sgpgme.c;  ) > 1.9.12cvs82.patchset
 ( cvs diff -u -r 1.60.2.18 -r 1.60.2.19 src/prefs_actions.c;  ) > 1.9.12cvs83.patchset
+( cvs diff -u -r 1.654.2.718 -r 1.654.2.719 configure.ac;  cvs diff -u -r 1.8.2.3 -r 1.8.2.4 src/plugins/Makefile.am;  diff -u /dev/null src/plugins/pgpinline/.cvsignore;  diff -u /dev/null src/plugins/pgpinline/Makefile.am;  diff -u /dev/null src/plugins/pgpinline/pgpinline.c;  diff -u /dev/null src/plugins/pgpinline/pgpinline.deps;  diff -u /dev/null src/plugins/pgpinline/pgpinline.h;  diff -u /dev/null src/plugins/pgpinline/plugin.c;  ) > 1.9.12cvs84.patchset
index c44efe70d8c0af0bc795e1dd0832046e9886dd84..87d07979c43e1d85fc3ec7cc8091189befee7712 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=12
 INTERFACE_AGE=0
 BINARY_AGE=0
 MICRO_VERSION=12
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=83
+EXTRA_VERSION=84
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
@@ -592,6 +592,23 @@ else
 fi
 AM_CONDITIONAL(BUILD_PGPMIME_PLUGIN, test x"$ac_cv_enable_pgpmime_plugin" = xyes)
 
 fi
 AM_CONDITIONAL(BUILD_PGPMIME_PLUGIN, test x"$ac_cv_enable_pgpmime_plugin" = xyes)
 
+AC_MSG_CHECKING([whether to build PGP/Inline plugin])
+AC_ARG_ENABLE(pgpinline-plugin,
+       [  --disable-pgpinline-plugin           Do not build PGP/Inline plugin],
+       [ac_cv_enable_pgpinline_plugin=$enableval], [ac_cv_enable_pgpinline_plugin=yes])
+if test x"$ac_cv_enable_pgpinline_plugin" = xyes; then
+       AC_MSG_RESULT(yes)
+       if test x"$ac_cv_enable_pgpcore_plugin" = xyes; then
+               PLUGINS="pgpinline $PLUGINS"
+       else
+               AC_MSG_WARN([*** PGP/Inline plugin cannot be built ***])
+               AC_MSG_WARN([*** without the PGP/CORE plugin     ***])
+       fi
+else
+       AC_MSG_RESULT(no)
+fi
+AM_CONDITIONAL(BUILD_PGPINLINE_PLUGIN, test x"$ac_cv_enable_pgpinline_plugin" = xyes)
+
 dnl --- MathML Viewer ---
 AC_MSG_CHECKING([whether to build MathML-Viewer plugin])
 AC_ARG_ENABLE(mathml-viewer-plugin,
 dnl --- MathML Viewer ---
 AC_MSG_CHECKING([whether to build MathML-Viewer plugin])
 AC_ARG_ENABLE(mathml-viewer-plugin,
@@ -742,6 +759,7 @@ src/plugins/trayicon/libeggtrayicon/Makefile
 src/plugins/clamav/Makefile
 src/plugins/pgpcore/Makefile
 src/plugins/pgpmime/Makefile
 src/plugins/clamav/Makefile
 src/plugins/pgpcore/Makefile
 src/plugins/pgpmime/Makefile
+src/plugins/pgpinline/Makefile
 doc/Makefile
 doc/faq/Makefile
 doc/faq/de/Makefile
 doc/Makefile
 doc/faq/Makefile
 doc/faq/de/Makefile
index 532e9fecf46f06ad7aaa760d9bb597d2db50fd94..c9727a8992e6848aafd86cc0d2b6fd82daf15d3c 100644 (file)
@@ -27,6 +27,9 @@ pgpcore_dir = pgpcore
 if BUILD_PGPMIME_PLUGIN
 pgpmime_dir = pgpmime
 endif
 if BUILD_PGPMIME_PLUGIN
 pgpmime_dir = pgpmime
 endif
+if BUILD_PGPINLINE_PLUGIN
+pgpinline_dir = pgpinline
+endif
 endif
 
 SUBDIRS = $(demo_dir) \
 endif
 
 SUBDIRS = $(demo_dir) \
@@ -36,4 +39,5 @@ SUBDIRS = $(demo_dir) \
        $(trayicon_dir) \
        $(clamav_dir) \
        $(pgpcore_dir) \
        $(trayicon_dir) \
        $(clamav_dir) \
        $(pgpcore_dir) \
-       $(pgpmime_dir)
+       $(pgpmime_dir) \
+       $(pgpinline_dir)
diff --git a/src/plugins/pgpinline/.cvsignore b/src/plugins/pgpinline/.cvsignore
new file mode 100644 (file)
index 0000000..2a6ab49
--- /dev/null
@@ -0,0 +1,7 @@
+.deps
+.libs
+Makefile
+Makefile.in
+*.o
+*.lo
+*.la
diff --git a/src/plugins/pgpinline/Makefile.am b/src/plugins/pgpinline/Makefile.am
new file mode 100644 (file)
index 0000000..686f71a
--- /dev/null
@@ -0,0 +1,30 @@
+plugindir = $(pkglibdir)/plugins
+plugin_DATA=pgpinline.deps
+
+plugin_LTLIBRARIES = pgpinline.la
+
+EXTRA_DIST=pgpinline.deps
+
+pgpinline_la_SOURCES = \
+       plugin.c \
+       pgpinline.c
+
+pluginincludedir = $(pkgincludedir)/plugins/pgpinline
+plugininclude_HEADERS = \
+       pgpinline.h 
+
+pgpinline_la_LDFLAGS = \
+       -avoid-version -module \
+        $(GTK_LIBS) \
+       $(GPGME_LIBS)
+               
+
+INCLUDES = \
+       -I../../ \
+       -I../../common \
+       -I../../gtk
+
+AM_CPPFLAGS = \
+       $(GLIB_CFLAGS) \
+       $(GTK_CFLAGS) \
+       $(GPGME_CFLAGS)
diff --git a/src/plugins/pgpinline/pgpinline.c b/src/plugins/pgpinline/pgpinline.c
new file mode 100644 (file)
index 0000000..8d4b304
--- /dev/null
@@ -0,0 +1,585 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2003 Hiroyuki Yamamoto & the Sylpheed-Claws team
+ * This file (C) 2004 Colin Leroy <colin@colino.net>
+ *
+ * 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 "defs.h"
+#include <glib.h>
+#include <gpgme.h>
+
+#include "utils.h"
+#include "privacy.h"
+#include "procmime.h"
+#include "pgpinline.h"
+#include <plugins/pgpcore/sgpgme.h>
+#include <plugins/pgpcore/prefs_gpg.h>
+#include <plugins/pgpcore/passphrase.h>
+#include "quoted-printable.h"
+#include "base64.h"
+#include "codeconv.h"
+
+extern struct GPGConfig prefs_gpg;
+
+typedef struct _PrivacyDataPGP PrivacyDataPGP;
+
+struct _PrivacyDataPGP
+{
+       PrivacyData     data;
+       
+       gboolean        done_sigtest;
+       gboolean        is_signed;
+       gpgme_verify_result_t   sigstatus;
+       gpgme_ctx_t     ctx;
+};
+
+static PrivacySystem pgpinline_system;
+
+static gint pgpinline_check_signature(MimeInfo *mimeinfo);
+
+static PrivacyDataPGP *pgpinline_new_privacydata()
+{
+       PrivacyDataPGP *data;
+
+       data = g_new0(PrivacyDataPGP, 1);
+       data->data.system = &pgpinline_system;
+       data->done_sigtest = FALSE;
+       data->is_signed = FALSE;
+       data->sigstatus = NULL;
+       gpgme_new(&data->ctx);
+       
+       return data;
+}
+
+static void pgpinline_free_privacydata(PrivacyData *_data)
+{
+       PrivacyDataPGP *data = (PrivacyDataPGP *) _data;
+       gpgme_release(data->ctx);
+       g_free(data);
+}
+
+static gchar *get_part_as_string(MimeInfo *mimeinfo)
+{
+       gchar *textdata = NULL;
+
+       g_return_val_if_fail(mimeinfo != NULL, 0);
+       procmime_decode_content(mimeinfo);
+       if (mimeinfo->content == MIMECONTENT_MEM)
+               textdata = g_strdup(mimeinfo->data.mem);
+       else
+               textdata = file_read_to_str(mimeinfo->data.filename);
+
+       return textdata;        
+}
+
+static gboolean pgpinline_is_signed(MimeInfo *mimeinfo)
+{
+       PrivacyDataPGP *data = NULL;
+       const gchar *sig_indicator = "-----BEGIN PGP SIGNED MESSAGE-----";
+       gchar *textdata, *sigpos;
+       
+       g_return_val_if_fail(mimeinfo != NULL, FALSE);
+       
+       if (procmime_mimeinfo_parent(mimeinfo) == NULL)
+               return FALSE; /* not parent */
+
+       if (mimeinfo->type != MIMETYPE_TEXT)
+               return FALSE;
+       
+       if (mimeinfo->privacy != NULL) {
+               data = (PrivacyDataPGP *) mimeinfo->privacy;
+               if (data->done_sigtest)
+                       return data->is_signed;
+       }
+       
+       textdata = get_part_as_string(mimeinfo);
+       if (!textdata)
+               return FALSE;
+       
+       if (data == NULL) {
+               data = pgpinline_new_privacydata();
+               mimeinfo->privacy = (PrivacyData *) data;
+       }
+       data->done_sigtest = TRUE;
+       data->is_signed = FALSE;
+
+       if ((sigpos = strstr(textdata, sig_indicator)) == NULL) {
+               g_free(textdata);
+               return FALSE;
+       }
+
+       if (!(sigpos == textdata) && !(sigpos[-1] == '\n')) {
+               g_free(textdata);
+               return FALSE;
+       }
+
+       g_free(textdata);
+
+       data->is_signed = TRUE;
+
+       return TRUE;
+}
+
+static gint pgpinline_check_signature(MimeInfo *mimeinfo)
+{
+       PrivacyDataPGP *data = NULL;
+       gchar *textdata = NULL, *tmp = NULL;
+       gpgme_data_t plain = NULL, cipher = NULL;
+       gpgme_ctx_t ctx;
+       
+       g_return_val_if_fail(mimeinfo != NULL, 0);
+
+       if (procmime_mimeinfo_parent(mimeinfo) == NULL)
+               return 0; /* not parent */
+       if (mimeinfo->type != MIMETYPE_TEXT)
+               return 0;
+
+       g_return_val_if_fail(mimeinfo->privacy != NULL, 0);
+       data = (PrivacyDataPGP *) mimeinfo->privacy;
+
+       textdata = get_part_as_string(mimeinfo);
+       
+       if (!textdata) {
+               g_free(textdata);
+               return 0;
+       }
+
+       /* gtk2: convert back from utf8 */
+       tmp = conv_codeset_strdup(textdata, CS_UTF_8,
+                       procmime_mimeinfo_get_parameter(mimeinfo, "charset"));
+       g_free(textdata);
+       textdata = g_strdup(tmp);
+       g_free(tmp);
+       
+       gpgme_new(&ctx);
+       gpgme_set_textmode(ctx, 1);
+       gpgme_set_armor(ctx, 1);
+       
+       gpgme_data_new_from_mem(&plain, textdata, strlen(textdata), 1);
+       gpgme_data_new(&cipher);
+
+       data->sigstatus = sgpgme_verify_signature(ctx, plain, NULL, cipher);
+       
+       gpgme_data_release(plain);
+       gpgme_data_release(cipher);
+       
+       g_free(textdata);
+       
+       return 0;
+}
+
+static SignatureStatus pgpinline_get_sig_status(MimeInfo *mimeinfo)
+{
+       PrivacyDataPGP *data = (PrivacyDataPGP *) mimeinfo->privacy;
+       
+       g_return_val_if_fail(data != NULL, SIGNATURE_INVALID);
+
+       if (data->sigstatus == NULL && 
+           prefs_gpg_get_config()->auto_check_signatures)
+               pgpinline_check_signature(mimeinfo);
+
+       return sgpgme_sigstat_gpgme_to_privacy(data->ctx, data->sigstatus);
+}
+
+static gchar *pgpinline_get_sig_info_short(MimeInfo *mimeinfo)
+{
+       PrivacyDataPGP *data = (PrivacyDataPGP *) mimeinfo->privacy;
+       
+       g_return_val_if_fail(data != NULL, g_strdup("Error"));
+
+       if (data->sigstatus == NULL && 
+           prefs_gpg_get_config()->auto_check_signatures)
+               pgpinline_check_signature(mimeinfo);
+       
+       return sgpgme_sigstat_info_short(data->ctx, data->sigstatus);
+}
+
+static gchar *pgpinline_get_sig_info_full(MimeInfo *mimeinfo)
+{
+       PrivacyDataPGP *data = (PrivacyDataPGP *) mimeinfo->privacy;
+       
+       g_return_val_if_fail(data != NULL, g_strdup("Error"));
+
+       return sgpgme_sigstat_info_full(data->ctx, data->sigstatus);
+}
+
+
+
+static gboolean pgpinline_is_encrypted(MimeInfo *mimeinfo)
+{
+       const gchar *enc_indicator = "-----BEGIN PGP MESSAGE-----";
+       gchar *textdata;
+       
+       g_return_val_if_fail(mimeinfo != NULL, FALSE);
+       
+       if (procmime_mimeinfo_parent(mimeinfo) == NULL)
+               return FALSE; /* not parent */
+       
+       if (mimeinfo->type != MIMETYPE_TEXT)
+               return FALSE;
+       
+       textdata = get_part_as_string(mimeinfo);
+       if (!textdata)
+               return FALSE;
+       
+       if (!strstr(textdata, enc_indicator)) {
+               g_free(textdata);
+               return FALSE;
+       }
+
+       g_free(textdata);
+       return TRUE;
+}
+
+static MimeInfo *pgpinline_decrypt(MimeInfo *mimeinfo)
+{
+       MimeInfo *decinfo, *parseinfo;
+       gpgme_data_t cipher, plain;
+       FILE *dstfp;
+       gchar *fname;
+       gchar *textdata = NULL;
+       static gint id = 0;
+       const gchar *src_codeset = NULL;
+       gpgme_verify_result_t sigstat = 0;
+       PrivacyDataPGP *data = NULL;
+       gpgme_ctx_t ctx;
+       gchar *chars;
+       int len;
+       
+       if (gpgme_new(&ctx) != GPG_ERR_NO_ERROR)
+               return NULL;
+
+       gpgme_set_textmode(ctx, 1);
+       gpgme_set_armor(ctx, 1);
+
+       g_return_val_if_fail(mimeinfo != NULL, NULL);
+       g_return_val_if_fail(pgpinline_is_encrypted(mimeinfo), NULL);
+       
+       if (procmime_mimeinfo_parent(mimeinfo) == NULL ||
+           mimeinfo->type != MIMETYPE_TEXT) {
+               gpgme_release(ctx);
+               return NULL;
+       }
+
+       textdata = get_part_as_string(mimeinfo);
+       if (!textdata) {
+               gpgme_release(ctx);
+               return NULL;
+       }
+
+       debug_print("decrypting '%s'\n", textdata);
+       gpgme_data_new_from_mem(&cipher, textdata, strlen(textdata), 1);
+
+       plain = sgpgme_decrypt_verify(cipher, &sigstat, ctx);
+       if (sigstat && !sigstat->signatures)
+               sigstat = NULL;
+
+       gpgme_data_release(cipher);
+       
+       if (plain == NULL) {
+               gpgme_release(ctx);
+               return NULL;
+       }
+
+       fname = g_strdup_printf("%s%cplaintext.%08x",
+               get_mime_tmp_dir(), G_DIR_SEPARATOR, ++id);
+
+       if ((dstfp = fopen(fname, "wb")) == NULL) {
+               FILE_OP_ERROR(fname, "fopen");
+               g_free(fname);
+               gpgme_data_release(plain);
+               gpgme_release(ctx);
+               return NULL;
+       }
+
+       src_codeset = procmime_mimeinfo_get_parameter(mimeinfo, "charset");
+       if (src_codeset == NULL)
+               src_codeset = CS_ISO_8859_1;
+               
+       fprintf(dstfp, "MIME-Version: 1.0\r\n"
+                       "Content-Type: text/plain; charset=%s\r\n"
+                       "Content-Transfer-Encoding: 8bit\r\n"
+                       "\r\n",
+                       src_codeset);
+       
+       chars = gpgme_data_release_and_get_mem(plain, &len);
+       if (len > 0)
+               fwrite(chars, len, 1, dstfp);
+
+       fclose(dstfp);
+       
+       gpgme_data_release(plain);
+
+       parseinfo = procmime_scan_file(fname);
+       g_free(fname);
+       
+       if (parseinfo == NULL) {
+               gpgme_release(ctx);
+               return NULL;
+       }
+       decinfo = g_node_first_child(parseinfo->node) != NULL ?
+               g_node_first_child(parseinfo->node)->data : NULL;
+               
+       if (decinfo == NULL) {
+               gpgme_release(ctx);
+               return NULL;
+       }
+
+       g_node_unlink(decinfo->node);
+       procmime_mimeinfo_free_all(parseinfo);
+
+       decinfo->tmp = TRUE;
+
+       if (sigstat != GPGME_SIG_STAT_NONE) {
+               if (decinfo->privacy != NULL) {
+                       data = (PrivacyDataPGP *) decinfo->privacy;
+               } else {
+                       data = pgpinline_new_privacydata();
+                       decinfo->privacy = (PrivacyData *) data;        
+               }
+               data->done_sigtest = TRUE;
+               data->is_signed = TRUE;
+               data->sigstatus = sigstat;
+               if (data->ctx)
+                       gpgme_release(data->ctx);
+               data->ctx = ctx;
+       } else
+               gpgme_release(ctx);
+
+       return decinfo;
+}
+
+static gboolean pgpinline_sign(MimeInfo *mimeinfo, PrefsAccount *account)
+{
+       MimeInfo *msgcontent;
+       gchar *textstr, *tmp;
+       FILE *fp;
+       gchar *sigcontent;
+       gpgme_ctx_t ctx;
+       gpgme_data_t gpgtext, gpgsig;
+       guint len;
+       struct passphrase_cb_info_s info;
+
+       memset (&info, 0, sizeof info);
+
+       /* get content node from message */
+       msgcontent = (MimeInfo *) mimeinfo->node->children->data;
+       if (msgcontent->type == MIMETYPE_MULTIPART)
+               msgcontent = (MimeInfo *) msgcontent->node->children->data;
+
+       /* get rid of quoted-printable or anything */
+       procmime_decode_content(msgcontent);
+
+       fp = my_tmpfile();
+       procmime_write_mimeinfo(msgcontent, fp);
+       rewind(fp);
+
+       /* read temporary file into memory */
+       textstr = file_read_stream_to_str(fp);
+       
+       /* gtk2: convert back from utf8 */
+       tmp = conv_codeset_strdup(textstr, CS_UTF_8, 
+                       procmime_mimeinfo_get_parameter(msgcontent, "charset"));
+       g_free(textstr);
+       textstr = g_strdup(tmp);
+       g_free(tmp);
+
+       fclose(fp);
+               
+       gpgme_data_new_from_mem(&gpgtext, textstr, strlen(textstr), 0);
+       gpgme_data_new(&gpgsig);
+       gpgme_new(&ctx);
+       gpgme_set_textmode(ctx, 1);
+       gpgme_set_armor(ctx, 1);
+
+       if (!sgpgme_setup_signers(ctx, account)) {
+               gpgme_release(ctx);
+               return FALSE;
+       }
+
+       if (!getenv("GPG_AGENT_INFO")) {
+               info.c = ctx;
+               gpgme_set_passphrase_cb (ctx, gpgmegtk_passphrase_cb, &info);
+       }
+
+       if (gpgme_op_sign(ctx, gpgtext, gpgsig, GPGME_SIG_MODE_CLEAR) 
+           != GPG_ERR_NO_ERROR) {
+               gpgme_release(ctx);
+               return FALSE;
+       }
+
+       gpgme_release(ctx);
+       sigcontent = gpgme_data_release_and_get_mem(gpgsig, &len);
+       tmp = g_malloc(len+1);
+       g_memmove(tmp, sigcontent, len+1);
+       tmp[len] = '\0';
+       gpgme_data_release(gpgtext);
+       g_free(textstr);
+       g_free(sigcontent);
+
+       if (msgcontent->content == MIMECONTENT_FILE &&
+           msgcontent->data.filename != NULL) {
+               unlink(msgcontent->data.filename);
+               g_free(msgcontent->data.filename);
+       }
+       msgcontent->data.mem = g_strdup(tmp);
+       msgcontent->content = MIMECONTENT_MEM;
+       g_free(tmp);
+
+       /* avoid all sorts of clear-signing problems with non ascii
+        * chars
+        */
+       procmime_encode_content(msgcontent, ENC_BASE64);
+                       
+       return TRUE;
+}
+
+static gchar *pgpinline_get_encrypt_data(GSList *recp_names)
+{
+       return sgpgme_get_encrypt_data(recp_names);
+}
+
+static gboolean pgpinline_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
+{
+       MimeInfo *msgcontent;
+       FILE *fp;
+       gchar *enccontent;
+       guint len;
+       gchar *textstr, *tmp;
+       gpgme_data_t gpgtext, gpgenc;
+       gpgme_ctx_t ctx;
+       gpgme_key_t *kset = NULL;
+       gchar **fprs = g_strsplit(encrypt_data, " ", -1);
+       gint i = 0;
+       while (fprs[i] && strlen(fprs[i])) {
+               i++;
+       }
+       
+       kset = g_malloc(sizeof(gpgme_key_t)*(i+1));
+       memset(kset, 0, sizeof(gpgme_key_t)*(i+1));
+       gpgme_new(&ctx);
+       i = 0;
+       while (fprs[i] && strlen(fprs[i])) {
+               gpgme_key_t key;
+               gpgme_error_t err;
+               err = gpgme_get_key(ctx, fprs[i], &key, 0);
+               if (err) {
+                       debug_print("can't add key '%s'[%d] (%s)\n", fprs[i],i, gpgme_strerror(err));
+                       break;
+               }
+               debug_print("found %s at %d\n", fprs[i], i);
+               kset[i] = key;
+               i++;
+       }
+       
+
+       debug_print("Encrypting message content\n");
+
+       /* get content node from message */
+       msgcontent = (MimeInfo *) mimeinfo->node->children->data;
+       if (msgcontent->type == MIMETYPE_MULTIPART)
+               msgcontent = (MimeInfo *) msgcontent->node->children->data;
+
+       /* get rid of quoted-printable or anything */
+       procmime_decode_content(msgcontent);
+
+       fp = my_tmpfile();
+       procmime_write_mimeinfo(msgcontent, fp);
+       rewind(fp);
+
+       /* read temporary file into memory */
+       textstr = file_read_stream_to_str(fp);
+       
+       /* gtk2: convert back from utf8 */
+       tmp = conv_codeset_strdup(textstr, CS_UTF_8, 
+                       procmime_mimeinfo_get_parameter(msgcontent, "charset"));
+       g_free(textstr);
+       textstr = g_strdup(tmp);
+       g_free(tmp);
+       fclose(fp);
+
+       /* encrypt data */
+       gpgme_data_new_from_mem(&gpgtext, textstr, strlen(textstr), 0);
+       gpgme_data_new(&gpgenc);
+       gpgme_new(&ctx);
+       gpgme_set_armor(ctx, 1);
+
+       gpgme_op_encrypt(ctx, kset, GPGME_ENCRYPT_ALWAYS_TRUST, gpgtext, gpgenc);
+
+       gpgme_release(ctx);
+       enccontent = gpgme_data_release_and_get_mem(gpgenc, &len);
+
+       tmp = g_malloc(len+1);
+       g_memmove(tmp, enccontent, len+1);
+       tmp[len] = '\0';
+       g_free(enccontent);
+
+       gpgme_data_release(gpgtext);
+       g_free(textstr);
+
+       if (msgcontent->content == MIMECONTENT_FILE &&
+           msgcontent->data.filename != NULL) {
+               unlink(msgcontent->data.filename);
+               g_free(msgcontent->data.filename);
+       }
+       msgcontent->data.mem = g_strdup(tmp);
+       msgcontent->content = MIMECONTENT_MEM;
+       g_free(tmp);
+
+       return TRUE;
+}
+
+static PrivacySystem pgpinline_system = {
+       "pgpinline",                    /* id */
+       "PGP Inline",                   /* name */
+
+       pgpinline_free_privacydata,     /* free_privacydata */
+
+       pgpinline_is_signed,            /* is_signed(MimeInfo *) */
+       pgpinline_check_signature,      /* check_signature(MimeInfo *) */
+       pgpinline_get_sig_status,       /* get_sig_status(MimeInfo *) */
+       pgpinline_get_sig_info_short,   /* get_sig_info_short(MimeInfo *) */
+       pgpinline_get_sig_info_full,    /* get_sig_info_full(MimeInfo *) */
+
+       pgpinline_is_encrypted,         /* is_encrypted(MimeInfo *) */
+       pgpinline_decrypt,              /* decrypt(MimeInfo *) */
+
+       TRUE,
+       pgpinline_sign,
+
+       TRUE,
+       pgpinline_get_encrypt_data,
+       pgpinline_encrypt,
+};
+
+void pgpinline_init()
+{
+       privacy_register_system(&pgpinline_system);
+}
+
+void pgpinline_done()
+{
+       privacy_unregister_system(&pgpinline_system);
+}
+
+#endif /* USE_GPGME */
diff --git a/src/plugins/pgpinline/pgpinline.deps b/src/plugins/pgpinline/pgpinline.deps
new file mode 100644 (file)
index 0000000..222cb5d
--- /dev/null
@@ -0,0 +1 @@
+pgpcore
diff --git a/src/plugins/pgpinline/pgpinline.h b/src/plugins/pgpinline/pgpinline.h
new file mode 100644 (file)
index 0000000..bb9b23a
--- /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 PGPINLINE_H
+#define PGPINLINE_H 1
+
+void pgpinline_init(void);
+void pgpinline_done(void);
+
+#endif /* PGPINLINE_H */
diff --git a/src/plugins/pgpinline/plugin.c b/src/plugins/pgpinline/plugin.c
new file mode 100644 (file)
index 0000000..d5a1d6c
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2003 Hiroyuki Yamamoto
+ *
+ * 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
+
+#include <stddef.h>
+
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include "version.h"
+#include "pgpinline.h"
+
+gint plugin_init(gchar **error)
+{
+       if ((sylpheed_get_version() > VERSION_NUMERIC)) {
+               *error = g_strdup("Your sylpheed version is newer than the version the plugin was built with");
+               return -1;
+       }
+
+       if ((sylpheed_get_version() < MAKE_NUMERIC_VERSION(1, 9, 12, 49))) {
+               *error = g_strdup("Your sylpheed version is too old");
+               return -1;
+       }
+
+       pgpinline_init();
+
+       return 0;       
+}
+
+void plugin_done(void)
+{
+       pgpinline_done();
+}
+
+const gchar *plugin_name(void)
+{
+       return _("PGP/inline");
+}
+
+const gchar *plugin_desc(void)
+{
+       return _("This plugin enables signature verification of "
+                "digitally signed messages, and decryption of "
+                "encrypted messages. \n"
+                "\n"
+                "It also lets you send signed and encrypted "
+                "messages.");
+}
+
+const gchar *plugin_type(void)
+{
+       return "GTK2";
+}