mhstore -auto: Never store into subdirs, but use basename of filename.
[mmh] / uip / mhstore.c
index 6f6746d..50c911c 100644 (file)
@@ -470,7 +470,7 @@ store_switch(CT ct)
 static int
 store_generic(CT ct)
 {
-       char **ap, **ep, *cp;
+       char **ap, **vp, *cp;
        CI ci = &ct->c_ctinfo;
 
        /*
@@ -483,17 +483,20 @@ store_generic(CT ct)
        if (autosw && ct->c_type != CT_MESSAGE && !ct->c_storeproc) {
                /*
                ** Check the attribute/value pairs, for the attribute "name".
-               ** If found, do a few sanity checks and copy the value into
-               ** the storeproc.
+               ** If found, take the basename, do a few sanity checks and
+               ** copy the value into c_storeproc.
                */
-               for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
-                       if (mh_strcasecmp(*ap, "name")==0 &&
-                                       *(cp = *ep) != '/' && *cp != '.' &&
-                                       *cp != '|' && *cp != '!' &&
+               for (ap = ci->ci_attrs, vp = ci->ci_values; *ap; ap++,vp++) {
+                       if (mh_strcasecmp(*ap, "name")!=0) {
+                               continue;
+                       }
+                       cp = mhbasename(*vp);
+                       if (*cp && *cp!='.' && *cp!='|' && *cp!='!' &&
                                        !strchr(cp, '%')) {
+                               /* filename looks good: use it */
                                ct->c_storeproc = getcpy(cp);
-                               break;
                        }
+                       break;
                }
        }
 
@@ -650,8 +653,10 @@ store_external(CT ct)
        if (autosw) {
                char *cp;
 
-               if ((cp = e->eb_name) && *cp != '/' && *cp != '.' &&
-                               *cp != '|' && *cp != '!' && !strchr(cp, '%')) {
+               cp = mhbasename(e->eb_name);
+               if (*cp && *cp!='.' && *cp!='|' && *cp!='!' &&
+                               !strchr(cp, '%')) {
+                       /* filename looks good: use it */
                        if (!ct->c_storeproc)
                                ct->c_storeproc = getcpy(cp);
                        if (!p->c_storeproc)
@@ -900,8 +905,8 @@ output_content_file(CT ct, int appending)
        FILE *fp;
 
        /*
-       ** If the pathname is absolute, make sure
-       ** all the relevant directories exist.
+       ** If the pathname contains directories, make sure
+       ** all of them exist.
        */
        if (strchr(ct->c_storage, '/') && make_intermediates(ct->c_storage)
                        == NOTOK)