[pan2: 124/268] Fixed uuencode/own bug with plain encoding (i.e. no encoding/raw attachment)



commit 9210b2ae74d36bd0f31e29ea47cc02506dd622bd
Author: Heinrich MÃller <sphemuel stud informatik uni-erlangen de>
Date:   Sat Jul 9 14:01:55 2011 +0200

    Fixed uuencode/own bug with plain encoding (i.e.
    no encoding/raw attachment)

 pan/data/encode-cache.cc |    2 -
 pan/tasks/encoder.cc     |   28 +++--
 pan/tasks/task-upload.cc |    7 +-
 uulib/uuencode.c         |  321 ++++++++++++++++++++++++----------------------
 4 files changed, 188 insertions(+), 170 deletions(-)
---
diff --git a/pan/data/encode-cache.cc b/pan/data/encode-cache.cc
index 0d39ddf..ff07772 100644
--- a/pan/data/encode-cache.cc
+++ b/pan/data/encode-cache.cc
@@ -130,7 +130,6 @@ EncodeCache :: add (const Quark& message_id)
   info._message_id = message_id;
   info._size = 0;
   info._date = time(0);
-//  info._fp = get_fp_from_mid(message_id);
   _mid_to_info.insert (mid_to_info_t::value_type (info._message_id, info));
 }
 
@@ -231,7 +230,6 @@ EncodeCache :: resize (guint64 max_bytes)
         unlink (buf);
         _current_bytes -= it->_size;
         removed.insert (mid);
-//        if (it->_fp) fclose(it->_fp);
         _mid_to_info.erase (mid);
       }
     }
diff --git a/pan/tasks/encoder.cc b/pan/tasks/encoder.cc
index 21d8266..c39c340 100644
--- a/pan/tasks/encoder.cc
+++ b/pan/tasks/encoder.cc
@@ -125,22 +125,29 @@ Encoder :: do_work()
 
       int enc(YENC_ENCODED);
       std::ofstream out;
-      std::stringstream txt;
+      std::ifstream in;
       switch (encode_mode)
       {
           case TaskUpload::YENC:
               enc = YENC_ENCODED;
               break;
           case TaskUpload::PLAIN:
-              std::ifstream in(filename.c_str(), std::ios::in);
-              char buf[4096];
-              cache->get_filename(cachename, it->second.message_id);
-              out.open(cachename, std::ios::out);
-              while (in.getline(buf,sizeof(buf))) out << buf;
-              out.close();
-              in.close();
-              res = UURET_OK;
-              goto _no_encode;
+//              in.open(filename.c_str(), std::ios::in);
+//              char buf[4096];
+//              cache->get_filename(cachename, it->second.message_id);
+//              out.open(cachename, std::ios::out);
+//
+//              out<<"MIME-Version: 1.0\n";
+////              out << "Content-Type: text/plain\n";
+//              out << "Content-Transfer-Encoding: 8bit\n";
+//              out << "Content-Disposition: attachment; filename=\""<<basename<<"\"\n";
+//
+//              while (in.good()) out << (char)in.get();
+//              out.close();
+//              in.close();
+//              res = UURET_OK;
+//              goto _no_encode;
+              enc = PT_ENCODED;
               break;
           case TaskUpload::BASE64:
               enc = B64ENCODED;
@@ -171,7 +178,6 @@ _no_encode:
       task->_all_bytes += sb.st_size;
       tmp->add_part(cnt, StringView(it->second.mid), sb.st_size);
       if (res != UURET_CONT) break;
-
     }
 
     if (res != UURET_OK && res != UURET_CONT)
diff --git a/pan/tasks/task-upload.cc b/pan/tasks/task-upload.cc
index 5dd7c7c..099f5b5 100644
--- a/pan/tasks/task-upload.cc
+++ b/pan/tasks/task-upload.cc
@@ -149,6 +149,8 @@ TaskUpload :: update_work (NNTP* checkin_pending)
   }
   else if ((_encoder_has_run && !_needed.empty()))
   {
+//    _state.set_completed();
+//    set_finished(_queue_pos);
     _state.set_need_nntp(_server);
   }
   else if (_needed.empty())
