[pan2/testing] + nntp fix + pgp-encryption/signing support + revert download all flagged, not needed



commit 9be8d9751cb18dfcb2cf8e4079127280a078ab08
Author: Heinrich MÃller <henmull src gnome org>
Date:   Fri Dec 9 15:25:59 2011 +0100

    + nntp fix
    + pgp-encryption/signing support
    + revert download all flagged, not needed

 pan/data-impl/article-filter.cc   |    3 +-
 pan/data/article-cache.cc         |    4 +-
 pan/data/article-cache.h          |    2 +-
 pan/gui/body-pane.cc              |   77 ++++++++++++++++++++----------------
 pan/gui/body-pane.h               |    3 +
 pan/gui/gpg.cc                    |   53 +++++++++++++++----------
 pan/gui/gpg.h                     |   15 ++++---
 pan/gui/gui.cc                    |    3 +-
 pan/gui/post-ui.cc                |    7 +--
 pan/tasks/nntp.cc                 |   12 +++---
 pan/usenet-utils/message-check.cc |    3 -
 pan/usenet-utils/mime-utils.cc    |   60 +++++++++++++----------------
 pan/usenet-utils/mime-utils.h     |    9 +++-
 13 files changed, 134 insertions(+), 117 deletions(-)
---
diff --git a/pan/data-impl/article-filter.cc b/pan/data-impl/article-filter.cc
index 2ea298b..3432334 100644
--- a/pan/data-impl/article-filter.cc
+++ b/pan/data-impl/article-filter.cc
@@ -189,8 +189,9 @@ ArticleFilter :: test_article (const Data        & data,
         {
           if (cache.contains(article.message_id)) {
             GPGDecErr unused_for_now;
+            GPGSignersInfo unused;
             ArticleCache::mid_sequence_t mid(1, article.message_id);
-            GMimeMessage *msg = cache.get_message(mid, unused_for_now);
+            GMimeMessage *msg = cache.get_message(mid, unused, unused_for_now);
             const char *hdr = g_mime_object_get_header(GMIME_OBJECT(msg), criteria._header);
             pass = criteria._text.test (hdr);
             g_object_unref(msg);
diff --git a/pan/data/article-cache.cc b/pan/data/article-cache.cc
index e24e8ef..f28d2ed 100644
--- a/pan/data/article-cache.cc
+++ b/pan/data/article-cache.cc
@@ -398,7 +398,7 @@ ArticleCache :: get_message_mem_stream (const Quark& mid) const
 }
 
 GMimeMessage*
-ArticleCache :: get_message (const mid_sequence_t& mids, GPGDecErr& err) const
+ArticleCache :: get_message (const mid_sequence_t& mids, GPGSignersInfo& signer_info, GPGDecErr& err) const
 {
    debug ("trying to get a message with " << mids.size() << " parts");
    GMimeMessage * retval = NULL;
@@ -421,7 +421,7 @@ ArticleCache :: get_message (const mid_sequence_t& mids, GPGDecErr& err) const
 
    // build the message
    if (!streams.empty())
-     retval = mime :: construct_message (&streams.front(), streams.size(), err);
+     retval = mime :: construct_message (&streams.front(), streams.size(), signer_info, err);
 
    // cleanup
    foreach (streams_t, streams, it)
diff --git a/pan/data/article-cache.h b/pan/data/article-cache.h
index f05954b..0dab3f4 100644
--- a/pan/data/article-cache.h
+++ b/pan/data/article-cache.h
@@ -74,7 +74,7 @@ namespace pan
       void resize ();
       void clear ();
 
-      GMimeMessage* get_message (const mid_sequence_t&, GPGDecErr&) const;
+      GMimeMessage* get_message (const mid_sequence_t&, GPGSignersInfo&, GPGDecErr&) const;
 
       typedef std::vector<std::string> strings_t;
       strings_t get_filenames (const mid_sequence_t&);
diff --git a/pan/gui/body-pane.cc b/pan/gui/body-pane.cc
index df0fcea..78ea7f7 100644
--- a/pan/gui/body-pane.cc
+++ b/pan/gui/body-pane.cc
@@ -886,6 +886,22 @@ namespace
     g_object_unref (G_OBJECT(l));
     return pixbuf;
   }
+
+}
+
+bool
+BodyPane ::get_gpgsig_from_gmime_part (GMimePart * part)
+{
+  GMimeDataWrapper * wrapper (g_mime_part_get_content_object (part));
+  GMimeStream * mem_stream (g_mime_stream_mem_new ());
+  if (wrapper)
+  {
+    g_mime_data_wrapper_write_to_stream (wrapper, mem_stream);
+    g_mime_stream_reset(mem_stream);
+    gpd_decrypt_and_verify(_signer_info, _gpgerr, mem_stream);
+    return true;
+  }
+  return false;
 }
 
 void
@@ -927,6 +943,7 @@ BodyPane :: append_part (GMimeObject * obj, GtkAllocation * widget_size)
       // rembember the location of the first picture.
       if (gtk_text_buffer_get_mark (_buffer, FIRST_PICTURE) == NULL)
         gtk_text_buffer_create_mark (_buffer, FIRST_PICTURE, &iter, true);
+        gtk_text_buffer_create_mark (_buffer, FIRST_PICTURE, &iter, true);
 
       // add the picture
       const int begin_offset (gtk_text_iter_get_offset (&iter));
@@ -952,7 +969,8 @@ BodyPane :: append_part (GMimeObject * obj, GtkAllocation * widget_size)
   }
 
   // or, if it's text, display it
