Make mhstore(1) use "filename" attr of Content-Disposition
[mmh] / uip / mhstore.c
index adaca77..2b909ef 100644 (file)
@@ -468,7 +468,7 @@ store_switch(CT ct)
 static int
 store_generic(CT ct)
 {
-       char **ap, **vp, *cp;
+       char **ap, **vp, *cp, *filename;
        CI ci = &ct->c_ctinfo;
 
        /*
@@ -477,6 +477,18 @@ store_generic(CT ct)
        ** (only the "message" subtype "rfc822" will use store_generic).
        */
        if (autosw && ct->c_type != CT_MESSAGE) {
+               /* First check for "filename" in Content-Disposition header */
+               filename = extract_name_value("filename", ct->c_dispo);
+               if (strcmp(filename, ct->c_dispo)!=0) {
+                       /* We found "filename" */
+                       cp = mhbasename(filename);
+                       if (*cp && *cp!='.' && *cp!='|' && *cp!='!' &&
+                                       !strchr(cp, '%')) {
+                               /* filename looks good: use it */
+                               ct->c_storeproc = mh_xstrdup(cp);
+                               goto finished;
+                       }
+               }
                /*
                ** Check the attribute/value pairs, for the attribute "name".
                ** If found, take the basename, do a few sanity checks and
@@ -496,6 +508,7 @@ store_generic(CT ct)
                }
        }
 
+finished:
        return store_content(ct, NULL);
 }