Search in sources :

Example 1 with FetchProfile

use of javax.mail.FetchProfile in project xwiki-platform by xwiki.

the class MailPluginApi method getMailHeaders.

public Message[] getMailHeaders(String provider, String server, String user, String password) throws MessagingException {
    // Get a session. Use a blank Properties object.
    Session session = Session.getInstance(new Properties());
    // Get a Store object
    Store store = session.getStore(provider);
    store.connect(server, user, password);
    try {
        // Get "INBOX"
        Folder fldr = store.getFolder("INBOX");
        fldr.open(Folder.READ_ONLY);
        Message[] messages = new Message[fldr.getMessageCount()];
        FetchProfile profile = new FetchProfile();
        profile.add(FetchProfile.Item.CONTENT_INFO);
        profile.add(FetchProfile.Item.ENVELOPE);
        profile.add(FetchProfile.Item.FLAGS);
        fldr.fetch(messages, profile);
        return messages;
    } finally {
        store.close();
    }
}
Also used : FetchProfile(javax.mail.FetchProfile) Message(javax.mail.Message) Store(javax.mail.Store) Properties(java.util.Properties) Folder(javax.mail.Folder) Session(javax.mail.Session)

Example 2 with FetchProfile

use of javax.mail.FetchProfile in project spring-integration by spring-projects.

the class AbstractMailReceiver method fetchMessages.

/**
 * Fetches the specified messages from this receiver's folder. Default
 * implementation {@link Folder#fetch(Message[], FetchProfile) fetches}
 * every {@link javax.mail.FetchProfile.Item}.
 *
 * @param messages the messages to fetch
 * @throws MessagingException in case of JavaMail errors
 */
protected void fetchMessages(Message[] messages) throws MessagingException {
    FetchProfile contentsProfile = new FetchProfile();
    contentsProfile.add(FetchProfile.Item.ENVELOPE);
    contentsProfile.add(FetchProfile.Item.CONTENT_INFO);
    contentsProfile.add(FetchProfile.Item.FLAGS);
    this.folder.fetch(messages, contentsProfile);
}
Also used : FetchProfile(javax.mail.FetchProfile)

Aggregations

FetchProfile (javax.mail.FetchProfile)2 Properties (java.util.Properties)1 Folder (javax.mail.Folder)1 Message (javax.mail.Message)1 Session (javax.mail.Session)1 Store (javax.mail.Store)1