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

📄 mimebodypart.java

📁 java Email you can use it to send email to others
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	} else {	    setDataHandler(new DataHandler(o, type));	}    }    /**     * Convenience method that sets the given String as this     * part's content, with a MIME type of "text/plain". If the     * string contains non US-ASCII characters, it will be encoded     * using the platform's default charset. The charset is also     * used to set the "charset" parameter. <p>     *     * Note that there may be a performance penalty if     * <code>text</code> is large, since this method may have     * to scan all the characters to determine what charset to     * use. <p>     *     * If the charset is already known, use the     * <code>setText</code> method that takes the charset parameter.     *     * @param	text	the text content to set     * @exception	MessagingException	if an error occurs     * @see	#setText(String text, String charset)     */    public void setText(String text) throws MessagingException {	setText(text, null);    }    /**     * Convenience method that sets the given String as this part's     * content, with a MIME type of "text/plain" and the specified     * charset. The given Unicode string will be charset-encoded     * using the specified charset. The charset is also used to set     * the "charset" parameter.     *     * @param	text	the text content to set     * @param	charset	the charset to use for the text     * @exception	MessagingException	if an error occurs     */    public void setText(String text, String charset)			throws MessagingException {	setText(this, text, charset, "plain");    }    /**     * Convenience method that sets the given String as this part's     * content, with a primary MIME type of "text" and the specified     * MIME subtype.  The given Unicode string will be charset-encoded     * using the specified charset. The charset is also used to set     * the "charset" parameter.     *     * @param	text	the text content to set     * @param	charset	the charset to use for the text     * @param	subtype	the MIME subtype to use (e.g., "html")     * @exception	MessagingException	if an error occurs     * @since	JavaMail 1.4     */    public void setText(String text, String charset, String subtype)                        throws MessagingException {	setText(this, text, charset, subtype);    }     /**     * This method sets the body part's content to a Multipart object.     *     * @param  mp      	The multipart object that is the Message's content     * @exception       IllegalWriteException if the underlying     *			implementation does not support modification of     *			existing values.     * @exception	IllegalStateException if this body part is     *			obtained from a READ_ONLY folder.     */    public void setContent(Multipart mp) throws MessagingException {	setDataHandler(new DataHandler(mp, mp.getContentType()));	mp.setParent(this);    }    /**     * Use the specified file to provide the data for this part.     * The simple file name is used as the file name for this     * part and the data in the file is used as the data for this     * part.  The encoding will be chosen appropriately for the     * file data.     *     * @param		file		the File object to attach     * @exception	IOException	errors related to accessing the file     * @exception	MessagingException	message related errors     * @since		JavaMail 1.4     */    public void attachFile(File file) throws IOException, MessagingException {    	FileDataSource fds = new FileDataSource(file);   	        this.setDataHandler(new DataHandler(fds));        this.setFileName(fds.getName());    }    /**     * Use the specified file to provide the data for this part.     * The simple file name is used as the file name for this     * part and the data in the file is used as the data for this     * part.  The encoding will be chosen appropriately for the     * file data.     *     * @param		file		the name of the file to attach     * @exception	IOException	errors related to accessing the file     * @exception	MessagingException	message related errors     * @since		JavaMail 1.4     */    public void attachFile(String file) throws IOException, MessagingException {    	File f = new File(file);    	attachFile(f);    }    /**     * Save the contents of this part in the specified file.  The content     * is decoded and saved, without any of the MIME headers.     *     * @param		file		the File object to write to     * @exception	IOException	errors related to accessing the file     * @exception	MessagingException	message related errors     * @since		JavaMail 1.4     */    public void saveFile(File file) throws IOException, MessagingException {    	OutputStream out = null;        InputStream in = null;        try {	    out = new BufferedOutputStream(new FileOutputStream(file));	    in = this.getInputStream();	    byte[] buf = new byte[8192];	    int len;	    while ((len = in.read(buf)) > 0)		out.write(buf, 0, len);         } finally {	    // close streams, but don't mask original exception, if any	    try {		if (in != null)		    in.close();	    } catch (IOException ex) { }	    try {		if (out != null)		    out.close();	    } catch (IOException ex) { }        }    }    /**     * Save the contents of this part in the specified file.  The content     * is decoded and saved, without any of the MIME headers.     *     * @param		file		the name of the file to write to     * @exception	IOException	errors related to accessing the file     * @exception	MessagingException	message related errors     * @since		JavaMail 1.4     */    public void saveFile(String file) throws IOException, MessagingException {    	File f = new File(file);    	saveFile(f);    }    /**     * Output the body part as an RFC 822 format stream.     *     * @exception MessagingException     * @exception IOException	if an error occurs writing to the     *				stream or if an error is generated     *				by the javax.activation layer.     * @see javax.activation.DataHandler#writeTo     */    public void writeTo(OutputStream os)				throws IOException, MessagingException {	writeTo(this, os, null);    }    /**     * Get all the headers for this header_name. Note that certain     * headers may be encoded as per RFC 2047 if they contain     * non US-ASCII characters and these should be decoded.     *     * @param   name    name of header     * @return  array of headers     * @see     javax.mail.internet.MimeUtility     */      public String[] getHeader(String name) throws MessagingException {	return headers.getHeader(name);    }    /**     * Get all the headers for this header name, returned as a single     * String, with headers separated by the delimiter. If the     * delimiter is <code>null</code>, only the first header is      * returned.     *     * @param name		the name of this header     * @param delimiter		delimiter between fields in returned string     * @return			the value fields for all headers with      *				this name     * @exception       	MessagingException     */    public String getHeader(String name, String delimiter)				throws MessagingException {	return headers.getHeader(name, delimiter);    }    /**     * Set the value for this header_name. Replaces all existing     * header values with this new value. Note that RFC 822 headers     * must contain only US-ASCII characters, so a header that     * contains non US-ASCII characters must be encoded as per the     * rules of RFC 2047.     *     * @param   name    header name     * @param   value   header value     * @see     javax.mail.internet.MimeUtility     */    public void setHeader(String name, String value)                                throws MessagingException {	headers.setHeader(name, value);    }     /**     * Add this value to the existing values for this header_name.     * Note that RFC 822 headers must contain only US-ASCII     * characters, so a header that contains non US-ASCII characters     * must be encoded as per the rules of RFC 2047.     *     * @param   name    header name     * @param   value   header value     * @see     javax.mail.internet.MimeUtility     */    public void addHeader(String name, String value)                                throws MessagingException {	headers.addHeader(name, value);        }    /**     * Remove all headers with this name.     */    public void removeHeader(String name) throws MessagingException {	headers.removeHeader(name);    }     /**     * Return all the headers from this Message as an Enumeration of     * Header objects.     */    public Enumeration getAllHeaders() throws MessagingException {	return headers.getAllHeaders();    }       /**     * Return matching headers from this Message as an Enumeration of     * Header objects. <p>     */    public Enumeration getMatchingHeaders(String[] names)                        throws MessagingException {	return headers.getMatchingHeaders(names);    }     /**     * Return non-matching headers from this Message as an     * Enumeration of Header objects.     */    public Enumeration getNonMatchingHeaders(String[] names)                        throws MessagingException {	return headers.getNonMatchingHeaders(names);    }          /**     * Add a header line to this body part     */    public void addHeaderLine(String line) throws MessagingException {	headers.addHeaderLine(line);    }         /**     * Get all header lines as an Enumeration of Strings. A Header     * line is a raw RFC 822 header line, containing both the "name"     * and "value" field.     */    public Enumeration getAllHeaderLines() throws MessagingException {  	return headers.getAllHeaderLines();     }     /**     * Get matching header lines as an Enumeration of Strings.     * A Header line is a raw RFC 822 header line, containing both     * the "name" and "value" field.     */    public Enumeration getMatchingHeaderLines(String[] names)                                    throws MessagingException {	return headers.getMatchingHeaderLines(names);    }     /**     * Get non-matching header lines as an Enumeration of Strings.     * A Header line is a raw RFC 822 header line, containing both     * the "name"  and "value" field.     */    public Enumeration getNonMatchingHeaderLines(String[] names)                                          throws MessagingException {	return headers.getNonMatchingHeaderLines(names);    }    /**     * Examine the content of this body part and update the appropriate     * MIME headers.  Typical headers that get set here are     * <code>Content-Type</code> and <code>Content-Transfer-Encoding</code>.     * Headers might need to be updated in two cases:     *     * <br>     * - A message being crafted by a mail application will certainly     * need to activate this method at some point to fill up its internal     * headers.     *     * <br>     * - A message read in from a Store will have obtained     * all its headers from the store, and so doesn't need this.     * However, if this message is editable and if any edits have     * been made to either the content or message structure, we might     * need to resync our headers.     *     * <br>     * In both cases this method is typically called by the     * <code>Message.saveChanges</code> method.     */    protected void updateHeaders() throws MessagingException {	updateHeaders(this);	/*	 * If we've cached a Multipart or Message object then	 * we're now committed to using this instance of the	 * object and we discard any stream data used to create	 * this object.	 */	if (cachedContent != null) {	    dh = new DataHandler(cachedContent, getContentType());	    cachedContent = null;	    content = null;	    if (contentStream != null) {		try {		    contentStream.close();		} catch (IOException ioex) { }	// nothing to do	    }	    contentStream = null;	}    }    /////////////////////////////////////////////////////////////    // Package private convenience methods to share code among //    // MimeMessage and MimeBodyPart                            //    /////////////////////////////////////////////////////////////    static boolean isMimeType(MimePart part, String mimeType)				throws MessagingException {

⌨️ 快捷键说明

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