[pan2] First patch to enable GMime 3.0 lib. Porting to GMime 3.0 not yet completed.



commit 90c1604cdb6b500bd4f6fd74c2a85377ae92eefb
Author: Detlef Graef <detlef graef yahoo de>
Date:   Tue Oct 3 16:51:21 2017 +0200

    First patch to enable GMime 3.0 lib. Porting to GMime 3.0 not yet completed.

 configure.ac                      |   14 ++++--
 pan/general/utf8-utils.cc         |   21 ++++++++
 pan/gui/body-pane.cc              |   50 ++++++++++++++++++++
 pan/gui/gui.cc                    |   52 ++++++++++++++++++++
 pan/gui/pan.cc                    |    3 +
 pan/gui/post-ui.cc                |   93 ++++++++++++++++++++++++++++++++++++-
 pan/tasks/nzb.cc                  |    4 ++
 pan/tasks/task-post.cc            |    4 ++
 pan/tasks/task-upload.cc          |   21 ++++++++
 pan/tasks/task-xover.cc           |    5 ++
 pan/usenet-utils/message-check.cc |    4 ++
 pan/usenet-utils/mime-utils.cc    |   54 +++++++++++++++++++++
 pan/usenet-utils/mime-utils.h     |    4 ++
 13 files changed, 323 insertions(+), 6 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index d8cc17d..aad40d0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -52,8 +52,8 @@ m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
 dnl glib, gmime, and gtk are mandatory prerequisites.
 GLIB_REQUIRED=2.17.6
 GLIB_REQUIRED_FOR_DBUS=2.26.0
-GMIME24_REQUIRED=2.4.0
-GMIME26_REQUIRED=2.5.5
+GMIME26_REQUIRED=2.6.20
+GMIME30_REQUIRED=3.0.0
 GTK_REQUIRED=2.16.0
 GTK3_REQUIRED=3.0.0
 GTKSPELL_REQUIRED=2.0.7
@@ -114,13 +114,17 @@ else
 fi
 
 dnl Check for GMime