-  else if (g_mime_content_type_is_type (type, "text", "*"))
+  else if (g_mime_content_type_is_type (type, "text", "*") ||
+           (g_mime_content_type_is_type (type, "application", "pgp-signature")))
   {
     const char * fallback_charset (_charset.c_str());
     const char * p_flowed (g_mime_object_get_content_type_parameter(obj,"format"));
@@ -968,10 +986,13 @@ BodyPane :: append_part (GMimeObject * obj, GtkAllocation * widget_size)
     const bool do_urls (_prefs.get_flag ("highlight-urls", true));
     append_text_buffer_nolock (&_tm, _buffer, str, do_mute, do_smilies, do_markup, do_urls);
     is_done = true;
-  }
 
-  else if (g_mime_content_type_is_type (type, "text", "*"))
-  {
+    /* verify signature */
+    if (g_mime_content_type_is_type (type, "*", "pgp-signature"))
+    {
+      bool res = get_gpgsig_from_gmime_part(part);
+      if (res) update_sig_valid(_gpgerr.verify_ok);
+    }
 
   }
 
@@ -987,6 +1008,7 @@ BodyPane :: append_part (GMimeObject * obj, GtkAllocation * widget_size)
     g_free (pch);
   }
 }
+
 void
 BodyPane :: foreach_part_cb (GMimeObject* /*parent*/, GMimeObject* o, gpointer self)
 {
@@ -1228,7 +1250,6 @@ namespace
   {
     size_t in = s.find("<");
     size_t out = s.find(">");
-    std::cerr<<s<<" "<<in<<" "<<out<<"\n";
     if (in == std::string::npos || out == std::string::npos) return "...";
 
     return s.substr (in+1,out-in-1);
@@ -1243,34 +1264,26 @@ BodyPane:: on_tooltip_query(GtkWidget  *widget,
                             GtkTooltip *tooltip,
                             gpointer    data)
 {
-  GPGDecErr* err = static_cast<GPGDecErr*>(data);
-
-  g_return_val_if_fail(err, false);
-  g_return_val_if_fail(err->dec_ok, false);
-  g_return_val_if_fail(err->err == GPG_ERR_NO_ERROR, false);
-
-  if (err->no_sigs) return false;
-  std::cerr<<"bla 1\n";
-  if (!err->v_res) return false;
-  std::cerr<<"bla 2\n";
-  if (!err->v_res->signatures) return false;
-  std::cerr<<"bla 3\n";
-  if (!err->v_res->signatures->fpr) return false;
-  std::cerr<<"bla 4\n";
-
-  // get uid from fingerprint
-  // mask out higher bytes of key (example) 0E A9 59 12 68 0A D9 CF
-  size_t len (strlen(err->v_res->signatures->fpr));
-  size_t off (0);
-  if (len > 16) off += len - 16;
-  GPGSignersInfo info = get_uids_from_fingerprint(err->v_res->signatures->fpr+off);
-  std::cerr<<"infos "<<info.expires<<" "<<info.creation_timestamp<<" "<<info.real_name<<"\n";
+  BodyPane* pane = static_cast<BodyPane*>(data);
+  GPGDecErr& err = pane->_gpgerr;
+  GPGSignersInfo& info = pane->_signer_info;
+
+  g_return_val_if_fail(err.dec_ok, false);
+  g_return_val_if_fail(err.err == GPG_ERR_NO_ERROR || err.err == GPG_ERR_NO_DATA, false);
+
+  if (err.no_sigs) return false;
+  if (!err.v_res) return false;
+  if (!err.v_res->signatures) return false;
+  if (!err.v_res->signatures->fpr) return false;
+
+// get uid from fingerprint
+//  GPGSignersInfo info = get_uids_from_fingerprint(err->v_res->signatures->fpr);
+
   EvolutionDateMaker ed;
 
   char buf[2048];
   g_snprintf(buf, sizeof(buf),
              "<u>This is a <b>GPG-Signed</b> message.</u>\n\n"
-             "Information:\n"
              "<b>Signer</b> : %s (\"%s\")\n"
              "<b>Valid until</b> : %s\n"
              "<b>Created on</b> : %s",
@@ -1289,8 +1302,6 @@ void
 BodyPane :: update_sig_valid(int i)
 {
 
-  std::cerr<<"udpate icon "<<i<<"\n";
-
   gtk_image_clear(GTK_IMAGE(_sig_icon));
 
   switch (i)
@@ -1312,15 +1323,13 @@ BodyPane :: set_article (const Article& a)
 
   if (_message)
     g_object_unref (_message);
-  _message = _cache.get_message (_article.get_part_mids(), _gpgerr);
+  _message = _cache.get_message (_article.get_part_mids(), _signer_info, _gpgerr);
 
   const char* gpg_sign = g_mime_object_get_header(GMIME_OBJECT(_message), "X-GPG-Signed");
   int val(-1);
 
   if (gpg_sign)
   {
-    std::cerr<<"gpg flag "<<gpg_sign<<"\n";
-
     if (!strcmp(gpg_sign, "valid"))
       val = 1;
     else if (!strcmp(gpg_sign, "invalid"))
@@ -1569,7 +1578,7 @@ BodyPane :: BodyPane (Data& data, ArticleCache& cache, Prefs& prefs):
   gtk_widget_set_size_request (_sig_icon, 32, 32);
   gtk_box_pack_start (GTK_BOX(hbox), _sig_icon, true, true, PAD_SMALL);
   gtk_widget_set_has_tooltip (_sig_icon, true);
-  g_signal_connect(_sig_icon,"query-tooltip",G_CALLBACK(on_tooltip_query), &_gpgerr);
+  g_signal_connect(_sig_icon,"query-tooltip",G_CALLBACK(on_tooltip_query), this);
 
   w = _xface = gtk_image_new();
   gtk_widget_set_size_request (w, 48, 48);
diff --git a/pan/gui/body-pane.h b/pan/gui/body-pane.h
index ce54a2d..afdf73d 100644
--- a/pan/gui/body-pane.h
+++ b/pan/gui/body-pane.h
@@ -109,7 +109,10 @@ namespace pan
       gboolean mouse_button_pressed (GtkWidget*, GdkEventButton*);
 
       /* updated with values from gmimemessage */
+   public:
       GPGDecErr _gpgerr;
+      GPGSignersInfo _signer_info;
+      bool get_gpgsig_from_gmime_part (GMimePart * part);
 
     private:
       std::string _hover_url;
diff --git a/pan/gui/gpg.cc b/pan/gui/gpg.cc
index d5bf79d..4cb2353 100644
--- a/pan/gui/gpg.cc
+++ b/pan/gui/gpg.cc
@@ -27,6 +27,7 @@
 extern "C" {
   #include <stdlib.h>
   #include <unistd.h>
+  #include <string.h>
 }
 
 namespace pan
@@ -50,6 +51,26 @@ namespace pan
     gpgme_release(gpg_ctx);
   }
 
+  void fill_signer_info(GPGSignersInfo& info, gpgme_key_t key)
+  {
+    if (!key) return;
+    if (key->uids)
+    {
+      if (key->uids->name) info.real_name = key->uids->name;
+      if (key->uids->uid)  info.uid = key->uids->uid;
+    }
+    info.auth = key->can_authenticate == 1 ? true : false;
+    info.sign = key->can_sign == 1 ? true : false;
+    info.certify = key->can_certify == 1 ? true : false;
+    info.enc = key->can_encrypt == 1 ? true : false;
+
+    if (key->subkeys)
+    {
+      info.expires = key->subkeys->expires;
+      info.creation_timestamp = key->subkeys->timestamp;
+    }
+  }
+
   void init_gpg()
   {
     gpgme_error_t gpg_err;
@@ -59,8 +80,6 @@ namespace pan
     gpg_err = gpgme_new (&gpg_ctx);
     if (!gpg_err) gpg_inited = true; else return;
 
-  //  gpgme_set_armor (gpg_ctx, 1);
-
     /* get all keys */
     gpgme_key_t key;
 
@@ -74,42 +93,32 @@ namespace pan
       gpg_err = gpgme_op_keylist_next (gpg_ctx, &key);
       if (gpg_err) break;
       // have i forgotten anything ? ;)
-      if (!key->can_certify && !key->can_sign && !key->can_authenticate) continue;
+      if (!key->can_certify && !key->can_sign && !key->can_authenticate && !key->can_encrypt) continue;
       if (key->revoked || key->expired || key->disabled || key->subkeys->expired) continue;
       if (key->uids->revoked || key->uids->invalid) continue;
 
-      gpgme_signers_add(gpg_ctx, key);
-      info.real_name = key->uids->name;
-      info.auth = key->can_authenticate == 1 ? true : false;
-      info.sign = key->can_sign == 1 ? true : false;
-      info.certify = key->can_certify == 1 ? true : false;
-      info.enc = key->can_encrypt == 1 ? true : false;
-      info.expires = key->subkeys->expires;
-      info.uid = key->uids->uid;
-      info.creation_timestamp = key->subkeys->timestamp;
-      std::cerr<<"uid of signer "<<info.real_name<<" : "<<info.uid<<", "<<key->subkeys->keyid<<"\n";
+      fill_signer_info(info, key);
       gpg_signers.insert(std::pair<std::string, GPGSignersInfo>(key->subkeys->keyid,info));
     }
 
     if (gpg_err_code (gpg_err) != GPG_ERR_EOF)
     {
         Log::add_err("GPG Error : can't list the keys from the keyvault, please check your settings.\n");
-
     }
   }
 
   GPGSignersInfo get_uids_from_fingerprint(char* fpr)
   {
-    GPGSignersInfo empty;
 
-    foreach(signers_m, gpg_signers, it)
-    {
-      const GPGSignersInfo& info(it->second);
-      std::cerr<<fpr<<" // uid "<<it->first<<" "<<info.uid<<" "<<info.real_name<<" "<<info.expires<<" "<<info.creation_timestamp<<"\n\n";
-    }
+    size_t len (strlen(fpr));
+    size_t off (0);
+    if (len > 16) off += len - 16;
+
+    GPGSignersInfo empty;
 
-    if (gpg_signers.count(fpr) != 0)
-      return gpg_signers[fpr];
+    char* n = fpr+off;
+    if (gpg_signers.count(n) != 0)
+      return gpg_signers[n];
 
     return empty;
   }
diff --git a/pan/gui/gpg.h b/pan/gui/gpg.h
index 7c02fe3..32e9c5c 100644
--- a/pan/gui/gpg.h
+++ b/pan/gui/gpg.h
@@ -34,6 +34,8 @@ namespace pan
     std::string uid;  // userid /hex
     long int creation_timestamp;
 
+    GPGSignersInfo() : real_name(""), auth(false), sign(false),
+        certify(false), enc(false), expires(0), uid(""), creation_timestamp(0) {}
   };
 
   typedef std::map<std::string,GPGSignersInfo> signers_m;
@@ -42,6 +44,7 @@ namespace pan
   extern bool gpg_inited;
   extern signers_m gpg_signers;
 
+  /* Error struct for gpg_decrypt */
   struct GPGDecErr
   {
     gpg_error_t err;
@@ -50,25 +53,25 @@ namespace pan
     bool dec_ok;
     bool verify_ok;
     bool no_sigs;
+
     GPGDecErr() : dec_ok(false), verify_ok(false), no_sigs(true), err(GPG_ERR_NO_ERROR) {}
   };
 
-  /** Error struct for gpg_sign_and_encrypt
-    * @see gpg_sign_and_encrypt
-   **/
+  /* Error struct for gpg_sign_and_encrypt */
   struct GPGEncErr
   {
-    /** common gpg errcode */
     gpgme_error_t err;
-    /** encode result */
     gpgme_encrypt_result_t enc_res;
-    /** sign result */
     gpgme_sign_result_t sign_res;
+
+    GPGEncErr() : err(GPG_ERR_NO_ERROR) {}
+
   };
 
   GPGSignersInfo get_uids_from_fingerprint(char*);
   void init_gpg();
   void deinit_gpg();
+  void fill_signer_info(GPGSignersInfo& info, gpgme_key_t key);
 
 }
 
diff --git a/pan/gui/gui.cc b/pan/gui/gui.cc
index 1ebea19..d2ee329 100644
--- a/pan/gui/gui.cc
+++ b/pan/gui/gui.cc
@@ -696,8 +696,9 @@ namespace
     virtual void on_progress_finished (Progress&, int status)
     {
       GPGDecErr unused;
+      GPGSignersInfo unuse;
       if (status == OK) {
-        GMimeMessage * message = _cache.get_message (_article.get_part_mids(), unused);
+        GMimeMessage * message = _cache.get_message (_article.get_part_mids(), unuse, unused);
         g_mime_message_foreach (message, foreach_part_cb, this);
         g_object_unref (message);
       }
diff --git a/pan/gui/post-ui.cc b/pan/gui/post-ui.cc
index a560ad9..e32ac04 100644
--- a/pan/gui/post-ui.cc
+++ b/pan/gui/post-ui.cc
@@ -122,7 +122,6 @@ namespace pan
     if (!self->_realized) return;
 
     gpg_enc = gtk_toggle_action_get_active (toggle);
-    std::cerr<<"gpg enc "<<gpg_enc<<"\n";
     if (gpg_enc)
     {
       gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (gtk_action_group_get_action (self->_agroup, "gpg-sign")),false);
@@ -137,7 +136,6 @@ namespace pan
     if (!self->_realized) return;
 
     gpg_sign = gtk_toggle_action_get_active (toggle);
-    std::cerr<<"gpg sign "<<gpg_sign<<"\n";
     if (gpg_sign)
     {
       gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (gtk_action_group_get_action (self->_agroup, "gpg-encrypt")),false);
@@ -379,9 +377,10 @@ PostUI :: gpg_sign_and_encrypt(const std::string& body, GPGEncErr& fail)
   }
   if (!mykey) { fail.err = GPG_ERR_NO_PUBKEY; return std::string(""); }
 
-  gpgme_key_t keys[] = { mykey, NULL} ;
   gpgme_key_t enc_keys[] = { mykey, NULL};
 
+  gpgme_signers_clear(gpg_ctx);
+  gpgme_signers_add(gpg_ctx, mykey);
 
   if (gpg_sign)
   {
@@ -417,8 +416,6 @@ PostUI :: gpg_sign_and_encrypt(const std::string& body, GPGEncErr& fail)
   gpgme_data_release(gpg_buf);
   gpgme_data_release(gpg_out_buf);
 
-  std::cerr<<"\n"<<ret_str.str()<<"\n";
-
   fail.err = GPG_ERR_NO_ERROR;
   return ret_str.str();
 }
diff --git a/pan/tasks/nntp.cc b/pan/tasks/nntp.cc
index 2f3c469..fc6b560 100644
--- a/pan/tasks/nntp.cc
+++ b/pan/tasks/nntp.cc
@@ -302,7 +302,7 @@ NNTP :: help (Listener * l)
 }
 
 void
-NNTP :: get_group (Listener * l, const Quark& group)
+NNTP :: get_group (const Quark& group)
 {
    if (group != _group)
     _commands.push_back (build_command ("GROUP %s\r\n",group.c_str()));
@@ -330,7 +330,7 @@ NNTP :: xover_count_only (const Quark   & group,
 {
    _listener = l;
 
-   get_group(l,group);
+   get_group(group);
 
    _commands.push_back (build_command ("XOVER"));
 
@@ -388,7 +388,7 @@ NNTP :: get_headers (const Quark     & group,
 {
   _listener = l;
 
-   get_group(l,group);
+   get_group(group);
 
    _commands.push_back (build_command ("HEAD %s\r\n", message_id));
 
@@ -402,7 +402,7 @@ NNTP :: get_headers (const Quark     & group,
 {
    _listener = l;
 
-   get_group(l,group);
+   get_group(group);
 
    _commands.push_back (build_command ("HEAD %"G_GUINT64_FORMAT"\r\n", article_number));
 
@@ -416,7 +416,7 @@ NNTP :: get_body (const Quark     & group,
 {
   _listener = l;
 
-   get_group(l,group);
+   get_group(group);
 
    _commands.push_back (build_command ("BODY %s\r\n", message_id));
 
@@ -430,7 +430,7 @@ NNTP :: get_body (const Quark     & group,
 {
    _listener = l;
 
-   if (group != _group) get_group(l,group);
+   get_group(group);
 
    _commands.push_back (build_command ("BODY %"G_GUINT64_FORMAT"\r\n", article_number));
 
diff --git a/pan/usenet-utils/message-check.cc b/pan/usenet-utils/message-check.cc
index 3de8c71..50ec84f 100644
--- a/pan/usenet-utils/message-check.cc
+++ b/pan/usenet-utils/message-check.cc
@@ -428,8 +428,6 @@ MessageCheck :: message_check (const GMimeMessage * message_const,
                                bool                 binpost)
 {
 
-  std::cerr<<"message check entry\n";
-
   goodness.clear ();
   errors.clear ();
 
@@ -457,7 +455,6 @@ MessageCheck :: message_check (const GMimeMessage * message_const,
   if (!binpost)
     check_body (errors, goodness, tm, message, body, attribution);
   g_free (body);
-  std::cerr<<"goodness "<<goodness.state<<"\n";
 
   // check the optional followup-to...
   bool followup_to_set (false);
diff --git a/pan/usenet-utils/mime-utils.cc b/pan/usenet-utils/mime-utils.cc
index d5582c7..c33b3ad 100644
--- a/pan/usenet-utils/mime-utils.cc
+++ b/pan/usenet-utils/mime-utils.cc
@@ -418,7 +418,7 @@ enum EncType
 	ENC_BASE64 = 1<< 4
 };
 
-namespace
+namespace pan
 {
   struct TempPart
   {
@@ -478,11 +478,9 @@ namespace
     return true;
   }
 
-  GMimeStream* gpg_decrypt (GPGDecErr& info, GMimeStream* s, TempPart* part)
+  GMimeStream* gpd_decrypt_and_verify (GPGSignersInfo& signer_info, GPGDecErr& info, GMimeStream* s)
   {
 
-    std::cerr<<"gpg decrypt\n";
-
     GMimeStream* decrypted = g_mime_stream_mem_new ();
 
     ssize_t stream_len = g_mime_stream_length(s);
@@ -513,17 +511,15 @@ namespace
       return decrypted;
 
     info.dec_res  = gpgme_op_decrypt_result (gpg_ctx);
-    info.v_res    = gpgme_op_verify_result (gpg_ctx);
+    info.v_res    = gpgme_op_verify_result  (gpg_ctx);
 
     if (info.v_res->signatures)
     {
       info.no_sigs = false;
-
       if (gpgme_err_code(info.v_res->signatures->status) == GPG_ERR_NO_ERROR)
         info.verify_ok = true;
-      else
-        return decrypted;
-    } else
+    }
+    else
       info.no_sigs = true;
 
     delete streambuf;
@@ -540,14 +536,24 @@ namespace
     }
 
     g_mime_stream_flush (decrypted);
+    g_mime_stream_reset(decrypted);
 
     gpgme_data_release(gpg_buf);
     gpgme_data_release(gpg_out_buf);
 
-    g_mime_stream_reset(decrypted);
+    GPGSignersInfo si;
 
-    std::cerr<<"infos "<<info.dec_ok<<" "<<info.verify_ok<<"\n";
+    if (info.verify_ok && !info.no_sigs)
+    {
+      if (info.v_res->signatures->fpr)
+        gpgme_get_key (gpg_ctx, info.v_res->signatures->fpr, &key, 0);
+      if (key)
+      {
+        fill_signer_info(si, key);
+      }
+    }
 
+    signer_info = si;
     info.err = GPG_ERR_NO_ERROR;
 
     return decrypted;
@@ -588,6 +594,7 @@ namespace
     TempPart *uu_temp;
     std::string gpg_verified;
     GPGDecErr gpgerr;
+    GPGSignersInfo signer_info;
 
     sep_state():uu_temp(NULL), gpg_verified("") {};
   };
@@ -626,11 +633,8 @@ namespace
         line_len = pch - line_str;
       }
 
-      std::cerr<<"LINE   "<<line_str;
-
       if (gpg_is_signed_begin_line(line_str))
       {
-        std::cerr<<"signed begin\n";
         gpg_is_signed = true;
         signed_msg_start = linestart_pos;
       }
@@ -638,7 +642,6 @@ namespace
       {
         gboolean gpg_signed_end_found = true;
         signed_msg_end = linestart_pos+line_len;
-        std::cerr<<"signed offsets "<<signed_msg_start<<" "<<signed_msg_end<<"\n";
       }
 
       switch (type)
@@ -809,16 +812,14 @@ namespace
           if (gpg_is_ending_line(line_str))
           {
             GMimeStream * stream = g_mime_stream_substream (istream, sub_begin, linestart_pos+line_len);
-            GPGDecErr info;
-            GMimeStream * dec = gpg_decrypt(info, stream, cur);
-            std::cerr<<"info verify "<<info.verify_ok<<"\n";
-            if (info.verify_ok)
+            GMimeStream * dec = gpd_decrypt_and_verify(state.signer_info, state.gpgerr, stream);
+            if (state.gpgerr.verify_ok)
               state.gpg_verified = "valid";
-            else if (!info.verify_ok && !info.no_sigs)
+            else if (!state.gpgerr.verify_ok && !state.gpgerr.no_sigs)
               state.gpg_verified = "invalid";
-            state.gpgerr = info;
+
             gpg_looking_for_line = false;
-            if (info.dec_ok)
+            if (state.gpgerr.dec_ok)
             {
               apply_source_and_maybe_filter (cur, dec);
               if( append_if_not_present (master, cur) )
@@ -963,8 +964,6 @@ namespace
   void handle_uu_and_yenc_in_text_plain_cb (GMimeObject *parent, GMimeObject *part, gpointer data)
   {
 
-    std::cerr<<"handle uu yenc "<<part<<"\n";
-
     if (!part)
       return;
 
@@ -995,7 +994,6 @@ namespace
       //this part was completely folded into a previous part
       //so delete it
       if(parts.size()==0) {
-        std::cerr<<"folded\n";
         GMimeMultipart *mp = GMIME_MULTIPART (parent);
         int index = g_mime_multipart_index_of (mp,part);
         if(index>0)
@@ -1004,8 +1002,6 @@ namespace
       }
       else
       {
-        std::cerr<<"not folded "<<parts.size()<<"\n";
-
         GMimeMultipart * multipart = g_mime_multipart_new_with_subtype ("mixed");
 
         const TempPart *tmp_part;
@@ -1047,7 +1043,6 @@ namespace
         }
         if(GMIME_IS_MULTIPART(parent))
         {
-          std::cerr<<"parent is multipart\n";
           GMimeMultipart *mp = GMIME_MULTIPART (parent);
           int index = g_mime_multipart_index_of (mp, part);
           g_mime_multipart_remove_at (mp, index);
@@ -1062,7 +1057,6 @@ namespace
         }
         else if(GMIME_IS_MESSAGE(parent))
         {
-          std::cerr<<"parent is msg\n";
           g_mime_message_set_mime_part((GMimeMessage*)parent, newpart);
         }
         g_object_unref(newpart);
@@ -1116,15 +1110,14 @@ namespace{
 ***/
 
 GMimeMessage*
-mime :: construct_message (GMimeStream  ** istreams,
+mime :: construct_message (GMimeStream    ** istreams,
                            int             qty,
-                           GPGDecErr     & gpgerr)
+                           GPGSignersInfo & signer_info,
+                           GPGDecErr      & gpgerr)
 {
   const char * message_id = "Foo <bar mum>";
   GMimeMessage * retval = 0;
 
-  std::cerr<<"construct message "<<qty<<"\n";
-
   // sanity clause
   pan_return_val_if_fail (is_nonempty_string(message_id), NULL);
   pan_return_val_if_fail (istreams!=NULL, NULL);
@@ -1170,6 +1163,7 @@ mime :: construct_message (GMimeStream  ** istreams,
     /* set gpg signature verify success/fail flag */
     g_mime_object_set_header(GMIME_OBJECT(data.parent), "X-GPG-Signed", state.gpg_verified.c_str());
     gpgerr = state.gpgerr;
+    signer_info = state.signer_info;
   }
 
   // cleanup
diff --git a/pan/usenet-utils/mime-utils.h b/pan/usenet-utils/mime-utils.h
index 55b4287..0f886af 100644
--- a/pan/usenet-utils/mime-utils.h
+++ b/pan/usenet-utils/mime-utils.h
@@ -76,6 +76,8 @@
 namespace pan
 {
 
+  GMimeStream* gpd_decrypt_and_verify (GPGSignersInfo& signer_info, GPGDecErr& info, GMimeStream* s);
+
   /**
    * Utilities to build and parse GMimeMessages.
    *
@@ -88,9 +90,10 @@ namespace pan
   struct mime
   {
     static GMimeMessage *
-    construct_message (GMimeStream ** istreams,
-                         int            qty,
-                         GPGDecErr  & gpgerr);
+    construct_message (GMimeStream      ** istreams,
+                         int              qty,
+                         GPGSignersInfo & signer_info,
+                         GPGDecErr      & gpgerr);
 
 
     static const char *



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]