org.pentaho.di.job.entries.getpop
Class MailConnection

java.lang.Object
  extended by org.pentaho.di.job.entries.getpop.MailConnection

public class MailConnection
extends Object

MailConnection handles the process of connecting to, reading from POP3/IMAP.

Since:
01-04-2009
Author:
Samatar

Constructor Summary
MailConnection(LogChannelInterface log, int protocol, String server, int port, String username, String password, boolean usessl, boolean useproxy, String proxyusername)
          Construct a new Database MailConnection
 
Method Summary
 void clearFilters()
          Clear search terms.
 void closeFolder(boolean expunge)
          Close folder.
 void connect()
          Open the connection.
 void deleteMessage()
          Delete current fetched message
 void deleteMessages(boolean setCounter)
          Delete messages.
 void disconnect()
          Disconnect from the server and close folder, connection.
 void disconnect(boolean expunge)
          Disconnect from the server and close folder, connection.
 void fetchNext()
          Get next message.
 boolean folderExists(String foldername)
          Check if a folder exists on server (only IMAP).
 int getAttachedFilesCount(Pattern pattern)
          Returns attached files count for the current message
 int getDeletedMessagesCounter()
           
 javax.mail.Folder getFolder()
           
 String getFolderName()
          Returns the foldername.
 javax.mail.Message getMessage()
          Returns the current message.
 String getMessageBody()
           
 javax.mail.Message[] getMessages()
          Returns all messages.
 int getMessagesCount()
          Returns the number of messages.
 int getMovedMessagesCounter()
          Returns count of moved messages.
 int getProtocol()
          Returns the protocol.
 String getProxyUsername()
           
 int getSavedAttachedFilesCounter()
           
 int getSavedMessagesCounter()
           
 String getServer()
          Returns the server name/Ip.
 javax.mail.Store getStore()
           
 boolean isConnected()
           
 boolean isMessageDeleted()
          Returns if message is deleted
 boolean isMessageDraft()
          Returns if message is Draft
 boolean isMessageFlagged()
          Returns if message is read
 boolean isMessageNew()
          Returns if message is new
 boolean isMessageRead()
          Returns if message is read
 boolean isUseProxy()
           
 boolean isUseSSL()
           
 void moveMessage()
          Move current message to a target folder.
 void moveMessages()
          Move messages to a folder.
 void openFolder(boolean write)
          Open the default folder (INBOX)
 void openFolder(String foldername, boolean write)
          Open the folder.
 void openFolder(String foldername, boolean defaultFolder, boolean write)
          Open the folder.
 void retrieveMessages()
          Retrieve all messages from server
 String[] returnAllFolders()
          Returns all subfolders of the current folder
 String[] returnAllFolders(javax.mail.Folder folder)
          Returns all subfolders of the specified folder
 String[] returnAllFolders(String folder)
          Returns all subfolders of the folder folder
 void saveAttachedFiles(String foldername)
          Save attached files to a folder.
 void saveAttachedFiles(String foldername, Pattern pattern)
          Save attached files to a folder.
 void saveMessageContentToFile(String filename, String foldername)
          Export message content to a filename.
 void setBodyTerm(String bodyfilter, boolean notTerm)
          Search all messages with body containing the word bodyfilter
 void setDestinationFolder(String foldername, boolean createFolder)
          Set destination folder
 void setFlagTermDraft()
           
 void setFlagTermFlagged()
           
 void setFlagTermNew()
           
 void setFlagTermNotDraft()
           
 void setFlagTermNotFlagged()
           
 void setFlagTermOld()
           
 void setFlagTermRead()
           
 void setFlagTermUnread()
           
 void setReceipientTerm(String receipient)
          Set filter on receipient.
 void setReceivedDateTermBetween(Date beginDate, Date endDate)
           
 void setReceivedDateTermEQ(Date receiveddate)
          Set filter on message received date.
 void setReceivedDateTermGT(Date pastDate)
          Set filter on message received date.
 void setReceivedDateTermLT(Date futureDate)
          Set filter on message received date.
 void setSenderTerm(String sender, boolean notTerm)
          Set filter on message sender.
 void setSubjectTerm(String subject, boolean notTerm)
          Set filter on subject.
 String toString()
           
 void updateSavedAttachedFilesCounter()
           
 void updateSavedMessagesCounter()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MailConnection

