[pan2: 244/268] * modify compiler flags * base64 en/decode, qp en/decode * selectable cte in post ui dialog * fix to



commit 6ce9f1fb3a2b93155591efec58dbc4658943f6cd
Author: Heinrich MÃller <henmull src gnome org>
Date:   Fri Dec 16 18:10:12 2011 +0100

    * modify compiler flags
    * base64 en/decode, qp en/decode
    * selectable cte in post ui dialog
    * fix to gpg profiles setting sensitize

 configure.in                   |    4 +-
 pan.cbp                        |    6 -
 pan/gui/Makefile.am            |    2 +
 pan/gui/actions.cc             |    9 +-
 pan/gui/body-pane.cc           |    4 +-
 pan/gui/gui.cc                 |    2 +
 pan/gui/post-ui.cc             |   27 +++++-
 pan/gui/post-ui.h              |    3 +
 pan/gui/post.ui.h              |    1 +
 pan/gui/profiles-dialog.cc     |    4 +-
 pan/gui/server-ui.cc           |    2 +-
 pan/usenet-utils/gpg.cc        |    2 +
 pan/usenet-utils/gpg.h         |    4 +
 pan/usenet-utils/mime-utils.cc |  199 ++++++++++++++++++++++++++++++++++++----
 pan/usenet-utils/mime-utils.h  |    6 +
 15 files changed, 235 insertions(+), 40 deletions(-)
---
diff --git a/configure.in b/configure.in
index 1c85995..f40f73c 100644
--- a/configure.in
+++ b/configure.in
@@ -205,8 +205,8 @@ case $host_os in
 esac
 AM_CONDITIONAL([HAVE_WIN32],[test "$win32" = "yes"])
 
-CXXFLAGS="$CXXFLAGS -g -I/usr/lib/"
-CPPFLAGS="$CPPFLAGS -g -I/usr/lib/"
+CXXFLAGS="$CXXFLAGS -O0 -g -I/usr/lib/"
+CPPFLAGS="$CPPFLAGS -O0 -g -I/usr/lib/"
 CFLAGS="$CFLAGS -g -I/usr/lib/"
 
 dnl build the output files
diff --git a/pan.cbp b/pan.cbp
index 02227b0..7a104e1 100644
--- a/pan.cbp
+++ b/pan.cbp
@@ -22,9 +22,6 @@
 				<Option object_output="obj/Release/" />
 				<Option type="0" />
 				<Option compiler="gcc" />
-				<Compiler>
-					<Add option="-O2" />
-				</Compiler>
 				<Linker>
 					<Add option="-s" />
 				</Linker>
@@ -42,9 +39,6 @@
 				<Option output="pan/gui/pan" prefix_auto="1" extension_auto="1" />
 				<Option type="0" />
 				<Option compiler="gcc" />
-				<Compiler>
-					<Add option="-O2" />
-				</Compiler>
 				<Linker>
 					<Add option="-s" />
 				</Linker>
diff --git a/pan/gui/Makefile.am b/pan/gui/Makefile.am
index 7730a7c..53ae102 100644
--- a/pan/gui/Makefile.am
+++ b/pan/gui/Makefile.am
@@ -11,6 +11,7 @@ libpangui_a_SOURCES = \
  e-charset.c \
  e-charset-combo-box.c \
  e-charset-dialog.c \
+ e-cte-dialog.c \
  group-pane.cc \
  group-prefs.cc \
  group-prefs-dialog.cc \
@@ -45,6 +46,7 @@ noinst_HEADERS = \
  e-charset.h \
  e-charset-combo-box.h \
  e-charset-dialog.h \
+ e-cte-dialog.h \
  group-pane.h \
  group-prefs.h \
  group-prefs-dialog.h \
diff --git a/pan/gui/actions.cc b/pan/gui/actions.cc
index a2e0ea5..881a839 100644
--- a/pan/gui/actions.cc
+++ b/pan/gui/actions.cc
@@ -262,6 +262,10 @@ namespace
 
   GtkActionEntry entries[] =
   {
+
+    // dummy
+    { "set-charset", NULL, "", NULL, NULL, NULL },
+
     { "file-menu", NULL, N_("_File"), NULL, NULL, NULL },
     { "edit-menu", NULL, N_("_Edit"), NULL, NULL, NULL },
     { "view-layout-menu", NULL, N_("_Layout"), NULL, NULL, NULL },
@@ -278,11 +282,6 @@ namespace
     { "post-menu", NULL, N_("_Post"), NULL, NULL, NULL },
     { "help-menu", NULL, N_("_Help"), NULL, NULL, NULL },
 
-    { "set-charset", NULL,
-      N_("Set Character _Encoding..."), NULL,
-      N_("Set Character Encoding..."),
-      G_CALLBACK(do_prompt_for_charset) },
-
     { "read-selected-group", "ICON_READ_MORE",
       N_("_Read Group"), NULL,
       N_("Read Group"),
diff --git a/pan/gui/body-pane.cc b/pan/gui/body-pane.cc
index 55f80c0..ea8697f 100644
--- a/pan/gui/body-pane.cc
+++ b/pan/gui/body-pane.cc
@@ -1003,8 +1003,8 @@ BodyPane :: append_part (GMimeObject * parent, GMimeObject * obj, GtkAllocation
   if (!is_done) {
     const char * filename = g_mime_part_get_filename (part);
     char * pch = (filename && *filename)
-      ? g_strdup_printf (_("Attachment not shown: MIME type %s/%s; filename %s\n"), type->type, type->subtype, filename)
-      : g_strdup_printf (_("Attachment not shown: MIME type %s/%s\n"), type->type, type->subtype);
+      ? g_strdup_printf (_("\nAttachment not shown: MIME type %s/%s; filename %s\n"), type->type, type->subtype, filename)
+      : g_strdup_printf (_("\nAttachment not shown: MIME type %s/%s\n"), type->type, type->subtype);
     GtkTextIter iter;
     gtk_text_buffer_get_end_iter (_buffer, &iter);
     gtk_text_buffer_insert (_buffer, &iter, pch, -1);
diff --git a/pan/gui/gui.cc b/pan/gui/gui.cc
index 334f7b5..74462e4 100644
--- a/pan/gui/gui.cc
+++ b/pan/gui/gui.cc
@@ -1978,6 +1978,8 @@ void GUI :: do_prompt_for_charset ()
   set_charset (tmp);
   free (tmp);
 }
+
+
 void GUI :: set_charset (const StringView& s)
 {
   _charset.assign (s.str, s.len);
diff --git a/pan/gui/post-ui.cc b/pan/gui/post-ui.cc
index ca0247d..e2f66d8 100644
--- a/pan/gui/post-ui.cc
+++ b/pan/gui/post-ui.cc
@@ -41,11 +41,13 @@ extern "C" {
 #include <pan/usenet-utils/gpg.h>
 #include <pan/usenet-utils/message-check.h>
 #include <pan/usenet-utils/mime-utils.h>
+#include <pan/usenet-utils/MimeCodes.h>
 #include <pan/data/data.h>
 #include <pan/tasks/nzb.h>
 #include <pan/gui/gui.h>
 #include <pan/tasks/task-post.h>
 #include "e-charset-dialog.h"
+#include "e-cte-dialog.h"
 #include "pad.h"
 #include "hig.h"
 #include "post-ui.h"
@@ -375,6 +377,7 @@ namespace
   void do_save     (GtkAction*, gpointer p) { static_cast<PostUI*>(p)->save_draft (); }
   void do_open     (GtkAction*, gpointer p) { static_cast<PostUI*>(p)->open_draft (); }
   void do_charset  (GtkAction*, gpointer p) { static_cast<PostUI*>(p)->prompt_for_charset (); }
+  void do_cte      (GtkAction*, gpointer p) { static_cast<PostUI*>(p)->prompt_for_cte (); }
   void do_close    (GtkAction*, gpointer p) { static_cast<PostUI*>(p)->close_window (); }
   void do_wrap     (GtkToggleAction * w, gpointer p) { static_cast<PostUI*>(p)->set_wrap_mode (gtk_toggle_action_get_active (w)); }
   void do_edit2    (GtkToggleAction * w, gpointer p) { static_cast<PostUI*>(p)->set_always_run_editor (gtk_toggle_action_get_active (w)); }
@@ -391,6 +394,7 @@ namespace
     { "post-article", GTK_STOCK_EXECUTE, N_("_Send Article"), "<control>Return", N_("Send Article Now"), G_CALLBACK(do_send) },
     { "post-and-save-articles", GTK_STOCK_FLOPPY, N_("_Send and Save Articles to NZB"), 0, N_("Send and Save Articles to NZB"), G_CALLBACK(do_send_and_save) },
     { "set-charset", 0, N_("Set Character _Encoding..."), 0, 0, G_CALLBACK(do_charset) },
+    { "set-encoding", 0, N_("Set Content _Transfer Encoding..."), 0, 0, G_CALLBACK(do_cte) },
     { "save-draft", GTK_STOCK_SAVE, N_("Sa_ve Draft"), "<control>s", N_("Save as a Draft for Future Posting"), G_CALLBACK(do_save) },
     { "open-draft", GTK_STOCK_OPEN, N_("_Open Draft..."), "<control>o", N_("Open an Article Draft"), G_CALLBACK(do_open) },
     { "close", GTK_STOCK_CLOSE, 0, 0, 0, G_CALLBACK(do_close) },
@@ -493,6 +497,15 @@ PostUI :: prompt_for_charset ()
 }
 
 void
+PostUI :: prompt_for_cte ()
+{
+  GMimeContentEncoding enc = e_cte_dialog (_("Content Transfer Encoding"),
+                                 _("New Article's Content Transfer Encoding:"),
+                                 _enc, GTK_WINDOW(root()));
+  _enc = enc;
+}
+
+void
 PostUI::  do_popup_menu (GtkWidget *treeview, GdkEventButton *event, gpointer userdata)
 {
   PostUI * self (static_cast<PostUI*>(userdata));
@@ -995,6 +1008,8 @@ PostUI :: maybe_post_message (GMimeMessage * message)
     return true;
   }
 
+  g_object_unref(message);
+
   /**
   ***  Make sure we're online...
   **/
@@ -1024,9 +1039,11 @@ PostUI :: maybe_post_message (GMimeMessage * message)
     GMimeMessage* msg = new_message_from_ui(POSTING);
     bool go_on(true);
 
+    /* adding yourself to the list of recipients */
     GPtrArray * rcp = g_ptr_array_new();
     Profile p(get_current_profile());
     g_ptr_array_add(rcp, (gpointer)p.gpg_sig_uid.c_str());
+
     if (user_has_gpg && gpg_sign && !gpg_enc)
       go_on = go_on && message_add_signed_part(p.gpg_sig_uid, get_body(), msg);
     else if (user_has_gpg && gpg_enc && !gpg_sign)
@@ -1419,6 +1436,7 @@ namespace
 GMimeMessage*
 PostUI :: new_message_from_ui (Mode mode, bool copy_body)
 {
+
   GMimeMessage * msg(0);
   msg = g_mime_message_new (false);
 
@@ -1498,7 +1516,9 @@ PostUI :: new_message_from_ui (Mode mode, bool copy_body)
   {
     std::string body;
     if (copy_body) body = get_body();
-    GMimeStream * stream = g_mime_stream_mem_new_with_buffer (body.c_str(), body.size());
+
+    GMimeStream *  stream =  g_mime_stream_mem_new_with_buffer (body.c_str(), body.size());
+
     const std::string charset ((mode==POSTING && !_charset.empty()) ? _charset : "UTF-8");
     if (charset != "UTF-8") {
       // add a wrapper to convert from UTF-8 to $charset
@@ -1518,7 +1538,7 @@ PostUI :: new_message_from_ui (Mode mode, bool copy_body)
     g_free (pch);
     g_mime_object_set_content_type ((GMimeObject *) part, type); // part owns type now. type isn't refcounted.
     g_mime_part_set_content_object (part, content_object);
-    g_mime_part_set_content_encoding (part, GMIME_CONTENT_ENCODING_8BIT);
+    g_mime_part_set_content_encoding (part, _enc);
     g_object_unref (content_object);
     g_mime_message_set_mime_part (msg, GMIME_OBJECT(part));
     g_object_unref (part);
@@ -2900,7 +2920,8 @@ PostUI :: PostUI (GtkWindow    * parent,
   _filequeue_eventbox (0),
   _filequeue_label (0),
   _realized(false),
-  _uploads(0)
+  _uploads(0),
+  _enc(GMIME_CONTENT_ENCODING_8BIT)
 {
 
   rng.seed();
diff --git a/pan/gui/post-ui.h b/pan/gui/post-ui.h
index 4ae458c..632a8b0 100644
--- a/pan/gui/post-ui.h
+++ b/pan/gui/post-ui.h
@@ -77,6 +77,7 @@ namespace pan
       void open_draft ();
       void import_draft (const char* fn);
       void prompt_for_charset ();
+      void prompt_for_cte ();
       void send_now ();
       void send_and_save_now ();
       void add_files ();
@@ -153,6 +154,8 @@ namespace pan
       std::string _unchanged_body;
       int _wrap_pixels;
 
+      GMimeContentEncoding _enc;
+
       /* binpost */
       bool _file_queue_empty;
       TaskUpload* _upload_ptr;
diff --git a/pan/gui/post.ui.h b/pan/gui/post.ui.h
index 00c149f..aee9347 100644
--- a/pan/gui/post.ui.h
+++ b/pan/gui/post.ui.h
@@ -17,6 +17,7 @@ const char * fallback_post_ui =
 "      <menuitem action='paste' />\n"
 "      <menuitem action='rot13' />\n"
 "      <separator />\n"
+"      <menuitem action='set-encoding' />\n"
 "      <menuitem action='set-charset' />\n"
 "      <menuitem action='remember-charset' />\n"
 "      <separator />\n"
diff --git a/pan/gui/profiles-dialog.cc b/pan/gui/profiles-dialog.cc
index 14716f6..ad73d53 100644
--- a/pan/gui/profiles-dialog.cc
+++ b/pan/gui/profiles-dialog.cc
@@ -260,8 +260,8 @@ ProfileDialog :: ProfileDialog (const Data         & data,
     gtk_container_add (GTK_CONTAINER(eventbox), scrolled_window);
     HIG :: workarea_add_row (t, &row, _("E_xtra Headers:"), eventbox, w);
 
-  on_sig_file_toggled (GTK_TOGGLE_BUTTON(_signature_file_check), _signature_file);
-  on_sig_file_toggled (GTK_TOGGLE_BUTTON(_signature_file_check), _signature_file_combo_box);
+//  on_sig_file_toggled (GTK_TOGGLE_BUTTON(_signature_file_check), _signature_file);
+//  on_sig_file_toggled (GTK_TOGGLE_BUTTON(_signature_file_check), _signature_file_combo_box);
 
   gtk_box_pack_start (GTK_BOX( gtk_dialog_get_content_area( GTK_DIALOG(_root))), t, true, true, 0);
   gtk_widget_show_all (t);
diff --git a/pan/gui/server-ui.cc b/pan/gui/server-ui.cc
index b6cabac..826872e 100644
--- a/pan/gui/server-ui.cc
+++ b/pan/gui/server-ui.cc
@@ -107,7 +107,7 @@ namespace
     GtkTreeIter iter;
     if (gtk_combo_box_get_active_iter (w, &iter))
       gtk_tree_model_get (gtk_combo_box_get_model(w), &iter, 1, &ssl, -1);
-    pan_spin_button_set (d->port_spin, ssl==0 ? STD_NNTP_PORT : STD_SSL_PORT);
+    pan_spin_button_set (d->port_spin, ssl == 0 ? STD_NNTP_PORT : STD_SSL_PORT);
 #endif
   }
 
diff --git a/pan/usenet-utils/gpg.cc b/pan/usenet-utils/gpg.cc
index 869e2c7..ca23be2 100644
--- a/pan/usenet-utils/gpg.cc
+++ b/pan/usenet-utils/gpg.cc
@@ -28,6 +28,8 @@ extern "C" {
   #include <stdlib.h>
   #include <unistd.h>
   #include <string.h>
+  #include <glib/gi18n.h>
+  #include <gmime/gmime.h>
 }
 
 namespace pan
diff --git a/pan/usenet-utils/gpg.h b/pan/usenet-utils/gpg.h
index e959597..d48f790 100644
--- a/pan/usenet-utils/gpg.h
+++ b/pan/usenet-utils/gpg.h
@@ -125,6 +125,10 @@ namespace pan
   void init_gpg();
   void deinit_gpg();
   void fill_signer_info(GPGSignersInfo& info, GMimeSignatureList * sig_list);
+  int
+  __g_mime_multipart_signed_sign (GMimeMultipartSigned *mps, GMimeObject *content,
+              GMimeCryptoContext *ctx, const char *userid,
+              GMimeDigestAlgo digest, GError **err);
 
 }
 
diff --git a/pan/usenet-utils/mime-utils.cc b/pan/usenet-utils/mime-utils.cc
index ee32bd6..34179ef 100644
--- a/pan/usenet-utils/mime-utils.cc
+++ b/pan/usenet-utils/mime-utils.cc
@@ -34,6 +34,7 @@ extern "C"
 #include <pan/general/string-view.h>
 #include <pan/general/log.h>
 #include "mime-utils.h"
+#include "gpg.h"
 
 #define is_nonempty_string(a) ((a) && (*a))
 
@@ -362,11 +363,138 @@ enum EncType
 {
 	ENC_PLAIN ,
 	ENC_YENC,
-	ENC_UU
+	ENC_UU,
+	ENC_BASE64,
+	ENC_QP
 };
 
 namespace pan
 {
+
+  /*
+   base64.cpp and base64.h
+
+   Copyright (C) 2004-2008 Renéyffenegger
+
+   This source code is provided 'as-is', without any express or implied
+   warranty. In no event will the author be held liable for any damages
+   arising from the use of this software.
+
+   Permission is granted to anyone to use this software for any purpose,
+   including commercial applications, and to alter it and redistribute it
+   freely, subject to the following restrictions:
+
+   1. The origin of this source code must not be misrepresented; you must not
+      claim that you wrote the original source code. If you use this source code
+      in a product, an acknowledgment in the product documentation would be
+      appreciated but is not required.
+
+   2. Altered source versions must be plainly marked as such, and must not be
+      misrepresented as being the original source code.
+
+   3. This notice may not be removed or altered from any source distribution.
+
+   Renéyffenegger rene nyffenegger adp-gmbh ch
+
+*/
+
+  static const std::string base64_chars =
+             "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+             "abcdefghijklmnopqrstuvwxyz"
+             "0123456789+/";
+
+
+  static inline bool is_base64(unsigned char c) {
+    return (isalnum(c) || (c == '+') || (c == '/'));
+  }
+
+  std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
+    std::string ret;
+    int i = 0;
+    int j = 0;
+    unsigned char char_array_3[3];
+    unsigned char char_array_4[4];
+
+    while (in_len--) {
+      char_array_3[i++] = *(bytes_to_encode++);
+      if (i == 3) {
+        char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
+        char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
+        char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
+        char_array_4[3] = char_array_3[2] & 0x3f;
+
+        for(i = 0; (i <4) ; i++)
+          ret += base64_chars[char_array_4[i]];
+        i = 0;
+      }
+    }
+
+    if (i)
+    {
+      for(j = i; j < 3; j++)
+        char_array_3[j] = '\0';
+
+      char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
+      char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
+      char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
+      char_array_4[3] = char_array_3[2] & 0x3f;
+
+      for (j = 0; (j < i + 1); j++)
+        ret += base64_chars[char_array_4[j]];
+
+      while((i++ < 3))
+        ret += '=';
+
+    }
+
+    return ret;
+
+  }
+
+  std::string base64_decode(std::string const& encoded_string) {
+    int in_len = encoded_string.size();
+    int i = 0;
+    int j = 0;
+    int in_ = 0;
+    unsigned char char_array_4[4], char_array_3[3];
+    std::string ret;
+
+    while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
+      char_array_4[i++] = encoded_string[in_]; in_++;
+      if (i ==4) {
+        for (i = 0; i <4; i++)
+          char_array_4[i] = base64_chars.find(char_array_4[i]);
+
+        char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
+        char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
+        char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
+
+        for (i = 0; (i < 3); i++)
+          ret += char_array_3[i];
+        i = 0;
+      }
+    }
+
+    if (i) {
+      for (j = i; j <4; j++)
+        char_array_4[j] = 0;
+
+      for (j = 0; j <4; j++)
+        char_array_4[j] = base64_chars.find(char_array_4[j]);
+
+      char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
+      char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
+      char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
+
+      for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
+    }
+
+    return ret;
+  }
+}
+
+namespace pan
+{
   struct TempPart
   {
     GMimeStream * stream;
@@ -398,7 +526,7 @@ namespace pan
       if (filter)
         g_object_unref (filter);
       if (filter_stream)
-	g_object_unref (filter_stream);
+        g_object_unref (filter_stream);
     }
   };
 
@@ -425,9 +553,12 @@ namespace pan
     return true;
   }
 
+
   void apply_source_and_maybe_filter (TempPart * part, GMimeStream * s)
   {
 
+    bool skip(false);
+
     if (!part->stream) {
       part->stream = g_mime_stream_mem_new ();
       if (part->type != ENC_PLAIN) {
@@ -438,6 +569,14 @@ namespace pan
             part->filter = g_mime_filter_basic_new (GMIME_CONTENT_ENCODING_UUENCODE, FALSE);
             break;
 
+          case ENC_BASE64:
+            part->filter = g_mime_filter_basic_new (GMIME_CONTENT_ENCODING_BASE64, FALSE);
+            break;
+
+          case ENC_QP:
+            part->filter = g_mime_filter_basic_new (GMIME_CONTENT_ENCODING_QUOTEDPRINTABLE, FALSE);
+            break;
+
           case ENC_YENC:
             part->filter = g_mime_filter_yenc_new (FALSE);
             break;
@@ -448,8 +587,8 @@ namespace pan
       }
     }
 
-    g_mime_stream_write_to_stream (s, (part->type == ENC_PLAIN ?
-				   part->stream : part->filter_stream));
+    g_mime_stream_write_to_stream (s, (part->type == ENC_PLAIN  ? part->stream : part->filter_stream));
+
     g_object_unref (s);
   }
 
@@ -462,12 +601,12 @@ namespace pan
   };
 
   bool
-  separate_encoded_parts (GMimeStream  * istream, sep_state &state)
+  separate_encoded_parts (GMimeStream  * istream, sep_state &state, EncType et)
   {
     temp_parts_t& master(state.master_list);
     temp_parts_t& appendme(state.current_list);
     TempPart * cur = NULL;
-    EncType type = ENC_PLAIN;
+    EncType type = et;
     GByteArray * line;
     gboolean yenc_looking_for_part_line = FALSE;
     gint64 linestart_pos = 0;
@@ -494,6 +633,17 @@ namespace pan
 
       switch (type)
       {
+
+        case ENC_QP:
+          sub_begin = linestart_pos;
+          cur = new TempPart(type = ENC_QP);
+          break;
+
+        case ENC_BASE64:
+          sub_begin = linestart_pos;
+          cur = new TempPart(type = ENC_BASE64);
+          break;
+
         case ENC_PLAIN:
         {
           const StringView line_pstr (line_str, line_len);
@@ -578,8 +728,8 @@ namespace pan
           else if (cur == NULL)
           {
             sub_begin = linestart_pos;
+            cur = new TempPart(type = type);
 
-            cur = new TempPart (type = ENC_PLAIN);
           }
           break;
         }
@@ -667,6 +817,7 @@ namespace pan
         append_if_not_present (appendme, cur);
       cur = NULL;
       type = ENC_PLAIN;
+
     }
 
     g_byte_array_free (line, TRUE);
@@ -685,6 +836,7 @@ mime :: guess_part_type_from_filename (const char   * filename,
 		const char * type;
 		const char * subtype;
 	} suffixes[] = {
+	  { ".asc",   "text",         "plain" }, // plain-encoded signature
 		{ ".avi",   "video",        "vnd.msvideo" },
 		{ ".dtd",   "text",         "xml-dtd" },
 		{ ".flac",  "audio",        "ogg" },
@@ -773,11 +925,11 @@ namespace
     array->pdata[index] = object;
   }
 
-  void handle_uu_and_yenc_in_text_plain_cb (GMimeObject *parent, GMimeObject *part, gpointer data)
+
+  void handle_encoded_in_text_plain_cb (GMimeObject *parent, GMimeObject *part, gpointer data)
   {
 
-    if (!part)
-      return;
+    if (!part) return;
 
     // we assume that inlined yenc and uu are only in text/plain blocks
     GMimeContentType * content_type = g_mime_object_get_content_type (part);
@@ -797,7 +949,7 @@ namespace
     // break it into separate parts for text, uu, and yenc pieces.
     sep_state &state(*(sep_state*)data);
     temp_parts_t &parts(state.current_list);
-    bool split = separate_encoded_parts (istream, state);
+    bool split = separate_encoded_parts (istream, state, ENC_PLAIN);
     g_mime_stream_reset (istream);
 
     // split?
@@ -1027,7 +1179,6 @@ mime :: construct_message (GMimeStream    ** istreams,
           g_mime_multipart_foreach (GMIME_MULTIPART(part), mixed_mp_cb, &qtype);
           err.verify_ok = gpg_verify_mps(GMIME_OBJECT(new_mp), err);
           g_mime_message_set_mime_part(messages[i], GMIME_OBJECT(new_mp));
-          std::cerr<<"algo : "<<g_mime_object_to_string(GMIME_OBJECT(new_mp))<<"\n";
         }
 
         if (qtype.type == GPG_DECODE)
@@ -1077,12 +1228,14 @@ mime :: construct_message (GMimeStream    ** istreams,
   if (retval != NULL)
     g_mime_message_foreach(retval, find_text_cb, &partslist);
 
+
   foreach(temp_p_t, partslist, it)
   {
     temp_p &data(*it);
-    handle_uu_and_yenc_in_text_plain_cb(data.parent, data.part, &state);
+    handle_encoded_in_text_plain_cb(data.parent, data.part, &state);
   }
 
+
   // cleanup
   foreach (temp_parts_t, state.master_list, it)
   {
@@ -1317,9 +1470,6 @@ namespace
   }
 
 }
-#define NEEDS_DECODING(encoding) ((encoding == GMIME_CONTENT_ENCODING_BASE64) ||   \
-                                  (encoding == GMIME_CONTENT_ENCODING_UUENCODE) || \
-                                  (encoding == GMIME_CONTENT_ENCODING_QUOTEDPRINTABLE))
 
 namespace
 {
@@ -1472,7 +1622,6 @@ namespace pan
       if (!sig_list) return false;
       fill_signer_info(info.signers, sig_list);
 
-      return get_sig_status(sig_list) == GMIME_SIGNATURE_STATUS_GOOD;
     }
 
     if (info.type == GPG_DECODE)
@@ -1487,12 +1636,19 @@ namespace pan
         info.no_sigs = false;
         fill_signer_info(info.signers, sigs);
       }
-      return get_sig_status(info.result->signatures) == GMIME_SIGNATURE_STATUS_GOOD || !info.err;
+
     }
-    return false;
+
+    return get_sig_status(info.result->signatures) == GMIME_SIGNATURE_STATUS_GOOD || !info.err;
 
   }
 
+  enum
+  {
+    GMIME_MULTIPART_SIGNED_CONTENT,
+    GMIME_MULTIPART_SIGNED_SIGNATURE
+  };
+
   GMimeMessage*
   message_add_signed_part (const std::string& uid, const std::string& body_str, GMimeMessage* body)
   {
@@ -1513,6 +1669,11 @@ namespace pan
       return 0;
     }
 
+    /* GMIME _dirty_ hack : set filename for signature attachment */
+    /// FIXME : gets scrambled somehow, but _atm_ i don't care ....
+    GMimeObject * signature = g_mime_multipart_get_part (GMIME_MULTIPART (mps), GMIME_MULTIPART_SIGNED_SIGNATURE);
+    g_mime_part_set_filename (GMIME_PART(signature), "signature.asc");
+
     g_mime_message_set_mime_part(body,GMIME_OBJECT(mps));
     g_object_unref(G_OBJECT(part));
     g_object_unref(mps);
diff --git a/pan/usenet-utils/mime-utils.h b/pan/usenet-utils/mime-utils.h
index 15e2188..f25ce2f 100644
--- a/pan/usenet-utils/mime-utils.h
+++ b/pan/usenet-utils/mime-utils.h
@@ -56,9 +56,15 @@
 #define YENC_SHIFT             42
 #define YENC_QUOTE_SHIFT       64
 
+#define NEEDS_DECODING(encoding) ((encoding == GMIME_CONTENT_ENCODING_BASE64) ||   \
+                                 (encoding == GMIME_CONTENT_ENCODING_QUOTEDPRINTABLE))
+
 namespace pan
 {
 
+  std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len);
+  std::string base64_decode(std::string const& encoded_string);
+
   GMimeMessage* message_add_signed_part (const std::string& uid, const std::string& body_str, GMimeMessage* body);
   GMimeMessage* gpg_encrypt (const std::string& uid, const std::string& body_str, GMimeMessage* body, GPtrArray* rcp, bool sign);
   bool gpg_verify_mps (GMimeObject*, GPGDecErr&);



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