com.day.cq.mcm.core.importer
Class AbstractMailImporter

java.lang.Object
  extended by com.day.cq.mcm.core.importer.AbstractMailImporter
All Implemented Interfaces:
Importer
Direct Known Subclasses:
ImapImporter, Pop3Importer

public abstract class AbstractMailImporter
extends Object
implements Importer

Abstract base class for mail (polling) importers.

Mail importers are reading mails from the given data source and save them to the repository for later use and processing. Each message polled is stored as a node, using the message id as node name. Message data is stored in properties below. See saveMessage(Message, Node) for the list of properties.

Data Source:
The data source is a mail URI defining all the required parts to connect and get mails from. Since the import is a batch process there is no interactivity to request a password or other configuration options. So all information must go into the data source URI. This mail importer expects the following scheme:

protocol://host:port/folder?username=user&password=secret

More protocol specific configuration can be placed in the query part like this:

protocol://host:port/folder?username=user&password=secret&config.property=configValue

Note:
Mail importers are currently not intended to be fully-fledged mail clients. Their purpose is to poll mails from mail accounts and store them.

See Also:
Pop3Importer, ImapImporter

Field Summary
static String NODE_MESSAGE
          The node name of the message itself = "message"
static String PROPERTY_DATE
          The date property on the mail node = "date"
static String PROPERTY_FROM
          The from property on the mail node = "from"
static String PROPERTY_SUBJECT
          The subject property on the mail node = "subject"
 
Fields inherited from interface com.day.cq.polling.importer.Importer
SCHEME_PROPERTY, SERVICE_NAME
 
Constructor Summary
AbstractMailImporter()
           
 
Method Summary
protected  Folder connect(Properties mailProperties, MailDataSource mailDataSource)
          Connect to a mail folder of the mail data source using the given properties.
protected  void disconnect(Folder folder)
          Disconnect the given mail folder by closing it and also closing the session.
protected abstract  Properties getMailProperties(MailDataSource mailDataSource)
          Get the properties to use when establishing a mail session.
protected abstract  Message[] getMessages(Folder folder, MailDataSource mailDataSource)
          Get the messages from the given folder.
 void importData(String scheme, String dataSource, Resource target)
          Start importing mails by polling from the given mail source and save mails under the given target.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_FROM

public static final String PROPERTY_FROM
The from property on the mail node = "from"

See Also:
Constant Field Values

PROPERTY_SUBJECT

public static final String PROPERTY_SUBJECT
The subject property on the mail node = "subject"

See Also:
Constant Field Values

PROPERTY_DATE

public static final String PROPERTY_DATE
The date property on the mail node = "date"

See Also:
Constant Field Values

NODE_MESSAGE

public static final String NODE_MESSAGE
The node name of the message itself = "message"

See Also:
Constant Field Values
Constructor Detail

AbstractMailImporter

public AbstractMailImporter()
Method Detail

importData

public void importData(String scheme,
                       String dataSource,
                       Resource target)
                throws ImportException
Start importing mails by polling from the given mail source and save mails under the given target.

Specified by:
importData in interface Importer
Parameters:
scheme - The actual scheme of the data source. If an Importer is registered for multiple schemes, this scheme may for example be used to decide on which data represenation can be expected. This value is one of the schemes with which the Importer service has been configured in the importer.scheme service property.
dataSource - The scheme specific string (generally an URI) describing the location at which the data is to be polled. The format of this string is specific to the actual scheme used. For example, this may be a plain HTTP URL of the form http://host/some/data.xml.
target - The target resource into which the data has to be imported
Throws:
ImportException - may be thrown in case of problems accessing, transferring or actually importing the data. If the failure is caused by an exception, this exception ( Throwable) should be made available as the cause of this exception.
See Also:
Importer.importData(java.lang.String, java.lang.String, org.apache.sling.api.resource.Resource)

connect

protected Folder connect(Properties mailProperties,
                         MailDataSource mailDataSource)
                  throws MessagingException
Connect to a mail folder of the mail data source using the given properties. The folder is opened in READ_WRITE mode.

Parameters:
mailProperties -
mailDataSource -
Returns:
Throws:
MessagingException

disconnect

protected void disconnect(Folder folder)
                   throws MessagingException
Disconnect the given mail folder by closing it and also closing the session. The folder is closed with the expunge flag set to true, to save changes.

Parameters:
folder -
Throws:
MessagingException

getMailProperties

protected abstract Properties getMailProperties(MailDataSource mailDataSource)
                                         throws ImportException
Get the properties to use when establishing a mail session. The properties to use are specific for a certain protocol provider.

For example: The IMAP protocol provider properties.

Parameters:
mailDataSource -
Returns:
Throws:
ImportException

getMessages

protected abstract Message[] getMessages(Folder folder,
                                         MailDataSource mailDataSource)
                                  throws MessagingException
Get the messages from the given folder. There are different ways to get messages depending on the protocol used.

Parameters:
folder -
mailDataSource -
Returns:
Throws:
MessagingException


Copyright © 2011-2012 Adobe Systems Incorporated. All Rights Reserved.