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

📄 mimemessagewrapper.java

📁 java 开发的邮件服务器平台。支持以下协议。 协议可以修改为自己的专门标识
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            }            catch(javax.mail.MessagingException me) {                /* This could be another kind of MessagingException                 * thrown by MimeMessage.getInputStream(), such as a                 * javax.mail.internet.ParseException.                 *                 * The ParseException is precisely one of the reasons                 * why the getRawInputStream() method exists, so that we                 * can continue to stream the content, even if we cannot                 * handle it.  Again, if we get an exception, we throw                 * the one that caused us to call getRawInputStream().                 */                try {                    bis = message.getRawInputStream();                    bos = bodyOs;                } catch(javax.mail.MessagingException _) {                    throw me;                }            }            try {                copyStream(bis, bos);            }            finally {                IOUtil.shutdownStream(bis);                         }        }    }    /**     * Various reader methods     */    public Address[] getFrom() throws MessagingException {        if (headers == null) {            loadHeaders();        }        Address from[] = getAddressHeader(RFC2822Headers.FROM);        if(from == null) {            from = getAddressHeader(RFC2822Headers.SENDER);        }        return from;    }    public Address[] getRecipients(Message.RecipientType type) throws MessagingException {        if (headers == null) {            loadHeaders();        }        if (type == RecipientType.NEWSGROUPS) {            String s = headers.getHeader("Newsgroups", ",");            if(s == null) {                return null;            } else {                return NewsAddress.parse(s);            }        } else {            return getAddressHeader(getHeaderName(type));        }    }    public Address[] getAllRecipients() throws MessagingException {        if (headers == null) {            loadHeaders();        }        Address toAddresses[] = getRecipients(RecipientType.TO);        Address ccAddresses[] = getRecipients(RecipientType.CC);        Address bccAddresses[] = getRecipients(RecipientType.BCC);        Address newsAddresses[] = getRecipients(RecipientType.NEWSGROUPS);        if(ccAddresses == null && bccAddresses == null && newsAddresses == null) {            return toAddresses;        }        int i = (toAddresses == null ? 0 : toAddresses.length)                + (ccAddresses == null ? 0 : ccAddresses.length)                + (bccAddresses == null ? 0 : bccAddresses.length)                + (newsAddresses == null ? 0 : newsAddresses.length);        Address allAddresses[] = new Address[i];        int j = 0;        if (toAddresses != null) {            System.arraycopy(toAddresses, 0, allAddresses, j, toAddresses.length);            j += toAddresses.length;        }        if(ccAddresses != null) {            System.arraycopy(ccAddresses, 0, allAddresses, j, ccAddresses.length);            j += ccAddresses.length;        }        if(bccAddresses != null) {            System.arraycopy(bccAddresses, 0, allAddresses, j, bccAddresses.length);            j += bccAddresses.length;        }        if(newsAddresses != null) {            System.arraycopy(newsAddresses, 0, allAddresses, j, newsAddresses.length);            j += newsAddresses.length;        }        return allAddresses;    }    public Address[] getReplyTo() throws MessagingException {        if (headers == null) {            loadHeaders();        }        Address replyTo[] = getAddressHeader(RFC2822Headers.REPLY_TO);        if(replyTo == null) {            replyTo = getFrom();        }        return replyTo;    }    public String getSubject() throws MessagingException {        if (headers == null) {            loadHeaders();        }        String subject = getHeader(RFC2822Headers.SUBJECT, null);        if (subject == null) {            return null;        }        try {            return MimeUtility.decodeText(subject);        } catch(UnsupportedEncodingException _ex) {            return subject;        }    }    public Date getSentDate() throws MessagingException {        if (headers == null) {            loadHeaders();        }        String header = getHeader(RFC2822Headers.DATE, null);        if(header != null) {            try {                return mailDateFormat.parse(header);            } catch(ParseException _ex) {                return null;            }        } else {            return null;        }    }    /**     * We do not attempt to define the received date, although in theory this is the last     * most date in the Received: headers.  For now we return null, which means we are     * not implementing it.     */    public Date getReceivedDate() throws MessagingException {        if (headers == null) {            loadHeaders();        }        return null;    }    /**     * 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 (message == null) {            loadMessage();        }        return message.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 = new LineNumberReader(new InputStreamReader(in, getEncoding()));            //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. Current implementation     * actually returns number of characters in headers plus number of bytes     * in the internal content byte array.     */    public long getMessageSize() throws MessagingException {        try {            return source.getMessageSize();        } catch (IOException ioe) {            throw new MessagingException("Error retrieving message size", ioe);        }    }    public String getContentType() throws MessagingException {        if (headers == null) {            loadHeaders();        }        String value = getHeader(RFC2822Headers.CONTENT_TYPE, null);        if (value == null) {            return "text/plain";        } else {            return value;        }    }    public boolean isMimeType(String mimeType) throws MessagingException {        if (message == null) {            loadMessage();        }        return message.isMimeType(mimeType);    }    public String getDisposition() throws MessagingException {        if (message == null) {            loadMessage();        }        return message.getDisposition();    }    public String getEncoding() throws MessagingException {        if (message == null) {            loadMessage();        }        return message.getEncoding();    }    public String getContentID() throws MessagingException {        if (headers == null) {            loadHeaders();        }        return getHeader("Content-Id", null);    }    public String getContentMD5() throws MessagingException {        if (headers == null) {            loadHeaders();        }        return getHeader("Content-MD5", null);    }    public String getDescription() throws MessagingException {        if (message == null) {            loadMessage();        }        return message.getDescription();    }    public String[] getContentLanguage() throws MessagingException {        if (message == null) {            loadMessage();        }        return message.getContentLanguage();    }    public String getMessageID() throws MessagingException {        if (headers == null) {            loadHeaders();        }        return getHeader(RFC2822Headers.MESSAGE_ID, null);    }    public String getFileName() throws MessagingException {        if (message == null) {            loadMessage();        }        return message.getFileName();    }    public InputStream getInputStream() throws IOException, MessagingException {        if (message == null) {            //This is incorrect... supposed to return a decoded inputstream of            //  the message body            //return source.getInputStream();            loadMessage();            return message.getInputStream();        } else {            return message.getInputStream();        }    }    public DataHandler getDataHandler() throws MessagingException {        if (message == null) {            loadMessage();        }        return message.getDataHandler();    }    public Object getContent() throws IOException, MessagingException {        if (message == null) {            loadMessage();        }        return message.getContent();    }    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);    }

⌨️ 快捷键说明

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