bug=63656, r=ducarroz, sr=bienvenu
more support RFC2231 git-svn-id: svn://10.0.0.236/trunk@87217 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -882,11 +882,18 @@ extern PRInt16 INTL_DefaultMailToWinCharSetID(PRInt16 csid);
|
||||
/* Given text purporting to be a qtext header value, strip backslashes that
|
||||
may be escaping other chars in the string. */
|
||||
char *
|
||||
mime_decode_filename(char *name)
|
||||
mime_decode_filename(char *name, const char *charset)
|
||||
{
|
||||
char *s = name, *d = name;
|
||||
char *cvt, *returnVal = NULL;
|
||||
|
||||
// If charset parameter is used, this is RFC2231 encoding.
|
||||
if (charset)
|
||||
{
|
||||
MIME_ConvertString(charset, "UTF-8", name, &returnVal);
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
while (*s)
|
||||
{
|
||||
/* Remove backslashes when they are used to escape special characters. */
|
||||
@@ -918,11 +925,12 @@ char *
|
||||
MimeHeaders_get_name(MimeHeaders *hdrs)
|
||||
{
|
||||
char *s = 0, *name = 0, *cvt = 0;
|
||||
char *charset = nsnull; // for RFC2231 support
|
||||
|
||||
s = MimeHeaders_get(hdrs, HEADER_CONTENT_DISPOSITION, PR_FALSE, PR_FALSE);
|
||||
if (s)
|
||||
{
|
||||
name = MimeHeaders_get_parameter(s, HEADER_PARM_FILENAME, NULL, NULL);
|
||||
name = MimeHeaders_get_parameter(s, HEADER_PARM_FILENAME, &charset, NULL);
|
||||
PR_Free(s);
|
||||
}
|
||||
|
||||
@@ -931,7 +939,9 @@ MimeHeaders_get_name(MimeHeaders *hdrs)
|
||||
s = MimeHeaders_get(hdrs, HEADER_CONTENT_TYPE, PR_FALSE, PR_FALSE);
|
||||
if (s)
|
||||
{
|
||||
name = MimeHeaders_get_parameter(s, HEADER_PARM_NAME, NULL, NULL);
|
||||
PR_FREEIF(charset);
|
||||
|
||||
name = MimeHeaders_get_parameter(s, HEADER_PARM_NAME, &charset, NULL);
|
||||
PR_Free(s);
|
||||
}
|
||||
}
|
||||
@@ -954,7 +964,9 @@ MimeHeaders_get_name(MimeHeaders *hdrs)
|
||||
/* Argh. What we should do if we want to be robust is to decode qtext
|
||||
in all appropriate headers. Unfortunately, that would be too scary
|
||||
at this juncture. So just decode qtext/mime2 here. */
|
||||
cvt = mime_decode_filename(name);
|
||||
cvt = mime_decode_filename(name, charset);
|
||||
PR_FREEIF(charset);
|
||||
|
||||
if (cvt && cvt != name)
|
||||
{
|
||||
PR_Free(name);
|
||||
|
||||
@@ -77,6 +77,6 @@ HG77761
|
||||
*/
|
||||
extern char *MimeHeaders_get_name(MimeHeaders *hdrs);
|
||||
|
||||
extern char *mime_decode_filename(char *name);
|
||||
extern char *mime_decode_filename(char *name, const char* charset);
|
||||
|
||||
#endif /* _MIMEHDRS_H_ */
|
||||
|
||||
@@ -98,6 +98,7 @@ ProcessBodyAsAttachment(MimeObject *obj, nsMsgAttachmentData **data)
|
||||
nsMsgAttachmentData *tmp;
|
||||
PRInt32 n;
|
||||
char *disp = nsnull;
|
||||
char *charset = nsnull;
|
||||
|
||||
// Ok, this is the special case when somebody sends an "attachment" as the body
|
||||
// of an RFC822 message...I really don't think this is the way this should be done.
|
||||
@@ -116,11 +117,12 @@ ProcessBodyAsAttachment(MimeObject *obj, nsMsgAttachmentData **data)
|
||||
tmp->real_type = child->content_type ? nsCRT::strdup(child->content_type) : NULL;
|
||||
tmp->real_encoding = child->encoding ? nsCRT::strdup(child->encoding) : NULL;
|
||||
disp = MimeHeaders_get(child->headers, HEADER_CONTENT_DISPOSITION, PR_FALSE, PR_FALSE);
|
||||
tmp->real_name = MimeHeaders_get_parameter(disp, "name", NULL, NULL);
|
||||
tmp->real_name = MimeHeaders_get_parameter(disp, "name", &charset, NULL);
|
||||
if (tmp->real_name)
|
||||
{
|
||||
char *fname = NULL;
|
||||
fname = mime_decode_filename(tmp->real_name);
|
||||
fname = mime_decode_filename(tmp->real_name, charset);
|
||||
PR_FREEIF(charset);
|
||||
if (fname && fname != tmp->real_name)
|
||||
{
|
||||
PR_Free(tmp->real_name);
|
||||
@@ -276,6 +278,7 @@ BuildAttachmentList(MimeObject *aChild, nsMsgAttachmentData *aAttachData,
|
||||
nsMsgAttachmentData *tmp = nsnull;
|
||||
PRBool isAlternativeOrRelated;
|
||||
PRBool isIMAPPart = PR_FALSE;
|
||||
char *charset = nsnull;
|
||||
|
||||
if ( (!aChild) || (!cobj->children) ||
|
||||
(mime_typep(aChild, (MimeObjectClass *)&mimeExternalBodyClass)))
|
||||
@@ -339,19 +342,28 @@ BuildAttachmentList(MimeObject *aChild, nsMsgAttachmentData *aAttachData,
|
||||
|
||||
if (disp)
|
||||
{
|
||||
tmp->real_name = MimeHeaders_get_parameter(disp, "filename", NULL, NULL);
|
||||
tmp->real_name = MimeHeaders_get_parameter(disp, "filename", &charset, NULL);
|
||||
if (isAnAppleDoublePart)
|
||||
for (j = 0; j < 2 && !tmp->real_name; j ++)
|
||||
{
|
||||
PR_FREEIF(disp);
|
||||
PR_FREEIF(charset);
|
||||
disp = MimeHeaders_get(((MimeContainer *)child)->children[j]->headers, HEADER_CONTENT_DISPOSITION, PR_FALSE, PR_FALSE);
|
||||
tmp->real_name = MimeHeaders_get_parameter(disp, "filename", NULL, NULL);
|
||||
tmp->real_name = MimeHeaders_get_parameter(disp, "filename", &charset, NULL);
|
||||
}
|
||||
|
||||
if (tmp->real_name)
|
||||
{
|
||||
// check encoded type
|
||||
//
|
||||
// The parameter of Content-Disposition must use RFC 2231.
|
||||
// But old Netscape 4.x and Outlook Express etc. use RFC2047.
|
||||
// So we should parse both types.
|
||||
|
||||
char *fname = NULL;
|
||||
fname = mime_decode_filename(tmp->real_name);
|
||||
fname = mime_decode_filename(tmp->real_name, charset);
|
||||
PR_FREEIF(charset);
|
||||
|
||||
if (fname && fname != tmp->real_name)
|
||||
{
|
||||
PR_FREEIF(tmp->real_name);
|
||||
@@ -371,19 +383,28 @@ BuildAttachmentList(MimeObject *aChild, nsMsgAttachmentData *aAttachData,
|
||||
if (!tmp->real_name || *tmp->real_name == 0)
|
||||
{
|
||||
PR_FREEIF(tmp->real_name);
|
||||
tmp->real_name = MimeHeaders_get_parameter(disp, "name", NULL, NULL);
|
||||
tmp->real_name = MimeHeaders_get_parameter(disp, "name", &charset, NULL);
|
||||
if (isAnAppleDoublePart)
|
||||
for (j = 0; j < 2 && !tmp->real_name; j ++)
|
||||
{
|
||||
PR_FREEIF(disp);
|
||||
PR_FREEIF(charset);
|
||||
disp = MimeHeaders_get(((MimeContainer *)child)->children[j]->headers, HEADER_CONTENT_TYPE, PR_FALSE, PR_FALSE);
|
||||
tmp->real_name = MimeHeaders_get_parameter(disp, "name", NULL, NULL);
|
||||
tmp->real_name = MimeHeaders_get_parameter(disp, "name", &charset, NULL);
|
||||
}
|
||||
|
||||
if (tmp->real_name)
|
||||
{
|
||||
// check encoded type
|
||||
//
|
||||
// The parameter of Content-Disposition must use RFC 2231.
|
||||
// But old Netscape 4.x and Outlook Express etc. use RFC2047.
|
||||
// So we should parse both types.
|
||||
|
||||
char *fname = NULL;
|
||||
fname = mime_decode_filename(tmp->real_name);
|
||||
fname = mime_decode_filename(tmp->real_name, charset);
|
||||
PR_FREEIF(charset);
|
||||
|
||||
if (fname && fname != tmp->real_name)
|
||||
{
|
||||
PR_Free(tmp->real_name);
|
||||
|
||||
Reference in New Issue
Block a user