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

📄 mimemessagewrapper.java

📁 java mail,java mailjava mailjava mailjava mail
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                MimeMessageUtil.copyStream(in, bodyOs);            } finally {                IOUtil.shutdownStream(in);            }        } else {            MimeMessageUtil.writeToInternal(this, headerOs, bodyOs, ignoreList);        }    }    /**     * This is the MimeMessage implementation - this should return ONLY the     * body, not the entire message (should not count headers).  Will have     * to parse the message.     */    public int getSize() throws MessagingException {        if (!messageParsed) {            loadMessage();        }        return super.getSize();    }    /**     * Corrects JavaMail 1.1 version which always returns -1.     * Only corrected for content less than 5000 bytes,     * to avoid memory hogging.     */    public int getLineCount() throws MessagingException {            InputStream in=null;        try{            in = getContentStream();        }catch(Exception e){            return -1;        }        if (in == null) {            return -1;        }        //Wrap input stream in LineNumberReader        //Not sure what encoding to use really...        try {            LineNumberReader counter;            if (getEncoding() != null) {                counter = new LineNumberReader(new InputStreamReader(in, getEncoding()));            } else {                counter = new LineNumberReader(new InputStreamReader(in));            }            //Read through all the data            char[] block = new char[4096];            while (counter.read(block) > -1) {                //Just keep reading            }            return counter.getLineNumber();        } catch (IOException ioe) {            return -1;        } finally {            IOUtil.shutdownStream(in);        }    }    /**     * Returns size of message, ie headers and content     */    public long getMessageSize() throws MessagingException {        if (source != null && !isModified()) {            try {                return source.getMessageSize();            } catch (IOException ioe) {                throw new MessagingException("Error retrieving message size", ioe);            }        } else {            return MimeMessageUtil.calculateMessageSize(this);        }    }        /**     * We override all the "headers" access methods to be sure that we     * loaded the headers      */        public String[] getHeader(String name) throws MessagingException {        if (headers == null) {            loadHeaders();        }        return headers.getHeader(name);    }    public String getHeader(String name, String delimiter) throws MessagingException {        if (headers == null) {            loadHeaders();        }        return headers.getHeader(name, delimiter);    }    public Enumeration getAllHeaders() throws MessagingException {        if (headers == null) {            loadHeaders();        }        return headers.getAllHeaders();    }    public Enumeration getMatchingHeaders(String[] names) throws MessagingException {        if (headers == null) {            loadHeaders();        }        return headers.getMatchingHeaders(names);    }    public Enumeration getNonMatchingHeaders(String[] names) throws MessagingException {        if (headers == null) {            loadHeaders();        }        return headers.getNonMatchingHeaders(names);    }    public Enumeration getAllHeaderLines() throws MessagingException {        if (headers == null) {            loadHeaders();        }        return headers.getAllHeaderLines();    }    public Enumeration getMatchingHeaderLines(String[] names) throws MessagingException {        if (headers == null) {            loadHeaders();        }        return headers.getMatchingHeaderLines(names);    }    public Enumeration getNonMatchingHeaderLines(String[] names) throws MessagingException {        if (headers == null) {            loadHeaders();        }        return headers.getNonMatchingHeaderLines(names);    }    private synchronized void checkModifyHeaders() throws MessagingException {        // Disable only-header loading optimizations for JAMES-559        if (!messageParsed) {            loadMessage();        }        // End JAMES-559        if (headers == null) {            loadHeaders();        }        modified = true;        saved = false;        headersModified = true;    }    public void setHeader(String name, String value) throws MessagingException {        checkModifyHeaders();        super.setHeader(name, value);    }    public void addHeader(String name, String value) throws MessagingException {        checkModifyHeaders();        super.addHeader(name, value);    }    public void removeHeader(String name) throws MessagingException {        checkModifyHeaders();        super.removeHeader(name);    }    public void addHeaderLine(String line) throws MessagingException {        checkModifyHeaders();        super.addHeaderLine(line);    }    /**     * The message is changed when working with headers and when altering the content.     * Every method that alter the content will fallback to this one.     *      * @see javax.mail.Part#setDataHandler(javax.activation.DataHandler)     */    public synchronized void setDataHandler(DataHandler arg0) throws MessagingException {        modified = true;        saved = false;        bodyModified = true;        super.setDataHandler(arg0);    }    /**     * @see org.apache.avalon.framework.activity.Disposable#dispose()     */    public void dispose() {        if (sourceIn != null) {            IOUtil.shutdownStream(sourceIn);        }        if (source != null) {            ContainerUtil.dispose(source);        }    }    /**     * @see javax.mail.internet.MimeMessage#parse(java.io.InputStream)     */    protected synchronized void parse(InputStream is) throws MessagingException {        // the super implementation calls        // headers = createInternetHeaders(is);        super.parse(is);        messageParsed = true;    }    /**     * If we already parsed the headers then we simply return the updated ones.     * Otherwise we parse     *      * @see javax.mail.internet.MimeMessage#createInternetHeaders(java.io.InputStream)     */    protected synchronized InternetHeaders createInternetHeaders(InputStream is) throws MessagingException {        /* This code is no more needed: see JAMES-570 and new tests                    * InternetHeaders can be a bit awkward to work with due to         * its own internal handling of header order.  This hack may         * not always be necessary, but for now we are trying to         * ensure that there is a Return-Path header, even if just a         * placeholder, so that later, e.g., in LocalDelivery, when we         * call setHeader, it will remove any other Return-Path         * headers, and ensure that ours is on the top. addHeader         * handles header order, but not setHeader. This may change in         * future JavaMail.  But if there are other Return-Path header         * values, let's drop our placeholder.        MailHeaders newHeaders = new MailHeaders(new ByteArrayInputStream((RFC2822Headers.RETURN_PATH + ": placeholder").getBytes()));        newHeaders.setHeader(RFC2822Headers.RETURN_PATH, null);        newHeaders.load(is);        String[] returnPathHeaders = newHeaders.getHeader(RFC2822Headers.RETURN_PATH);        if (returnPathHeaders.length > 1) newHeaders.setHeader(RFC2822Headers.RETURN_PATH, returnPathHeaders[1]);        */                // Keep this: skip the headers from the stream        // we could put that code in the else and simple write an "header" skipping        // reader for the others.        MailHeaders newHeaders = new MailHeaders(is);                if (headers != null) {            return headers;        } else {            return newHeaders;        }    }    /**     * @see javax.mail.internet.MimeMessage#getContentStream()     */    protected InputStream getContentStream() throws MessagingException {        if (!messageParsed) {            loadMessage();        }        return super.getContentStream();    }    /**     * @see javax.mail.internet.MimeMessage#getRawInputStream()     */    public InputStream getRawInputStream() throws MessagingException {        if (!messageParsed && !isModified() && source != null) {            InputStream is;            try {                is = source.getInputStream();                // skip the headers.                new MailHeaders(is);                return is;            } catch (IOException e) {                throw new MessagingException("Unable to read the stream: " + e.getMessage(), e);            }        } else return super.getRawInputStream();    }        }

⌨️ 快捷键说明

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