* static prototypes
*/
static int init_decoded_content (CT);
-static void setup_attach_content(CT, const char *);
+static void setup_attach_content(CT, char *);
static char *fgetstr (char *, int, FILE *);
static int user_content (FILE *, char *, char *, CT *);
static void set_id (CT, int);
if (strcasecmp(ATTACH_FIELD, np) == 0) {
struct attach_list *entry;
+ char *s = vp, *e = vp + strlen(vp) - 1;
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->filename = vp;
- if (! attach_tail) {
+ entry->filename = getcpy(s);
+ free(vp);
+ if (attach_tail) {
attach_tail->next = entry;
attach_tail = entry;
} else {
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);
}
*/
static void
-setup_attach_content(CT ct, const char *filename)
+setup_attach_content(CT ct, char *filename)
{
- char *type, **ap, **ep;
+ char *type, **ap, **ep, *simplename = r1bindex(filename, '/');
struct str2init *s2i;
if (! (type = mime_type(filename))) {
if (strcasecmp(*ap, "name") == 0) {
if (*ep)
free(*ep);
- *ep = getcpy(filename);
+ *ep = getcpy(simplename);
break;
}
}
if (*ap == NULL) {
*ap = getcpy("name");
- *ep = getcpy(filename);
+ *ep = getcpy(simplename);
}
- ct->c_descr = getcpy(filename);
+ ct->c_descr = getcpy(simplename);
+ ct->c_descr = add("\n", ct->c_descr);
+ ct->c_cefile.ce_file = getcpy(filename);
/*
* If it's a text/calendar, we need to make sure it's an inline,
ct->c_dispo = getcpy("attachment; filename=\"");
}
- ct->c_dispo = add(filename, ct->c_dispo);
- ct->c_dispo = add("\"", ct->c_dispo);
+ ct->c_dispo = add(simplename, ct->c_dispo);
+ ct->c_dispo = add("\"\n", ct->c_dispo);
}