Sidebar 16.1 Java Mail
Java Mail is part of the Java Enterprise Edition and contains the classes modelling
a mail system. The javax.mail package defines classes that are common to all mail
systems (see http://developer.java.sun.com/developer/onlineTraining/JavaMail/).
The main class is Session which behaves like a factory (see the Class Factory
pattern (see Gamma et al . 1995)) for the mail stores (class Store ) and transport
protocols (class Transport ).
The first step in using Java Mail is to create a session object specifying some
Properties props # new Properties();
Session ms # Session.getInstance(props);
Then it is possible to create a mail store and connect it to the server, the mail
store is a proxy (see the Proxy pattern (see Gamma et al . 1995)) of the server:
Store pop # ms.getStore("pop3");
The mail stored on a mail store can be browsed through the class Folder . Folder
is an abstract class that represents a folder for mail messages. The case-insensitive
folder name INBOX is reserved to mean the “primary folder for this user on this
Folder folder # pop.getFolder("INBOX");
The Message objects within the Folder represent the email messages.
Message msg # folder.getMessage(1);
System.out.println("Subject: " ! msg.getSubject());
The messages implement the Part interface, and its contents can be either
simple or composed of multiple parts.
Multipart multi # (Multipart)msg.getContent();
BodyPart part # multi.getBodyPart(0);
System.out.println("Type: " ! part.getContentType());
System.out.println("Content: " ! part.getContent());
Because of its easier syntax we opt for the JSP technology. Each HTML
page with dynamic contents corresponds to a JSP (see Sidebar 16.2). We
design the structure of JSPs in accordance with the state flow presented in
Figure 16.4. We represent the web pages (both static HTML and dynamic
JSPs) as classes; the links between them are represented as associations with
the stereotype «link» . Figure 16.5 shows the class diagram describing the
structure of the prototype's user interface.
How do we convert the information on the mail server into HTML pages?