Java Reference
In-Depth Information
// return the description of the last error
public
String getError(){
return
lastError; }
// update the user profile
public boolean
update(User user){
return
user.update(stmt);
}
}
Class
User
embeds the profile information; it provides two methods to
open and close a connection to the mail server:
openPopServer()
and
closePopServer()
. In addition it provides getter and setter methods to access
the profile parameters.
Several methods have package visibility. The constructors can load the
information from a row of the database represented by a
ResultSet
object, or
create a brand new profile with only the name.
package
UbiMail;
import
java.sql.*;
import
javax.mail.*;
import
java.util.Properties;
// represents a user profile
public class
User {
// profile information
private
String username;
private
String pass;
private
String firstname;
private
String lastname;
private
String popserver;
private
String popuser;
private
String poppass;
// error message
private
String lastError;
// mail server connection
private
Session ms;
private
Store pop;
private
Folder folder;
// creates a user from a row in the database
User(ResultSet rs)
throws
SQLException {
username
#
rs.getString("username");
pass
#
rs.getString("pass");
firstname
#
rs.getString("firstname");
lastname
#
rs.getString("lastname");
popserver
#
rs.getString("popserver");
popuser
#
rs.getString("popuser");
poppass
#
rs.getString("poppass");
Properties props
#
new
Properties();
props.setProperty("mail.store.protocol","pop3");
ms
#
Session.getInstance(props);
}