managed rfc2047 and rfc2184 for attache name
manage name= / name*= / name*[0-9]= / name*[0-9]*=
This commit is contained in:
@@ -65,8 +65,8 @@ const string Attachment::ALTERNATIVE ("alternative");
|
|||||||
const string Attachment::KAZ_ATTACH_NAME ("vos-pieces-jointes-kaz-ici.html");
|
const string Attachment::KAZ_ATTACH_NAME ("vos-pieces-jointes-kaz-ici.html");
|
||||||
const string Attachment::MULTIPART ("multipart/");
|
const string Attachment::MULTIPART ("multipart/");
|
||||||
|
|
||||||
const regex Attachment::nameCharsetRegEx ( ".*name\\*=\\s*([; \t]*)");
|
const string Attachment::nameLeftToken (".*name");
|
||||||
const regex Attachment::nameRegEx ( ".*name=\\s*((\"(\\\\.|[^\\\\])*\")|[^; \t]*).*");
|
const string Attachment::nameRightToken ("=\\s*((\"(\\\\.|[^\\\\])*\")|[^; \t]*).*");
|
||||||
const regex Attachment::boundaryRegEx (".*boundary=\\s*((\"(\\\\.|[^\\\\])*\")|[^; \t]*).*");
|
const regex Attachment::boundaryRegEx (".*boundary=\\s*((\"(\\\\.|[^\\\\])*\")|[^; \t]*).*");
|
||||||
const regex Attachment::cidDefRegEx (".*<([^>]*)>.*");
|
const regex Attachment::cidDefRegEx (".*<([^>]*)>.*");
|
||||||
const regex Attachment::textRegEx (".*text/("+PLAIN+"|"+HTML+").*");
|
const regex Attachment::textRegEx (".*text/("+PLAIN+"|"+HTML+").*");
|
||||||
@@ -179,47 +179,31 @@ Attachment::getAttachName () const {
|
|||||||
static string tokens [] = {contentTypeToken, contentDispositionToken};
|
static string tokens [] = {contentTypeToken, contentDispositionToken};
|
||||||
DEF_LOG ("Attachment::getAttachName", "");
|
DEF_LOG ("Attachment::getAttachName", "");
|
||||||
for (string token : tokens) {
|
for (string token : tokens) {
|
||||||
// name=
|
for (string star : {"", "\\*"}) {
|
||||||
string result = getProp (token, nameRegEx);
|
|
||||||
|
// name= | name*=
|
||||||
|
regex nameAloneRegEx (nameLeftToken+star+nameRightToken);
|
||||||
|
string result = getProp (token, nameAloneRegEx);
|
||||||
removeQuote (result);
|
removeQuote (result);
|
||||||
if (result.length ()) {
|
if (result.length ()) {
|
||||||
LOG ("name=: " << result);
|
LOG (("name"+star+=": ") << result);
|
||||||
encodedWordDecode (result);
|
charsetDecode (result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
// name*x=
|
|
||||||
|
// name*[0-9]= | name*[0-9]*=
|
||||||
for (int id = 0; ; ++id) {
|
for (int id = 0; ; ++id) {
|
||||||
string item = getProp (token, regex (".*name\\*"+to_string (id)+"=\\s*((\"(\\\\.|[^\\\\])*\")|[; \t]*).*"));
|
string item = getProp (token, regex (nameLeftToken+"\\*"+to_string (id)+star+nameRightToken));
|
||||||
if (item.empty ())
|
if (item.empty ())
|
||||||
break;
|
break;
|
||||||
result += item;
|
result += item;
|
||||||
}
|
}
|
||||||
removeQuote (result);
|
removeQuote (result);
|
||||||
if (result.length ()) {
|
if (result.length ()) {
|
||||||
LOG ("name*x=: " << result);
|
LOG (("name*x"+star+"=: ") << result);
|
||||||
encodedWordDecode (result);
|
charsetDecode (result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
// name*=
|
|
||||||
result = getProp (token, nameCharsetRegEx);
|
|
||||||
removeQuote (result);
|
|
||||||
if (result.length ()) {
|
|
||||||
LOG ("name*=: " << result);
|
|
||||||
charsetValueDecode (result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
// name*x*=
|
|
||||||
for (int id = 0; ; ++id) {
|
|
||||||
string item = getProp (token, regex (".*name\\*"+to_string (id)+"\\*=\\s*([^; ]*)"));
|
|
||||||
if (item.empty ())
|
|
||||||
break;
|
|
||||||
result += item;
|
|
||||||
}
|
|
||||||
removeQuote (result);
|
|
||||||
if (result.length ()) {
|
|
||||||
LOG ("name*x*=: " << result);
|
|
||||||
encodedWordDecode (result);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return getUnknown (getContentType ());
|
return getUnknown (getContentType ());
|
||||||
|
|||||||
@@ -439,16 +439,17 @@ kaz::encodedWordDecode (string &content) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ================================================================================
|
// ================================================================================
|
||||||
void
|
bool
|
||||||
kaz::charsetValueDecode (string &content) {
|
kaz::charsetValueDecode (string &content) {
|
||||||
// rfc2184
|
// rfc2184
|
||||||
DEF_LOG ("kazMisc::charsetValueDecode", "content: " << content.substr (0, 100) << "...");
|
DEF_LOG ("kazMisc::charsetValueDecode", "content: " << content.substr (0, 100) << "...");
|
||||||
string::size_type langPos = content.find ("'");
|
string::size_type langPos = content.find ("'");
|
||||||
|
if (langPos == string::npos)
|
||||||
LOG_BUG (langPos == string::npos, return, "kazMisc::charsetValueDecode bug: no '. (content: " << content.substr (0, 100) << "...)");
|
return false;
|
||||||
string::size_type contentPos = content.find ("'", langPos+1);
|
string::size_type contentPos = content.find ("'", langPos+1);
|
||||||
|
if (contentPos == string::npos)
|
||||||
|
return false;
|
||||||
|
|
||||||
LOG_BUG (contentPos == string::npos, return, "kazMisc::charsetValueDecode bug: no double '. (content: " << content.substr (0, 100) << "...)");
|
|
||||||
string tmp (content.substr (contentPos+1));
|
string tmp (content.substr (contentPos+1));
|
||||||
quotedDecode<'%'> (tmp);
|
quotedDecode<'%'> (tmp);
|
||||||
LOG ("tmp: " << tmp.substr (0, 100) << "...");
|
LOG ("tmp: " << tmp.substr (0, 100) << "...");
|
||||||
@@ -458,6 +459,17 @@ kaz::charsetValueDecode (string &content) {
|
|||||||
iso2utf (tmp);
|
iso2utf (tmp);
|
||||||
content = tmp;
|
content = tmp;
|
||||||
LOG ("content: " << content.substr (0, 100) << "...");
|
LOG ("content: " << content.substr (0, 100) << "...");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================================================================================
|
||||||
|
void
|
||||||
|
kaz::charsetDecode (string &content) {
|
||||||
|
// rfc2047 | rfc2184
|
||||||
|
DEF_LOG ("kazMisc::charsetDecode", "content: " << content.substr (0, 100) << "...");
|
||||||
|
if (charsetValueDecode (content))
|
||||||
|
return;
|
||||||
|
encodedWordDecode (content);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================================================================================
|
// ================================================================================
|
||||||
|
|||||||
@@ -55,8 +55,9 @@ namespace kaz {
|
|||||||
static vector<string> stringsToUpdate;
|
static vector<string> stringsToUpdate;
|
||||||
/*! mime tokens */
|
/*! mime tokens */
|
||||||
static const string contentTypeToken, contentDispositionToken, contentTransferEncodingToken, base64Token, quotedPrintableToken, contentIDToken, PLAIN, HTML, MULTIPART, RELATED, ALTERNATIVE, SIGNED, KAZ_ATTACH_NAME;
|
static const string contentTypeToken, contentDispositionToken, contentTransferEncodingToken, base64Token, quotedPrintableToken, contentIDToken, PLAIN, HTML, MULTIPART, RELATED, ALTERNATIVE, SIGNED, KAZ_ATTACH_NAME;
|
||||||
|
static const string nameLeftToken, nameRightToken;
|
||||||
/*! pattern to extract mime values */
|
/*! pattern to extract mime values */
|
||||||
static const regex nameRegEx, nameCharsetRegEx, boundaryRegEx, cidDefRegEx, textRegEx, multiRegEx;
|
static const regex boundaryRegEx, cidDefRegEx, textRegEx, multiRegEx;
|
||||||
|
|
||||||
/*! get uniq filename */
|
/*! get uniq filename */
|
||||||
static string getUnknown (const string &ext = "");
|
static string getUnknown (const string &ext = "");
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
#define _kaz_misc_hpp
|
#define _kaz_misc_hpp
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <ctype.h>
|
#include <inttypes.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
@@ -91,7 +91,9 @@ namespace kaz {
|
|||||||
/*! side effect to get the encoded word according rfc2047 rfc5987 rfc2978 */
|
/*! side effect to get the encoded word according rfc2047 rfc5987 rfc2978 */
|
||||||
void encodedWordDecode (string &content);
|
void encodedWordDecode (string &content);
|
||||||
/*! side effect to get the charsetValue according rfc2184 */
|
/*! side effect to get the charsetValue according rfc2184 */
|
||||||
void charsetValueDecode (string &content);
|
bool charsetValueDecode (string &content);
|
||||||
|
/*! side effect to remove quote */
|
||||||
|
void charsetDecode (string &content);
|
||||||
/*! side effect to remove quote */
|
/*! side effect to remove quote */
|
||||||
void removeQuote (string &content);
|
void removeQuote (string &content);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user