Fixed attachment name parsing

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2018-07-10 11:17:57 +00:00
parent 3088b4c401
commit c5959f79c4
2 changed files with 30 additions and 14 deletions

View File

@ -824,21 +824,22 @@ void extractNameFromHeaderLine(char *s, char *name, char *resultbuf, int resultb
if(p){
p++;
// If the line has the 'name' more than once, then truncate the subsequent parts, ie.
// utf-8''P;LAN%20Holden%204.docx;filename="P;LAN Holden 4.docx" ==> utf-8''P;LAN%20Holden%204.docx
q = strstr(p, name);
if(q) *q = '\0';
// skip any whitespace after name=, ie. name = "
while(*p==' ' || *p=='\t') p++;
q = strrchr(p, ';');
if(q) *q = '\0';
q = strrchr(p, '"');
if(q){
*q = '\0';
p = strchr(p, '"');
if(p){
p++;
}
// if there's a double quote after the equal symbol (=), ie. name*="utf-8....
if(*p == '"'){
p++;
q = strchr(p, '"');
if(q) *q = '\0';
}
else {
// no " after =, so split on ;
q = strchr(p, ';');
if(q) *q = '\0';
}
if(extended == 1){
encoding = p;

View File

@ -97,10 +97,25 @@ static void test_extractNameFromHeaderLine(){
{"Content-Type: image/png; name=\"Screenshot from 2015-11-10 10:07:13.png\"", "name", "Screenshot from 2015-11-10 10:07:13.png"},
{"Content-Disposition: attachment; filename=\"zzzzz Email Examples.zip\";", "name", "zzzzz Email Examples.zip"},
{"Content-Type: application/msword; name*=\"iso-8859-1''Einverst%E4ndniserkl%E4rung_Kids-PKW_Familienname.doc\"", "name", "Einverständniserklärung_Kids-PKW_Familienname.doc"},
{"Content-Type: application/msword; name*= \"iso-8859-1''Einverst%E4ndniserkl%E4rung_Kids-PKW_Familienname.doc\"", "name", "Einverständniserklärung_Kids-PKW_Familienname.doc"},
// This one sucks, and I don't think it's a proper definition
{"Content-Type: application/msword; filename*=utf-8''P;LAN%20Holden%204.docx;filename=\"P;LAN Holden 4.docx\"", "name", "P"},
// Adding quotes makes it acceptable to the parser
{"Content-Type: application/msword; filename*=\"utf-8''P;LAN%20Holden%204.docx\";filename=\"P;LAN Holden 4.docx\"", "name", "P;LAN Holden 4.docx"},
{"Content-Type: null; name=\"toDev-Netengineering.png\"", "name", "toDev-Netengineering.png"},
{"Content-Type: null; name=\"toDev-name-Netengineering.png\"", "name", "toDev-name-Netengineering.png"},
{"Content-Type: null; name*=\"iso-8859-1''toDev-Netengineering.png\"", "name", "toDev-Netengineering.png"},
{"Content-Type: null; name*=\"iso-8859-1''toDev-name-Netengineering.png\"", "name", "toDev-name-Netengineering.png"},
{"Content-Type: null; name*=\"iso-8859-1''toDevnameNetengineering.png\"", "name", "toDevnameNetengineering.png"},
{"Content-Type: null; name*=\"iso-8859-1''toDev-namE-Netengineering.png\"", "name", "toDev-namE-Netengineering.png"},
{"foo: bar; title=Economy", "title", "Economy"},
{"foo: bar; title=\"US-$ rates\"", "title", "US-$ rates"},
{"foo: bar; title*=iso-8859-1'en'%A3%20rates", "title", "£ rates"},
{"foo: bar; title*=UTF-8''%c2%a3%20and%20%e2%82%ac%20rates", "title", "£ and € rates"}
{"foo: bar; title*=UTF-8''%c2%a3%20and%20%e2%82%ac%20rates", "title", "£ and € rates"},
};
TEST_HEADER();