Rocco Rutte:
authorpdmef <pdmef@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Thu, 25 Aug 2005 21:05:08 +0000 (21:05 +0000)
committerpdmef <pdmef@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Thu, 25 Aug 2005 21:05:08 +0000 (21:05 +0000)
- experimental: add a routine doing space-stuffing as required once

git-svn-id: svn://svn.berlios.de/mutt-ng/trunk@444 e385b8ad-14ed-0310-8656-cc95a2468c6d

VERSION.svn
rfc3676.c
rfc3676.h
send.c

index 6a13cf6..1e6fd03 100644 (file)
@@ -1 +1 @@
-443
+444
index 9efa39d..7ca8726 100644 (file)
--- a/rfc3676.c
+++ b/rfc3676.c
@@ -275,3 +275,49 @@ void rfc3676_quote_line (STATE* s, char* dst, size_t dstlen,
             option (OPTSTUFFQUOTED) && line[offset] != ' ' ? " " : "",
             &line[offset]);
 }
             option (OPTSTUFFQUOTED) && line[offset] != ' ' ? " " : "",
             &line[offset]);
 }
+
+void rfc3676_space_stuff (HEADER* hdr) {
+#if DEBUG
+  int lc = 0;
+  size_t len = 0;
+  unsigned char c = '\0';
+#endif
+  FILE* in = NULL, *out = NULL;
+  char buf[LONG_STRING];
+  char tmpfile[_POSIX_PATH_MAX];
+
+  if (!hdr || !hdr->content || !hdr->content->filename)
+    return;
+
+  debug_print (2, ("f=f: postprocess %s\n", hdr->content->filename));
+  if ((in = safe_fopen (hdr->content->filename, "r")) == NULL)
+    return;
+  mutt_mktemp (tmpfile);
+  if ((out = safe_fopen (tmpfile, "w+")) == NULL) {
+    fclose (in);
+    return;
+  }
+
+  while (fgets (buf, sizeof (buf), in)) {
+    if (ascii_strncmp ("From ", buf, 4) == 0 || buf[0] == ' ') {
+      fputc (' ', out);
+#if DEBUG
+      lc++;
+      len = str_len (buf);
+      if (len > 0) {
+        c = buf[len-1];
+        buf[len-1] = '\0';
+      }
+      debug_print (4, ("f=f: line %d needs space-stuffing: '%s'\n",
+                       lc, buf));
+      if (len > 0)
+        buf[len-1] = c;
+#endif
+    }
+    fputs (buf, out);
+  }
+  fclose (in);
+  unlink (hdr->content->filename);
+  fclose (out);
+  str_replace (&hdr->content->filename, tmpfile);
+}
index 9dfcfd8..bb9d960 100644 (file)
--- a/rfc3676.h
+++ b/rfc3676.h
@@ -25,4 +25,12 @@ int rfc3676_handler (BODY * a, STATE * s);
 void rfc3676_quote_line (STATE* s, char* dst, size_t dstlen,
                          const char* line);
 
 void rfc3676_quote_line (STATE* s, char* dst, size_t dstlen,
                          const char* line);
 
+/*
+ * this does the space-stuffing required as in 'MUST'
+ * this is only used right after editing the initial message's content
+ * as elsewhere it's too difficult to catch all circumstances right;
+ * esp. with '>' which this routine doesn't cover... XXX
+ */
+void rfc3676_space_stuff (HEADER* hdr);
+
 #endif /* !_MUTT_RFC3676_H */
 #endif /* !_MUTT_RFC3676_H */
diff --git a/send.c b/send.c
index 876ffff..10803c4 100644 (file)
--- a/send.c
+++ b/send.c
@@ -16,6 +16,7 @@
 #include "ascii.h"
 #include "mutt_curses.h"
 #include "rfc2047.h"
 #include "ascii.h"
 #include "mutt_curses.h"
 #include "rfc2047.h"
+#include "rfc3676.h"
 #include "keymap.h"
 #include "mime.h"
 #include "copy.h"
 #include "keymap.h"
 #include "mime.h"
 #include "copy.h"
@@ -1440,6 +1441,9 @@ int ci_send_message (int flags, /* send mode */
       else
         mutt_edit_file (Editor, msg->content->filename);
 
       else
         mutt_edit_file (Editor, msg->content->filename);
 
+      if (option (OPTTEXTFLOWED))
+        rfc3676_space_stuff (msg);
+
       mutt_message_hook (NULL, msg, M_SEND2HOOK);
     }
 
       mutt_message_hook (NULL, msg, M_SEND2HOOK);
     }