1. /*
  2. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  3. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  4. */
  5. package javax.mail.internet;
  6. import javax.mail.*;
  7. import java.io.*;
  8. import java.util.Enumeration;
  9. /**
  10. * The MimePart interface models an <strong>Entity</strong> as defined
  11. * by MIME (RFC2045, Section 2.4). <p>
  12. *
  13. * MimePart extends the Part interface to add additional RFC822 and MIME
  14. * specific semantics and attributes. It provides the base interface for
  15. * the MimeMessage and MimeBodyPart classes
  16. *
  17. * <hr> <strong>A note on RFC822 and MIME headers</strong><p>
  18. *
  19. * RFC822 and MIME header fields <strong>must</strong> contain only
  20. * US-ASCII characters. If a header contains non US-ASCII characters,
  21. * it must be encoded as per the rules in RFC 2047. The MimeUtility
  22. * class provided in this package can be used to to achieve this.
  23. * Callers of the <code>setHeader</code>, <code>addHeader</code>, and
  24. * <code>addHeaderLine</code> methods are responsible for enforcing
  25. * the MIME requirements for the specified headers. In addition, these
  26. * header fields must be folded (wrapped) before being sent if they
  27. * exceed the line length limitation for the transport (1000 bytes for
  28. * SMTP). Received headers may have been folded. The application is
  29. * responsible for folding and unfolding headers as appropriate. <p>
  30. *
  31. * @see MimeUtility
  32. * @see javax.mail.Part
  33. * @author John Mani
  34. */
  35. public interface MimePart extends Part {
  36. /**
  37. * Get the values of all header fields available for this header,
  38. * returned as a single String, with the values separated by the
  39. * delimiter. If the delimiter is <code>null</code>, only the
  40. * first value is returned.
  41. *
  42. * @param header_name the name of this header
  43. * @return the value fields for all headers with
  44. * this name
  45. * @exception MessagingException
  46. */
  47. public String getHeader(String header_name, String delimiter)
  48. throws MessagingException;
  49. /**
  50. * Add a raw RFC822 header-line.
  51. * @exception IllegalWriteException if the underlying
  52. * implementation does not support modification
  53. * @exception IllegalStateException if this Part is
  54. * obtained from a READ_ONLY folder
  55. */
  56. public void addHeaderLine(String line) throws MessagingException;
  57. /**
  58. * Get all header lines as an Enumeration of Strings. A Header
  59. * line is a raw RFC822 header-line, containing both the "name"
  60. * and "value" field.
  61. */
  62. public Enumeration getAllHeaderLines() throws MessagingException;
  63. /**
  64. * Get matching header lines as an Enumeration of Strings.
  65. * A Header line is a raw RFC822 header-line, containing both
  66. * the "name" and "value" field.
  67. */
  68. public Enumeration getMatchingHeaderLines(String[] names)
  69. throws MessagingException;
  70. /**
  71. * Get non-matching header lines as an Enumeration of Strings.
  72. * A Header line is a raw RFC822 header-line, containing both
  73. * the "name" and "value" field.
  74. */
  75. public Enumeration getNonMatchingHeaderLines(String[] names)
  76. throws MessagingException;
  77. /**
  78. * Get the transfer encoding of this part.
  79. *
  80. * @return content-transfer-encoding
  81. * @exception MessagingException
  82. */
  83. public String getEncoding() throws MessagingException;
  84. /**
  85. * Get the Content-ID of this part. Returns null if none present.
  86. *
  87. * @return content-ID
  88. */
  89. public String getContentID() throws MessagingException;
  90. /**
  91. * Get the Content-MD5 digest of this part. Returns null if
  92. * none present.
  93. *
  94. * @return content-MD5
  95. */
  96. public String getContentMD5() throws MessagingException;
  97. /**
  98. * Set the Content-MD5 of this part.
  99. *
  100. * @param cid content-id
  101. * @exception IllegalWriteException if the underlying
  102. * implementation does not support modification
  103. * @exception IllegalStateException if this Part is
  104. * obtained from a READ_ONLY folder
  105. */
  106. public void setContentMD5(String md5) throws MessagingException;
  107. /**
  108. * Get the language tags specified in the Content-Language header
  109. * of this MimePart. The Content-Language header is defined by
  110. * RFC 1766. Returns <code>null</code> if this header is not
  111. * available.
  112. */
  113. public String[] getContentLanguage() throws MessagingException;
  114. /**
  115. * Set the Content-Language header of this MimePart. The
  116. * Content-Language header is defined by RFC1766.
  117. *
  118. * @param languages array of language tags
  119. * @exception IllegalWriteException if the underlying
  120. * implementation does not support modification
  121. * @exception IllegalStateException if this Part is
  122. * obtained from a READ_ONLY folder
  123. */
  124. public void setContentLanguage(String[] languages)
  125. throws MessagingException;
  126. /**
  127. * Convenience method that sets the given String as this
  128. * part's content, with a MIME type of "text/plain". If the
  129. * string contains non US-ASCII characters. it will be encoded
  130. * using the platform's default charset. The charset is also
  131. * used to set the "charset" parameter. <p>
  132. *
  133. * Note that there may be a performance penalty if
  134. * <code>text</code> is large, since this method may have
  135. * to scan all the characters to determine what charset to
  136. * use. <p>
  137. * If the charset is already known, use the
  138. * setText() version that takes the charset parameter.
  139. *
  140. * @see #setText(String text, String charset)
  141. */
  142. public void setText(String text) throws MessagingException;
  143. /**
  144. * Convenience method that sets the given String as this part's
  145. * content, with a MIME type of "text/plain" and the specified
  146. * charset. The given Unicode string will be charset-encoded
  147. * using the specified charset. The charset is also used to set
  148. * "charset" parameter.
  149. */
  150. public void setText(String text, String charset)
  151. throws MessagingException;
  152. }