FileDocCategorySizeDatePackage
MailUserBean.javaAPI DocGlassfish v2 API5578Mon Oct 17 14:54:24 BST 2005demo

MailUserBean

public class MailUserBean extends Object
This JavaBean is used to store mail user information.

Fields Summary
private Folder
folder
private String
hostname
private String
username
private String
password
private Session
session
private Store
store
private URLName
url
private String
protocol
private String
mbox
Constructors Summary
public MailUserBean()

	

     
Methods Summary
public javax.mail.FoldergetFolder()
Returns the javax.mail.Folder object.

        return folder;
    
public java.lang.StringgetHostname()
hostname getter method.

        return hostname;
    
public intgetMessageCount()
Returns the number of messages in the folder.

        return folder.getMessageCount();
    
public java.lang.StringgetPassword()
password getter method.

        return password;
    
public javax.mail.SessiongetSession()
session getter method.

        return session;
    
public javax.mail.StoregetStore()
store getter method.

        return store;
    
public javax.mail.URLNamegetUrl()
url getter method.

        return url;
    
public java.lang.StringgetUsername()
username getter method.

        return username;
    
public booleanisLoggedIn()
Method for checking if the user is logged in.

        return store.isConnected();
    
public voidlogin()
Method used to login to the mail host.

        url = new URLName(protocol, getHostname(), -1, mbox, 
                          getUsername(), getPassword());
	/*
	 * First, try to get the session from JNDI,
	 * as would be done under J2EE.
	 */
	try {
	    InitialContext ic = new InitialContext();
	    Context ctx = (Context)ic.lookup("java:comp/env");
	    session = (Session)ctx.lookup("MySession");
	} catch (Exception ex) {
	    // ignore it
	}

	// if JNDI fails, try the old way that should work everywhere
	if (session == null) {
	    Properties props = null;
	    try {
		props = System.getProperties();
	    } catch (SecurityException sex) {
		props = new Properties();
	    }
	    session = Session.getInstance(props, null);
	}
        store = session.getStore(url);
        store.connect();
        folder = store.getFolder(url);
        
        folder.open(Folder.READ_WRITE);
    
public voidlogin(java.lang.String hostname, java.lang.String username, java.lang.String password)
Method used to login to the mail host.

            
        this.hostname = hostname;
        this.username = username;
        this.password = password;
	    
        login();
    
public voidlogout()
Method used to logout from the mail host.

        folder.close(false);
        store.close();
        store = null;
        session = null;
    
public voidsetHostname(java.lang.String hostname)
hostname setter method.

        this.hostname = hostname;
    
public voidsetPassword(java.lang.String password)
password setter method.

        this.password = password;
    
public voidsetSession(javax.mail.Session session)
session setter method.

        this.session = session;
    
public voidsetStore(javax.mail.Store store)
store setter method.

        this.store = store;
    
public voidsetUsername(java.lang.String username)
username setter method.

        this.username = username;