Top Description Inners Fields Constructors Methods
javax.mail

public Class Flags

extends Object
implements Cloneable, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Cloneable
Known Direct Subclasses
com.sun.mail.imap.protocol.FLAGS
Imports
java.io.Serializable, java.util.*

The Flags class represents the set of flags on a Message. Flags are composed of predefined system flags, and user defined flags.

A System flag is represented by the Flags.Flag inner class. A User defined flag is represented as a String. User flags are case-independent.

A set of standard system flags are predefined. Most folder implementations are expected to support these flags. Some implementations may also support arbitrary user-defined flags. The getPermanentFlags method on a Folder returns a Flags object that holds all the flags that are supported by that folder implementation.

A Flags object is serializable so that (for example) the use of Flags objects in search terms can be serialized along with the search terms.

Warning

Serialized objects of this class may not be compatible with future JavaMail API releases. The current serialization support is appropriate for short term storage.

The below code sample illustrates how to set, examine, and get the flags for a message.


 Message m = folder.getMessage(1);
 m.setFlag(Flags.Flag.DELETED, true); // set the DELETED flag

 // Check if DELETED flag is set on this message
 if (m.isSet(Flags.Flag.DELETED))
	System.out.println("DELETED message");

 // Examine ALL system flags for this message
 Flags flags = m.getFlags();
 Flags.Flag[] sf = flags.getSystemFlags();
 for (int i = 0; i < sf.length; i++) {
	if (sf[i] == Flags.Flag.DELETED)
            System.out.println("DELETED message");
	else if (sf[i] == Flags.Flag.SEEN)
            System.out.println("SEEN message");
      ......
      ......
 }
 

Authors
John Mani, Bill Shannon
See Also
Folder#getPermanentFlags

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Flags.Flag

This inner class represents an individual system flag.

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final long
private int
private static final int
private Hashtable<String, String>

Constructor Summary

AccessConstructor and Description
public
Flags()

Construct an empty Flags object.

public
Flags(Flags
the flags for initialization
flags
)

Construct a Flags object initialized with the given flags.

public
Flags(Flags.Flag
the flag for initialization
flag
)

Construct a Flags object initialized with the given system flag.

public
Flags(String
the flag for initialization
flag
)

Construct a Flags object initialized with the given user flag.

Method Summary

Modifier and TypeMethod and Description
public void
add(Flags.Flag
the flag to add
flag
)

Add the specified system flag to this Flags object.

public void
add(String
the flag to add
flag
)

Add the specified user flag to this Flags object.

public void
add(Flags
Flags object
f
)

Add all the flags in the given Flags object to this Flags object.

public void
clearSystemFlags()

Clear all of the system flags.

public void
clearUserFlags()

Clear all of the user flags.

public Object
clone()

Overrides java.lang.Object.clone.

Returns a clone of this Flags object.
public boolean

Returns:

true of the given flag is present, otherwise false.
contains
(Flags.Flag
the flag to test
flag
)

Check whether the specified system flag is present in this Flags object.

public boolean

Returns:

true of the given flag is present, otherwise false.
contains
(String
the flag to test
flag
)

Check whether the specified user flag is present in this Flags object.

public boolean

Returns:

true if all flags in the given Flags object are present, otherwise false.
contains
(Flags
the flags to test
f
)

Check whether all the flags in the specified Flags object are present in this Flags object.

public boolean

Returns:

