Java Reference
In-Depth Information
if
(
messages
[
i
].
isSet
(
Flags
.
Flag
.
USER
))
{
// We don't know what the user flags might be in advance
// so they're returned as an array of strings
String
[]
userFlags
=
messages
[
i
].
getFlags
().
getUserFlags
();
for
(
String
flag
:
userFlags
)
{
System
.
out
.
println
(
"User flag: "
+
flag
);
}
}
System
.
out
.
println
();
}
// Close the connection
// but don't remove the messages from the server
folder
.
close
(
false
);
}
catch
(
MessagingException
ex
)
{
ex
.
printStackTrace
();
}
// Since we may have brought up a GUI to authenticate,
// we can't rely on returning from main() to exit
System
.
exit
(
0
);
}
}
Here's a sample run. The first message has been read and deleted. The second message
has no set flags; it hasn't been read, deleted, or answered. The third message has been
read and answered but not deleted. Notice that I'm using an IMAP server instead of a
POP server:
%
java FlagsClient imap://elharo@mail.ibiblio.org/INBOX
------------ Message 1 ------------
From: Mike Hall <mikehall@spacestar.com>
Reply-to: Mike Hall <mikehall@spacestar.com>
To: mrj-dev@public.lists.apple.com
Subject: Re: dialog box, parents & X-platform
Sent: Sun Dec 13 05:24:38 PST 2009
Received: Sun Dec 13 06:33:00 PST 2009
Deleted
Read
------------ Message 2 ------------
From: Kapil Madan <kapil.madan@MIT-MISYS.COM>
Reply-to: XML-INTEREST@JAVA.SUN.COM
To: XML-INTEREST@JAVA.SUN.COM
Subject: Re: first mail to the list!
Sent: Sun Dec 13 06:19:46 PST 2009
Received: Sun Dec 13 06:40:00 PST 2009
------------ Message 3 ------------
From: Jim Jackl-Mochel <jmochel@foliage.com>
Reply-to: Jim Jackl-Mochel <jmochel@foliage.com>
To: elharo@ibiblio.org