Thursday, July 15, 2010

Message Flags In Java Mailing


  • If a folder supports the special USER flag, you can set arbitrary user-definable flags on any message belonging to this folder. Other flags are:
    • ANSWERED: Message has been answered.
    • DRAFT: Message is a draft.
    • FLAGGED: Mark a message as flagged.
    • RECENT: This message is newly arrived in this folder. This flag is set when the message is first delivered into the folder and cleared when the containing folder is closed. Clients cannot set this flag.
    • SEEN: Marks a message that has been opened. It gets set when the message contents are retrieved.
    • DELETED: Allows undoable message deletion. Setting this flag for a message marks it deleted but does not physically remove the message from its folder. The client calls the expunge method on a folder to remove all deleted messages in that folder.
  • Methods to operate on flags of a message
    // Get current flags set on a message
    Flags msgFlags = msg.getFlags();

    // Get all supported flags by this folder
    Flags allowedFlags = fldr.getPermanentFlags();

    // Check if a Flags object contains a flag
    allowedFlags.contains(flagToCheck);

    // Add a flag to a set of flags using a Flags.Flag object
    msgFlags.add(flagToAdd);

    // Set the flags on a message
    msg.setFlags(msgFlags, isToBeSet);

No comments:

Post a Comment