Interface change for the conversion utils and changes for mime encoder.

This commit is contained in:
nhotta%netscape.com 1999-04-01 20:04:51 +00:00
Родитель 3dab96e1be
Коммит 77e1993e15
2 изменённых файлов: 60 добавлений и 64 удалений

Просмотреть файл

@ -420,7 +420,6 @@ char * intlmime_encode_mail_address(char *name, const char *src,
int iThreshold; /* how many bytes we can convert from the src */ int iThreshold; /* how many bytes we can convert from the src */
int iEffectLen; /* the maximum length we can convert from the src */ int iEffectLen; /* the maximum length we can convert from the src */
PRBool bChop = PR_FALSE; PRBool bChop = PR_FALSE;
PRBool is_being_used_in_email_summary_file = (maxLineLen > 120);
CCCFunc cvtfunc = NULL; CCCFunc cvtfunc = NULL;
if (obj) if (obj)
@ -463,62 +462,58 @@ char * intlmime_encode_mail_address(char *name, const char *src,
retbuflen = PL_strlen(retbuf); retbuflen = PL_strlen(retbuf);
end = NULL; end = NULL;
//naoki: I think this check is not needed for iso-2022-jp because it will be B encoded.
if (stateful_encoding((const char *) name) || is_being_used_in_email_summary_file) {
} else {
/* scan for separator, conversion happens on 8bit /* scan for separator, conversion happens on 8bit
word between separators word between separators
we need to exclude RFC822 special characters from encoded word
regardless of the encoding method ('B' or 'Q').
*/ */
if (IS_MAIL_SEPARATOR(begin)) if (IS_MAIL_SEPARATOR(begin))
{ /* skip white spaces and separator */ { /* skip white spaces and separator */
q = begin; q = begin;
while ( IS_MAIL_SEPARATOR(q) ) while ( IS_MAIL_SEPARATOR(q) )
q ++ ; q ++ ;
sep = *(q - 1); sep = *(q - 1);
sep_p = (q - 1); sep_p = (q - 1);
*(q - 1) = '\0'; *(q - 1) = '\0';
end = q - 1; end = q - 1;
} }
else else
{
sep = '\0';
/* scan for next separator */
non_ascii = PR_FALSE;
for (q = begin; *q;)
{ {
sep = '\0'; if ((unsigned char) *q > 0x7F)
/* scan for next separator */ non_ascii = PR_TRUE;
non_ascii = PR_FALSE; if ( IS_MAIL_SEPARATOR(q) )
for (q = begin; *q;)
{ {
if ((unsigned char) *q > 0x7F) if ((*q == ' ') && (non_ascii == PR_TRUE))
non_ascii = PR_TRUE;
if ( IS_MAIL_SEPARATOR(q) )
{ {
if ((*q == ' ') && (non_ascii == PR_TRUE)) while ((p = intlmime_encode_next8bitword(wincsid, q)) != NULL)
{ {
while ((p = intlmime_encode_next8bitword(wincsid, q)) != NULL) if (p == NULL)
{ break;
if (p == NULL) q = p;
break; if (*p != ' ')
q = p; break;
if (*p != ' ')
break;
}
} }
sep = *q;
sep_p = q;
*q = '\0';
end = q;
break;
} }
q = INTL_NextChar(wincsid, q); sep = *q;
sep_p = q;
*q = '\0';
end = q;
break;
} }
q = INTL_NextChar(wincsid, q);
} }
} }
/* get the to_be_converted_buffer's len */ /* get the to_be_converted_buffer's len */
len = PL_strlen(begin); len = PL_strlen(begin);
//naoki: I changed the code to skip this for iso-2022-jp. if ( !intlmime_only_ascii_str(begin) )
// TODO: However, this part also dealing with a truncation. The code should be rewritten in order to
// do the truncation correctly.
if ( stateful_encoding((const char *) name) || !intlmime_only_ascii_str(begin) )
{ {
if (obj && cvtfunc) if (obj && cvtfunc)
{ {
@ -582,8 +577,8 @@ char * intlmime_encode_mail_address(char *name, const char *src,
*/ */
bChop = PR_TRUE; /* append CRLFTAB */ bChop = PR_TRUE; /* append CRLFTAB */
if (buf1 && (buf1 != begin)){ if (buf1 && (buf1 != begin)){
PR_Free(buf1); PR_Free(buf1);
buf1 = NULL; buf1 = NULL;
} }
} else { } else {
end = begin + len - 1; end = begin + len - 1;
@ -608,9 +603,9 @@ char * intlmime_encode_mail_address(char *name, const char *src,
buf1 = (char *) PR_Malloc(len + 1); buf1 = (char *) PR_Malloc(len + 1);
if (!buf1) if (!buf1)
{ {
PR_Free(srcbuf); PR_Free(srcbuf);
PR_Free(retbuf); PR_Free(retbuf);
return NULL; return NULL;
} }
XP_MEMCPY(buf1, begin, len); XP_MEMCPY(buf1, begin, len);
*(buf1 + len) = '\0'; *(buf1 + len) = '\0';
@ -1382,22 +1377,26 @@ encodedWordSize);
} }
PRUint32 MIME_ConvertCharset(const char* from_charset, const char* to_charset, PRUint32 MIME_ConvertCharset(const char* from_charset, const char* to_charset,
const char* inBuffer, const PRInt32 inLength, const char* inCstring, char** outCstring)
char** outBuffer)
{ {
return INTL_ConvertCharset(from_charset, to_charset, inBuffer, inLength, outBuffer); // optimization for the special case
if (!PL_strcasecmp(from_charset, "us-ascii") && !PL_strcasecmp(from_charset, "utf-8")) {
*outCstring = PL_strdup(inCstring);
return 0;
}
return INTL_ConvertCharset(from_charset, to_charset, inCstring, PL_strlen(inCstring), outCstring);
} }
PRUint32 MIME_ConvertToUnicode(const char* from_charset, const char* aBuffer, const PRInt32 aLength, PRUint32 MIME_ConvertToUnicode(const char* from_charset, const char* inCstring,
void** uniBuffer, PRInt32* uniLength) void** uniBuffer, PRInt32* uniLength)
{ {
return INTL_ConvertToUnicode(from_charset, aBuffer, aLength, uniBuffer, uniLength); return INTL_ConvertToUnicode(from_charset, inCstring, PL_strlen(inCstring), uniBuffer, uniLength);
} }
PRUint32 MIME_ConvertFromUnicode(const char* to_charset, const void* uniBuffer, const PRInt32 uniLength, PRUint32 MIME_ConvertFromUnicode(const char* to_charset, const void* uniBuffer, const PRInt32 uniLength,
char** aBuffer) char** outCstring)
{ {
return INTL_ConvertFromUnicode(to_charset, uniBuffer, uniLength, aBuffer); return INTL_ConvertFromUnicode(to_charset, uniBuffer, uniLength, outCstring);
} }
extern "C" char *MIME_DecodeMimePartIIStr(const char *header, char *charset) extern "C" char *MIME_DecodeMimePartIIStr(const char *header, char *charset)

Просмотреть файл

@ -22,7 +22,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
#ifndef kMIME_ENCODED_WORD_SIZE #ifndef kMIME_ENCODED_WORD_SIZE
#define kMIME_ENCODED_WORD_SIZE 72 #define kMIME_ENCODED_WORD_SIZE 75
#endif #endif
#ifndef kMAX_CSNAME #ifndef kMAX_CSNAME
@ -64,27 +64,24 @@ char *MIME_EncodeMimePartIIStr(const char *header, const char* mailCharset, cons
* *
* @param from_charset[IN] A charset name in C string. * @param from_charset[IN] A charset name in C string.
* @param to_charset [IN] A charset name in C string. * @param to_charset [IN] A charset name in C string.
* @param inBuffer [IN] Input buffer to convert. * @param inCstring [IN] Input buffer (in C string) to convert.
* @param inLength [IN] Input buffer length. * @param outCstring [OUT] Converted buffer (in C string) is set. Allocated buffer should be freed by PR_FREE.
* @param outBuffer [OUT] Converted buffer (in C string) is set. Allocated buffer should be freed by PR_FREE.
* @return nsresult, 0 is success, otherwise error. * @return nsresult, 0 is success, otherwise error.
*/ */
PRUint32 MIME_ConvertCharset(const char* from_charset, const char* to_charset, PRUint32 MIME_ConvertCharset(const char* from_charset, const char* to_charset,
const char* inBuffer, const PRInt32 inLength, const char* inCstring, char** outCstring);
char** outBuffer);
/** /**
* Convert an input buffer with a charset into unicode. * Convert an input buffer with a charset into unicode.
* *
* *
* @param from_charset [IN] A charset name in C string. * @param from_charset [IN] A charset name in C string.
* @param aBuffer [IN] Input buffer to convert. * @param inCstring [IN] Input buffer (in C string) to convert.
* @param aLength [IN] Input buffer length.
* @param uniBuffer [OUT] Output unicode buffer is set. Allocated buffer should be freed by PR_FREE. * @param uniBuffer [OUT] Output unicode buffer is set. Allocated buffer should be freed by PR_FREE.
* @param uniLength [OUT] Output unicode buffer character length is set. * @param uniLength [OUT] Output unicode buffer character length is set.
* @return nsresult, 0 is success, otherwise error. * @return nsresult, 0 is success, otherwise error.
*/ */
PRUint32 MIME_ConvertToUnicode(const char* from_charset, const char* aBuffer, const PRInt32 aLength, PRUint32 MIME_ConvertToUnicode(const char* from_charset, const char* inCstring,
void** uniBuffer, PRInt32* uniLength); void** uniBuffer, PRInt32* uniLength);
/** /**
@ -94,11 +91,11 @@ PRUint32 MIME_ConvertToUnicode(const char* from_charset, const char* aBuffer, co
* @param to_charset [IN] A charset name in C string. * @param to_charset [IN] A charset name in C string.
* @param uniBuffer [IN] Input unicode buffer to convert. * @param uniBuffer [IN] Input unicode buffer to convert.
* @param uniLength [IN] Input unicode buffer character length. * @param uniLength [IN] Input unicode buffer character length.
* @param aBuffer [OUT] Output buffer (in C string) is set. Allocated buffer should be freed by PR_FREE. * @param outCstring [OUT] Output buffer (in C string) is set. Allocated buffer should be freed by PR_FREE.
* @return nsresult, 0 is success, otherwise error. * @return nsresult, 0 is success, otherwise error.
*/ */
PRUint32 MIME_ConvertFromUnicode(const char* to_charset, const void* uniBuffer, const PRInt32 uniLength, PRUint32 MIME_ConvertFromUnicode(const char* to_charset, const void* uniBuffer, const PRInt32 uniLength,
char** aBuffer); char** outCstring);
/* /*