fix unexpected boundary not in multipart
This commit is contained in:
parent
df7a25d331
commit
fbaaf6ea3d
@ -73,7 +73,7 @@ const regex Attachment::nameRegEx (".*name=[ \t]*((\"(\\\\.|[^\\\\\r])*\")|[^\
|
||||
// boundary="_000_PAVPR10MB6792713B313048E3A259B215B2079PAVPR10MB6792EURP_"
|
||||
// boundary=--boundary_1351_64006126-2b0e-4a3b-98ac-4797d1634188
|
||||
// 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::textRegEx (".*text/("+PLAIN+"|"+HTML+").*");
|
||||
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 RFC822 ("message/rfc822");
|
||||
static const string MULTIPART ("multipart/");
|
||||
|
||||
// ================================================================================
|
||||
string
|
||||
@ -182,37 +183,26 @@ Attachment::getContentType () const {
|
||||
|
||||
const string
|
||||
Attachment::getAttachName () const {
|
||||
static string tokens [] = {contentTypeToken, contentDispositionToken};
|
||||
DEF_LOG ("Attachment::getAttachName", "");
|
||||
string result = getProp (contentTypeToken, nameRegEx);
|
||||
removeQuote (result);
|
||||
if (result.length ()) {
|
||||
LOG ("name=: " << result);
|
||||
encodedWord (result);
|
||||
return result;
|
||||
}
|
||||
result = getProp (contentTypeToken, nameCharsetRegEx);
|
||||
removeQuote (result);
|
||||
if (result.length ()) {
|
||||
LOG ("name*=: " << result);
|
||||
charsetValue (result);
|
||||
return result;
|
||||
for (string token : tokens) {
|
||||
string result = getProp (token, nameRegEx);
|
||||
removeQuote (result);
|
||||
if (result.length ()) {
|
||||
LOG ("name=: " << result);
|
||||
encodedWord (result);
|
||||
return result;
|
||||
}
|
||||
result = getProp (token, nameCharsetRegEx);
|
||||
removeQuote (result);
|
||||
if (result.length ()) {
|
||||
LOG ("name*=: " << result);
|
||||
charsetValue (result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
// 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*=
|
||||
result = getProp (contentDispositionToken, nameCharsetRegEx);
|
||||
removeQuote (result);
|
||||
if (result.length ()) {
|
||||
LOG ("filename*=: " << result);
|
||||
charsetValue (result);
|
||||
return result;
|
||||
}
|
||||
return getUnknown (getContentType ());
|
||||
}
|
||||
|
||||
@ -328,12 +318,15 @@ Attachment::readMime (ifstream &mbox, streamoff &curPos) {
|
||||
|
||||
contentPos = curPos;
|
||||
cid = getProp (contentIDToken, cidDefRegEx);
|
||||
boundary = getProp (contentTypeToken, boundaryRegEx);
|
||||
removeQuote (boundary);
|
||||
LOG ("boundary: " << boundary);
|
||||
if (boundary.length ()) {
|
||||
boundary = "--"+boundary+"--";
|
||||
boundaryMiddleSize = boundary.length () - 2;
|
||||
|
||||
if (caseInsensitiveFind (getContentType (), MULTIPART) != string::npos) {
|
||||
boundary = getProp (contentTypeToken, boundaryRegEx);
|
||||
removeQuote (boundary);
|
||||
LOG ("boundary: " << boundary);
|
||||
if (boundary.length ()) {
|
||||
boundary = "--"+boundary+"--";
|
||||
boundaryMiddleSize = boundary.length () - 2;
|
||||
}
|
||||
}
|
||||
LOG ("readMime contentPos: " << contentPos << " cid: " << cid << " boundary: " << boundary);
|
||||
}
|
||||
|
@ -186,13 +186,13 @@ kaz::quotedDecode (string &content) {
|
||||
}
|
||||
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;
|
||||
--q;
|
||||
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]));
|
||||
p += 2;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user