public MailConnection(LogChannelInterface log,
                      int protocol,
                      String server,
                      int port,
                      String username,
                      String password,
                      boolean usessl,
                      boolean useproxy,
                      String proxyusername)
               throws KettleException
Construct a new Database MailConnection

Parameters:
protocol - the protocol used : MailConnection.PROTOCOL_POP3 or MailConnection.PROTOCOL_IMAP.
server - the target server (ip ou name)
port - port number on the server
password -
usessl - specify if the connection is established via SSL
useproxy - specify if we use proxy authentication
proxyusername - proxy authorised user
Throws:
KettleException
Method Detail

isConnected

public boolean isConnected()
Returns:
Returns the connection status. true if the connection is still opened

isUseSSL

public boolean isUseSSL()
Returns:
Returns the use of SSL. true if the connection use SSL

isUseProxy

public boolean isUseProxy()
Returns:
Returns the use of proxy. true if the connection use proxy

getProxyUsername

public String getProxyUsername()
Returns:
Returns the proxy username.

getStore

public javax.mail.Store getStore()
Returns:
Returns the store

getFolder

public javax.mail.Folder getFolder()
Returns:
Returns the folder

connect

public void connect()
             throws KettleException
Open the connection.

Throws:
KettleException - if something went wrong.

openFolder

public void openFolder(boolean write)
                throws KettleException
Open the default folder (INBOX)

Parameters:
write - open the folder in write mode
Throws:
KettleException - if something went wrong.

openFolder

public void openFolder(String foldername,
                       boolean write)
                throws KettleException
Open the folder.

Parameters:
foldername - the name of the folder to open
write - open the folder in write mode
Throws:
KettleException - if something went wrong.

openFolder

public void openFolder(String foldername,
                       boolean defaultFolder,
                       boolean write)
                throws KettleException
Open the folder.

Parameters:
foldername - the name of the folder to open
defaultFolder - true to open the default folder (INBOX)
write - open the folder in write mode
Throws:
KettleException - if something went wrong.

clearFilters

public void clearFilters()
Clear search terms.


disconnect

public void disconnect()
                throws KettleException
Disconnect from the server and close folder, connection.

Throws:
KettleException

closeFolder

public void closeFolder(boolean expunge)
                 throws KettleException
Close folder.

Parameters:
expunge - expunge folder
Throws:
KettleException

setSubjectTerm

public void setSubjectTerm(String subject,
                           boolean notTerm)
Set filter on subject.

Parameters:
subject - messages will be filtered on subject
notTerm - negate condition

setBodyTerm

public void setBodyTerm(String bodyfilter,
                        boolean notTerm)
Search all messages with body containing the word bodyfilter

Parameters:
bodyfilter -
notTerm - negate condition

setSenderTerm

public void setSenderTerm(String sender,
                          boolean notTerm)
Set filter on message sender.

Parameters:
sender - messages will be filtered on sender
notTerm - negate condition

setReceipientTerm

public void setReceipientTerm(String receipient)
Set filter on receipient.

Parameters:
receipient - messages will be filtered on receipient
notTerm - negate condition

setReceivedDateTermEQ

public void setReceivedDateTermEQ(Date receiveddate)
Set filter on message received date.

Parameters:
receiveddate - messages will be filtered on receiveddate
notTerm - negate condition

setReceivedDateTermLT

public void setReceivedDateTermLT(Date futureDate)
Set filter on message received date.

Parameters:
futureDate - messages will be filtered on futureDate
notTerm - negate condition

setReceivedDateTermGT

public void setReceivedDateTermGT(Date pastDate)
Set filter on message received date.

Parameters:
pastDate - messages will be filtered on pastDate
notTerm - negate condition

setReceivedDateTermBetween

public void setReceivedDateTermBetween(Date beginDate,
                                       Date endDate)

setFlagTermNew

public void setFlagTermNew()

setFlagTermOld

public void setFlagTermOld()

setFlagTermRead

public void setFlagTermRead()

setFlagTermUnread

public void setFlagTermUnread()

setFlagTermFlagged

public void setFlagTermFlagged()

setFlagTermNotFlagged

public void setFlagTermNotFlagged()

setFlagTermDraft

public void setFlagTermDraft()

setFlagTermNotDraft

public void setFlagTermNotDraft()

retrieveMessages

public void retrieveMessages()
                      throws KettleException
Retrieve all messages from server

Throws:
KettleException

disconnect

public void disconnect(boolean expunge)
                throws KettleException
