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

📄 mailimpl.java

📁 java mail,java mailjava mailjava mailjava mail
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        return recipients;    }    /**     * Get the sender of this MailImpl.     *     * @return the sender of this MailImpl     */    public MailAddress getSender() {        return sender;    }    /**     * Get the state of this MailImpl.     *     * @return the state of this MailImpl     */    public String getState() {        return state;    }    /**     * Get the remote host associated with this MailImpl.     *     * @return the remote host associated with this MailImpl     */    public String getRemoteHost() {        return remoteHost;    }    /**     * Get the remote address associated with this MailImpl.     *     * @return the remote address associated with this MailImpl     */    public String getRemoteAddr() {        return remoteAddr;    }    /**     * Get the last updated time for this MailImpl.     *     * @return the last updated time for this MailImpl     */    public Date getLastUpdated() {        return lastUpdated;    }        /**     * <p>Return the size of the message including its headers.     * MimeMessage.getSize() method only returns the size of the     * message body.</p>     *     * <p>Note: this size is not guaranteed to be accurate - see Sun's     * documentation of MimeMessage.getSize().</p>     *     * @return approximate size of full message including headers.     *     * @throws MessagingException if a problem occurs while computing the message size     */    public long getMessageSize() throws MessagingException {        return MimeMessageUtil.getMessageSize(message);    }        /**     * Set the error message associated with this MailImpl.     *     * @param msg the new error message associated with this MailImpl     */    public void setErrorMessage(String msg) {        this.errorMessage = msg;    }    /**     * Set the MimeMessage associated with this MailImpl.     *     * @param message the new MimeMessage associated with this MailImpl     */    public void setMessage(MimeMessage message) {        if (this.message != message) {            // If a setMessage is called on a Mail that already have a message            // (discouraged) we have to make sure that the message we remove is            // correctly unreferenced and disposed, otherwise it will keep locks            if (this.message != null) {                ContainerUtil.dispose(this.message);            }            this.message = message;        }    }    /**     * Set the recipients for this MailImpl.     *     * @param recipients the recipients for this MailImpl     */    public void setRecipients(Collection recipients) {        this.recipients = recipients;    }    /**     * Set the sender of this MailImpl.     *     * @param sender the sender of this MailImpl     */    public void setSender(MailAddress sender) {        this.sender = sender;    }    /**     * Set the state of this MailImpl.     *     * @param state the state of this MailImpl     */    public void setState(String state) {        this.state = state;    }    /**     * Set the remote address associated with this MailImpl.     *     * @param remoteHost the new remote host associated with this MailImpl     */    public void setRemoteHost(String remoteHost) {        this.remoteHost = remoteHost;    }    /**     * Set the remote address associated with this MailImpl.     *     * @param remoteAddr the new remote address associated with this MailImpl     */    public void setRemoteAddr(String remoteAddr) {        this.remoteAddr = remoteAddr;    }    /**     * Set the date this mail was last updated.     *     * @param lastUpdated the date the mail was last updated     */    public void setLastUpdated(Date lastUpdated) {        // Make a defensive copy to ensure that the date        // doesn't get changed external to the class        if (lastUpdated != null) {            lastUpdated = new Date(lastUpdated.getTime());        }        this.lastUpdated = lastUpdated;    }    /**     * Writes the message out to an OutputStream.     *     * @param out the OutputStream to which to write the content     *     * @throws MessagingException if the MimeMessage is not set for this MailImpl     * @throws IOException if an error occurs while reading or writing from the stream     */    public void writeMessageTo(OutputStream out) throws IOException, MessagingException {        if (message != null) {            message.writeTo(out);        } else {            throw new MessagingException("No message set for this MailImpl.");        }    }        // Serializable Methods    // TODO: These need some work.  Currently very tightly coupled to    //       the internal representation.    /**     * Read the MailImpl from an <code>ObjectInputStream</code>.     *     * @param in the ObjectInputStream from which the object is read     *     * @throws IOException if an error occurs while reading from the stream     * @throws ClassNotFoundException ?     * @throws ClassCastException if the serialized objects are not of the appropriate type     */    private void readObject(java.io.ObjectInputStream in)        throws IOException, ClassNotFoundException {        try {            Object obj = in.readObject();            if (obj == null) {                sender = null;            } else if (obj instanceof String) {                sender = new MailAddress((String) obj);            } else if (obj instanceof MailAddress) {                sender = (MailAddress) obj;            }        } catch (ParseException pe) {            throw new IOException("Error parsing sender address: " + pe.getMessage());        }        recipients = (Collection) in.readObject();        state = (String) in.readObject();        errorMessage = (String) in.readObject();        name = (String) in.readObject();        remoteHost = (String) in.readObject();        remoteAddr = (String) in.readObject();        setLastUpdated((Date) in.readObject());        // the following is under try/catch to be backwards compatible        // with messages created with James version <= 2.2.0a8        try {            attributes = (HashMap) in.readObject();        } catch (OptionalDataException ode) {            if (ode.eof) {                attributes = new HashMap();            } else {                throw ode;            }        }    }    /**     * Write the MailImpl to an <code>ObjectOutputStream</code>.     *     * @param in the ObjectOutputStream to which the object is written     *     * @throws IOException if an error occurs while writing to the stream     */    private void writeObject(java.io.ObjectOutputStream out) throws IOException {        out.writeObject(sender);        out.writeObject(recipients);        out.writeObject(state);        out.writeObject(errorMessage);        out.writeObject(name);        out.writeObject(remoteHost);        out.writeObject(remoteAddr);        out.writeObject(lastUpdated);        out.writeObject(attributes);    }    /**     * @see org.apache.avalon.framework.activity.Disposable#dispose()     */    public void dispose() {        ContainerUtil.dispose(message);        message = null;    }    /**     * This method is necessary, when Mail repositories needs to deal     * explicitly with storing Mail attributes as a Serializable     * Note: This method is not exposed in the Mail interface,     * it is for internal use by James only.     * @return Serializable of the entire attributes collection     * @since 2.2.0     **/    public HashMap getAttributesRaw () {        return attributes;    }        /**     * This method is necessary, when Mail repositories needs to deal     * explicitly with retriving Mail attributes as a Serializable     * Note: This method is not exposed in the Mail interface,     * it is for internal use by James only.     * @return Serializable of the entire attributes collection     * @since 2.2.0     **/    public void setAttributesRaw (HashMap attr)    {        this.attributes = (attr == null) ? new HashMap() : attr;    }    /**     * @see org.apache.mailet.Mail#getAttribute(String)     * @since 2.2.0     */    public Serializable getAttribute(String key) {        return (Serializable)attributes.get(key);    }    /**     * @see org.apache.mailet.Mail#setAttribute(String,Serializable)     * @since 2.2.0     */    public Serializable setAttribute(String key, Serializable object) {        return (Serializable)attributes.put(key, object);    }    /**     * @see org.apache.mailet.Mail#removeAttribute(String)     * @since 2.2.0     */    public Serializable removeAttribute(String key) {        return (Serializable)attributes.remove(key);    }    /**     * @see org.apache.mailet.Mail#removeAllAttributes()     * @since 2.2.0     */    public void removeAllAttributes() {        attributes.clear();    }    /**     * @see org.apache.mailet.Mail#getAttributeNames()     * @since 2.2.0     */    public Iterator getAttributeNames() {        return attributes.keySet().iterator();    }    /**     * @see org.apache.mailet.Mail#hasAttributes()     * @since 2.2.0     */    public boolean hasAttributes() {        return !attributes.isEmpty();    }    /**     * This methods provide cloning for serializable objects.     * Mail Attributes are Serializable but not Clonable so we need a deep copy     *     * @param input Object to be cloned     * @return the cloned Object     * @throws IOException     * @throws ClassNotFoundException     */    private static Object cloneSerializableObject(Object o) throws IOException, ClassNotFoundException {        ByteArrayOutputStream b = new ByteArrayOutputStream();        ObjectOutputStream out = new ObjectOutputStream(b);        out.writeObject(o);        out.flush();        out.close();        ByteArrayInputStream bi=new ByteArrayInputStream(b.toByteArray());        ObjectInputStream in = new ObjectInputStream(bi);        Object no = in.readObject();        return no;    }}

⌨️ 快捷键说明

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