@@ -378,7 +380,6 @@ TaskUpload :: on_worker_done (bool cancelled)
   {
     // the encoder is done... catch up on all housekeeping
     // now that we're back in the main thread.
-
     foreach_const(Encoder::log_t, _encoder->log_severe, it)
       Log :: add_err(it->c_str());
     foreach_const(Encoder::log_t, _encoder->log_errors, it)
@@ -415,6 +416,6 @@ TaskUpload :: ~TaskUpload ()
       _encoder->cancel_silently();
 
   g_object_unref (G_OBJECT(_msg));
-  _cache.release(_mids);
-  _cache.resize();
+//  _cache.release(_mids);
+//  _cache.resize();
 }
diff --git a/uulib/uuencode.c b/uulib/uuencode.c
index 3235b9e..0f74ae1 100644
--- a/uulib/uuencode.c
+++ b/uulib/uuencode.c
@@ -683,8 +683,6 @@ UUEncodeStream_byFSize (FILE *outfile, FILE *infile, int encoding, long bpf, crc
   long offset=0;
   long line = 0;
   size_t llen;
-  ///TODO
-  int linperfile = 0;
 
   if (outfile==NULL || infile==NULL ||
       (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
@@ -698,164 +696,182 @@ UUEncodeStream_byFSize (FILE *outfile, FILE *infile, int encoding, long bpf, crc
    * read line oriented.
    */
 
+  long rest = bpf;
+  long current = 0;
+
   if (encoding == PT_ENCODED || encoding == QP_ENCODED)
     {
-      while (!feof (infile) && (linperfile <= 0 || line < linperfile))
-        {
-          if (_FP_fgets (itemp, 255, infile) == NULL)
-            {
-              break;
-            }
-
-          itemp[255] = '\0';
-          count = strlen (itemp);
-
-          llen = 0;
-          optr = otemp;
-
-          /*
-           * Busy Callback
-           */
-
-          if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize))
-            {
-              UUMessage (uuencode_id, __LINE__, UUMSG_NOTE,
-                         uustring (S_ENCODE_CANCEL));
-              return UURET_CANCEL;
-            }
-
-          if (encoding == PT_ENCODED)
-            {
-              /*
-               * If there is a line feed, replace by eolstring
-               */
-              if (count > 0 && itemp[count-1] == '\n')
-                {
-                  itemp[--count] = '\0';
-                  if (fwrite (itemp, 1, count, outfile) != count ||
-                      fwrite ((char *) eolstring, 1,
-                              strlen(eolstring), outfile) != strlen (eolstring))
-                    {
-                      return UURET_IOERR;
-                    }
-                }
-              else
-                {
-                  if (fwrite (itemp, 1, count, outfile) != llen)
-                    {
-                      return UURET_IOERR;
-                    }
-                }
-            }
-          else if (encoding == QP_ENCODED)
-            {
-              for (index=0; index<count; index++)
-                {
-                  if (llen == 0 && itemp[index] == '.')
-                    {
-                      /*
-                       * Special rule: encode '.' at the beginning of a line, so
-                       * that some mailers aren't confused.
-                       */
-                      *optr++ = '=';
-                      *optr++ = HexEncodeTable[itemp[index] >> 4];
-                      *optr++ = HexEncodeTable[itemp[index] & 0x0f];
-                      llen += 3;
-                    }
-                  else if ((itemp[index] >= 33 && itemp[index] <= 60) ||
-                           (itemp[index] >= 62 && itemp[index] <= 126) ||
-                           itemp[index] == 9 || itemp[index] == 32)
-                    {
-                      *optr++ = itemp[index];
-                      llen++;
-                    }
-                  else if (itemp[index] == '\n')
-                    {
-                      /*
-                       * If the last character before EOL was a space or tab,
-                       * we must encode it. If llen > 74, there's no space to do
-                       * that, so generate a soft line break instead.
-                       */
-
-                      if (index>0 && (itemp[index-1] == 9 || itemp[index-1] == 32))
-                        {
-                          *(optr-1) = '=';
-                          if (llen <= 74)
-                            {
-                              *optr++ = HexEncodeTable[itemp[index-1] >> 4];
-                              *optr++ = HexEncodeTable[itemp[index-1] & 0x0f];
-                              llen += 2;
-                            }
-                        }
+      while (rest > 0 )
+      {
+        current = rest > 255 ? 255 : rest;
 
-                      if (fwrite (otemp, 1, llen, outfile) != llen ||
-                          fwrite ((char *) eolstring, 1,
-                                  strlen(eolstring), outfile) != strlen (eolstring))
-                        {
-                          return UURET_IOERR;
-                        }
+//        if (_FP_fgets (itemp, 255, infile) == NULL)
+//          break;
 
-                      /*
-                       * Fix the soft line break condition from above
-                       */
+      if ((count = fread (itemp, sizeof(unsigned char), current, infile)) != 255)
+      {
+        if (count == 0)
+          break;
+        else if (ferror (infile))
+          return UURET_IOERR;
+      }
 
-                      if (index>0 && (itemp[index-1] == 9 || itemp[index-1] == 32) &&
-                          *(optr-1) == '=')
-                        {
-                          otemp[0] = '=';
-                          otemp[1] = HexEncodeTable[itemp[index-1] >> 4];
-                          otemp[2] = HexEncodeTable[itemp[index-1] & 0x0f];
+      rest -= count;
 
-                          if (fwrite (otemp, 1, 3, outfile) != 3 ||
-                              fwrite ((char *) eolstring, 1,
-                                      strlen(eolstring), outfile) != strlen (eolstring))
-                            {
-                              return UURET_IOERR;
-                            }
-                        }
 
-                      optr = otemp;
-                      llen = 0;
-                    }
-                  else
-                    {
-                      *optr++ = '=';
-                      *optr++ = HexEncodeTable[itemp[index] >> 4];
-                      *optr++ = HexEncodeTable[itemp[index] & 0x0f];
-                      llen += 3;
-                    }
+        itemp[count] = '\0';
+//        count = strlen (itemp);
 
-                  /*
-                   * Lines must be shorter than 76 characters (not counting CRLF).
-                   * If the line grows longer than that, we must include a soft
-                   * line break.
-                   */
+        llen = 0;
+        optr = otemp;
 
-                  if (itemp[index+1] != 0 && itemp[index+1] != '\n' &&
-                      (llen >= 75 ||
-                       (!((itemp[index+1] >= 33 && itemp[index+1] <= 60) ||
-                          (itemp[index+1] >= 62 && itemp[index+1] <= 126)) &&
-                        llen >= 73)))
-                    {
-
-                      *optr++ = '=';
-                      llen++;
+        /*
+         * Busy Callback
+         */
 
-                      if (fwrite (otemp, 1, llen, outfile) != llen ||
-                          fwrite ((char *) eolstring, 1,
-                                  strlen(eolstring), outfile) != strlen (eolstring))
-                        {
-                          return UURET_IOERR;
-                        }
+        if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize))
+          {
+//            UUMessage (uuencode_id, __LINE__, UUMSG_NOTE,
+//                       uustring (S_ENCODE_CANCEL));
+            printf("cancel\n");
+            return UURET_CANCEL;
+          }
 
-                      optr = otemp;
-                      llen = 0;
-                    }
-                }
-            }
+        if (encoding == PT_ENCODED)
+          {
 
-          line++;
-        }
+            /*
+             * If there is a line feed, replace by eolstring
+             */
+            if (count > 0 && itemp[count-1] == '\n')
+              {
+                itemp[--count] = '\0';
+                if (fwrite (itemp, sizeof(unsigned char), count, outfile) != count ||
+                    fwrite ((char *) eolstring, sizeof(unsigned char),
+                            strlen(eolstring), outfile) != strlen (eolstring))
+                  {
+                    printf("error count>0 \n");
+                    return UURET_IOERR;
+                  }
+              }
+              else
+              {
+                size_t res;
+                if ((res=fwrite (itemp, sizeof(unsigned char), count, outfile)) != count)
+                  {
+                    printf("error count %d %u %lu\n",count, res,llen);
+                    return UURET_IOERR;
+                  }
+              }
+          }
+          else if (encoding == QP_ENCODED)
+          {
+            for (index=0; index<count; index++)
+              {
+                if (llen == 0 && itemp[index] == '.')
+                  {
+                    /*
+                     * Special rule: encode '.' at the beginning of a line, so
+                     * that some mailers aren't confused.
+                     */
+                    *optr++ = '=';
+                    *optr++ = HexEncodeTable[itemp[index] >> 4];
+                    *optr++ = HexEncodeTable[itemp[index] & 0x0f];
+                    llen += 3;
+                  }
+                else if ((itemp[index] >= 33 && itemp[index] <= 60) ||
+                         (itemp[index] >= 62 && itemp[index] <= 126) ||
+                         itemp[index] == 9 || itemp[index] == 32)
+                  {
+                    *optr++ = itemp[index];
+                    llen++;
+                  }
+                else if (itemp[index] == '\n')
+                  {
+                    /*
+                     * If the last character before EOL was a space or tab,
+                     * we must encode it. If llen > 74, there's no space to do
+                     * that, so generate a soft line break instead.
+                     */
+
+                    if (index>0 && (itemp[index-1] == 9 || itemp[index-1] == 32))
+                      {
+                        *(optr-1) = '=';
+                        if (llen <= 74)
+                          {
+                            *optr++ = HexEncodeTable[itemp[index-1] >> 4];
+                            *optr++ = HexEncodeTable[itemp[index-1] & 0x0f];
+                            llen += 2;
+                          }
+                      }
+
+                    if (fwrite (otemp, 1, llen, outfile) != llen ||
+                        fwrite ((char *) eolstring, 1,
+                                strlen(eolstring), outfile) != strlen (eolstring))
+                      {
+                        return UURET_IOERR;
+                      }
+
+                    /*
+                     * Fix the soft line break condition from above
+                     */
+
+                    if (index>0 && (itemp[index-1] == 9 || itemp[index-1] == 32) &&
+                        *(optr-1) == '=')
+                      {
+                        otemp[0] = '=';
+                        otemp[1] = HexEncodeTable[itemp[index-1] >> 4];
+                        otemp[2] = HexEncodeTable[itemp[index-1] & 0x0f];
+
+                        if (fwrite (otemp, 1, 3, outfile) != 3 ||
+                            fwrite ((char *) eolstring, 1,
+                                    strlen(eolstring), outfile) != strlen (eolstring))
+                          {
+                            return UURET_IOERR;
+                          }
+                      }
+
+                    optr = otemp;
+                    llen = 0;
+                  }
+                else
+                  {
+                    *optr++ = '=';
+                    *optr++ = HexEncodeTable[itemp[index] >> 4];
+                    *optr++ = HexEncodeTable[itemp[index] & 0x0f];
+                    llen += 3;
+                  }
+
+                /*
+                 * Lines must be shorter than 76 characters (not counting CRLF).
+                 * If the line grows longer than that, we must include a soft
+                 * line break.
+                 */
+
+                if (itemp[index+1] != 0 && itemp[index+1] != '\n' &&
+                    (llen >= 75 ||
+                     (!((itemp[index+1] >= 33 && itemp[index+1] <= 60) ||
+                        (itemp[index+1] >= 62 && itemp[index+1] <= 126)) &&
+                      llen >= 73)))
+                  {
+
+                    *optr++ = '=';
+                    llen++;
+
+                    if (fwrite (otemp, 1, llen, outfile) != llen ||
+                        fwrite ((char *) eolstring, 1,
+                                strlen(eolstring), outfile) != strlen (eolstring))
+                      {
+                        return UURET_IOERR;
+                      }
+
+                    optr = otemp;
+                    llen = 0;
+                  }
+              }
+          }
+        line++;
+      }
 
       return UURET_OK;
     }
@@ -988,9 +1004,6 @@ UUEncodeStream_byFSize (FILE *outfile, FILE *infile, int encoding, long bpf, crc
     return UURET_ILLVAL;
   }
 
-  long rest = bpf;
-  long current = 0;
-
   while (!feof (infile) && rest > 0)
   {
     current = rest >  bpl[encoding] ?  bpl[encoding] : rest;



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