Java Reference
In-Depth Information
The added methods
In order to ease the developer's work, JavaMail 1.5 added new methods that
provide really interesting shortcuts. For example, the addition of the Trans-
port.send(msg, username, password) method avoids creating additional ob-
jects for authentication parameters when sending the message. Before this, authen-
tication parameters were defined at the session object and as you can see with the
following code:
Session session = Session.getInstance(props,new
javax.mail.Authenticator() {
protected PasswordAuthentication
getPasswordAuthentication() {
return new PasswordAuthentication(username,
password);
}
});
As another example of an added method, you have the Message.getSession()
method, which allows you to access the session type object that was used to cre-
ate the message. This may prevent you from having to drag the session throughout
your treatment. The last added method that we will talk about is the MimeMes-
sage.reply(replyToAll, setAnswered) method, which, due to the second
parameter, allows you to automatically add a Re prefix to the subject line when you
respond, for example, to a message.
The changing of some access modifiers
Concerning access modifiers, the JavaMail 1.5 Specification has put an emphasis
on good practice in some classes and facilitated the extension of others.
You will see, for example, that the access modifiers of the protected fields in the
final classes of the javax.mail.search package have been changed to private.
In fact, it is not important that the final class contains protected fields with public
getter / setter method. So it is better to make them private and let getter / set-
ter be public so that we can access/edit their values from outside.
Search WWH ::




Custom Search