Skip to content
Snippets Groups Projects
Commit 0c503c4e authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Add support for parsing format parameter of plain/text content-type MIME field

This sets the SMB MSG_FIXED_FORMAT auxattr header flag automatically when
importing MIME-compliant messages.
parent e713206e
No related branches found
No related tags found
No related merge requests found
Pipeline #8936 passed
......@@ -902,7 +902,7 @@ static void set_convenience_ptr(smbmsg_t* msg, uint16_t hfield_type, size_t len,
p += 13;
SKIP_WHITESPACE(p);
msg->content_type = p;
smb_parse_content_type(p, &(msg->text_subtype), &(msg->text_charset));
smb_parse_content_type(p, &(msg->text_subtype), &(msg->text_charset), &(msg->hdr.auxattr));
break;
}
if (strnicmp(p, "Content-Transfer-Encoding:", 26) == 0) {
......
......@@ -268,7 +268,7 @@ SMBEXPORT char* smb_getmsgtxt(smb_t*, smbmsg_t*, uint mode);
SMBEXPORT char* smb_getplaintext(smbmsg_t*, char* body);
SMBEXPORT uint8_t* smb_getattachment(smbmsg_t*, char* body, char* filename, size_t filename_len, uint32_t* filelen, int index);
SMBEXPORT uint smb_countattachments(smb_t*, smbmsg_t*, const char* body);
SMBEXPORT void smb_parse_content_type(const char* content_type, char** subtype, char** charset);
SMBEXPORT void smb_parse_content_type(const char* content_type, char** subtype, char** charset, uint32_t* auxattr);
/* smbfile.c */
SMBEXPORT int smb_feof(FILE* fp);
......
......@@ -361,7 +361,7 @@ static bool mime_getattachment(const char* beg, const char* end, char* attachmen
}
// Parses a MIME text/* content-type header field
void smb_parse_content_type(const char* content_type, char** subtype, char** charset)
void smb_parse_content_type(const char* content_type, char** subtype, char** charset, uint32_t* auxattr)
{
if (subtype != NULL) {
FREE_AND_NULL(*subtype);
......@@ -389,6 +389,31 @@ void smb_parse_content_type(const char* content_type, char** subtype, char** cha
*tp = 0;
}
}
char* format;
if (auxattr != NULL &&
((format = strcasestr(p, " format=")) != NULL
|| (format = strcasestr(p, ";foramt=")) != NULL
|| (format = strcasestr(p, "\tformat=")) != NULL)) {
bool quoted = false;
format += 8;
if (*format == '"') {
quoted = true;
format++;
}
char* tp = format;
FIND_WHITESPACE(tp);
*tp = 0;
tp = format;
if (quoted) {
FIND_CHAR(tp, '"');
} else {
FIND_CHAR(tp, ';');
}
*tp = 0;
if (stricmp(format, "fixed") == 0)
*auxattr |= MSG_FIXED_FORMAT;
}
char* parms = p;
if (charset != NULL &&
((p = strcasestr(parms, " charset=")) != NULL
......@@ -491,7 +516,7 @@ static const char* mime_getpart(const char* buf, const char* content_type, const
if (encoding != NULL)
*encoding = mime_getxferencoding(txt, p);
if (charset != NULL)
smb_parse_content_type(content_type, NULL, charset);
smb_parse_content_type(content_type, NULL, charset, NULL);
txt = p + 4; // strlen("\r\n\r\n")
SKIP_WHITESPACE(txt);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment