org.ow2.petals.bc.mail
Class MailSessionManager

java.lang.Object
  extended by org.ow2.petals.bc.mail.MailSessionManager

public class MailSessionManager
extends java.lang.Object

This manager can be used to manage session with mail servers : create and open sessions, send and receive mails

Author:
ofabre - EBM Websourcing

Field Summary
protected  java.util.logging.Logger log
           
 
Constructor Summary
MailSessionManager(java.util.logging.Logger log)
           
 
Method Summary
 void closeFolderAndStore(javax.mail.Folder folder, javax.mail.Store store, boolean expunge)
          Close previously opened folder and store.
 javax.mail.Session createSessionPropertiesFromDescriptor(ConsumeDescriptor consumeDescriptor)
          Create a Properties object with given properties.
 javax.mail.Session createSessionPropertiesFromDescriptor(ProvideDescriptor provideDescriptor)
          Create a Properties object with given properties.
 javax.mail.Folder getFolderAndOpen(javax.mail.Store store, ConsumeDescriptor consumeDescriptor)
          Retrieve a specified Folder from the given Store and open it.
 java.util.List<javax.mail.Message> getNewMails(javax.mail.Folder folder)
          Retrieve new mails into the given folder.
 javax.mail.Store getStoreAndConnect(javax.mail.Session session, ConsumeDescriptor consumeDescriptor)
          Retrieve a Store from the given Session.
 void sendMail(javax.mail.internet.MimeMessage mimeMessage, ProvideDescriptor sessionDescriptor, javax.mail.Session session)
          Send an email based on the given MimeMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected java.util.logging.Logger log
Constructor Detail

MailSessionManager

public MailSessionManager(java.util.logging.Logger log)
Parameters:
log - the component logger
Method Detail

closeFolderAndStore

public void closeFolderAndStore(javax.mail.Folder folder,
                                javax.mail.Store store,
                                boolean expunge)
Close previously opened folder and store. folder is expunged if needed

Parameters:
folder - the folder to close
store - the store to close
expunge -

createSessionPropertiesFromDescriptor

public javax.mail.Session createSessionPropertiesFromDescriptor(ProvideDescriptor provideDescriptor)
Create a Properties object with given properties. Then create a new Session initialized with the given properties

Parameters:
consumeDescriptor - a SessionDescriptor build from an address URI
Returns:
the Mail Server Session

createSessionPropertiesFromDescriptor

public javax.mail.Session createSessionPropertiesFromDescriptor(ConsumeDescriptor consumeDescriptor)
Create a Properties object with given properties. Then create a new Session initialized with the given properties

Parameters:
consumeDescriptor - a SessionDescriptor build from an address URI
Returns:
the Mail Server Session

getFolderAndOpen

public javax.mail.Folder getFolderAndOpen(javax.mail.Store store,
                                          ConsumeDescriptor consumeDescriptor)
                                   throws javax.mail.MessagingException
Retrieve a specified Folder from the given Store and open it.

Parameters:
store - the mail Store
consumeDescriptor - the mail SessionDescriptor
Returns:
the opened Folder
Throws:
javax.mail.MessagingException

getNewMails

public java.util.List<javax.mail.Message> getNewMails(javax.mail.Folder folder)
                                               throws javax.mail.MessagingException
Retrieve new mails into the given folder. Just unread mail are considered as new mail.

Parameters:
folder - the folder used to search for new mail
Returns:
the new mail Array
Throws:
javax.mail.MessagingException

getStoreAndConnect

public javax.mail.Store getStoreAndConnect(javax.mail.Session session,
                                           ConsumeDescriptor consumeDescriptor)
                                    throws javax.mail.MessagingException
Retrieve a Store from the given Session. Then connect to it.

Parameters:
session - the mail Session
consumeDescriptor - the SessionDescriptor associated to this session
Returns:
the mail Store
Throws:
javax.mail.MessagingException
javax.jbi.JBIException - if error occurs during mail Store retrieval

sendMail

public void sendMail(javax.mail.internet.MimeMessage mimeMessage,
                     ProvideDescriptor sessionDescriptor,
                     javax.mail.Session session)
              throws javax.mail.MessagingException
Send an email based on the given MimeMessage

Parameters:
mimeMessage - the MimeMessage to send. The resulting email will conform to the RFC822 and MIME standards
sessionDescriptor - a SessionDescriptor build from an address URI
session - the mail Session
Throws:
javax.mail.MessagingException - if error occurs during message sending
See Also:
Transport.send(javax.mail.Message);


Copyright © 2005-2011 Petals Link (EBM Websourcing). All Rights Reserved.