]> diplodocus.org Git - nmh/commitdiff
A bit closer, but don't run the test just yet.
authorKen Hornstein <kenh@pobox.com>
Fri, 10 Jan 2014 04:17:25 +0000 (23:17 -0500)
committerKen Hornstein <kenh@pobox.com>
Fri, 10 Jan 2014 04:17:25 +0000 (23:17 -0500)
test/mhbuild/test-attach [new file with mode: 0755]
test/mhbuild/tiny.jpg [new file with mode: 0644]
uip/mhbuildsbr.c

diff --git a/test/mhbuild/test-attach b/test/mhbuild/test-attach
new file mode 100755 (executable)
index 0000000..8bd3a64
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/sh
+######################################################
+#
+# Test the use of the Attach: header
+#
+######################################################
+
+if test -z "${MH_OBJ_DIR}"; then
+    srcdir=`dirname "$0"`/../..
+    MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
+fi
+
+. "$MH_OBJ_DIR/test/common.sh"
+
+setup_test
+
+draft="$MH_TEST_DIR/$$.draft"
+expected="$MH_TEST_DIR/$$.expected"
+actual="$MH_TEST_DIR/$$.actual"
+
+#
+# Test out a simple draft
+#
+
+cat > "$draft" <<EOF
+To: Mr Test <mrtest@example.com>
+cc:
+Fcc: +outbox
+Attach: ${srcdir}/test/mhbuild/tiny.jpg
+------
+Test
+EOF
+
+mhbuild "$draft"
+
+cat $draft
+
+exit $failed
diff --git a/test/mhbuild/tiny.jpg b/test/mhbuild/tiny.jpg
new file mode 100644 (file)
index 0000000..d17e4da
--- /dev/null
@@ -0,0 +1 @@
+ÿØ
\ No newline at end of file
index 58540f1b35e261341d69c3eb5641553f600ffa3e..efd3c64fa87e939d446c90dac7e142daef6f1d87 100644 (file)
@@ -211,10 +211,30 @@ build_mime (char *infile, int directives, int header_encoding)
 
            if (strcasecmp(ATTACH_FIELD, np) == 0) {
                struct attach_list *entry;
 
            if (strcasecmp(ATTACH_FIELD, np) == 0) {
                struct attach_list *entry;
+               char *s = vp, *e = vp + strlen(vp) - 1;
                free(np);
                free(np);
+
+               /*
+                * Make sure we can find the start of this filename.
+                * If it's blank, we skip completely.  Otherwise, strip
+                * off any leading spaces and trailing newlines.
+                */
+
+               while (isspace((unsigned char) *s))
+                   s++;
+
+               while (e > s && *e == '\n')
+                   *e-- = '\0';
+
+               if (*s == '\0') {
+                   free(vp);
+                   goto finish_field;
+               }
+
                entry = mh_xmalloc(sizeof(*entry));
                entry = mh_xmalloc(sizeof(*entry));
-               entry->filename = vp;
-               if (! attach_tail) {
+               entry->filename = getcpy(s);
+               free(vp);
+               if (attach_tail) {
                    attach_tail->next = entry;
                    attach_tail = entry;
                } else {
                    attach_tail->next = entry;
                    attach_tail = entry;
                } else {
@@ -320,7 +340,7 @@ finish_field:
        struct part *part;
        CT p;
 
        struct part *part;
        CT p;
 
-       if (! access(at_entry->filename, R_OK)) {
+       if (access(at_entry->filename, R_OK) != 0) {
            adios("reading", "Unable to open %s for", at_entry->filename);
        }
 
            adios("reading", "Unable to open %s for", at_entry->filename);
        }
 
@@ -1853,6 +1873,7 @@ setup_attach_content(CT ct, const char *filename)
     }
 
     ct->c_descr = getcpy(filename);
     }
 
     ct->c_descr = getcpy(filename);
+    ct->c_cefile.ce_file = getcpy(filename);
 
     /*
      * If it's a text/calendar, we need to make sure it's an inline,
 
     /*
      * If it's a text/calendar, we need to make sure it's an inline,