more documentation.
[apps/madmutt.git] / lib-mime / rfc3676.c
index 1fdcf0d..42bf5ac 100644 (file)
@@ -9,26 +9,14 @@
  * please see the file GPL in the top level source directory.
  */
 
  * please see the file GPL in the top level source directory.
  */
 
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <ctype.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-
-#include <lib-lib/mem.h>
-#include <lib-lib/str.h>
-#include <lib-lib/ascii.h>
-#include <lib-lib/macros.h>
-#include <lib-lib/file.h>
+#include <lib-lib/lib-lib.h>
+
+#include <utime.h>
 
 #include <lib-ui/curses.h>
 
 #include "state.h"
 
 #include <lib-ui/curses.h>
 
 #include "state.h"
+#include "rfc3676.h"
 
 #define FLOWED_MAX 77
 
 
 #define FLOWED_MAX 77
 
@@ -177,7 +165,7 @@ int rfc3676_handler (BODY * a, STATE * s) {
      * which may make the line look like fixed although it wasn't
      * so keep this in mind for later processing */
     fixed = buf_len == 0 || buf[buf_len - 1] != ' ' ||
      * which may make the line look like fixed although it wasn't
      * so keep this in mind for later processing */
     fixed = buf_len == 0 || buf[buf_len - 1] != ' ' ||
-            (strcmp(buf + buf_off, "-- ") == 0);
+            (m_strcmp(buf + buf_off, "-- ") == 0);
 
     if (delsp && buf_len >= 1 && buf[buf_len-1] == ' ')
       buf[--buf_len] = '\0';
 
     if (delsp && buf_len >= 1 && buf[buf_len-1] == ' ')
       buf[--buf_len] = '\0';
@@ -192,14 +180,14 @@ int rfc3676_handler (BODY * a, STATE * s) {
     }
 
     /* signature separator also flushes the previous paragraph */
     }
 
     /* signature separator also flushes the previous paragraph */
-    if (strcmp(buf + buf_off, "-- ") == 0 && curline && *curline) {
+    if (m_strcmp(buf + buf_off, "-- ") == 0 && curline && *curline) {
       print_flowed_line (curline, s, quotelevel);
       *curline = '\0';
       curline_len = 1;
     }
 
     p_realloc(&curline, curline_len + buf_len - buf_off);
       print_flowed_line (curline, s, quotelevel);
       *curline = '\0';
       curline_len = 1;
     }
 
     p_realloc(&curline, curline_len + buf_len - buf_off);
-    strcpy (curline + curline_len - 1, buf + buf_off);
+    m_strcpy(curline + curline_len - 1, buf_len - buf_off + 1, buf + buf_off);
     curline_len += buf_len - buf_off;
 
     /* if this was a fixed line the paragraph is finished */
     curline_len += buf_len - buf_off;
 
     /* if this was a fixed line the paragraph is finished */
@@ -214,6 +202,18 @@ int rfc3676_handler (BODY * a, STATE * s) {
   return (0);
 }
 
   return (0);
 }
 
+/* sets mtime of 'to' to mtime of 'from' */
+static void mutt_set_mtime (const char* from, const char* to) {
+  struct utimbuf utim;
+  struct stat st;
+
+  if (stat (from, &st) != -1) {
+    utim.actime = st.st_mtime;
+    utim.modtime = st.st_mtime;
+    utime (to, &utim);
+  }
+}
+
 void rfc3676_space_stuff (HEADER* hdr) {
   FILE* in = NULL, *out = NULL;
   char buf[LONG_STRING];
 void rfc3676_space_stuff (HEADER* hdr) {
   FILE* in = NULL, *out = NULL;
   char buf[LONG_STRING];
@@ -224,20 +224,21 @@ void rfc3676_space_stuff (HEADER* hdr) {
 
   if ((in = safe_fopen (hdr->content->filename, "r")) == NULL)
     return;
 
   if ((in = safe_fopen (hdr->content->filename, "r")) == NULL)
     return;
-  mutt_mktemp (tmpf);
-  if ((out = safe_fopen (tmpf, "w+")) == NULL) {
-    fclose (in);
+
+  out = m_tempfile(tmpf, sizeof(tmpf), NONULL(Tempdir), NULL);
+  if (!out) {
+    m_fclose(&in);
     return;
   }
 
     return;
   }
 
-  while (fgets (buf, sizeof (buf), in)) {
-    if (ascii_strncmp ("From ", buf, 4) == 0 || buf[0] == ' ') {
+  while (fgets(buf, sizeof (buf), in)) {
+    if (m_strncmp("From ", buf, 4) == 0 || buf[0] == ' ') {
       fputc (' ', out);
     }
     fputs (buf, out);
   }
       fputc (' ', out);
     }
     fputs (buf, out);
   }
-  fclose (in);
-  fclose (out);
+  m_fclose(&in);
+  m_fclose(&out);
   mutt_set_mtime (hdr->content->filename, tmpf);
   unlink (hdr->content->filename);
   m_strreplace(&hdr->content->filename, tmpf);
   mutt_set_mtime (hdr->content->filename, tmpf);
   unlink (hdr->content->filename);
   m_strreplace(&hdr->content->filename, tmpf);