Example usage for javax.mail.internet InternetHeaders getNonMatchingHeaderLines

List of usage examples for javax.mail.internet InternetHeaders getNonMatchingHeaderLines

Introduction

In this page you can find the example usage for javax.mail.internet InternetHeaders getNonMatchingHeaderLines.

Prototype

public Enumeration<String> getNonMatchingHeaderLines(String[] names) 

Source Link

Document

Return all non-matching header lines

Usage

From source file:org.apache.james.core.MimeMessageWrapper.java

public synchronized void writeTo(OutputStream headerOs, OutputStream bodyOs, String[] ignoreList,
        boolean preLoad) throws IOException, MessagingException {

    if (!preLoad && source != null && !isBodyModified()) {
        // We do not want to instantiate the message... just read from
        // source
        // and write to this outputstream

        // First handle the headers
        InputStream in = source.getInputStream();
        try {//w  w w  .  ja va  2s .c  o  m
            InternetHeaders myHeaders;
            MailHeaders parsedHeaders = new MailHeaders(in);

            // check if we should use the parsed headers or not
            if (!isHeaderModified()) {
                myHeaders = parsedHeaders;
            } else {
                // The headers was modified so we need to call saveChanges() just to be sure
                // See JAMES-1320
                if (!saved)
                    saveChanges();
                myHeaders = headers;
            }
            @SuppressWarnings("unchecked")
            Enumeration<String> filteredHeaders = myHeaders.getNonMatchingHeaderLines(ignoreList);
            IOUtils.copy(new InternetHeadersInputStream(filteredHeaders), headerOs);
            IOUtils.copy(in, bodyOs);
        } finally {
            IOUtils.closeQuietly(in);
        }
    } else {
        // save the changes as the message was modified
        // See JAMES-1320
        if (!saved)
            saveChanges();

        // MimeMessageUtil.writeToInternal(this, headerOs, bodyOs,
        // ignoreList);
        if (headers == null) {
            loadHeaders();
        }
        @SuppressWarnings("unchecked")
        Enumeration<String> filteredHeaders = headers.getNonMatchingHeaderLines(ignoreList);
        IOUtils.copy(new InternetHeadersInputStream(filteredHeaders), headerOs);

        if (preLoad && !messageParsed) {
            loadMessage();
        }
        MimeMessageUtil.writeMessageBodyTo(this, bodyOs);
    }
}

From source file:org.apache.james.server.core.MimeMessageWrapper.java

public synchronized void writeTo(OutputStream headerOs, OutputStream bodyOs, String[] ignoreList,
        boolean preLoad) throws IOException, MessagingException {

    if (!preLoad && source != null && !isBodyModified()) {
        // We do not want to instantiate the message... just read from
        // source
        // and write to this outputstream

        // First handle the headers
        try (InputStream in = source.getInputStream()) {
            InternetHeaders myHeaders;
            MailHeaders parsedHeaders = new MailHeaders(in);

            // check if we should use the parsed headers or not
            if (!isHeaderModified()) {
                myHeaders = parsedHeaders;
            } else {
                // The headers was modified so we need to call saveChanges() just to be sure
                // See JAMES-1320
                if (!saved) {
                    saveChanges();//from  ww w.ja v  a2 s. co  m
                }
                myHeaders = headers;
            }
            Enumeration<String> filteredHeaders = myHeaders.getNonMatchingHeaderLines(ignoreList);
            IOUtils.copy(new InternetHeadersInputStream(filteredHeaders), headerOs);
            IOUtils.copy(in, bodyOs);
        }
    } else {
        // save the changes as the message was modified
        // See JAMES-1320
        if (!saved) {
            saveChanges();
        }

        // MimeMessageUtil.writeToInternal(this, headerOs, bodyOs,
        // ignoreList);
        if (headers == null) {
            loadHeaders();
        }
        Enumeration<String> filteredHeaders = headers.getNonMatchingHeaderLines(ignoreList);
        IOUtils.copy(new InternetHeadersInputStream(filteredHeaders), headerOs);

        if (preLoad && !messageParsed) {
            loadMessage();
        }
        MimeMessageUtil.writeMessageBodyTo(this, bodyOs);
    }
}