Program: MailReaderBean

Example 19-10 shows the complete MailReaderBean program. As the name implies, it can be used as a bean in larger programs, but also has a main method for standalone use. Clicking on a message displays it in the message view part of the window; this is handled by the TreeSelectionListener called tsl.

Example 19-10. MailReaderBean.java

import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.tree.*; import javax.swing.event.*; import javax.mail.*; import javax.mail.internet.*; /** * Display a mailbox or mailboxes. * This is the generic version in javasrc/email, split off from * JabaDex because of the latter's domain-specific "implements module" stuff. */ public class MailReaderBean extends JSplitPane { private JTextArea bodyText; /* Construct a mail reader bean with all defaults. */ public MailReaderBean( ) throws Exception { this("smtp", "mailhost", "user", "nopasswd", "/"); } /* Construct a mail reader bean with all values. */ public MailReaderBean( String protocol, String host, String user, String password, String rootName) throws Exception { super(VERTICAL_SPLIT); boolean recursive = false; // Start with a Mail Session object Session session = Session.getDefaultInstance( System.getProperties( ), null); session.setDebug(false); // Get a Store object for the given protocol Store store = session.getStore(protocol); store.connect(host, user, password); // Get Folder object for root, and list it // If root name = "", getDefaultFolder( ...

Get Java Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.