true if they're equal
equals
(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Check whether the two Flags objects are equal.
public Flags.Flag[]

Returns:

array of Flags.Flag objects representing system flags
getSystemFlags
()

Return all the system flags in this Flags object.

public String[]

Returns:

array of Strings, each String represents a flag.
getUserFlags
()

Return all the user flags in this Flags object.

public int

Returns:

the hash code
hashCode
()

Overrides java.lang.Object.hashCode.

Compute a hash code for this Flags object.
public void
remove(Flags.Flag
the flag to be removed
flag
)

Remove the specified system flag from this Flags object.

public void
remove(String
the flag to be removed
flag
)

Remove the specified user flag from this Flags object.

public void
remove(Flags
the flag to be removed
f
)

Remove all flags in the given Flags object from this Flags object.

public boolean

Returns:

true if this Flags object changed
retainAll
(Flags
the flags to keep
f
)

Remove any flags not in the given Flags object.

public String
toString()

Overrides java.lang.Object.toString.

Return a string representation of this Flags object.
Inherited from java.lang.Object:
finalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

ANSWERED_BITback to summary
private static final int ANSWERED_BIT
DELETED_BITback to summary
private static final int DELETED_BIT
DRAFT_BITback to summary
private static final int DRAFT_BIT
FLAGGED_BITback to summary
private static final int FLAGGED_BIT
RECENT_BITback to summary
private static final int RECENT_BIT
SEEN_BITback to summary
private static final int SEEN_BIT
serialVersionUIDback to summary
private static final long serialVersionUID
system_flagsback to summary
private int system_flags
USER_BITback to summary
private static final int USER_BIT
user_flagsback to summary
private Hashtable<String, String> user_flags

Constructor Detail

Flagsback to summary
public Flags()

Construct an empty Flags object.

Flagsback to summary
public Flags(Flags flags)

Construct a Flags object initialized with the given flags.

Parameters
flags:Flags

the flags for initialization

Annotations
@SuppressWarnings:unchecked
Flagsback to summary
public Flags(Flags.Flag flag)

Construct a Flags object initialized with the given system flag.

Parameters
flag:Flags.Flag

the flag for initialization

Flagsback to summary
public Flags(String flag)

Construct a Flags object initialized with the given user flag.

Parameters
flag:String

the flag for initialization

Method Detail

addback to summary
public void add(Flags.Flag flag)

Add the specified system flag to this Flags object.

Parameters
flag:Flags.Flag

the flag to add

addback to summary
public void add(String flag)

Add the specified user flag to this Flags object.

Parameters
flag:String

the flag to add

addback to summary
public void add(Flags f)

Add all the flags in the given Flags object to this Flags object.

Parameters
f:Flags

Flags object

clearSystemFlagsback to summary
public void clearSystemFlags()

Clear all of the system flags.

Since
JavaMail 1.6
clearUserFlagsback to summary
public void clearUserFlags()

Clear all of the user flags.

Since
JavaMail 1.6
cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Returns a clone of this Flags object.

Returns:Object

Doc from java.lang.Object.clone.

a clone of this instance.

Annotations
@SuppressWarnings:unchecked
@Override
containsback to summary
public boolean contains(Flags.Flag flag)

Check whether the specified system flag is present in this Flags object.

Parameters
flag:Flags.Flag

the flag to test

Returns:boolean

true of the given flag is present, otherwise false.

containsback to summary
public boolean contains(String flag)

Check whether the specified user flag is present in this Flags object.

Parameters
flag:String

the flag to test

Returns:boolean

true of the given flag is present, otherwise false.

containsback to summary
public boolean contains(Flags f)

Check whether all the flags in the specified Flags object are present in this Flags object.

Parameters
f:Flags

the flags to test

Returns:boolean

true if all flags in the given Flags object are present, otherwise false.

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Check whether the two Flags objects are equal.

Parameters
obj:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

true if they're equal

Annotations
@Override
getSystemFlagsback to summary
public Flags.Flag[] getSystemFlags()

Return all the system flags in this Flags object. Returns an array of size zero if no flags are set.

Returns:Flags.Flag[]

array of Flags.Flag objects representing system flags

getUserFlagsback to summary
public String[] getUserFlags()

Return all the user flags in this Flags object. Returns an array of size zero if no flags are set.

Returns:String[]

array of Strings, each String represents a flag.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Compute a hash code for this Flags object.

Returns:int

the hash code

Annotations
@Override
removeback to summary
public void remove(Flags.Flag flag)

Remove the specified system flag from this Flags object.

Parameters
flag:Flags.Flag

the flag to be removed

removeback to summary
public void remove(String flag)

Remove the specified user flag from this Flags object.

Parameters
flag:String

the flag to be removed

removeback to summary
public void remove(Flags f)

Remove all flags in the given Flags object from this Flags object.

Parameters
f:Flags

the flag to be removed

retainAllback to summary
public boolean retainAll(Flags f)

Remove any flags not in the given Flags object. Useful for clearing flags not supported by a server. If the given Flags object includes the Flags.Flag.USER flag, all user flags in this Flags object are retained.

Parameters
f:Flags

the flags to keep

Returns:boolean

true if this Flags object changed

Since
JavaMail 1.6
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Return a string representation of this Flags object. Note that the exact format of the string is subject to change.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

javax.mail back to summary

public final Class Flags.Flag

extends Object
Class Inheritance

This inner class represents an individual system flag. A set of standard system flag objects are predefined here.

Field Summary

Modifier and TypeField and Description
public static final Flags.Flag
ANSWERED

This message has been answered.

private int
public static final Flags.Flag
DELETED

This message is marked deleted.

public static final Flags.Flag
DRAFT

This message is a draft.

public static final Flags.Flag
FLAGGED

This message is flagged.

public static final Flags.Flag
RECENT

This message is recent.

public static final Flags.Flag
SEEN

This message is seen.

public static final Flags.Flag
USER

A special flag that indicates that this folder supports user defined flags.

Constructor Summary

AccessConstructor and Description
private
Flag(int bit)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ANSWEREDback to summary
public static final Flags.Flag ANSWERED

This message has been answered. This flag is set by clients to indicate that this message has been answered to.

bitback to summary
private int bit
DELETEDback to summary
public static final Flags.Flag DELETED

This message is marked deleted. Clients set this flag to mark a message as deleted. The expunge operation on a folder removes all messages in that folder that are marked for deletion.

DRAFTback to summary
public static final Flags.Flag DRAFT

This message is a draft. This flag is set by clients to indicate that the message is a draft message.

FLAGGEDback to summary
public static final Flags.Flag FLAGGED

This message is flagged. No semantic is defined for this flag. Clients alter this flag.

RECENTback to summary
public static final Flags.Flag RECENT

This message is recent. Folder implementations set this flag to indicate that this message is new to this folder, that is, it has arrived since the last time this folder was opened.

Clients cannot alter this flag.

SEENback to summary
public static final Flags.Flag SEEN

This message is seen. This flag is implicitly set by the implementation when this Message's content is returned to the client in some form. The getInputStream and getContent methods on Message cause this flag to be set.

Clients can alter this flag.

USERback to summary
public static final Flags.Flag USER

A special flag that indicates that this folder supports user defined flags.

The implementation sets this flag. Clients cannot alter this flag but can use it to determine if a folder supports user defined flags by using folder.getPermanentFlags().contains(Flags.Flag.USER).

Constructor Detail

Flagback to summary
private Flag(int bit)