⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mimemessage.java

📁 java Email you can use it to send email to others
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * @see		#headers     */    public String getSubject() throws MessagingException {	String rawvalue = getHeader("Subject", null);	if (rawvalue == null)	    return null;	try {	    return MimeUtility.decodeText(MimeUtility.unfold(rawvalue));	} catch (UnsupportedEncodingException ex) {	    return rawvalue;	}    }    /**     * Set the "Subject" header field. If the subject contains      * non US-ASCII characters, it will be encoded using the      * platform's default charset. If the subject contains only      * US-ASCII characters, no encoding is done and it is used      * as-is. If the subject is null, the existing "Subject" field     * is removed. <p>     *     * The application must ensure that the subject does not contain     * any line breaks. <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 	subject		The subject     * @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. An     * 			UnsupportedEncodingException may be included     *			in the exception chain if the charset     *			conversion fails.     */    public void setSubject(String subject) throws MessagingException {	setSubject(subject, null);    }    /**     * Set the "Subject" header field. If the subject contains non      * US-ASCII characters, it will be encoded using the specified     * charset. If the subject contains only US-ASCII characters, no      * encoding is done and it is used as-is. If the subject is null,      * the existing "Subject" header field is removed. <p>     *     * The application must ensure that the subject does not contain     * any line breaks. <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	subject		The subject     * @param	charset		The charset      * @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. An     * 				UnsupportedEncodingException may be included     *				in the exception chain if the charset     *				conversion fails.     */    public void setSubject(String subject, String charset)			throws MessagingException {	if (subject == null) {	    removeHeader("Subject");	} else {	    try {		setHeader("Subject", MimeUtility.fold(9,		    MimeUtility.encodeText(subject, charset, null)));	    } catch (UnsupportedEncodingException uex) {		throw new MessagingException("Encoding error", uex);	    }	}    }    /**     * Returns the value of the RFC 822 "Date" field. This is the date      * on which this message was sent. Returns null 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          The sent Date     * @exception	MessagingException     */    public Date getSentDate() throws MessagingException {	String s = getHeader("Date", null);	if (s != null) {	    try {		synchronized (mailDateFormat) {		    return mailDateFormat.parse(s);		}	    } catch (ParseException pex) {		return null;	    }	}		return null;    }    /**     * Set the RFC 822 "Date" header field. This is the date on which the     * creator of the message indicates that the message is complete     * and ready for delivery. If the date parameter is      * <code>null</code>, the existing "Date" field is removed.     *     * @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 setSentDate(Date d) throws MessagingException {	if (d == null)	    removeHeader("Date");	else {	    synchronized (mailDateFormat) {		setHeader("Date", mailDateFormat.format(d));	    }	}    }    /**     * Returns the Date on this message was received. Returns      * <code>null</code> if this date cannot be obtained. <p>     *     * Note that RFC 822 does not define a field for the received     * date. Hence only implementations that can provide this date     * need return a valid value. <p>     *     * This implementation returns <code>null</code>.     *     * @return          the date this message was received     * @exception	MessagingException     */    public Date getReceivedDate() throws MessagingException {	return null;	    }    /**     * Return the size of the content of this message in bytes.      * Return -1 if the size cannot be determined. <p>     *     * Note that this number may not be an exact measure of the     * content size and may or may not account for any transfer     * encoding of the content. <p>     *     * This implementation returns the size of the <code>content</code>     * array (if not null), or, if <code>contentStream</code> is not     * null, and the <code>available</code> method returns a positive     * number, it returns that number as the size.  Otherwise, it returns     * -1.     *     * @return          size of content in bytes     * @exception	MessagingException     */      public int getSize() throws MessagingException {	if (content != null)	    return content.length;	if (contentStream != null) {	    try {		int size = contentStream.available();		// only believe the size if it's greater than zero, since zero		// is the default returned by the InputStream class itself		if (size > 0)		    return size;	    } catch (IOException ex) {		// ignore it	    }	}	return -1;    }    /**     * Return the number of lines for the content of this message.     * Return -1 if this number cannot be determined. <p>     *     * Note that this number may not be an exact measure of the      * content length and may or may not account for any transfer      * encoding of the content. <p>     *     * This implementation returns -1.     *     * @return          number of lines in the content.     * @exception	MessagingException     */       public int getLineCount() throws MessagingException {	return -1;     }    /**     * Returns the value of the RFC 822 "Content-Type" header field.      * This represents the content-type of the content of this      * message. This value must not be null. If this field is      * unavailable, "text/plain" should be returned. <p>     *     * This implementation uses the <code>getHeader</code> method     * to obtain the requisite header field.     *     * @return          The ContentType of this part     * @exception	MessagingException     * @see             javax.activation.DataHandler     */    public String getContentType() throws MessagingException {	String s = getHeader("Content-Type", null);	if (s == null)	    return "text/plain";	return s;    }    /**     * Is this Part of the specified MIME type?  This method     * compares <strong>only the <code>primaryType</code> and      * <code>subType</code></strong>.     * The parameters of the content types are ignored. <p>     *     * For example, this method will return <code>true</code> when     * comparing a Part of content type <strong>"text/plain"</strong>     * with <strong>"text/plain; charset=foobar"</strong>. <p>     *     * If the <code>subType</code> of <code>mimeType</code> is the     * special character '*', then the subtype is ignored during the     * comparison.     */    public boolean isMimeType(String mimeType) throws MessagingException {	return MimeBodyPart.isMimeType(this, mimeType);    }    /**     * Returns the value of the "Content-Disposition" header field.     * This represents the disposition of this part. The disposition     * describes how the part should be presented to the user. <p>     *     * If the Content-Disposition field is unavailable,      * <code>null</code> is returned. <p>     *     * This implementation uses the <code>getHeader</code> method     * to obtain the requisite header field.     *     * @return          disposition of this part, or null if unknown     * @exception	MessagingException     */    public String getDisposition() throws MessagingException {	return MimeBodyPart.getDisposition(this);    }    /**     * Set the "Content-Disposition" header field of this Message.     * If <code>disposition</code> is null, any existing "Content-Disposition"     * header field is removed.     *     * @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 setDisposition(String disposition) throws MessagingException {	MimeBodyPart.setDisposition(this, disposition);    }    /**     * Returns the content transfer encoding from the     * "Content-Transfer-Encoding" header     * field. Returns <code>null</code> if the header is unavailable     * or its value is absent. <p>     *     * This implementation uses the <code>getHeader</code> method     * to obtain the requisite header field.     *     * @return          content-transfer-encoding     * @exception	MessagingException     */    public String getEncoding() throws MessagingException {	return MimeBodyPart.getEncoding(this);    }    /**     * Returns the value of the "Content-ID" header field. Returns     * <code>null</code> if the field is unavailable or its value is      * absent. <p>     *     * This implementation uses the <code>getHeader</code> method     * to obtain the requisite header field.     *     * @return          content-ID     * @exception	MessagingException     */    public String getContentID() throws MessagingException {	return getHeader("Content-Id", null);    }    /**     * Set the "Content-ID" header field of this Message.     * If the <code>cid</code> parameter is null, any existing      * "Content-ID" is removed.     *     * @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 setContentID(String cid) throws MessagingException {	if (cid == null)	    removeHeader("Content-ID");	else	    setHeader("Content-ID", cid);    }    /**     * Return the value of the "Content-MD5" header field. 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          content-MD5     * @exception	MessagingException     */    public String getContentMD5() throws MessagingException {	return getHeader("Content-MD5", null);    }    /**     * Set the "Content-MD5" header field of this Message.     *     * @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 setContentMD5(String md5) throws MessagingException {	setHeader("Content-MD5", md5);    }    /**     * Returns the "Content-Description" header field of this Message.     * This typically associates some descriptive information with      * this part. Returns null if this field is unavailable or its     * value is absent. <p>     *     * If the Content-Description field is encoded as per RFC 2047,     * it is decoded and converted into Unicode. If the decoding or      * conversion fails, the raw data is returned as-is <p>     *     * This implementation uses the <code>getHeader</code> method     * to obtain the requisite header field.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -