FileDocCategorySizeDatePackage
MailFolder.javaAPI DocJBoss 4.2.13480Fri Jul 13 21:01:14 BST 2007org.jboss.resource.adapter.mail.inflow

MailFolder

public class MailFolder extends Object
An encapsulation of a mail store folder used by the MailActivation.run to poll and retrieve new messages.
author
Scott.Stark@jboss.org
version
$Revision: 60787 $

Fields Summary
private Session
session
private Store
store
private Folder
folder
private String
mailServer
private String
folderName
private String
userName
private String
password
private Properties
sessionProps
Constructors Summary
public MailFolder(MailActivationSpec spec)

      mailServer = spec.getMailServer();
      String protocol = spec.getStoreProtocol();
      folderName = spec.getMailFolder();
      userName = spec.getUserName();
      password = spec.getPassword();

      sessionProps = new Properties();
      sessionProps.setProperty("mail.transport.protocol", "smtp");
      sessionProps.setProperty("mail.store.protocol", protocol);
      sessionProps.setProperty("mail.smtp.host", mailServer);
   
Methods Summary
public voidclose()

      this.folder.close(true);
      this.store.close();
      this.folder = null;
      this.store = null;
      this.session = null;
   
public javax.mail.Message[]getNewMessages()

      Message msgs[] = {};
      /* This does not seem to be the most reliable new msg check. This should
      probably be unread msgs with the msgs marked as read on successful
      delivery.
      */
      if( folder.hasNewMessages() )
      {
         int newCount = folder.getNewMessageCount();
         int msgCount = folder.getMessageCount();
         msgs = folder.getMessages(msgCount - newCount + 1, msgCount);
         return msgs;
      }
      return msgs;
   
public voidopen()

      // Get a session object
      session = Session.getInstance(sessionProps);
      
      // Get a store object
      store = session.getStore();
      store.connect(mailServer, userName, password);
      folder = store.getFolder(folderName);

      if (folder == null || (!this.folder.exists()))
      {
         MessagingException e = new MessagingException("Failed to find folder: " + folderName);
         throw e;
      }

      folder.open(Folder.READ_WRITE);