fix unexpected boundary not in multipart

This commit is contained in:
François 2022-12-17 08:47:22 +01:00
parent df7a25d331
commit fbaaf6ea3d
2 changed files with 29 additions and 36 deletions

View File

@ -73,7 +73,7 @@ const regex Attachment::nameRegEx (".*name=[ \t]*((\"(\\\\.|[^\\\\\r])*\")|[^\
// boundary="_000_PAVPR10MB6792713B313048E3A259B215B2079PAVPR10MB6792EURP_" // boundary="_000_PAVPR10MB6792713B313048E3A259B215B2079PAVPR10MB6792EURP_"
// boundary=--boundary_1351_64006126-2b0e-4a3b-98ac-4797d1634188 // boundary=--boundary_1351_64006126-2b0e-4a3b-98ac-4797d1634188
// boundary=--boundary_1352_7e294c9a-cfab-44a0-bfb3-7310380ac7cb; // boundary=--boundary_1352_7e294c9a-cfab-44a0-bfb3-7310380ac7cb;
const regex Attachment::boundaryRegEx (".*boundary=[ \t]*((\"(\\\\.|[^\\\\\r])*\")|[^\r; ]*);?.*"); const regex Attachment::boundaryRegEx (".*boundary=[ \t]*((\"(\\\\.|[^\\\\])*\")|[^; ]*);?.*");
const regex Attachment::cidDefRegEx (".*<([^>]*)>.*"); const regex Attachment::cidDefRegEx (".*<([^>]*)>.*");
const regex Attachment::textRegEx (".*text/("+PLAIN+"|"+HTML+").*"); const regex Attachment::textRegEx (".*text/("+PLAIN+"|"+HTML+").*");
const regex Attachment::multiRegEx ("\\s*multipart/(mixed|"+RELATED+"|"+ALTERNATIVE+").*"); const regex Attachment::multiRegEx ("\\s*multipart/(mixed|"+RELATED+"|"+ALTERNATIVE+").*");
@ -85,6 +85,7 @@ const string Attachment::IMG_END (">");
static const string SRC_BEGIN ("SRC=\""); static const string SRC_BEGIN ("SRC=\"");
static const string RFC822 ("message/rfc822"); static const string RFC822 ("message/rfc822");
static const string MULTIPART ("multipart/");
// ================================================================================ // ================================================================================
string string
@ -182,37 +183,26 @@ Attachment::getContentType () const {
const string const string
Attachment::getAttachName () const { Attachment::getAttachName () const {
static string tokens [] = {contentTypeToken, contentDispositionToken};
DEF_LOG ("Attachment::getAttachName", ""); DEF_LOG ("Attachment::getAttachName", "");
string result = getProp (contentTypeToken, nameRegEx); for (string token : tokens) {
string result = getProp (token, nameRegEx);
removeQuote (result); removeQuote (result);
if (result.length ()) { if (result.length ()) {
LOG ("name=: " << result); LOG ("name=: " << result);
encodedWord (result); encodedWord (result);
return result; return result;
} }
result = getProp (contentTypeToken, nameCharsetRegEx); result = getProp (token, nameCharsetRegEx);
removeQuote (result); removeQuote (result);
if (result.length ()) { if (result.length ()) {
LOG ("name*=: " << result); LOG ("name*=: " << result);
charsetValue (result); charsetValue (result);
return result; return result;
} }
}
// XXX il faut composer s'il y a plusieurs ligne filename*x= // XXX il faut composer s'il y a plusieurs ligne filename*x=
result = getProp (contentDispositionToken, nameRegEx);
removeQuote (result);
if (result.length ()) {
LOG ("filename=: " << result);
encodedWord (result);
return result;
}
// XXX il faut composer s'il y a plusieurs ligne filename*x*= // XXX il faut composer s'il y a plusieurs ligne filename*x*=
result = getProp (contentDispositionToken, nameCharsetRegEx);
removeQuote (result);
if (result.length ()) {
LOG ("filename*=: " << result);
charsetValue (result);
return result;
}
return getUnknown (getContentType ()); return getUnknown (getContentType ());
} }
@ -328,6 +318,8 @@ Attachment::readMime (ifstream &mbox, streamoff &curPos) {
contentPos = curPos; contentPos = curPos;
cid = getProp (contentIDToken, cidDefRegEx); cid = getProp (contentIDToken, cidDefRegEx);
if (caseInsensitiveFind (getContentType (), MULTIPART) != string::npos) {
boundary = getProp (contentTypeToken, boundaryRegEx); boundary = getProp (contentTypeToken, boundaryRegEx);
removeQuote (boundary); removeQuote (boundary);
LOG ("boundary: " << boundary); LOG ("boundary: " << boundary);
@ -335,6 +327,7 @@ Attachment::readMime (ifstream &mbox, streamoff &curPos) {
boundary = "--"+boundary+"--"; boundary = "--"+boundary+"--";
boundaryMiddleSize = boundary.length () - 2; boundaryMiddleSize = boundary.length () - 2;
} }
}
LOG ("readMime contentPos: " << contentPos << " cid: " << cid << " boundary: " << boundary); LOG ("readMime contentPos: " << contentPos << " cid: " << cid << " boundary: " << boundary);
} }

View File

@ -186,13 +186,13 @@ kaz::quotedDecode (string &content) {
} }
if (p+1 < content.end () && *(p+1) == '\n') { if (p+1 < content.end () && *(p+1) == '\n') {
LOG_BUG (q == content.begin (), ++p;continue, "kazMisc::quotedDecode bug: bad quoted-printable format. (start with '=', content: " << content << ")"); LOG_BUG (q == content.begin (), ++p;continue, "kazMisc::quotedDecode bug: bad quoted-printable format. (start with '=', delim: " << int (delim) << " content: " << content << ")");
++p; ++p;
--q; --q;
continue; continue;
} }
LOG_BUG (p+3 > content.end () || !isxdigit (p[1]) || !isxdigit (p[2]), return, "kazMisc::quotedDecode bug: bad quoted-printable format. (content: " << content << ")"); LOG_BUG (p+3 > content.end () || !isxdigit (p[1]) || !isxdigit (p[2]), return, "kazMisc::quotedDecode bug: bad quoted-printable format. (delim: " << int (delim) << " content: " << content << ")");
*q = (char) ((getHexaVal (p[1]) << 4) + getHexaVal (p[2])); *q = (char) ((getHexaVal (p[1]) << 4) + getHexaVal (p[2]));
p += 2; p += 2;
} }