-PKG_CHECK_MODULES([GMIME], [gmime-2.6 >= $GMIME26_REQUIRED],[have_gmime26=yes],
+PKG_CHECK_MODULES([GMIME], [gmime-3.0 >= $GMIME30_REQUIRED],[have_gmime30=yes],
   [
-    PKG_CHECK_MODULES([GMIME], [gmime-2.4 >= $GMIME24_REQUIRED])
-    have_gmime26=no
+    PKG_CHECK_MODULES([GMIME], [gmime-2.6 >= $GMIME26_REQUIRED])
+    have_gmime26=yes
   ]
   )
 
+if test "x$have_gmime30" = "xyes"; then
+   AC_DEFINE(HAVE_GMIME_30,[1],[Gmime 3.0 available])
+fi
+
 dnl Check for GMime cryptography support
 AC_ARG_WITH([gmime-crypto],
   AS_HELP_STRING([--with-gmime-crypto],[enable GMime cryptography support (overrides auto-on if GMime 2.6 is 
found) (normally: yes)]),
diff --git a/pan/general/utf8-utils.cc b/pan/general/utf8-utils.cc
index f7f95a2..d52f583 100644
--- a/pan/general/utf8-utils.cc
+++ b/pan/general/utf8-utils.cc
@@ -129,6 +129,22 @@ pan :: clean_utf8 (const StringView& in_arg)
   return out;
 }
 
+#ifdef HAVE_GMIME_30
+std::string
+pan :: header_to_utf8 (const StringView  & header,
+                       const char        * fallback_charset1,
+                       const char        * fallback_charset2)
+{
+  std::string s = content_to_utf8 (header, fallback_charset1, fallback_charset2);
+  if (header.strstr ("=?")) {
+    char * decoded (g_mime_utils_header_decode_text (NULL, s.c_str()));
+    s = clean_utf8 (decoded);
+    g_free (decoded);
+  }
+  return s;
+}
+
+#else
 std::string
 pan :: header_to_utf8 (const StringView  & header,
                        const char        * fallback_charset1,
@@ -142,6 +158,7 @@ pan :: header_to_utf8 (const StringView  & header,
   }
   return s;
 }
+#endif
 
 std::string
 pan :: mime_part_to_utf8 (GMimePart     * part,
@@ -152,7 +169,11 @@ pan :: mime_part_to_utf8 (GMimePart     * part,
   g_return_val_if_fail (GMIME_IS_PART(part), ret);
   const char * charset =
     g_mime_object_get_content_type_parameter (GMIME_OBJECT (part), "charset");
+#ifdef HAVE_GMIME_30
+  GMimeDataWrapper * content = g_mime_part_get_content (part);
+#else
   GMimeDataWrapper * content = g_mime_part_get_content_object (part);
+#endif
   GMimeStream *stream = g_mime_stream_mem_new ();
 
   g_mime_data_wrapper_write_to_stream (content, stream);
diff --git a/pan/gui/body-pane.cc b/pan/gui/body-pane.cc
index 3ce1801..0a40ca3 100644
--- a/pan/gui/body-pane.cc
+++ b/pan/gui/body-pane.cc
@@ -905,7 +905,11 @@ namespace
     GError * err (0);
 
     // populate the loader
+#ifdef HAVE_GMIME_30
+    GMimeDataWrapper * wrapper (g_mime_part_get_content (part));
+#else    
     GMimeDataWrapper * wrapper (g_mime_part_get_content_object (part));
+#endif    
     if (wrapper)
     {
       GMimeStream * mem_stream (g_mime_stream_mem_new ());
@@ -1250,7 +1254,11 @@ BodyPane :: set_text_from_message (GMimeMessage * message)
   // maybe add the headers
   const bool do_show_headers (_prefs.get_flag ("show-all-headers", false));
   if (message && do_show_headers) {
+#ifdef HAVE_GMIME_30
+    char * headers (g_mime_object_get_headers ((GMimeObject *) message, NULL));
+#else    
     char * headers (g_mime_object_get_headers ((GMimeObject *) message));
+#endif    
     GtkTextIter end;
     gtk_text_buffer_get_end_iter (_buffer, &end);
     StringView line, v(headers);
@@ -2062,10 +2070,18 @@ BodyPane :: create_followup_or_reply (bool is_reply)
 
     if (is_reply || fup_to=="poster") {
       const std::string& to (reply_to.empty() ? from : reply_to);
+#ifdef HAVE_GMIME_30
+      pan_g_mime_message_add_recipients_from_string (msg, GMIME_ADDRESS_TYPE_TO, to.c_str());
+#else      
       pan_g_mime_message_add_recipients_from_string (msg, GMIME_RECIPIENT_TYPE_TO, to.c_str());
+#endif      
     } else {
       const std::string& groups (fup_to.empty() ? newsgroups : fup_to);
+#ifdef HAVE_GMIME_30
+      g_mime_object_append_header ((GMimeObject *) msg, "Newsgroups", groups.c_str(), NULL);
+#else      
       g_mime_object_append_header ((GMimeObject *) msg, "Newsgroups", groups.c_str());
+#endif      
     }
 
     // Subject:
@@ -2074,21 +2090,43 @@ BodyPane :: create_followup_or_reply (bool is_reply)
     std::string val (normalize_subject_re (h));
     if (val.find ("Re:") != 0) // add "Re: " if we don't have one
       val.insert (0, "Re: ");
+#ifdef HAVE_GMIME_30
+    g_mime_message_set_subject (msg, val.c_str(), NULL);
+#else    
     g_mime_message_set_subject (msg, val.c_str());
+#endif    
 
     // attribution lines
     const char * cpch = g_mime_object_get_header (_message_obj, "From");
     h = header_to_utf8 (cpch, message_charset, group_charset);
+#ifdef HAVE_GMIME_30
+    g_mime_object_append_header (msg_obj, "X-Draft-Attribution-Author", h.c_str(), NULL);
+#else    
     g_mime_object_append_header (msg_obj, "X-Draft-Attribution-Author", h.c_str());
+#endif    
 
     cpch = g_mime_message_get_message_id (_message);
     h = header_to_utf8 (cpch, message_charset, group_charset);
+#ifdef HAVE_GMIME_30
+    g_mime_object_append_header (msg_obj, "X-Draft-Attribution-Id", h.c_str(), NULL);
+#else    
     g_mime_object_append_header (msg_obj, "X-Draft-Attribution-Id", h.c_str());
+#endif    
 
+#ifdef HAVE_GMIME_30
+    const char * header_t = "Date";
+    const char * tmp_s = g_mime_object_get_header (_message_obj, header_t);
+    const char * tmp = tmp_s;  // fixme: convert time to string
+#else    
     char * tmp = g_mime_message_get_date_as_string (_message);
+#endif    
     h = header_to_utf8 (tmp, message_charset, group_charset);
+#ifdef HAVE_GMIME_30
+    g_mime_object_append_header (msg_obj, "X-Draft-Attribution-Date", h.c_str(), NULL);
+#else    
     g_mime_object_append_header (msg_obj, "X-Draft-Attribution-Date", h.c_str());
     g_free (tmp);
+#endif    
 
     // references
     const char * header = "References";
@@ -2100,7 +2138,11 @@ BodyPane :: create_followup_or_reply (bool is_reply)
     val += g_mime_message_get_message_id (_message);
     val += ">";
     val = GNKSA :: trim_references (val);
+#ifdef HAVE_GMIME_30
+    g_mime_object_append_header (msg_obj, header, val.c_str(), NULL);
+#else    
     g_mime_object_append_header (msg_obj, header, val.c_str());
+#endif    
 
     ///
     ///  BODY
@@ -2138,9 +2180,17 @@ BodyPane :: create_followup_or_reply (bool is_reply)
     g_mime_stream_write_string (stream, s.c_str());
     GMimeDataWrapper * wrapper = g_mime_data_wrapper_new_with_stream (stream, GMIME_CONTENT_ENCODING_8BIT);
     GMimePart * part = g_mime_part_new ();
+#ifdef HAVE_GMIME_30
+    GMimeContentType * new_type = g_mime_content_type_parse (NULL, "text/plain; charset=UTF-8");
+#else    
     GMimeContentType * new_type = g_mime_content_type_new_from_string ("text/plain; charset=UTF-8");
+#endif    
     g_mime_object_set_content_type ((GMimeObject *) part, new_type);
+#ifdef HAVE_GMIME_30
+    g_mime_part_set_content (part, wrapper);
+#else    
     g_mime_part_set_content_object (part, wrapper);
+#endif    
     g_mime_part_set_content_encoding (part, GMIME_CONTENT_ENCODING_8BIT);
     g_mime_message_set_mime_part (msg, GMIME_OBJECT(part));
     g_object_unref (new_type);
diff --git a/pan/gui/gui.cc b/pan/gui/gui.cc
index 945ea55..c787bab 100644
--- a/pan/gui/gui.cc
+++ b/pan/gui/gui.cc
@@ -745,7 +745,11 @@ namespace
       if (GMIME_IS_PART(o))
       {
         GMimePart * part (GMIME_PART (o));
+#ifdef HAVE_GMIME_30
+        GMimeDataWrapper * wrapper (g_mime_part_get_content (part));
+#else        
         GMimeDataWrapper * wrapper (g_mime_part_get_content_object (part));
+#endif        
         GMimeStream * mem_stream (g_mime_stream_mem_new ());
         g_mime_data_wrapper_write_to_stream (wrapper, mem_stream);
         const GByteArray * buffer (GMIME_STREAM_MEM(mem_stream)->buffer);
@@ -1322,7 +1326,12 @@ void GUI :: do_supersede_article ()
     return;
 
   // did this user post the message?
+#ifdef HAVE_GMIME_30
+  InternetAddressList * Lsender (g_mime_message_get_sender (message));
+  char * sender = internet_address_list_to_string(Lsender, NULL,  TRUE);
+#else  
   const char * sender (g_mime_message_get_sender (message));
+#endif  
   const bool user_posted_this (_data.has_from_header (sender));
 
   if (!user_posted_this) {
@@ -1348,6 +1357,19 @@ void GUI :: do_supersede_article ()
   GMimeMessage * new_message (g_mime_message_new (false));
   GMimeObject * new_message_obj = (GMimeObject*)new_message;
 
+#ifdef HAVE_GMIME_30
+  g_mime_object_set_header (new_message_obj, "Supersedes", old_mid, NULL);
+  const char * addr = internet_address_list_to_string (g_mime_message_get_sender (message), NULL, TRUE);
+  g_mime_message_add_mailbox (new_message, GMIME_ADDRESS_TYPE_SENDER, NULL, addr);
+  g_mime_message_set_subject (new_message, g_mime_message_get_subject (message), NULL);
+  g_mime_object_set_header (new_message_obj, "Newsgroups", g_mime_object_get_header ((GMimeObject *)message, 
"Newsgroups"), NULL);
+  g_mime_object_set_header (new_message_obj, "References", g_mime_object_get_header ((GMimeObject *)message, 
"References"), NULL);
+  const char * r_addr = internet_address_list_to_string(g_mime_message_get_reply_to (message), NULL, TRUE);
+  if ((cpch = r_addr))
+              g_mime_message_add_mailbox (new_message, GMIME_ADDRESS_TYPE_REPLY_TO, NULL, cpch);
+  if ((cpch = g_mime_object_get_header ((GMimeObject *)message,     "Followup-To")))
+              g_mime_object_set_header (new_message_obj, "Followup-To", cpch, NULL);
+#else  
   g_mime_object_set_header (new_message_obj, "Supersedes", old_mid);
   g_mime_message_set_sender (new_message, g_mime_message_get_sender (message));
   g_mime_message_set_subject (new_message, g_mime_message_get_subject (message));
@@ -1357,13 +1379,18 @@ void GUI :: do_supersede_article ()
               g_mime_message_set_reply_to (new_message, cpch);
   if ((cpch = g_mime_object_get_header ((GMimeObject *)message,     "Followup-To")))
               g_mime_object_set_header (new_message_obj, "Followup-To", cpch);
+#endif  
   gboolean  unused (false);
   char * body (pan_g_mime_message_get_body (message, &unused));
   GMimeStream * stream = g_mime_stream_mem_new_with_buffer (body, strlen(body));
   g_free (body);
   GMimeDataWrapper * content_object = g_mime_data_wrapper_new_with_stream (stream, 
GMIME_CONTENT_ENCODING_DEFAULT);
   GMimePart * part = g_mime_part_new ();
+#ifdef HAVE_GMIME_30
+   g_mime_part_set_content(part, content_object);
+#else  
   g_mime_part_set_content_object (part, content_object);
+#endif  
   g_mime_message_set_mime_part (new_message, GMIME_OBJECT(part));
   g_object_unref (part);
   g_object_unref (content_object);
@@ -1397,7 +1424,11 @@ void GUI :: do_cancel_article ()
     return;
 
   // did this user post the message?
+#ifdef HAVE_GMIME_30
+  const char * sender = internet_address_list_to_string(g_mime_message_get_sender (message), NULL, TRUE);
+#else  
   const char * sender (g_mime_message_get_sender (message));
+#endif  
   const bool user_posted_this (_data.has_from_header (sender));
   if (!user_posted_this) {
     GtkWidget * w = gtk_message_dialog_new (
@@ -1417,15 +1448,28 @@ void GUI :: do_cancel_article ()
   // okay then...
   GMimeMessage * cancel = g_mime_message_new (false);
   char * cancel_message = g_strdup_printf ("cancel <%s>", g_mime_message_get_message_id(message));
+#ifdef HAVE_GMIME_30
+  const char * s_addr = internet_address_list_to_string(g_mime_message_get_sender (message), NULL, TRUE);
+  g_mime_message_add_mailbox (cancel, GMIME_ADDRESS_TYPE_SENDER, NULL, s_addr);
+  g_mime_message_set_subject (cancel, "Cancel", NULL);
+  g_mime_object_set_header ((GMimeObject *)cancel, "Newsgroups", g_mime_object_get_header ((GMimeObject 
*)message, "Newsgroups"), NULL);
+  g_mime_object_set_header ((GMimeObject *)cancel, "Control", cancel_message, NULL);
+#else  
   g_mime_message_set_sender (cancel, g_mime_message_get_sender (message));
   g_mime_message_set_subject (cancel, "Cancel");
   g_mime_object_set_header ((GMimeObject *)cancel, "Newsgroups", g_mime_object_get_header ((GMimeObject 
*)message, "Newsgroups"));
   g_mime_object_set_header ((GMimeObject *)cancel, "Control", cancel_message);
+
+#endif  
   const char * body ("Ignore\r\nArticle canceled by author using " PACKAGE_STRING "\r\n");
   GMimeStream * stream = g_mime_stream_mem_new_with_buffer (body, strlen(body));
   GMimeDataWrapper * content_object = g_mime_data_wrapper_new_with_stream (stream, 
GMIME_CONTENT_ENCODING_DEFAULT);
   GMimePart * part = g_mime_part_new ();
+#ifdef HAVE_GMIME_30
+  g_mime_part_set_content (part, content_object);
+#else  
   g_mime_part_set_content_object (part, content_object);
+#endif  
   g_mime_message_set_mime_part (cancel, GMIME_OBJECT(part));
   g_object_unref (part);
   g_object_unref (content_object);
@@ -1587,11 +1631,19 @@ GUI :: do_post ()
       newsgroups = group;
   }
   if (!newsgroups.empty())
+#ifdef HAVE_GMIME_30
+    g_mime_object_append_header ((GMimeObject *) message, "Newsgroups", newsgroups.c_str(), NULL);
+#else    
     g_mime_object_append_header ((GMimeObject *) message, "Newsgroups", newsgroups.c_str());
+#endif    
 
   // content type
   GMimePart * part = g_mime_part_new ();
+#ifdef HAVE_GMIME_30
+  GMimeContentType *type = g_mime_content_type_parse (NULL, "text/plain; charset=UTF-8");
+#else  
   GMimeContentType *type = g_mime_content_type_new_from_string ("text/plain; charset=UTF-8");
+#endif  
   g_mime_object_set_content_type ((GMimeObject *) part, type);
   g_object_unref (type);
   g_mime_part_set_content_encoding (part, GMIME_CONTENT_ENCODING_8BIT);
diff --git a/pan/gui/pan.cc b/pan/gui/pan.cc
index a05d180..dae4848 100644
--- a/pan/gui/pan.cc
+++ b/pan/gui/pan.cc
@@ -902,7 +902,10 @@ main (int argc, char *argv[])
 #if !GLIB_CHECK_VERSION(2,32,0)
   g_thread_init (0);
 #endif
+#ifdef HAVE_GMIME_30
+#else
   g_mime_init (GMIME_ENABLE_RFC2047_WORKAROUNDS);
+#endif  
 
   bool gui(true), nzb(false), verbosed(false);
   std::string url;
diff --git a/pan/gui/post-ui.cc b/pan/gui/post-ui.cc
index 91ddd08..7ee303e 100644
--- a/pan/gui/post-ui.cc
+++ b/pan/gui/post-ui.cc
@@ -957,7 +957,11 @@ PostUI :: maybe_mail_message (GMimeMessage * message)
 {
   std::string url, to, groups;
   gboolean unused;
+#ifdef HAVE_GMIME_30
+  char * headers (g_mime_object_get_headers ((GMimeObject *) message, NULL));
+#else  
   char * headers (g_mime_object_get_headers ((GMimeObject *) message));
+#endif  
   char * body (pan_g_mime_message_get_body (message, &unused));
   StringView key, val, v(headers);
   v.trim ();
@@ -1055,7 +1059,11 @@ PostUI :: save_message_in_local_folder(const Mode& mode, const std::string& fold
          p.get_from_header(author);
          std::string subject(utf8ize (g_mime_message_get_subject (msg)));
          const char * refs = g_mime_object_get_header(GMIME_OBJECT(msg), "References");
+#ifdef HAVE_GMIME_30
+         g_mime_object_set_header((GMimeObject *) msg, "Newsgroups", folder.c_str(), NULL);
+#else    
          g_mime_object_set_header((GMimeObject *) msg, "Newsgroups", folder.c_str());
+#endif   
 
          // pseudo mid to get data from cache
          std::string message_id = pan_g_mime_message_set_message_id(msg, mid.c_str());
@@ -1065,9 +1073,18 @@ PostUI :: save_message_in_local_folder(const Mode& mode, const std::string& fold
          const Article* article = _data.xover_add (p.posting_server, folder, subject, author, posted, 
message_id, refs, sizeof(*msg), 3, xref.str(), true);
          if (article)
          {
+#ifdef HAVE_GMIME_30
+          GDateTime * postedGDT = g_date_time_new_from_unix_utc(posted);  
+                 g_mime_message_set_date(msg, postedGDT);
+#else            
                  g_mime_message_set_date(msg, posted, 0);
+#endif           
                  ArticleCache& cache(_data.get_cache());
+#ifdef HAVE_GMIME_30  
+                 ArticleCache :: CacheResponse response = cache.add(mid, 
g_mime_object_to_string(GMIME_OBJECT(msg), NULL), true);
+#else            
                  ArticleCache :: CacheResponse response = cache.add(mid, 
g_mime_object_to_string(GMIME_OBJECT(msg)), true);
+#endif           
                  g_object_unref(msg);
 
                  if (response.type != ArticleCache::CACHE_OK)
@@ -1506,7 +1523,11 @@ PostUI :: open_draft ()
     {
       GMimeStream * stream = g_mime_stream_mem_new_with_buffer (txt.c_str(), txt.size());
       GMimeParser * parser = g_mime_parser_new_with_stream (stream);
+#ifdef HAVE_GMIME_30
+      GMimeMessage * message = g_mime_parser_construct_message (parser, NULL);
+#else      
       GMimeMessage * message = g_mime_parser_construct_message (parser);
+#endif      
       if (message) {
         set_message (message);
         g_object_unref (G_OBJECT(message));
@@ -1585,46 +1606,78 @@ PostUI :: new_message_from_ui (Mode mode, bool copy_body)
   const Profile profile (get_current_profile ());
   std::string s;
   profile.get_from_header (s);
+#ifdef HAVE_GMIME_30
+  g_mime_message_add_mailbox (msg, GMIME_ADDRESS_TYPE_SENDER, NULL, s.c_str());
+#else  
   g_mime_message_set_sender (msg, s.c_str());
+#endif  
 
   // headers from the ui: Subject
   const char * cpch (gtk_entry_get_text (GTK_ENTRY(_subject_entry)));
   if (cpch) {
+#ifdef HAVE_GMIME_30
+    g_mime_message_set_subject (msg, cpch, NULL);
+#else    
     g_mime_message_set_subject (msg, cpch);
+#endif
   }
 
   // headers from the ui: To
   const StringView to (gtk_entry_get_text (GTK_ENTRY(_to_entry)));
   if (!to.empty())
+#ifdef HAVE_GMIME_30
+    pan_g_mime_message_add_recipients_from_string (msg, GMIME_ADDRESS_TYPE_TO, to.str);
+#else    
     pan_g_mime_message_add_recipients_from_string (msg, GMIME_RECIPIENT_TYPE_TO, to.str);
+#endif    
 
   // headers from the ui: Newsgroups
   const StringView groups (gtk_entry_get_text (GTK_ENTRY(_groups_entry)));
   if (!groups.empty())
+#ifdef HAVE_GMIME_30
+    g_mime_object_set_header ((GMimeObject *) msg, "Newsgroups", groups.str, NULL);
+#else    
     g_mime_object_set_header ((GMimeObject *) msg, "Newsgroups", groups.str);
+#endif    
 
   // headers from the ui: Followup-To
   const StringView followupto (gtk_entry_get_text (GTK_ENTRY(_followupto_entry)));
   if (!followupto.empty())
+#ifdef HAVE_GMIME_30
+    g_mime_object_set_header ((GMimeObject *) msg, "Followup-To", followupto.str, NULL);
+#else    
     g_mime_object_set_header ((GMimeObject *) msg, "Followup-To", followupto.str);
+#endif    
 
   // headers from the ui: Reply-To
   const StringView replyto (gtk_entry_get_text (GTK_ENTRY(_replyto_entry)));
   if (!replyto.empty())
+#ifdef HAVE_GMIME_30
+    g_mime_object_set_header ((GMimeObject *) msg, "Reply-To", replyto.str, NULL);
+#else    
     g_mime_object_set_header ((GMimeObject *) msg, "Reply-To", replyto.str);
+#endif    
 
   // headers from posting profile(via prefs): X-Face
   if (!profile.xface.empty())
   {
     std::string f;
     f += " " + profile.xface;
+#ifdef HAVE_GMIME_30
+    g_mime_object_set_header ((GMimeObject *) msg, "X-Face", f.c_str(), NULL);
+#else    
     g_mime_object_set_header ((GMimeObject *) msg, "X-Face", f.c_str());
+#endif    
   }
 
   // add the 'hidden headers'
   foreach_const (str2str_t, _hidden_headers, it)
     if ((mode==DRAFTING) || (it->first.find ("X-Draft-")!=0))
+#ifdef HAVE_GMIME_30
+      g_mime_object_set_header ((GMimeObject *) msg, it->first.c_str(), it->second.c_str(), NULL);
+#else      
       g_mime_object_set_header ((GMimeObject *) msg, it->first.c_str(), it->second.c_str());
+#endif      
 
   // build headers from the 'more headers' entry field
   std::map<std::string,std::string> headers;
@@ -1640,14 +1693,23 @@ PostUI :: new_message_from_ui (Mode mode, bool copy_body)
     val.trim ();
     std::string key_str (key.to_string());
     if (extra_header_is_editable (key, val))
+#ifdef HAVE_GMIME_30
+      g_mime_object_set_header ((GMimeObject *) msg, key.to_string().c_str(),
+                                val.to_string().c_str(), NULL);
+#else                                
       g_mime_object_set_header ((GMimeObject *) msg, key.to_string().c_str(),
-                                val.to_string().c_str());
+                                val.to_string().c_str());                                
+#endif                                
   }
   g_free (pch);
 
   // User-Agent
   if ((mode==POSTING || mode == UPLOADING) && _prefs.get_flag (USER_AGENT_PREFS_KEY, true))
+#ifdef HAVE_GMIME_30
+    g_mime_object_set_header ((GMimeObject *) msg, "User-Agent", get_user_agent(), NULL);
+#else    
     g_mime_object_set_header ((GMimeObject *) msg, "User-Agent", get_user_agent());
+#endif    
 
   // Message-ID for single text-only posts
   if (mode==DRAFTING || ((mode==POSTING || mode==UPLOADING) && _prefs.get_flag (MESSAGE_ID_PREFS_KEY, 
false))) {
@@ -1677,10 +1739,18 @@ PostUI :: new_message_from_ui (Mode mode, bool copy_body)
     GMimePart * part = g_mime_part_new ();
     pch = g_strdup_printf ("text/plain; charset=%s", charset.c_str());
 
+#ifdef HAVE_GMIME_30
+    GMimeContentType * type = g_mime_content_type_parse (NULL, pch);
+#else    
     GMimeContentType * type = g_mime_content_type_new_from_string (pch);
+#endif    
     g_free (pch);
     g_mime_object_set_content_type ((GMimeObject *) part, type); // part owns type now. type isn't 
refcounted.
+#ifdef HAVE_GMIME_30
+    g_mime_part_set_content(part, content_object);
+#else    
     g_mime_part_set_content_object (part, content_object);
+#endif    
     if (mode != UPLOADING) g_mime_part_set_content_encoding (part, _enc);
     g_object_unref (content_object);
     g_mime_message_set_mime_part (msg, GMIME_OBJECT(part));
@@ -1763,7 +1833,11 @@ PostUI :: save_draft ()
     {
       errno = 0;
       std::ofstream o (filename);
+#ifdef HAVE_GMIME_30
+      char * pch = g_mime_object_to_string ((GMimeObject *) msg, NULL);
+#else      
       char * pch = g_mime_object_to_string ((GMimeObject *) msg);
+#endif      
       o << pch;
       o.close ();
 
@@ -2260,8 +2334,13 @@ PostUI :: set_message (GMimeMessage * message)
   s = utf8ize (g_mime_object_get_header ((GMimeObject *) message, "Reply-To"));
   gtk_entry_set_text (GTK_ENTRY(_replyto_entry), s.c_str());
 
+#ifdef HAVE_GMIME_30
+  InternetAddressList * addresses = g_mime_message_get_addresses (message, GMIME_ADDRESS_TYPE_TO);
+  char * pch  = internet_address_list_to_string (addresses, NULL, true);
+#else  
   InternetAddressList * addresses = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
   char * pch  = internet_address_list_to_string (addresses, true);
+#endif  
   s = utf8ize (pch);
   gtk_entry_set_text (GTK_ENTRY(_to_entry), s.c_str());
   g_free (pch);
@@ -2269,8 +2348,15 @@ PostUI :: set_message (GMimeMessage * message)
   // update 'other headers'
   SetMessageForeachHeaderData data;
   const char *name, *value;
+#ifdef HAVE_GMIME_30
+  GMimeHeaderList HList;
+#else  
   GMimeHeaderIter iter;
+#endif  
 
+#ifdef HAVE_GMIME_30
+     // GMime 3.0 not yet implemented
+#else
   if (message->mime_part && g_mime_header_list_get_stream (message->mime_part->headers)) {
     if (g_mime_header_list_get_iter (message->mime_part->headers, &iter)) {
       do {
@@ -2288,6 +2374,7 @@ PostUI :: set_message (GMimeMessage * message)
       set_message_foreach_header_func (name, value, &data);
     } while (g_mime_header_iter_next (&iter));
   }
+#endif
 
   s = utf8ize (data.visible_headers);
   if (!s.empty())
@@ -3055,7 +3142,11 @@ PostUI::draft_save_cb(gpointer ptr)
     char * filename = g_build_filename (draft_filename.c_str(), "autosave", NULL);
 
     std::ofstream o (filename);
+#ifdef HAVE_GMIME_30
+    char * headers (g_mime_object_get_headers ((GMimeObject *) msg, NULL));
+#else    
     char * headers (g_mime_object_get_headers ((GMimeObject *) msg));
+#endif    
     o << headers;
     const std::string body (data->get_body ());
     o << body;
diff --git a/pan/tasks/nzb.cc b/pan/tasks/nzb.cc
index 98589f6..1e7d03b 100644
--- a/pan/tasks/nzb.cc
+++ b/pan/tasks/nzb.cc
@@ -52,7 +52,11 @@ namespace
     {
       GMimeStream * stream = g_mime_stream_mem_new_with_buffer (txt.c_str(), txt.size());
       GMimeParser * parser = g_mime_parser_new_with_stream (stream);
+#ifdef HAVE_GMIME_30
+      msg   = g_mime_parser_construct_message (parser, NULL);
+#else      
       msg   = g_mime_parser_construct_message (parser);
+#endif      
       g_object_unref (G_OBJECT(parser));
       g_object_unref (G_OBJECT(stream));
     }
diff --git a/pan/tasks/task-post.cc b/pan/tasks/task-post.cc
index 985de7e..10c4bf1 100644
--- a/pan/tasks/task-post.cc
+++ b/pan/tasks/task-post.cc
@@ -57,7 +57,11 @@ TaskPost :: use_nntp (NNTP * nntp)
 {
   _state.set_working ();
 
+#ifdef HAVE_GMIME_30
+  char * text = g_mime_object_to_string (GMIME_OBJECT(_message), NULL);
+#else  
   char * text = g_mime_object_to_string (GMIME_OBJECT(_message));
+#endif  
   nntp->post (text, this);
   g_free (text);
 }
diff --git a/pan/tasks/task-upload.cc b/pan/tasks/task-upload.cc
index d0dd556..2ea8a82 100644
--- a/pan/tasks/task-upload.cc
+++ b/pan/tasks/task-upload.cc
@@ -194,19 +194,40 @@ TaskUpload :: prepend_headers(GMimeMessage* msg, TaskUpload::Needed * n, std::st
     //modify subject
     char buf[4096];
     if (_queue_pos != -1)
+#ifdef HAVE_GMIME_30    
+      g_mime_message_set_subject (msg, build_subject_line (buf, 4096, _subject, _basename, n->partno, 
_total_parts), NULL);
+#else      
       g_mime_message_set_subject (msg, build_subject_line (buf, 4096, _subject, _basename, n->partno, 
_total_parts));
+#endif      
 
     //modify references header
     std::string mids(_references);
     if (!_first_mid.empty()) mids += " <" + _first_mid + ">";
     if (_first_mid != n->last_mid && !_first && !n->last_mid.empty())  mids += " <" + n->last_mid + ">";
+#ifdef HAVE_GMIME_30
+    if (!mids.empty()) g_mime_object_set_header ((GMimeObject *) msg, "References", mids.c_str(), NULL);
+#else    
     if (!mids.empty()) g_mime_object_set_header ((GMimeObject *) msg, "References", mids.c_str());
+#endif
 
+#ifdef HAVE_GMIME_30
+    char * all(g_mime_object_get_headers ((GMimeObject *) msg, NULL));
+#else    
     char * all(g_mime_object_get_headers ((GMimeObject *) msg));
+#endif
+    
     if (_first && _queue_pos==-1)
+#ifdef HAVE_GMIME_30
+      all = g_mime_object_to_string ((GMimeObject *) msg, NULL);
+#else      
       all = g_mime_object_to_string ((GMimeObject *) msg);
+#endif      
     else if (_first && _queue_pos == 0)
+#ifdef HAVE_GMIME_30
+      all = g_mime_object_get_headers ((GMimeObject *) msg, NULL);
+#else      
       all = g_mime_object_get_headers ((GMimeObject *) msg);
+#endif      
 
     out << all << "\n";
     if (_first && _queue_pos == -1) g_free(all);
diff --git a/pan/tasks/task-xover.cc b/pan/tasks/task-xover.cc
index b694c4a..0295fc9 100644
--- a/pan/tasks/task-xover.cc
+++ b/pan/tasks/task-xover.cc
@@ -400,7 +400,12 @@ TaskXOver::on_nntp_line_process(NNTP * nntp, const StringView & line)
        const char * fallback_charset = NULL; // FIXME
 
        // are we done?
+#ifdef HAVE_GMIME_30
+       GDateTime * time_posted_gd = g_mime_utils_header_decode_date(date.str);
+       const time_t time_posted = g_date_time_to_unix(time_posted_gd);
+#else  
        const time_t time_posted = g_mime_utils_header_decode_date(date.str, NULL);
+#endif 
        if (_mode == DAYS && time_posted < _days_cutoff) {
                _server_to_minitasks[nntp->_server].clear();
                return;
diff --git a/pan/usenet-utils/message-check.cc b/pan/usenet-utils/message-check.cc
index e98ebee..d4b355f 100644
--- a/pan/usenet-utils/message-check.cc
+++ b/pan/usenet-utils/message-check.cc
@@ -480,7 +480,11 @@ MessageCheck :: message_check (const GMimeMessage * message_const,
   }
 
   // one last error check
+#ifdef  HAVE_GMIME_30
+  InternetAddressList * list (g_mime_message_get_addresses (message, GMIME_ADDRESS_TYPE_TO));
+#else  
   InternetAddressList * list (g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO));
+#endif  
   const int n_to (internet_address_list_length (list));
   if (!group_qty && !n_to) {
     errors.insert (_("Error: No Recipients."));
diff --git a/pan/usenet-utils/mime-utils.cc b/pan/usenet-utils/mime-utils.cc
index c4f9287..be2ccb8 100644
--- a/pan/usenet-utils/mime-utils.cc
+++ b/pan/usenet-utils/mime-utils.cc
@@ -915,7 +915,12 @@ namespace
       return;
 
     // get this part's content
+#ifdef HAVE_GMIME_30
+    GMimeDataWrapper * content = g_mime_part_get_content (GMIME_PART (part));
+#else    
     GMimeDataWrapper * content = g_mime_part_get_content_object (GMIME_PART (part));
+#endif
+
     if (!content)
       return;
 
@@ -968,7 +973,11 @@ namespace
 
           subpart_stream = tmp_part->stream;
           content = g_mime_data_wrapper_new_with_stream (subpart_stream, GMIME_CONTENT_ENCODING_DEFAULT);
+#ifdef HAVE_GMIME_30          
+          g_mime_part_set_content (subpart, content);
+#else          
           g_mime_part_set_content_object (subpart, content);
+#endif                    
           g_mime_multipart_add (GMIME_MULTIPART (multipart), GMIME_OBJECT (subpart));
 
           g_object_unref (content);
@@ -1138,11 +1147,19 @@ mime :: construct_message (GMimeStream    ** istreams,
 
   for (int i=0; i<qty; ++i) {
     GMimeParser* parser = g_mime_parser_new_with_stream (istreams[i]);
+#ifdef HAVE_GMIME_30
+    messages[i] = g_mime_parser_construct_message(parser, NULL);
+#else    
     messages[i] = g_mime_parser_construct_message(parser);
+#endif    
     g_object_unref(parser);
     g_mime_stream_reset(istreams[i]);
     parser = g_mime_parser_new_with_stream (istreams[i]);
+#ifdef HAVE_GMIME_30    
+    GMimeObject* part = g_mime_parser_construct_part(parser, NULL);
+#else        
     GMimeObject* part = g_mime_parser_construct_part(parser);
+#endif        
     g_object_unref (parser);
     parser = NULL;
     GMimeContentType * type = g_mime_object_get_content_type (part);
@@ -1485,7 +1502,11 @@ namespace
       return NULL;
     }
 
+#ifdef HAVE_GMIME_30
+    GMimeDataWrapper *wrapper = g_mime_part_get_content(mime_part);
+#else    
     GMimeDataWrapper *wrapper = g_mime_part_get_content_object(mime_part);
+#endif    
     GMimeStream *stream = g_mime_stream_mem_new();
     g_mime_data_wrapper_write_to_stream (wrapper, stream);
     GByteArray *bytes = g_mime_stream_mem_get_byte_array((GMimeStreamMem*)stream);
@@ -1535,6 +1556,20 @@ char *pan::pan_g_mime_message_get_body (GMimeMessage *message, gboolean *is_html
   return body;
 }
 
+#ifdef HAVE_GMIME_30
+void pan::pan_g_mime_message_add_recipients_from_string (GMimeMessage *message, GMimeAddressType type, const 
char *string)
+{
+  InternetAddressList *addrlist;
+  if ((addrlist = internet_address_list_parse (NULL, string))) {
+    for (int i = 0; i < internet_address_list_length (addrlist); ++i) {
+      InternetAddress *ia = internet_address_list_get_address (addrlist, i);
+      if (INTERNET_ADDRESS_IS_MAILBOX(ia))
+        g_mime_message_add_mailbox (message, type, internet_address_get_name(ia), 
internet_address_mailbox_get_addr(INTERNET_ADDRESS_MAILBOX(ia)));
+    }
+  }
+}
+#else
+
 void pan::pan_g_mime_message_add_recipients_from_string (GMimeMessage *message, GMimeRecipientType type, 
const char *string)
 {
   InternetAddressList *addrlist;
@@ -1546,10 +1581,24 @@ void pan::pan_g_mime_message_add_recipients_from_string (GMimeMessage *message,
     }
   }
 }
+#endif
 
 /**
 * Works around a GMime bug that uses `Message-Id' rather than `Message-ID'
 */
+#ifdef HAVE_GMIME_30
+std::string pan::pan_g_mime_message_set_message_id (GMimeMessage *msg, const char *mid)
+{
+       const char * charset = NULL; // "ISO-8859-1";  // fixme
+    g_mime_object_append_header ((GMimeObject *) msg, "Message-ID", mid, charset);
+    char * bracketed = g_strdup_printf ("<%s>", mid);
+    g_mime_header_list_set (GMIME_OBJECT(msg)->headers, "Message-ID", bracketed, charset);
+    std::string ret (bracketed);
+    g_free (bracketed);
+    return ret;
+}
+#else
+
 std::string pan::pan_g_mime_message_set_message_id (GMimeMessage *msg, const char *mid)
 {
     g_mime_object_append_header ((GMimeObject *) msg, "Message-ID", mid);
@@ -1559,6 +1608,7 @@ std::string pan::pan_g_mime_message_set_message_id (GMimeMessage *msg, const cha
     g_free (bracketed);
     return ret;
 }
+#endif
 
 namespace pan
 {
@@ -1573,7 +1623,11 @@ namespace pan
     content = g_mime_data_wrapper_new_with_stream (stream, GMIME_CONTENT_ENCODING_DEFAULT);
     g_object_unref (stream);
 
+#ifdef HAVE_GMIME_30
+    g_mime_part_set_content (part, content);
+#else    
     g_mime_part_set_content_object (part, content);
+#endif    
     g_object_unref (content);
   }
 #ifdef HAVE_GMIME_CRYPTO
diff --git a/pan/usenet-utils/mime-utils.h b/pan/usenet-utils/mime-utils.h
index fd3326e..34c1ecb 100644
--- a/pan/usenet-utils/mime-utils.h
+++ b/pan/usenet-utils/mime-utils.h
@@ -107,7 +107,11 @@ namespace pan
   };
 
   char *pan_g_mime_message_get_body (GMimeMessage *message, gboolean *is_html);
+#ifdef  HAVE_GMIME_30
+  void pan_g_mime_message_add_recipients_from_string (GMimeMessage *message, GMimeAddressType type, const 
char *string);
+#else
   void pan_g_mime_message_add_recipients_from_string (GMimeMessage *message, GMimeRecipientType type, const 
char *string);
+#endif  
   std::string pan_g_mime_message_set_message_id (GMimeMessage *msg, const char *mid);
 
   extern iconv_t conv;


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