Example usage for javax.mail FetchProfile contains

List of usage examples for javax.mail FetchProfile contains

Introduction

In this page you can find the example usage for javax.mail FetchProfile contains.

Prototype

public boolean contains(String headerName) 

Source Link

Document

Returns true if the fetch profile contains the given header name.

Usage

From source file:com.hs.mail.imap.message.response.FetchResponseBuilder.java

public FetchResponse build(long msgnum, FetchProfile fp, FetchData fd) {
    FetchResponse response = new FetchResponse(msgnum);
    if (fp.contains(FetchProfile.Item.FLAGS)) {
        response.setFlags(fd.getFlags());
    }/*from  w  ww . jav a 2  s . c  o m*/
    if (fp.contains(FetchData.FetchProfileItem.INTERNALDATE)) {
        response.setInternalDate(fd.getInternalDate());
    }
    if (fp.contains(FetchData.FetchProfileItem.SIZE)) {
        response.setSize(new Long(fd.getSize()));
    }
    if (fp.contains(FetchProfile.Item.ENVELOPE)) {
        Envelope envelope = buildEnvelope(fd.getPhysMessageID());
        response.setEnvelope(envelope);
    }
    if (fp.contains(FetchData.FetchProfileItem.BODY) || fp.contains(FetchData.FetchProfileItem.BODYSTRUCTURE)) {
        MimeDescriptor descriptor = getBodyStructure(fd);
        if (fp.contains(FetchData.FetchProfileItem.BODY)) {
            response.setBody(descriptor);
        }
        if (fp.contains(FetchData.FetchProfileItem.BODYSTRUCTURE)) {
            response.setBodyStructure(descriptor);
        }
    }
    if (fp.contains(FetchData.FetchProfileItem.UID)) {
        response.setUid(new Long(fd.getMessageID()));
    }
    BodyFetchItem item = getBodyFetchItem(fp);
    if (item != null) {
        try {
            byte[] contents = bodyFetch(fd, item);
            Content content = buildBodyContent(contents, item);
            response.setContent(content);
            // Check if this fetch will cause the "SEEN" flag to be set
            // on this message.
            if (!item.isPeek()) {
                if (fd.getFlags() == null || !fd.getFlags().contains(Flags.Flag.SEEN)) {
                    manager.setFlags(fd.getMessageID(), new Flags(Flags.Flag.SEEN), false, true);
                }
            }
        } catch (Exception e) {
            // FIXME The main reason for this exception is that the message
            // file is not exist.
            // If we throw exception, all subsequent fetch will fail.
            // So, ignore this exception at now.
        }
    }
    return response;
}

From source file:com.sun.mail.pop3.POP3Folder.java

/**
 * Prefetch information about POP3 messages.
 * If the FetchProfile contains <code>UIDFolder.FetchProfileItem.UID</code>,
 * POP3 UIDs for all messages in the folder are fetched using the POP3
 * UIDL command.//from w ww .j a  va  2s .  c o m
 * If the FetchProfile contains <code>FetchProfile.Item.ENVELOPE</code>,
 * the headers and size of all messages are fetched using the POP3 TOP
 * and LIST commands.
 */
public synchronized void fetch(Message[] msgs, FetchProfile fp) throws MessagingException {
    checkReadable();
    if (!doneUidl && fp.contains(UIDFolder.FetchProfileItem.UID)) {
        /*
         * Since the POP3 protocol only lets us fetch the UID
         * for a single message or for all messages, we go ahead
         * and fetch UIDs for all messages here, ignoring the msgs
         * parameter.  We could be more intelligent and base this
         * decision on the number of messages fetched, or the
         * percentage of the total number of messages fetched.
         */
        String[] uids = new String[message_cache.size()];
        try {
            if (!port.uidl(uids))
                return;
        } catch (EOFException eex) {
            close(false);
            throw new FolderClosedException(this, eex.toString());
        } catch (IOException ex) {
            throw new MessagingException("error getting UIDL", ex);
        }
        for (int i = 0; i < uids.length; i++) {
            if (uids[i] == null)
                continue;
            POP3Message m = (POP3Message) getMessage(i + 1);
            m.uid = uids[i];
        }
        doneUidl = true; // only do this once
    }
    if (fp.contains(FetchProfile.Item.ENVELOPE)) {
        for (int i = 0; i < msgs.length; i++) {
            try {
                POP3Message msg = (POP3Message) msgs[i];
                // fetch headers
                msg.getHeader("");
                // fetch message size
                msg.getSize();
            } catch (MessageRemovedException mex) {
                // should never happen, but ignore it if it does
            }
        }
    }
}