Java Reference
In-Depth Information
Getting folder /var/mail/ian.
Name: ian(/var/mail/ian)
No New Messages
irate_client@nosuchd Contract in Hawaii
mailer-daemon@kingcr Returned mail: Data format error
$
The main program shown in
Example 17-7
takes all five arguments from its command line.
Example 17-7. MailLister.java
public
public class
class
MailLister
MailLister
{
static
static
StringFormat fromFmt
=
new
new
StringFormat
(
20
,
StringFormat
.
JUST_LEFT
);
static
static
StringFormat subjFmt
=
new
new
StringFormat
(
40
,
StringFormat
.
JUST_LEFT
);
public
public static
throws
Exception
{
String fileName
=
MailConstants
.
PROPS_FILE_NAME
;
String protocol
=
null
static
void
void
main
(
String
[]
argv
)
throws
null
;
String host
=
null
null
;
String user
=
null
null
;
String password
=
null
null
;
String root
=
null
null
;
// If argc == 1, assume it's a Properties file.
iif
(
argv
.
length
==
1
) {
fileName
=
argv
[
0
];
FileProperties fp
=
new
new
FileProperties
(
fileName
);
fp
.
load
();
protocol
=
fp
.
getProperty
(
MailConstants
.
RECV_PROTO
);
host
=
fp
.
getProperty
(
MailConstants
.
RECV_HOST
);
user
=
fp
.
getProperty
(
MailConstants
.
RECV_USER
);
password
=
fp
.
getProperty
(
MailConstants
.
RECV_PASS
);
root
=
fp
.
getProperty
(
MailConstants
.
RECV_ROOT
);
}
// If not, assume listing all args in long form.
else
else
if
(
argv
.
length
==
5
) {
protocol
=
argv
[
0
];
host
=
argv
[
1
];
user
=
argv
[
2
];
password
=
argv
[
3
];
root
=
argv
[
4
];
}
// Otherwise give up.
else
else
{