Disconnect from the server and close folder, connection.

Parameters:
expunge - expunge folder
Throws:
KettleException

saveMessageContentToFile

public void saveMessageContentToFile(String filename,
                                     String foldername)
                              throws KettleException
Export message content to a filename.

Parameters:
filename - the target filename
foldername - the parent folder of filename
Throws:
KettleException.
KettleException

saveAttachedFiles

public void saveAttachedFiles(String foldername)
                       throws KettleException
Save attached files to a folder.

Parameters:
foldername - the target foldername
Throws:
KettleException.
KettleException

saveAttachedFiles

public void saveAttachedFiles(String foldername,
                              Pattern pattern)
                       throws KettleException
Save attached files to a folder.

Parameters:
foldername - the target foldername
pattern - regular expression to filter on files
Throws:
KettleException.
KettleException

deleteMessage

public void deleteMessage()
                   throws KettleException
Delete current fetched message

Throws:
KettleException

setDestinationFolder

public void setDestinationFolder(String foldername,
                                 boolean createFolder)
                          throws KettleException
Set destination folder

Parameters:
foldername - destination foldername
createFolder - flag create folder if needed
Throws:
KettleException

moveMessage

public void moveMessage()
                 throws KettleException
Move current message to a target folder. (IMAP) You must call setDestinationFolder before calling this method

Throws:
KettleException

getFolderName

public String getFolderName()
Returns the foldername.

Returns:
foldername

getServer

public String getServer()
Returns the server name/Ip.

Returns:
server

getProtocol

public int getProtocol()
Returns the protocol.

Returns:
protocol

getMessages

public javax.mail.Message[] getMessages()
Returns all messages.

Returns:
all messages

fetchNext

public void fetchNext()
               throws KettleException
Get next message.

Throws:
KettleException

getMessage

public javax.mail.Message getMessage()
Returns the current message.

Returns:
current message

getMessagesCount

public int getMessagesCount()
Returns the number of messages.

Returns:
messages count

updateSavedMessagesCounter

public void updateSavedMessagesCounter()

getSavedMessagesCounter

public int getSavedMessagesCounter()

getSavedAttachedFilesCounter

public int getSavedAttachedFilesCounter()

updateSavedAttachedFilesCounter

public void updateSavedAttachedFilesCounter()

getDeletedMessagesCounter

public int getDeletedMessagesCounter()

getMovedMessagesCounter

public int getMovedMessagesCounter()
Returns count of moved messages.

Returns:
count of moved messages

deleteMessages

public void deleteMessages(boolean setCounter)
                    throws KettleException
Delete messages.

Throws:
KettleException

moveMessages

public void moveMessages()
                  throws KettleException
Move messages to a folder. You must call setDestinationFolder before calling this method

Throws:
KettleException

folderExists

public boolean folderExists(String foldername)
Check if a folder exists on server (only IMAP).

Parameters:
foldername - the name of the folder
Returns:
true is folder exists

returnAllFolders

public String[] returnAllFolders(javax.mail.Folder folder)
                          throws KettleException
Returns all subfolders of the specified folder

Parameters:
taget - parent folder
Returns:
sub folders
Throws:
KettleException

returnAllFolders

public String[] returnAllFolders()
                          throws KettleException
Returns all subfolders of the current folder

Returns:
sub folders
Throws:
KettleException

returnAllFolders

public String[] returnAllFolders(String folder)
                          throws KettleException
Returns all subfolders of the folder folder

Parameters:
folder - target folder
Returns:
sub folders
Throws:
KettleException

getMessageBody

public String getMessageBody()
                      throws Exception
Throws:
Exception

isMessageNew

public boolean isMessageNew()
Returns if message is new

Returns:
true if new message

isMessageRead

public boolean isMessageRead()
Returns if message is read

Returns:
true if message is read

isMessageFlagged

public boolean isMessageFlagged()
Returns if message is read

Returns:
true if message is flagged

isMessageDeleted

public boolean isMessageDeleted()
Returns if message is deleted

Returns:
true if message is deleted

isMessageDraft

public boolean isMessageDraft()
Returns if message is Draft

Returns:
true if message is Draft

toString

public String toString()
Overrides:
toString in class Object

getAttachedFilesCount

public int getAttachedFilesCount(Pattern pattern)
                          throws KettleException
Returns attached files count for the current message

Parameters:
pattern - (optional)
Returns:
true if message is Draft
Throws:
KettleException