Example usage for javax.mail Folder getMessages

List of usage examples for javax.mail Folder getMessages

Introduction

In this page you can find the example usage for javax.mail Folder getMessages.

Prototype

public synchronized Message[] getMessages(int[] msgnums) throws MessagingException 

Source Link

Document

Get the Message objects for message numbers specified in the array.

Usage

From source file:net.wastl.webmail.server.WebMailSession.java

/**
 * Copy or move the selected messages from folder fromfolder to folder tofolder.
 *///from  w w  w  . j  av a2 s .com
public void copyMoveMessage(String fromfolder, String tofolder, HTTPRequestHeader head, boolean move)
        throws MessagingException {
    Folder from = getFolder(fromfolder);
    Folder to = getFolder(tofolder);
    if (user.wantsSetFlags()) {
        if (from.isOpen() && from.getMode() == Folder.READ_ONLY) {
            from.close(false);
            from.open(Folder.READ_WRITE);
        } else if (!from.isOpen()) {
            from.open(Folder.READ_WRITE);
        }
        if (to.isOpen() && to.getMode() == Folder.READ_ONLY) {
            to.close(false);
            to.open(Folder.READ_WRITE);
        } else if (!to.isOpen()) {
            to.open(Folder.READ_WRITE);
        }
    } else {
        if (!from.isOpen()) {
            from.open(Folder.READ_ONLY);
        }
        if (to.isOpen() && to.getMode() == Folder.READ_ONLY) {
            to.close(false);
            to.open(Folder.READ_WRITE);
        } else if (!to.isOpen()) {
            to.open(Folder.READ_WRITE);
        }
    }
    int m[] = getSelectedMessages(head, from.getMessageCount());
    Message msgs[] = from.getMessages(m);
    from.copyMessages(msgs, to);
    if (move && user.wantsSetFlags()) {
        from.setFlags(m, new Flags(Flags.Flag.DELETED), true);
        if (user.getBoolVar("autoexpunge")) {
            from.close(true);
            to.close(true);
        } else {
            if (need_expunge_folders == null) {
                need_expunge_folders = new Vector<String>();
            }
            need_expunge_folders.addElement(fromfolder);
            from.close(false);
            to.close(false);
        }
    } else {
        from.close(false);
        if (user.getBoolVar("autoexpunge")) {
            to.close(true);
        } else {
            to.close(false);
        }
    }
    from.open(Folder.READ_WRITE);
    to.open(Folder.READ_WRITE);
    refreshFolderInformation(fromfolder);
    refreshFolderInformation(tofolder);
}