1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef _nsMsgI18N_H_ 7 #define _nsMsgI18N_H_ 8 9 #include "nscore.h" 10 #include "msgCore.h" 11 #include "nsString.h" 12 class nsIFile; 13 14 /** 15 * Encode an input string into RFC 2047 form. 16 * 17 * @param header [IN] A header to encode. 18 * @param structured [IN] Specify the header is structured or non-structured 19 * field (See RFC-822). 20 * @param charset [IN] Charset name to convert. 21 * @param fieldnamelen [IN] Header field name length. (e.g. "From: " -> 6) 22 * @param usemime [IN] If false then apply charset conversion only no MIME 23 * encoding. 24 * @return Encoded buffer (in C string) or NULL in case of error. 25 */ 26 NS_MSG_BASE char* nsMsgI18NEncodeMimePartIIStr(const char* header, 27 bool structured, 28 const char* charset, 29 int32_t fieldnamelen, 30 bool usemime); 31 32 /** 33 * Check if given charset is stateful (e.g. ISO-2022-JP). 34 * 35 * @param charset [IN] Charset name. 36 * @return True if stateful 37 */ 38 NS_MSG_BASE bool nsMsgI18Nstateful_charset(const char* charset); 39 40 /** 41 * Check if given charset is multibyte (e.g. Shift_JIS, Big5). 42 * 43 * @param charset [IN] Charset name. 44 * @return True if multibyte 45 */ 46 NS_MSG_BASE bool nsMsgI18Nmultibyte_charset(const char* charset); 47 48 /** 49 * Check the input (unicode) string is in a range of the given charset after the 50 * conversion. Note, do not use this for large string (e.g. message body) since 51 * this actually applies the conversion to the buffer. 52 * 53 * @param charset [IN] Charset to be converted. 54 * @param inString [IN] Input unicode string to be examined. 55 * @return True if the string can be converted within the charset range. 56 * False if one or more characters cannot be converted to the 57 * target charset. 58 */ 59 NS_MSG_BASE bool nsMsgI18Ncheck_data_in_charset_range(const char* charset, 60 const char16_t* inString); 61 /** 62 * Convert from unicode to target charset. 63 * 64 * @param charset [IN] Charset name. 65 * @param inString [IN] Unicode string to convert. 66 * @param outString [OUT] Converted output string. 67 * @param aReportUencNoMapping [IN] Set encoder to report (instead of using 68 * replacement char on errors). Set to true 69 * to receive NS_ERROR_UENC_NOMAPPING when 70 * that happens. Note that 71 * NS_ERROR_UENC_NOMAPPING is a success code! 72 * @return nsresult. 73 */ 74 NS_MSG_BASE nsresult nsMsgI18NConvertFromUnicode( 75 const nsACString& aCharset, const nsAString& inString, 76 nsACString& outString, bool reportUencNoMapping = false); 77 /** 78 * Convert from charset to unicode. 79 * 80 * @param charset [IN] Charset name. 81 * @param inString [IN] Input string to convert. 82 * @param outString [OUT] Output unicode string. 83 * @return nsresult. 84 */ 85 NS_MSG_BASE nsresult nsMsgI18NConvertToUnicode(const nsACString& aCharset, 86 const nsACString& inString, 87 nsAString& outString); 88 /** 89 * Parse for META charset. 90 * 91 * @param file [IN] A nsIFile. 92 * @return A charset name or empty string if not found. 93 */ 94 NS_MSG_BASE const char* nsMsgI18NParseMetaCharset(nsIFile* file); 95 96 /** 97 * Shrink the aStr to aMaxLength bytes. Note that this doesn't check whether 98 * the aUTF8Str is valid UTF-8 string. 99 * 100 * @param inString [IN] Input UTF-8 string (it must be valid UTF-8 string) 101 * @param aMaxLength [IN] Shrink to this length (it means bytes) 102 * @param outString [OUT] Shrunken UTF-8 string 103 * @return nsresult 104 */ 105 NS_MSG_BASE nsresult nsMsgI18NShrinkUTF8Str(const nsCString& inString, 106 uint32_t aMaxLength, 107 nsACString& outString); 108 109 /* 110 * Convert raw bytes in header to UTF-16 111 * 112 * @param inString [IN] Input raw octets 113 * @param outString [OUT] Output UTF-16 string 114 */ 115 NS_MSG_BASE void nsMsgI18NConvertRawBytesToUTF16(const nsCString& inString, 116 const nsACString& charset, 117 nsAString& outString); 118 119 /* 120 * Convert raw bytes in header to UTF-8 121 * 122 * @param inString [IN] Input raw octets 123 * @param outString [OUT] Output UTF-8 string 124 */ 125 NS_MSG_BASE void nsMsgI18NConvertRawBytesToUTF8(const nsCString& inString, 126 const nsACString& charset, 127 nsACString& outString); 128 129 // Decode UTF-7 to UTF-16. No encoding supported. 130 NS_MSG_BASE nsresult CopyUTF7toUTF16(const nsACString& aSrc, nsAString& aDest); 131 132 // Convert between UTF-16 and modified UTF-7 used for IMAP. 133 NS_MSG_BASE nsresult CopyFolderNameToUTF16(const nsACString& aSrc, 134 nsAString& aDest); 135 NS_MSG_BASE nsresult CopyUTF16toMUTF7(const nsAString& aSrc, nsACString& aDest); 136 NS_MSG_BASE nsresult CopyMUTF7toUTF16(const nsACString& aSrc, nsAString& aDest); 137 138 #endif /* _nsMsgI18N_H_ */ 139