diff -r 28fb262886c3 sys/src/cmd/upas/marshal/marshal.c --- a/sys/src/cmd/upas/marshal/marshal.c Mon Dec 02 17:55:53 2019 +0200 +++ b/sys/src/cmd/upas/marshal/marshal.c Sat Dec 07 00:39:05 2019 +0100 @@ -871,6 +871,15 @@ return Bprint(out, "In-Reply-To: <%s>\n", buf); } +int +hassuffix(char *str, char *suff) +{ + int na = strlen(str), nb = strlen(suff); + if(na - nb) + return 0; + return strcmp(str + na, suff) == 0; +} + Attach* mkattach(char *file, char *type, int ainline) { @@ -902,31 +911,22 @@ } /* pick a type depending on extension */ - p = strchr(file, '.'); - if(p != nil) - p++; - - /* check the builtin extensions */ - if(p != nil){ - for(c = ctype; c->ext != nil; c++) - if(strcmp(p, c->ext) == 0){ - a->type = c->type; - a->ctype = c; - return a; - } - } + for(c = ctype; c->ext != nil; c++) + if(hassuffix(file, c->ext)){ + a->type = c->type; + a->ctype = c; + return a; + } /* try the mime types file */ - if(p != nil){ - if(mimetypes == nil) - readmimetypes(); - for(c = mimetypes; c != nil && c->ext != nil; c++) - if(strcmp(p, c->ext) == 0){ - a->type = c->type; - a->ctype = c; - return a; - } - } + if(mimetypes == nil) + readmimetypes(); + for(c = mimetypes; c != nil && c->ext != nil; c++) + if(hassuffix(file, c->ext)){ + a->type = c->type; + a->ctype = c; + return a; + } /* run file to figure out the type */ a->type = "application/octet-stream"; /* safest default */