Class MailConnection


  • public class MailConnection
    extends Object
    MailConnection handles the process of connecting to, reading from POP3/IMAP.
    Since:
    01-04-2009
    Author:
    Samatar
    • 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 server
        password -
        usessl - specify if the connection is established via SSL
        useproxy - specify if we use proxy authentication
        proxyusername - 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 open
        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 defaultFolder,
                               boolean write)
                        throws org.pentaho.di.core.exception.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:
        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 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
      • 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
      • 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 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 filename
        foldername - 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 foldername
        pattern - 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 foldername
        createFolder - 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