nsIMIMEHeaderParam.idl 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* vim:expandtab:shiftwidth=4:tabstop=4:
  3. */
  4. /* This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  7. /*
  8. * This interface allows any module to access the routine
  9. * for MIME header parameter parsing (RFC 2231/5987)
  10. */
  11. #include "nsISupports.idl"
  12. [scriptable, uuid(9c9252a1-fdaf-40a2-9c2b-a3dc45e28dde)]
  13. interface nsIMIMEHeaderParam : nsISupports {
  14. /**
  15. * Given the value of a single header field (such as
  16. * Content-Disposition and Content-Type) and the name of a parameter
  17. * (e.g. filename, name, charset), returns the value of the parameter.
  18. * The value is obtained by decoding RFC 2231/5987-style encoding,
  19. * RFC 2047-style encoding, and converting to UniChar(UTF-16)
  20. * from charset specified in RFC 2231/2047 encoding, UTF-8,
  21. * <code>aFallbackCharset</code>, the locale charset as fallback if
  22. * <code>TryLocaleCharset</code> is set, and null-padding as last resort
  23. * if all else fails.
  24. *
  25. * <p>
  26. * This method internally invokes <code>getParameterInternal</code>,
  27. * However, it does not stop at decoding RFC 2231 (the task for
  28. * <code>getParameterInternal</code> but tries to cope
  29. * with several non-standard-compliant cases mentioned below.
  30. *
  31. * <p>
  32. * Note that a lot of MUAs put RFC 2047-encoded parameters. Unfortunately,
  33. * this includes Mozilla as of 2003-05-30. Even more standard-ignorant MUAs,
  34. * web servers and application servers put 'raw 8bit characters'. This will
  35. * try to cope with all these cases as gracefully as possible. Additionally,
  36. * it returns the language tag if the parameter is encoded per RFC 2231 and
  37. * includes lang.
  38. *
  39. * <p>
  40. * Note that GetParameterHTTP skips some of the workarounds used for
  41. * mail (MIME) header fields, and thus SHOULD be used from non-mail
  42. * code.
  43. *
  44. *
  45. * @param aHeaderVal a header string to get the value of a parameter
  46. * from.
  47. * @param aParamName the name of a MIME header parameter (e.g.
  48. * filename, name, charset). If empty, returns
  49. * the first (possibly) _unnamed_ 'parameter'.
  50. * @param aFallbackCharset fallback charset to try if the string after
  51. * RFC 2231/2047 decoding or the raw 8bit
  52. * string is not UTF-8
  53. * @param aTryLocaleCharset If set, makes yet another attempt
  54. * with the locale charset.
  55. * @param aLang If non-null, assigns it to a pointer
  56. * to a string containing the value of language
  57. * obtained from RFC 2231 parsing. Caller has to
  58. * free it.
  59. * @return the value of <code>aParamName</code> in Unichar(UTF-16).
  60. */
  61. AString getParameter(in ACString aHeaderVal,
  62. in string aParamName,
  63. in ACString aFallbackCharset,
  64. in boolean aTryLocaleCharset,
  65. out string aLang);
  66. /**
  67. * Like getParameter, but disabling encodings and workarounds specific to
  68. * MIME (as opposed to HTTP).
  69. */
  70. AString getParameterHTTP(in ACString aHeaderVal,
  71. in string aParamName,
  72. in ACString aFallbackCharset,
  73. in boolean aTryLocaleCharset,
  74. out string aLang);
  75. /**
  76. * Given the value of a header field parameter using the encoding
  77. * defined in RFC 5987, decode the value into a Unicode string, and extract
  78. * the optional language parameter.
  79. *
  80. * <p>
  81. * This function is purposefully picky; it will abort for all (most?)
  82. * invalid inputs. This is by design. In particular, it does not support
  83. * any character encodings other than UTF-8, in order not to promote
  84. * non-interoperable usage.
  85. *
  86. * <p>
  87. * Code that parses HTTP header fields (as opposed to MIME header fields)
  88. * should use this function.
  89. *
  90. * @param aParamVal a header field parameter to decode.
  91. * @param aLang will be set to the language part (possibly
  92. * empty).
  93. * @return the decoded parameter value.
  94. */
  95. AString decodeRFC5987Param(in ACString aParamVal,
  96. out ACString aLang);
  97. /**
  98. * Given the value of a single header field (such as
  99. * Content-Disposition and Content-Type) and the name of a parameter
  100. * (e.g. filename, name, charset), returns the value of the parameter
  101. * after decoding RFC 2231-style encoding.
  102. * <p>
  103. * For <strong>internal use only</strong>. The only other place where
  104. * this needs to be invoked is |MimeHeaders_get_parameter| in
  105. * mailnews/mime/src/mimehdrs.cpp defined as
  106. * char * MimeHeaders_get_parameter (const char *header_value,
  107. * const char *parm_name,
  108. * char **charset, char **language)
  109. *
  110. * Otherwise, this method would have been made static.
  111. *
  112. * @param aHeaderVal a header string to get the value of a parameter from.
  113. * @param aParamName the name of a MIME header parameter (e.g.
  114. * filename, name, charset). If empty, returns
  115. * the first (possibly) _unnamed_ 'parameter'.
  116. * @param aCharset If non-null, it gets assigned a new pointer
  117. * to a string containing the value of charset obtained
  118. * from RFC 2231 parsing. Caller has to free it.
  119. * @param aLang If non-null, it gets assigned a new pointer
  120. * to a string containing the value of language obtained
  121. * from RFC 2231 parsing. Caller has to free it.
  122. * @return the value of <code>aParamName</code> after
  123. * RFC 2231 decoding but without charset conversion.
  124. */
  125. [noscript]
  126. string getParameterInternal(in string aHeaderVal,
  127. in string aParamName,
  128. out string aCharset,
  129. out string aLang);
  130. /**
  131. * Given a header value, decodes RFC 2047-style encoding and
  132. * returns the decoded header value in UTF-8 if either it's
  133. * RFC-2047-encoded or aDefaultCharset is given. Otherwise,
  134. * returns the input header value (in whatever encoding)
  135. * as it is except that RFC 822 (using backslash) quotation and
  136. * CRLF (if aEatContinuation is set) are stripped away
  137. * <p>
  138. * For internal use only. The only other place where this needs to be
  139. * invoked is <code>MIME_DecodeMimeHeader</code> in
  140. * mailnews/mime/src/mimehdrs.cpp defined as
  141. * char * Mime_DecodeMimeHeader(char *header_val, const char *charset,
  142. * bool override, bool eatcontinuation)
  143. *
  144. * @param aHeaderVal a header value to decode
  145. * @param aDefaultCharset MIME charset to use in place of MIME charset
  146. * specified in RFC 2047 style encoding
  147. * when <code>aOverrideCharset</code> is set.
  148. * @param aOverrideCharset When set, overrides MIME charset specified
  149. * in RFC 2047 style encoding with <code>aDefaultCharset</code>
  150. * @param aEatContinuation When set, removes CR/LF
  151. * @return decoded header value
  152. */
  153. [noscript]
  154. ACString decodeRFC2047Header(in string aHeaderVal,
  155. in string aDefaultCharset,
  156. in boolean aOverrideCharset,
  157. in boolean aEatContinuation);
  158. /**
  159. * Given a header parameter, decodes RFC 2047 style encoding (if it's
  160. * not obtained from RFC 2231 encoding), converts it to
  161. * UTF-8 and returns the result in UTF-8 if an attempt to extract
  162. * charset info. from a few different sources succeeds.
  163. * Otherwise, returns the input header value (in whatever encoding)
  164. * as it is except that RFC 822 (using backslash) quotation is
  165. * stripped off.
  166. * <p>
  167. * For internal use only. The only other place where this needs to be
  168. * invoked is <code>mime_decode_filename</code> in
  169. * mailnews/mime/src/mimehdrs.cpp defined as
  170. * char * mime_decode_filename(char *name, const char *charset,
  171. * MimeDisplayOptions *opt)
  172. *
  173. * @param aParamValue the value of a parameter to decode and convert
  174. * @param aCharset charset obtained from RFC 2231 decoding in which
  175. * <code>aParamValue</code> is encoded. If null,
  176. * indicates that it needs to try RFC 2047, instead.
  177. * @param aDefaultCharset MIME charset to use when aCharset is null and
  178. * cannot be obtained per RFC 2047 (most likely
  179. * because 'bare' string is used.) Besides, it
  180. * overrides aCharset/MIME charset obtained from
  181. * RFC 2047 if <code>aOverrideCharset</code> is set.
  182. * @param aOverrideCharset When set, overrides MIME charset specified
  183. * in RFC 2047 style encoding with
  184. * <code>aDefaultCharset</code>
  185. * @return decoded parameter
  186. */
  187. [noscript]
  188. ACString decodeParameter(in ACString aParamValue,
  189. in string aCharset,
  190. in string aDefaultCharset,
  191. in boolean aOverrideCharset);
  192. };