Designing JBiff
Our JBiff should be able to monitor a random mailbox and show its state. For simplicity, we will limit ourselves to IMAP mailboxes, which are handled in Sun’s reference implementation of the API. Since we can determine a lot about the state of IMAP mailboxes, (as described in Chapter 11, The Internet Message Access Protocol ), JBiff should be able to determine not only that we have new messages in the box, but also the number of unread messages and the number of total messages in the box. If we wanted to get carried away, we could show who the messages were from and their subjects, but we will leave this for a later day.
Both the IMAP protocol and the Java Mail API provide a way to determine message sizes. In IMAP, it is handled via the SEARCH command. In the Java Mail API, it is handled with the classes in the javax.mail.search hierarchy. It would be a nice addition to this script to note sizes of messages in the remote mailbox.
In order to access an IMAP mailbox, we will clearly need the name of the IMAP server (we will presume the port number to be standard) and the mailbox name. We will also need a username and password that can access the mailbox. In order to periodically refresh the display, we should also ask for a refresh rate.
With this information, we can construct a command line for the new script that looks like this:
$ java JBiff <username> <password> <host> <mailbox> <frequency (sec) >A good mailbox to try is Inbox since every valid IMAP account is guaranteed ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access