Example usage for javax.mail.internet MimeMessage setFlags

List of usage examples for javax.mail.internet MimeMessage setFlags

Introduction

In this page you can find the example usage for javax.mail.internet MimeMessage setFlags.

Prototype

@Override
public synchronized void setFlags(Flags flag, boolean set) throws MessagingException 

Source Link

Document

Set the flags for this message.

Usage

From source file:populate.java

/**
 * Copy message from src to dst. If dontPreserveFlags is set we first copy the
 * messages to memory, clear all the flags, and then copy to the destination.
 *///from w w  w.  j a  va2 s . c om
private static void copyMessages(Folder src, Folder dst) throws MessagingException {
    Message[] msgs = src.getMessages();
    if (dontPreserveFlags) {
        for (int i = 0; i < msgs.length; i++) {
            MimeMessage m = new MimeMessage((MimeMessage) msgs[i]);
            m.setFlags(m.getFlags(), false);
            msgs[i] = m;
        }
    }
    src.copyMessages(msgs, dst);
}

From source file:populate.java

/**
 * Copy message from src to dst.  If dontPreserveFlags is set
 * we first copy the messages to memory, clear all the flags,
 * and then copy to the destination./*from  w  w  w .ja  va 2 s  .c om*/
 */
private static void copyMessages(Folder src, Folder dst) throws MessagingException {
    Message[] msgs = src.getMessages();
    if (dontPreserveFlags) {
        for (int i = 0; i < msgs.length; i++) {
            MimeMessage m = new MimeMessage((MimeMessage) msgs[i]);
            m.setFlags(m.getFlags(), false);
            msgs[i] = m;
        }
    }
    if (warn) {
        // have to copy messages one at a time
        for (int i = 0; i < msgs.length; i++) {
            try {
                src.copyMessages(new Message[] { msgs[i] }, dst);
            } catch (MessagingException mex) {
                System.out.println("WARNING: Copy of message " + (i + 1) + " from " + src.getFullName() + " to "
                        + dst.getFullName() + " failed: " + mex.toString());
            }
        }
    } else
        src.copyMessages(msgs, dst);
}