📄 mimemessage.java
字号:
* * @return content-description * @exception MessagingException */ public String getDescription() throws MessagingException { return MimeBodyPart.getDescription(this); } /** * Set the "Content-Description" header field for this Message. * If the description parameter is <code>null</code>, then any * existing "Content-Description" fields are removed. <p> * * If the description contains non US-ASCII characters, it will * be encoded using the platform's default charset. If the * description contains only US-ASCII characters, no encoding * is done and it is used as-is. <p> * * Note that if the charset encoding process fails, a * MessagingException is thrown, and an UnsupportedEncodingException * is included in the chain of nested exceptions within the * MessagingException. * * @param description content-description * @exception IllegalWriteException if the underlying * implementation does not support modification * @exception IllegalStateException if this message is * obtained from a READ_ONLY folder. * @exception MessagingException. An * UnsupportedEncodingException may be included * in the exception chain if the charset * conversion fails. */ public void setDescription(String description) throws MessagingException { setDescription(description, null); } /** * Set the "Content-Description" header field for this Message. * If the description parameter is <code>null</code>, then any * existing "Content-Description" fields are removed. <p> * * If the description contains non US-ASCII characters, it will * be encoded using the specified charset. If the description * contains only US-ASCII characters, no encoding is done and * it is used as-is. <p> * * Note that if the charset encoding process fails, a * MessagingException is thrown, and an UnsupportedEncodingException * is included in the chain of nested exceptions within the * MessagingException. * * @param description Description * @param charset Charset for encoding * @exception IllegalWriteException if the underlying * implementation does not support modification * @exception IllegalStateException if this message is * obtained from a READ_ONLY folder. * @exception MessagingException. An * UnsupportedEncodingException may be included * in the exception chain if the charset * conversion fails. */ public void setDescription(String description, String charset) throws MessagingException { MimeBodyPart.setDescription(this, description, charset); } /** * Get the languages specified in the "Content-Language" header * field of this message. The Content-Language header is defined by * RFC 1766. Returns <code>null</code> if this field is unavailable * or its value is absent. <p> * * This implementation uses the <code>getHeader</code> method * to obtain the requisite header field. * * @return value of content-language header. * @exception MessagingException */ public String[] getContentLanguage() throws MessagingException { return MimeBodyPart.getContentLanguage(this); } /** * Set the "Content-Language" header of this MimePart. The * Content-Language header is defined by RFC 1766. * * @param languages array of language tags * @exception IllegalWriteException if the underlying * implementation does not support modification * @exception IllegalStateException if this message is * obtained from a READ_ONLY folder. * @exception MessagingException */ public void setContentLanguage(String[] languages) throws MessagingException { MimeBodyPart.setContentLanguage(this, languages); } /** * Returns the value of the "Message-ID" header field. Returns * null if this field is unavailable or its value is absent. <p> * * The default implementation provided here uses the * <code>getHeader</code> method to return the value of the * "Message-ID" field. * * @return Message-ID * @exception MessagingException if the retrieval of this field * causes any exception. * @see javax.mail.search.MessageIDTerm * @since JavaMail 1.1 */ public String getMessageID() throws MessagingException { return getHeader("Message-ID", null); } /** * Get the filename associated with this Message. <p> * * Returns the value of the "filename" parameter from the * "Content-Disposition" header field of this message. If it's * not available, returns the value of the "name" parameter from * the "Content-Type" header field of this BodyPart. * Returns <code>null</code> if both are absent. <p> * * If the <code>mail.mime.encodefilename</code> System property * is set to true, the {@link MimeUtility#decodeText * MimeUtility.decodeText} method will be used to decode the * filename. While such encoding is not supported by the MIME * spec, many mailers use this technique to support non-ASCII * characters in filenames. The default value of this property * is false. * * @return filename * @exception MessagingException */ public String getFileName() throws MessagingException { return MimeBodyPart.getFileName(this); } /** * Set the filename associated with this part, if possible. <p> * * Sets the "filename" parameter of the "Content-Disposition" * header field of this message. <p> * * If the <code>mail.mime.encodefilename</code> System property * is set to true, the {@link MimeUtility#encodeText * MimeUtility.encodeText} method will be used to encode the * filename. While such encoding is not supported by the MIME * spec, many mailers use this technique to support non-ASCII * characters in filenames. The default value of this property * is false. * * @exception IllegalWriteException if the underlying * implementation does not support modification * @exception IllegalStateException if this message is * obtained from a READ_ONLY folder. * @exception MessagingException */ public void setFileName(String filename) throws MessagingException { MimeBodyPart.setFileName(this, filename); } private String getHeaderName(Message.RecipientType type) throws MessagingException { String headerName; if (type == Message.RecipientType.TO) headerName = "To"; else if (type == Message.RecipientType.CC) headerName = "Cc"; else if (type == Message.RecipientType.BCC) headerName = "Bcc"; else if (type == MimeMessage.RecipientType.NEWSGROUPS) headerName = "Newsgroups"; else throw new MessagingException("Invalid Recipient Type"); return headerName; } /** * Return a decoded input stream for this Message's "content". <p> * * This implementation obtains the input stream from the DataHandler, * that is, it invokes <code>getDataHandler().getInputStream()</code>. * * @return an InputStream * @exception MessagingException * @exception IOException this is typically thrown by the * DataHandler. Refer to the documentation for * javax.activation.DataHandler for more details. * * @see #getContentStream * @see javax.activation.DataHandler#getInputStream */ public InputStream getInputStream() throws IOException, MessagingException { return getDataHandler().getInputStream(); } /** * Produce the raw bytes of the content. This method is used during * parsing, to create a DataHandler object for the content. Subclasses * that can provide a separate input stream for just the message * content might want to override this method. <p> * * This implementation returns a SharedInputStream, if * <code>contentStream</code> is not null. Otherwise, it * returns a ByteArrayInputStream constructed * out of the <code>content</code> byte array. * * @see #content */ protected InputStream getContentStream() throws MessagingException { if (contentStream != null) return ((SharedInputStream)contentStream).newStream(0, -1); if (content != null) return new SharedByteArrayInputStream(content); throw new MessagingException("No content"); } /** * Return an InputStream to the raw data with any Content-Transfer-Encoding * intact. This method is useful if the "Content-Transfer-Encoding" * header is incorrect or corrupt, which would prevent the * <code>getInputStream</code> method or <code>getContent</code> method * from returning the correct data. In such a case the application may * use this method and attempt to decode the raw data itself. <p> * * This implementation simply calls the <code>getContentStream</code> * method. * * @see #getInputStream * @see #getContentStream * @since JavaMail 1.2 */ public InputStream getRawInputStream() throws MessagingException { return getContentStream(); } /** * Return a DataHandler for this Message's content. <p> * * The implementation provided here works as follows. Note the use of * the <code>getContentStream</code> method to * generate the byte stream for the content. Also note that * any transfer-decoding is done automatically within this method.<p> * * <blockquote><pre> * getDataHandler() { * if (dh == null) { * dh = new DataHandler(new MimePartDataSource(this)); * } * return dh; * } * <p> * class MimePartDataSource implements DataSource { * public getInputStream() { * return MimeUtility.decode( * getContentStream(), getEncoding()); * } * * .... <other DataSource methods> * } * </pre></blockquote><p> * * @exception MessagingException */ public synchronized DataHandler getDataHandler() throws MessagingException { if (dh == null) dh = new DataHandler(new MimePartDataSource(this)); return dh; } /** * Return the content as a Java object. The type of this * object is dependent on the content itself. For * example, the native format of a "text/plain" content * is usually a String object. The native format for a "multipart" * message is always a Multipart subclass. For content types that are * unknown to the DataHandler system, an input stream is returned * as the content. <p> * * This implementation obtains the content from the DataHandler, * that is, it invokes <code>getDataHandler().getContent()</code>. * If the content is a Multipart or Message object and was created by * parsing a stream, the object is cached and returned in subsequent * calls so that modifications to the content will not be lost. * * @return Object * @see javax.mail.Part * @see javax.activation.DataHandler#getContent * @exception MessagingException * @exception IOException this is typically thrown by the * DataHandler. Refer to the documentation for * javax.activation.DataHandler for more details. */ public Object getContent() throws IOException, MessagingException { if (cachedContent != null) return cachedContent; Object c; try { c = getDataHandler().getContent(); } catch (FolderClosedIOException fex) { throw new FolderClosedException(fex.getFolder(), fex.getMessage()); } catch (MessageRemovedIOException mex) { throw new MessageRemovedException(mex.getMessage()); } if (MimeBodyPart.cacheMultipart && (c instanceof Multipart || c instanceof Message) && (content != null || contentStream != null)) { cachedContent = c; } return c; } /** * This method provides the mechanism to set this part's content. * The given DataHandler object should wrap the actual content. * * @param dh The DataHandler for the content. * @exception IllegalWriteException if the underlying * implementation does not support modification * @exception IllegalStateException if this message is * obtained from a READ_ONLY folder. * @exception MessagingException */ public synchronized void setDataHandler(DataHandler dh) throws MessagingException { this.dh = dh; cachedContent = null; MimeBodyPart.invalidateContentHeaders(this); } /** * A convenience method for setting this Message's content. <p> * * The content is wrapped in a DataHandler object. Note that a * DataContentHandler class for the specified type should be * available to the JavaMail implementation for this to work right. * i.e., to do <code>setContent(foobar, "application/x-foobar")</code>, * a DataContentHandler for "application/x-foobar" should be installed. * Refer to the Java Activation Framework for more information. * * @param o the content object * @param type Mime type of the object * @exception IllegalWriteException if the underlying * implementation does not support modification of * existing values * @exception IllegalStateException if this message is * obtained from a READ_ONLY folder. * @exception MessagingException */ public void setContent(Object o, String type) throws MessagingException { if (o instanceof Multipart) setContent((Multipart)o);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -