part of the fix for #119360. LDIF export is lossy. In this case,

I forgot we have to base64 encode any lines that contain \r or \n.
For example, the "notes" field in a card.  Thanks to Rich Ibbotson
(ribbotso@rochester.rr.com) for the initial patch.
r=dmose, sr=bienvenu
This commit is contained in:
sspitzer%netscape.com 2002-05-04 18:03:51 +00:00
Родитель 5d2d6a5cd0
Коммит 0eafdbd017
2 изменённых файлов: 24 добавлений и 7 удалений

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

@ -1731,19 +1731,35 @@ nsresult nsAddressBook::AppendBasicLDIFForCard(nsIAbCard *aCard, nsAFlatCString
return rv;
}
PRBool nsAddressBook::IsSafeLDIFString(const PRUnichar *aStr)
{
// follow RFC 2849 to determine if something is safe "as is" for LDIF
if (aStr[0] == PRUnichar(' ') ||
aStr[0] == PRUnichar(':') ||
aStr[0] == PRUnichar('<'))
return PR_FALSE;
PRUint32 i;
PRUint32 len = nsCRT::strlen(aStr);
for (i=0; i<len; i++) {
// If string contains CR or LF, it is not safe for LDIF
// and MUST be base64 encoded
if ((aStr[i] == PRUnichar('\n')) ||
(aStr[i] == PRUnichar('\r')) ||
(!nsCRT::IsAscii(aStr[i])))
return PR_FALSE;
}
return PR_TRUE;
}
nsresult nsAddressBook::AppendProperty(const char *aProperty, const PRUnichar *aValue, nsAFlatCString &aResult)
{
NS_ENSURE_ARG_POINTER(aValue);
aResult += aProperty;
// follow RFC 2849 for when we MUST base64 encode
if (nsCRT::IsAscii(aValue) &&
aValue[0] != PRUnichar(' ') &&
aValue[0] != PRUnichar('\n') &&
aValue[0] != PRUnichar('\r') &&
aValue[0] != PRUnichar(':') &&
aValue[0] != PRUnichar('<')) {
// if the string is not safe "as is", base64 encode it
if (IsSafeLDIFString(aValue)) {
aResult += NS_LITERAL_CSTRING(": ") + NS_LossyConvertUCS2toASCII(aValue);
}
else {

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

@ -81,6 +81,7 @@ private:
nsresult AppendDNForCard(const char *aProperty, nsIAbCard *aCard, nsAFlatCString &aResult);
nsresult AppendBasicLDIFForCard(nsIAbCard *aCard, nsAFlatCString &aResult);
nsresult AppendProperty(const char *aProperty, const PRUnichar *aValue, nsAFlatCString &aResult);
PRBool IsSafeLDIFString(const PRUnichar *aStr);
};
#endif