Class MailConnection
- java.lang.Object
-
- 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
Constructors Constructor Description MailConnection(org.pentaho.di.core.logging.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearFilters()
Clear search terms.void
closeFolder(boolean expunge)
Close folder.void
connect()
Open the connection.void
deleteMessage()
Delete current fetched messagevoid
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 messageint
getAttachedFilesCount(javax.mail.Message message, Pattern pattern)
int
getDeletedMessagesCounter()
javax.mail.Folder
getFolder()
String
getFolderName()
Returns the foldername.javax.mail.Message
getMessage()
Returns the current message.String
getMessageBody()
String
getMessageBody(javax.mail.Message m)
Return the primary text content of the message.String
getMessageBodyContentType(javax.mail.Message m)
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()
javax.mail.search.SearchTerm
getSearchTerm()
String
getServer()
Returns the server name/Ip.javax.mail.Store
getStore()
boolean
isConnected()
boolean
isMessageDeleted()
Returns if message is deletedboolean
isMessageDeleted(javax.mail.Message msg)
boolean
isMessageDraft()
Returns if message is Draftboolean
isMessageDraft(javax.mail.Message msg)
boolean
isMessageFlagged()
Returns if message is readboolean
isMessageFlagged(javax.mail.Message msg)
boolean
isMessageNew()
Returns if message is newboolean
isMessageNew(javax.mail.Message msg)
boolean
isMessageRead()
Returns if message is readboolean
isMessageRead(javax.mail.Message msg)
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 serverString[]
returnAllFolders()
Returns all subfolders of the current folderString[]
returnAllFolders(String folder)
Returns all subfolders of the folder folderString[]
returnAllFolders(javax.mail.Folder folder)
Returns all subfolders of the specified foldervoid
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 bodyfiltervoid
setDestinationFolder(String foldername, boolean createFolder)
Set destination foldervoid
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()
-
-
-
Constructor Detail
-
MailConnection
public MailConnection(org.pentaho.di.core.logging.LogChannelInterface log, int protocol, String server, int port, String username, String password, boolean usessl, boolean useproxy, String proxyusername) throws org.pentaho.di.core.exception.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 serverpassword
-usessl
- specify if the connection is established via SSLuseproxy
- specify if we use proxy authenticationproxyusername
- proxy authorised user- Throws:
org.pentaho.di.core.exception.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 org.pentaho.di.core.exception.KettleException
Open the connection.- Throws:
org.pentaho.di.core.exception.KettleException
- if something went wrong.
-
openFolder
public void openFolder(boolean write) throws org.pentaho.di.core.exception.KettleException
Open the default folder (INBOX)- Parameters:
write
- open the folder in write mode- Throws:
org.pentaho.di.core.exception.KettleException
- if something went wrong.
-
openFolder
public void openFolder(String foldername, boolean write) throws org.pentaho.di.core.exception.KettleException
Open the folder.- Parameters:
foldername
- the name of the folder to openwrite
- open the folder in write mode- Throws:
org.pentaho.di.core.exception.KettleException
- if something went wrong.
-
openFolder
public void openFolder(String foldername, boolean defaultFolder, boolean write) throws org.pentaho.di.core.exception.KettleException
Open the folder.- Parameters:
foldername
- the name of the folder to opendefaultFolder
- true to open the default folder (INBOX)write
- open the folder in write mode- Throws:
org.pentaho.di.core.exception.KettleException
- if something went wrong.
-
clearFilters
public void clearFilters()
Clear search terms.
-
disconnect
public void disconnect() throws org.pentaho.di.core.exception.KettleException
Disconnect from the server and close folder, connection.- Throws:
org.pentaho.di.core.exception.KettleException
-
closeFolder
public void closeFolder(boolean expunge) throws org.pentaho.di.core.exception.KettleException
Close folder.- Parameters:
expunge
- expunge folder- Throws:
org.pentaho.di.core.exception.KettleException
-
getSearchTerm
public javax.mail.search.SearchTerm getSearchTerm()
-
setSubjectTerm
public void setSubjectTerm(String subject, boolean notTerm)
Set filter on subject.- Parameters:
subject
- messages will be filtered on subjectnotTerm
- 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 sendernotTerm
- negate condition
-
setReceipientTerm
public void setReceipientTerm(String receipient)
Set filter on receipient.- Parameters:
receipient
- messages will be filtered on receipient
-
setReceivedDateTermEQ
public void setReceivedDateTermEQ(Date receiveddate)
Set filter on message received date.- Parameters:
receiveddate
- messages will be filtered on receiveddate
-
setReceivedDateTermLT
public void setReceivedDateTermLT(Date futureDate)
Set filter on message received date.- Parameters:
futureDate
- messages will be filtered on futureDate
-
setReceivedDateTermGT
public void setReceivedDateTermGT(Date pastDate)
Set filter on message received date.- Parameters:
pastDate
- messages will be filtered on pastDate
-
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 org.pentaho.di.core.exception.KettleException
Retrieve all messages from server- Throws:
org.pentaho.di.core.exception.KettleException
-
disconnect
public void disconnect(boolean expunge) throws org.pentaho.di.core.exception.KettleException
Disconnect from the server and close folder, connection.- Parameters:
expunge
- expunge folder- Throws:
org.pentaho.di.core.exception.KettleException
-
saveMessageContentToFile
public void saveMessageContentToFile(String filename, String foldername) throws org.pentaho.di.core.exception.KettleException
Export message content to a filename.- Parameters:
filename
- the target filenamefoldername
- the parent folder of filename- Throws:
org.pentaho.di.core.exception.KettleException
-
saveAttachedFiles
public void saveAttachedFiles(String foldername) throws org.pentaho.di.core.exception.KettleException
Save attached files to a folder.- Parameters:
foldername
- the target foldername- Throws:
org.pentaho.di.core.exception.KettleException
-
saveAttachedFiles
public void saveAttachedFiles(String foldername, Pattern pattern) throws org.pentaho.di.core.exception.KettleException
Save attached files to a folder.- Parameters:
foldername
- the target foldernamepattern
- regular expression to filter on files- Throws:
org.pentaho.di.core.exception.KettleException
-
deleteMessage
public void deleteMessage() throws org.pentaho.di.core.exception.KettleException
Delete current fetched message- Throws:
org.pentaho.di.core.exception.KettleException
-
setDestinationFolder
public void setDestinationFolder(String foldername, boolean createFolder) throws org.pentaho.di.core.exception.KettleException
Set destination folder- Parameters:
foldername
- destination foldernamecreateFolder
- flag create folder if needed- Throws:
org.pentaho.di.core.exception.KettleException
-
moveMessage
public void moveMessage() throws org.pentaho.di.core.exception.KettleException
Move current message to a target folder. (IMAP) You must call setDestinationFolder before calling this method- Throws:
org.pentaho.di.core.exception.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 org.pentaho.di.core.exception.KettleException
Get next message.- Throws:
org.pentaho.di.core.exception.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 org.pentaho.di.core.exception.KettleException
Delete messages.- Throws:
org.pentaho.di.core.exception.KettleException
-
moveMessages
public void moveMessages() throws org.pentaho.di.core.exception.KettleException
Move messages to a folder. You must call setDestinationFolder before calling this method- Throws:
org.pentaho.di.core.exception.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 org.pentaho.di.core.exception.KettleException
Returns all subfolders of the specified folder- Parameters:
folder
- parent folder- Returns:
- sub folders
- Throws:
org.pentaho.di.core.exception.KettleException
-
returnAllFolders
public String[] returnAllFolders() throws org.pentaho.di.core.exception.KettleException
Returns all subfolders of the current folder- Returns:
- sub folders
- Throws:
org.pentaho.di.core.exception.KettleException
-
returnAllFolders
public String[] returnAllFolders(String folder) throws org.pentaho.di.core.exception.KettleException
Returns all subfolders of the folder folder- Parameters:
folder
- target folder- Returns:
- sub folders
- Throws:
org.pentaho.di.core.exception.KettleException
-
getMessageBody
public String getMessageBody(javax.mail.Message m) throws javax.mail.MessagingException, IOException
Return the primary text content of the message.- Throws:
javax.mail.MessagingException
IOException
-
getMessageBodyContentType
public String getMessageBodyContentType(javax.mail.Message m) throws javax.mail.MessagingException, IOException
- Throws:
javax.mail.MessagingException
IOException
-
isMessageNew
public boolean isMessageNew()
Returns if message is new- Returns:
- true if new message
-
isMessageNew
public boolean isMessageNew(javax.mail.Message msg)
-
isMessageRead
public boolean isMessageRead()
Returns if message is read- Returns:
- true if message is read
-
isMessageRead
public boolean isMessageRead(javax.mail.Message msg)
-
isMessageFlagged
public boolean isMessageFlagged()
Returns if message is read- Returns:
- true if message is flagged
-
isMessageFlagged
public boolean isMessageFlagged(javax.mail.Message msg)
-
isMessageDeleted
public boolean isMessageDeleted()
Returns if message is deleted- Returns:
- true if message is deleted
-
isMessageDeleted
public boolean isMessageDeleted(javax.mail.Message msg)
-
isMessageDraft
public boolean isMessageDraft()
Returns if message is Draft- Returns:
- true if message is Draft
-
isMessageDraft
public boolean isMessageDraft(javax.mail.Message msg)
-
getAttachedFilesCount
public int getAttachedFilesCount(Pattern pattern) throws org.pentaho.di.core.exception.KettleException
Returns attached files count for the current message- Parameters:
pattern
- (optional)- Returns:
- true if message is Draft
- Throws:
org.pentaho.di.core.exception.KettleException
-
getAttachedFilesCount
public int getAttachedFilesCount(javax.mail.Message message, Pattern pattern) throws org.pentaho.di.core.exception.KettleException
- Throws:
org.pentaho.di.core.exception.KettleException
-
-