Java Reference
In-Depth Information
System
.
out
.
println
(
tab
+
"Name: "
+
folder
.
getName
() +
'('
+
folder
.
getFullName
() +
')'
);
iif
(!
folder
.
isSubscribed
())
System
.
out
.
println
(
tab
+
"Not Subscribed"
);
iif
((
folder
.
getType
() &
Folder
.
HOLDS_MESSAGES
) !=
0
) {
iif
(
folder
.
hasNewMessages
())
System
.
out
.
println
(
tab
+
"Has New Messages"
);
else
System
.
out
.
println
(
tab
+
"No New Messages"
);
Message
[]
msgs
=
folder
.
getMessages
();
for
for
(
Message m
:
msgs
) {
Address from
=
m
.
getFrom
()[
0
];
String fromAddress
;
iif
(
from
instanceof
instanceof
InternetAddress
)
fromAddress
= ((
InternetAddress
)
from
).
getAddress
();
else
fromAddress
=
from
.
toString
();
StringBuffer sb
=
new
new
StringBuffer
();
fromFmt
.
format
(
fromAddress
,
sb
,
null
null
);
sb
.
append
(
" "
);
subjFmt
.
format
(
m
.
getSubject
(),
sb
,
null
null
);
System
.
out
.
println
(
sb
.
toString
());
}
}
iif
((
folder
.
getType
() &
Folder
.
HOLDS_FOLDERS
) !=
0
) {
System
.
out
.
println
(
tab
+
"Is Directory"
);
}
iif
(
recurse
) {
Folder
[]
fs
=
folder
.
list
();
for
for
(
Folder f
:
fs
) {
listFolder
(
f
,
tab
+
""
,
recurse
);
}
}
}
}
This program has the core of a full mail reader but doesn't actually fetch the articles. To dis-
play a message, you have to get it (by number) from the folder, then call methods like
getSubject()
,
getFrom()
, and others. The
listFolder()
method does this to obtain
identifying information on each message, and formats them using the
StringAlign
class
from
Aligning Strings
.
If we add a GUI and a bit of code to get all the relevant header fields, we can have a working
mail reader. We'll show the messages in a tree view, because some protocols let you have