[pan2/testing: 124/279] party moved code to gmimemessage* calls, todo: nzb resuming.



commit 9a8826ea8aa0006d48b3b54be7c6565c4836606e
Author: Heinrich MÃller <sphemuel stud informatik uni-erlangen de>
Date:   Tue Jun 28 16:09:28 2011 +0200

    party moved code to gmimemessage* calls, todo: nzb resuming.

 pan/gui/post-ui.cc       |  183 ++++++++++++++++++++++++++--------------------
 pan/gui/post-ui.h        |    5 +
 pan/tasks/encoder.cc     |   71 +++---------------
 pan/tasks/encoder.h      |   14 ----
 pan/tasks/nzb.cc         |   10 ++-
 pan/tasks/task-upload.cc |   77 ++++++++++++-------
 pan/tasks/task-upload.h  |   23 ++++--
 uulib/uuencode.c         |    3 +
 8 files changed, 196 insertions(+), 190 deletions(-)
---
diff --git a/pan/gui/post-ui.cc b/pan/gui/post-ui.cc
index 580e0a3..2a64861 100644
--- a/pan/gui/post-ui.cc
+++ b/pan/gui/post-ui.cc
@@ -26,6 +26,7 @@ extern "C" {
   #include <gmime/gmime.h>
   #include <glib/gi18n.h>
   #include <gtk/gtk.h>
+  #include <sys/time.h>
 #ifdef HAVE_GTKSPELL
   #include <gtkspell/gtkspell.h>
 #endif
@@ -63,6 +64,33 @@ using namespace pan;
 #define MESSAGE_ID_PREFS_KEY "add-message-id-header-when-posting"
 #define USER_AGENT_EXTRA_PREFS_KEY "user-agent-extra-info"
 
+/** generates a unique message-id for a usenet post, consisting of
+ *  the current date and time (in seconds resolution) and three random numbers + part count
+ */
+void
+PostUI :: generate_unique_id (StringView& mid, int cnt, std::string& s)
+{
+
+  std::stringstream out;
+  struct stat sb;
+  struct timeval tv;
+  const time_t now (time(NULL));
+  struct tm local_now = *gmtime (&now);
+  char buf[64];
+  std::strftime (buf, sizeof(buf), "%Y%m%d%H%M%S", &local_now);
+  out << "pan$";
+  gettimeofday (&tv, NULL);
+  out << buf << "$" << std::hex << tv.tv_usec << "$" << std::hex
+      << mtrand.randInt() << "$" << std::hex << mtrand.randInt() << "$"
+      << std::hex << mtrand.randInt() << "$" << std::hex << cnt;
+  // delimit
+  out<< '@';
+  // add domain
+  out << mid;
+  //std::cerr << "rng : "<<out.str()<<std::endl;
+  s = out.str();
+}
+
 namespace
 {
 #ifndef HAVE_CLOSE
@@ -2756,6 +2784,8 @@ PostUI :: PostUI (GtkWindow    * parent,
   _body_changed_idle_tag(0)
 {
 
+  mtrand.seed();
+
   _upload_queue.add_listener (this);
 
   /* init timer for autosave */
@@ -2846,10 +2876,10 @@ PostUI :: prompt_user_for_queueable_files (GtkWindow * parent, const Prefs& pref
   struct stat sb;
 
   const Profile profile (get_current_profile ());
-  GMimeMessage * message (new_message_from_ui (POSTING));
-  if (!check_message(profile.posting_server, message, true))
+  GMimeMessage * tmp (new_message_from_ui (POSTING));
+  if (!check_message(profile.posting_server, tmp, true))
   {
-    g_object_unref (G_OBJECT(message));
+    g_object_unref (G_OBJECT(tmp));
     return;
   }
 
@@ -2869,88 +2899,82 @@ PostUI :: prompt_user_for_queueable_files (GtkWindow * parent, const Prefs& pref
 
 	const int response (gtk_dialog_run (GTK_DIALOG(w)));
 	if (response == GTK_RESPONSE_ACCEPT) {
-		GSList * tmp_list = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER (w));
-
-
-		GSList * cur = g_slist_nth (tmp_list,0);
-    GMimeMessage* msg = message;
-    gtk_widget_destroy (w);
-
-    char * tmp;
-    tmp = (char*)g_mime_object_get_header ((GMimeObject*)msg, "Subject");
-    std::string subject= std::string(tmp ? tmp : "");
-
-    std::string author;
-    profile.get_from_header (author);
-
-    quarks_t groups;
-    char * text = (char*)gtk_entry_get_text (GTK_ENTRY(_groups_entry));
-    StringView line(text), groupname;
-    while (line.pop_token (groupname, ',')) {
-      groupname.trim ();
-      if (!groupname.empty())
-        groups.insert(groupname);
-    }
 
-    TaskUpload::UploadInfo ui;
-    ui.comment1 = _prefs.get_flag("upload-queue-append-subject-enabled",false);
-
-    // query lines per file value
-    ui.lpf = _prefs.get_int("upload-option-lpf",4000);
-
-    // generate domain name for upload if the flag is set
-    bool custom_mid(_prefs.get_flag(MESSAGE_ID_PREFS_KEY,false));
-    if (custom_mid)
-      ui.domain = !profile.fqdn.empty()
-      ? GNKSA::generate_message_id (profile.fqdn)
-      : GNKSA::generate_message_id_from_email_address (profile.address);
-
-    // fill in message text
-    // NOTE: message text is saved on taskupload constructor, and doesn't change thereafter
-    // that means that if the user makes changes on the body buffer, they don't reflect in
-    // the upload!!
-    ui.buf = get_body ();
-
-    for (; cur; cur = cur->next)
-	{
-	  Article a;
-	  a.subject = subject;
-	  a.author = author;
-      stat ((const char*)cur->data,&sb);
-      int lpf = _prefs.get_int("upload-option-lpf",4000);
-      int total = std::max(1, (int) (((long)sb.st_size + (lpf*YENC_HALF_LINE_LEN-1)) /
-                          (lpf*YENC_HALF_LINE_LEN)));
-
-      char* basename = g_path_get_basename((const char*)cur->data);
-      TaskUpload::needed_t import;
-      TaskUpload::Needed n;
-      foreach_const (quarks_t, groups, git)
-         a.xref.insert (profile.posting_server, *git,0);
-
-      for (int i = 1; i <= total; ++i)
-      {
-        g_snprintf(buf,sizeof(buf),"%s.%d", basename, i);
-        n.message_id = buf;
-        n.partno = i;
-        import.insert(std::pair<int,TaskUpload::Needed>(i,n));
-      }
-      g_free(basename);
-
-      foreach_const (quarks_t, groups, git)
-        a.xref.insert (profile.posting_server, *git,0);
-
-		  TaskUpload* tmp = new TaskUpload(std::string((const char*)cur->data),
-                        profile.posting_server, _cache,
-                        a, ui, import, 0, TaskUpload::YENC);
-      _upload_queue.add_task(tmp);
-	}
+        GSList * tmp_list = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER (w));
+        gtk_widget_destroy (w);
+
+        TaskUpload::UploadInfo ui;
+        ui.comment1 = _prefs.get_flag("upload-queue-append-subject-enabled",false);
+        // query lines per file value
+        ui.lpf = _prefs.get_int("upload-option-lpf",4000);
+
+        // generate domain name for upload if the flag is set
+        bool custom_mid(_prefs.get_flag(MESSAGE_ID_PREFS_KEY,false));
+        std::string d;
+        if (custom_mid)
+          d = !profile.fqdn.empty()
+          ? GNKSA::generate_message_id (profile.fqdn)
+          : GNKSA::generate_message_id_from_email_address (profile.address);
+        StringView domain(d);
+
+        GSList * cur = g_slist_nth (tmp_list,0);
+        for (; cur; cur = cur->next)
+        {
+          GMimeMessage * msg (new_message_from_ui (POSTING));
+
+          //for nzb handling
+          Article a;
+          a.subject = utf8ize (g_mime_message_get_subject (msg));
+          std::string s;
+          profile.get_from_header(s);
+          a.author = s;
+
+          stat ((const char*)cur->data,&sb);
+          int lpf = _prefs.get_int("upload-option-lpf",4000);
+          int total = std::max(1, (int) (((long)sb.st_size + (lpf*YENC_HALF_LINE_LEN-1)) /
+                              (lpf*YENC_HALF_LINE_LEN)));
+
+
+          char* basename = g_path_get_basename((const char*)cur->data);
+
+          // build needed parts
+          TaskUpload::needed_t import;
+          TaskUpload::Needed n;
+///TODO for nzb.cc
+//          foreach_const (quarks_t, groups, git)
+//             a.xref.insert (profile.posting_server, *git,0);
+
+          for (int i = 1; i <= total; ++i)
+          {
+            if (custom_mid)
+            {
+                std::string out;
+                generate_unique_id(domain, i,out);
+                n.mid = out;
+            }
+
+            g_snprintf(buf,sizeof(buf),"%s.%d", basename, i);
+            n.message_id = buf;
+            n.partno = i;
+            import.insert(std::pair<int,TaskUpload::Needed>(i,n));
+          }
+          g_free(basename);
+
+              TaskUpload* tmp = new TaskUpload(std::string((const char*)cur->data),
+                            profile.posting_server, _cache,
+                            ///TODO implement custom encode mode options
+                            a, ui, import, msg,0, TaskUpload::YENC);
+          _upload_queue.add_task(tmp);
+        }
 
     if (_file_queue_empty) _file_queue_empty= false;
-
     g_slist_free (tmp_list);
+
   } else
+
     gtk_widget_destroy (w);
-  g_object_unref (G_OBJECT(message));
+
+  g_object_unref (G_OBJECT(tmp));
 
 }
 
@@ -2996,5 +3020,4 @@ PostUI :: prompt_user_for_upload_nzb_dir (GtkWindow * parent, const Prefs& prefs
 
   gtk_widget_destroy (w);
   return path;
-
 }
diff --git a/pan/gui/post-ui.h b/pan/gui/post-ui.h
index dd5d355..0b53c74 100644
--- a/pan/gui/post-ui.h
+++ b/pan/gui/post-ui.h
@@ -29,6 +29,8 @@
 #include <pan/data/encode-cache.h>
 #include "group-prefs.h"
 
+#include <pan/usenet-utils/MersenneTwister.h>
+
 namespace pan
 {
   class Profiles;
@@ -234,6 +236,9 @@ namespace pan
       bool update_queue_mids (bool enable=true);
       bool update_queue_save_file ();
 
+      void generate_unique_id (StringView& mid, int cnt, std::string& s);
+      MTRand mtrand;
+
     private:
       guint _draft_autosave_id;
       guint _draft_autosave_timeout;
diff --git a/pan/tasks/encoder.cc b/pan/tasks/encoder.cc
index 21b6733..c9438af 100644
--- a/pan/tasks/encoder.cc
+++ b/pan/tasks/encoder.cc
@@ -44,33 +44,6 @@ extern "C" {
 using namespace pan;
 
 
-/** generates a unique message-id for a usenet post, consisting of
- *  the current date and time (in seconds resolution) and three random numbers + part count
- */
-void
-Encoder :: generate_unique_id (StringView& mid, int cnt, std::string& s)
-{
-
-  std::stringstream out;
-  struct stat sb;
-  struct timeval tv;
-  const time_t now (time(NULL));
-  struct tm local_now = *gmtime (&now);
-  char buf[64];
-  std::strftime (buf, sizeof(buf), "%Y%m%d%H%M%S", &local_now);
-  out << "pan$";
-  gettimeofday (&tv, NULL);
-  out << buf << "$" << std::hex << tv.tv_usec << "$" << std::hex
-      << mtrand.randInt() << "$" << std::hex << mtrand.randInt() << "$"
-      << std::hex << mtrand.randInt() << "$" << std::hex << cnt;
-  // delimit
-  out<< '@';
-  // add domain
-  out << mid;
-  //std::cerr << "rng : "<<out.str()<<std::endl;
-  s = out.str();
-}
-
 Encoder :: Encoder (WorkerPool& pool):
   _worker_pool (pool),
   _gsourceid (-1)
@@ -92,14 +65,7 @@ Encoder :: enqueue (TaskUpload                      * task,
                     Article                         * article,
                     std::string                     & filename,
                     std::string                     & basename,
-                    std::string                     & groups,
-                    std::string                     & subject,
-                    std::string                     & author,
-                    std::string                     & agent,
-                    std::string                     & format,
-                    std::string                       global_mid,
                     int                               lpf,
-                    std::string                       buf,
                     const TaskUpload::EncodeMode    & enc)
 
 {
@@ -109,26 +75,16 @@ Encoder :: enqueue (TaskUpload                      * task,
   this->basename = basename;
   this->filename = filename;
   this->encode_mode = encode_mode;
-  this->groups = groups;
-  this->subject = subject;
-  this->author = author;
-  this->agent = agent;
   this->needed = &task->_needed;
-  this->global_mid = global_mid;
   this->cache = cache;
   this->article = article;
-  this->format = format;
   this->lpf = lpf;
-  this->buffer = buf;
 
   percent = 0;
   current_file.clear ();
   log_infos.clear();
   log_errors.clear();
 
-  // I don't know if this is bad, but practically, a new seed for every encoder (e.g. task) shouldn't be too much.
-  mtrand.seed();
-
   // gentlemen, start your encod'n...
   _worker_pool.push_work (this, task, false);
 }
@@ -145,7 +101,7 @@ Encoder :: do_work()
   std::string s;
   FILE* outfile, * infile ;
 
-  enable_progress_update();
+    enable_progress_update();
 
     int res;
     if (((res = UUInitialize())) != UURET_OK)
@@ -156,15 +112,18 @@ Encoder :: do_work()
       UUSetBusyCallback (this, uu_busy_poll, 200);
 
       PartBatch batch;
-      batch.init(StringView(basename), needed->size(), 0);
+      char cachename[4096];
       int cnt(1);
       Article* tmp = article;
 
-      /* build real subject line */
-      g_snprintf(buf, sizeof(buf), "\"%s\" - %s (/%03d)", basename.c_str(), subject.c_str(), (int)needed->size());
+      batch.init(StringView(basename), needed->size(), 0);
+
+      /* build real subject line for article*/
+      ///TODO should this be here??
+      g_snprintf(buf, sizeof(buf), "\"%s\" - %s (/%03d)", basename.c_str(), article->subject.to_string().c_str(), (int)needed->size());
       tmp->subject = buf;
 
-      char cachename[4096];
+
       for (TaskUpload::needed_t::iterator it = needed->begin(); it != needed->end(); ++it, ++cnt)
       {
         FILE * fp = cache->get_fp_from_mid(it->second.message_id);
@@ -174,15 +133,9 @@ Encoder :: do_work()
           log_errors.push_back(buf); // log error
           continue;
         }
-        StringView mid(global_mid);
-        if (!global_mid.empty())
-          generate_unique_id(mid, cnt, s);
-        std::cerr<<"buffer encode "<<(char*)buffer.c_str()<<std::endl;
-        res = UUE_PrepPartial (fp, NULL, (char*)filename.c_str(),YENC_ENCODED,
-                               (char*)basename.c_str(),0644, cnt, lpf,
-                               0, (char*)groups.c_str(), (char*)author.c_str(),
-                               (char*)subject.c_str(), s.empty() ? NULL : (char*)s.c_str(), (char*)format.c_str(),
-                               agent.empty() ? NULL : (char*)agent.c_str(), (char*)buffer.c_str(), 0);
+
+        crc32_t crc;
+        res = UUEncodePartial (fp, NULL, (char*)filename.c_str(),YENC_ENCODED, (char*)basename.c_str(), NULL, 0644, cnt, lpf,&crc);
 
         if (fp) fclose(fp);
         if (res != UURET_CONT && res != UURET_OK) break;
@@ -191,6 +144,7 @@ Encoder :: do_work()
         stat (cachename, &sb);
         it->second.bytes  = sb.st_size;
         task->_all_bytes += sb.st_size;
+        //dbg
         batch.add_part(cnt, StringView(s), 0);//sb.st_size);
         if (res != UURET_CONT) break;
       }
@@ -213,6 +167,7 @@ Encoder :: do_work()
     UUCleanUp ();
     }
   disable_progress_update();
+
 }
 
 /***
diff --git a/pan/tasks/encoder.h b/pan/tasks/encoder.h
index 11d19c4..dd5ef4c 100644
--- a/pan/tasks/encoder.h
+++ b/pan/tasks/encoder.h
@@ -31,7 +31,6 @@
 #include <pan/general/locking.h>
 #include <pan/general/worker-pool.h>
 #include <pan/tasks/task-upload.h>
-#include <pan/usenet-utils/MersenneTwister.h>
 
 extern "C" {
 #  define PROTOTYPES
@@ -66,14 +65,7 @@ namespace pan
                     Article                         * article,
                     std::string                     & filename,
                     std::string                     & basename,
-                    std::string                     & groups,
-                    std::string                     & subject,
-                    std::string                     & author,
-                    std::string                     & agent,
-                    std::string                     & format,
-                    std::string                       global_mid,
                     int                               lpf,
-                    std::string                       buf,
                     const TaskUpload::EncodeMode    & enc = TaskUpload::YENC);
 
     public:
@@ -92,16 +84,10 @@ namespace pan
       TaskUpload * task;
       TaskUpload::EncodeMode encode_mode;
       std::string   basename, filename;
-      std::string subject, author, groups, mid, format, agent;
       int lpf;
       EncodeCache * cache;
       TaskUpload::needed_t * needed;
-      std::string global_mid;
       Article * article;
-      MTRand mtrand;
-      std::string buffer;
-
-      void generate_unique_id (StringView& mid, int cnt, std::string& s);
 
       // These are set in the worker thread and polled in the main thread.
       Mutex mut;
diff --git a/pan/tasks/nzb.cc b/pan/tasks/nzb.cc
index f427272..501025a 100644
--- a/pan/tasks/nzb.cc
+++ b/pan/tasks/nzb.cc
@@ -192,12 +192,14 @@ namespace
         mc.a.xref.insert (mc.server, *git, 0);
       ///TODO export/import missing values to/from nzb
       TaskUpload::UploadInfo format;
-      format.domain = mc.domain;
+//      format.domain = mc.domain;
       format.comment1 = true;
       format.lpf = mc.lpf;
-      TaskUpload* tmp = new TaskUpload (mc.path, mc.server, mc.encode_cache,mc.a,
-                                        format, mc.needed_parts, 0, TaskUpload::YENC);
-      mc.tasks.push_back (tmp);
+
+///TODO implement gmimemessage here
+//      TaskUpload* tmp = new TaskUpload (mc.path, mc.server, mc.encode_cache,mc.a,
+//                                        format, mc.needed_parts, 0, TaskUpload::YENC);
+//      mc.tasks.push_back (tmp);
     }
   }
 
diff --git a/pan/tasks/task-upload.cc b/pan/tasks/task-upload.cc
index ced4c0f..9e35d16 100644
--- a/pan/tasks/task-upload.cc
+++ b/pan/tasks/task-upload.cc
@@ -62,24 +62,6 @@ namespace
     g_free(freeme);
     return buf;
   }
-
-  const char * get_user_agent () //from post-ui.cc
-  {
-      return "Pan/" PACKAGE_VERSION " (" VERSION_TITLE "; " GIT_REV ")";
-  }
-}
-
-std::string
-TaskUpload :: get_domain(const StringView& mid)
-{
-  const char * pch = mid.strchr ('@');
-  StringView domain;
-  if (pch) domain = mid.substr (pch+1, NULL);
-  if (pch) pch = domain.strchr ('>');
-  if (pch) domain = domain.substr (NULL, pch);
-  domain.trim ();
-
-  return domain.to_string();
 }
 
 /***
@@ -92,6 +74,7 @@ TaskUpload :: TaskUpload (const std::string         & filename,
                           Article                     article,
                           UploadInfo                  format,
                           needed_t                  & imported,
+                          GMimeMessage *              msg,
                           Progress::Listener        * listener,
                           const TaskUpload::EncodeMode  enc):
   Task ("UPLOAD", get_description(filename.c_str())),
@@ -108,14 +91,14 @@ TaskUpload :: TaskUpload (const std::string         & filename,
   _all_bytes(0),
   _format(format),
   _save_file(format.save_file),
-  _agent(get_user_agent()),
+  _lpf(format.lpf),
   _queue_pos(0),
-  _lpf(format.lpf)
+  _msg (msg)
 {
 
-    std::cerr<<"body : "<<format.buf<<std::endl;
-
-  if (!format.domain.empty())  _domain = get_domain(StringView(format.domain)) ;
+//    char * pch = g_mime_object_to_string ((GMimeObject *) _msg);
+//    std::cerr<<"gmimemessage:\n"<<pch<<std::endl;
+//    g_free(pch);
 
   if (!imported.empty())
     foreach (needed_t, imported, nit)
@@ -133,8 +116,6 @@ void
 TaskUpload :: build_needed_tasks(bool imported)
 {
 
-  _total_parts = std::max(1, (int) (((long)get_byte_count() + (_lpf*YENC_HALF_LINE_LEN-1)) /
-                        (_lpf*YENC_HALF_LINE_LEN)));
   quarks_t groups;
   foreach_const (Xref, _article.xref, it)
     _groups.insert (it->group);
@@ -146,6 +127,8 @@ TaskUpload :: build_needed_tasks(bool imported)
   }
   _cache.reserve(_mids);
   _needed_parts = _needed.size();
+  //dbg
+  _total_parts = _needed_parts;
 }
 
 void
@@ -160,20 +143,26 @@ TaskUpload :: update_work (NNTP* checkin_pending)
       ++working;
   }
 
+  /* only need encode if mode is NOT plain */
   if (!_encoder && !_encoder_has_run)
   {
+    std::cerr<<"need encoder\n";
     _state.set_need_encoder();
   }
   else if(working)
   {
+      std::cerr<<"working\n";
     _state.set_working();
   }
   else if (_encoder_has_run && !_needed.empty())
   {
+      std::cerr<<"need nntp\n";
     _state.set_need_nntp(_server);
   }
   else if (_needed.empty())
   {
+
+      std::cerr<<"completed\n";
     _state.set_completed();
     set_finished(_queue_pos);
   }
@@ -183,6 +172,34 @@ TaskUpload :: update_work (NNTP* checkin_pending)
 ****
 ***/
 
+namespace
+{
+    void pan_g_mime_message_set_message_id (GMimeMessage *msg, const char *mid)
+    {
+        g_mime_object_append_header ((GMimeObject *) msg, "Message-ID", mid);
+        char * bracketed = g_strdup_printf ("<%s>", mid);
+        g_mime_header_list_set (GMIME_OBJECT(msg)->headers, "Message-ID", bracketed);
+        g_free (bracketed);
+    }
+
+    void prepend_headers(GMimeMessage* msg, TaskUpload::Needed * n, std::string& d)
+    {
+        std::stringstream out;
+
+        //add headers to gmimemessage
+        if (!n->mid.empty()) pan_g_mime_message_set_message_id (msg, n->mid.c_str());
+
+        //extract body from gmimemessage
+        gboolean unused;
+        char * body (g_mime_object_to_string ((GMimeObject *) msg));
+        out<< body<<"\r\n";
+        std::cerr<<"message:\n"<<out.str()<<std::endl;
+        out<<d;
+        d = out.str();
+        std::cerr<<"message:\n"<<out.str()<<std::endl;
+    }
+}
+
 void
 TaskUpload :: use_nntp (NNTP * nntp)
 {
@@ -210,6 +227,7 @@ TaskUpload :: use_nntp (NNTP * nntp)
 
     std::string data;
     _cache.get_data(data,needed->message_id.c_str());
+    prepend_headers(_msg,needed, data);
     nntp->post(StringView(data), this);
     update_work ();
   }
@@ -235,6 +253,8 @@ TaskUpload :: on_nntp_done (NNTP * nntp,
   tmp.date = time(NULL);
   tmp.is_child = true;
 
+  std::cerr<<"nntp done : "<<response<<std::endl;
+
   needed_t::iterator it;
   for (it=_needed.begin(); it!=_needed.end(); ++it)
     if (it->second.nntp == nntp)
@@ -358,15 +378,14 @@ TaskUpload :: use_encoder (Encoder* encoder)
     groups += (*it).to_string();
   }
 
-  /* build format string */
+  /* build format string for yEnc */
   std::stringstream format_s;
   format_s << (_format.comment1 ? _subject : "");
   format_s << (_format.comment1 ? " - " : "");
   format_s << "\"%s\""; // will be filled in by uuencode
   format_s << " (%d/%d) yEnc";     // will be filled in by uuencode
   std::string format(format_s.str());
-  _encoder->enqueue (this, &_cache, &_article, _filename, _basename,
-                     groups, _subject, _author, _agent, format, _domain, _lpf, _format.buf, YENC);
+  _encoder->enqueue (this, &_cache, &_article, _filename, _basename, _lpf, YENC);//_encode_mode);
   debug ("encoder thread was free, enqueued work");
 }
 
@@ -422,6 +441,8 @@ TaskUpload :: ~TaskUpload ()
   if (_encoder)
       _encoder->cancel_silently();
 
+  g_object_unref (G_OBJECT(_msg));
+
   _cache.release(_mids);
   _cache.resize();
 }
diff --git a/pan/tasks/task-upload.h b/pan/tasks/task-upload.h
index 47fc477..e7fa4b7 100644
--- a/pan/tasks/task-upload.h
+++ b/pan/tasks/task-upload.h
@@ -33,6 +33,12 @@
 #include <pan/data/xref.h>
 #include <pan/tasks/nntp.h>
 #include <pan/tasks/task.h>
+
+extern "C" {
+#define PROTOTYPES
+#include <uulib/uudeview.h>
+};
+
 #include <set>
 
 namespace pan
@@ -52,9 +58,8 @@ namespace pan
       struct UploadInfo
       {
         bool comment1;
-        std::string  domain;
         std::string  save_file;
-        std::string  buf;
+        std::string  mid;
         int lpf;
       };
 
@@ -67,6 +72,7 @@ namespace pan
         int partno;
         NNTP* nntp;
         std::string message_id;
+        std::string mid; // for rng
         Xref xref;
         bool encoded;
         Needed (): nntp(0), bytes(0) , partno(1), encoded(false) {}
@@ -77,9 +83,13 @@ namespace pan
 
       enum EncodeMode
       {
-        YENC = 0,
-        BASE64,
-        PLAIN
+        UUENC = UU_ENCODED,
+        YENC = YENC_ENCODED,
+        BASE64 = B64ENCODED,
+        PLAIN = PT_ENCODED,
+        XXENC = XX_ENCODED,
+        QPENC = QP_ENCODED,
+        BHENC = BH_ENCODED
       };
 
       // life cycle
@@ -89,6 +99,7 @@ namespace pan
                    Article                     article,
                    UploadInfo                  format,
                    needed_t                  & imported,
+                   GMimeMessage *              msg,
                    Progress::Listener        * listener= 0,
                    TaskUpload::EncodeMode enc= YENC);
 
@@ -155,7 +166,7 @@ namespace pan
       void update_work (NNTP * checkin_pending = 0);
       void build_needed_tasks(bool);
 
-      std::string get_domain(const StringView&);
+      GMimeMessage * _msg;
 
   };
 }
diff --git a/uulib/uuencode.c b/uulib/uuencode.c
index ec0f9d3..f2df1c9 100644
--- a/uulib/uuencode.c
+++ b/uulib/uuencode.c
@@ -1686,6 +1686,9 @@ UUE_PrepPartialExt (FILE *outfile, FILE *infile,
     }
     else {
       if (fstat (fileno (infile), &finfo) != 0) {
+
+	printf("debug: %lu %lu\n",((long)finfo.st_size+(linperfile*bpl[encoding]-1)), linperfile*bpl[encoding]);
+
 	if (filesize <= 0) {
 	  UUMessage (uuencode_id, __LINE__, UUMSG_WARNING,
 		     uustring (S_STAT_ONE_PART));



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