if ( jobEntry.getName() != null ) { wName.setText( jobEntry.getName() ); if ( jobEntry.getServerName() != null ) { wServerName.setText( jobEntry.getServerName() ); if ( jobEntry.getUserName() != null ) { wUserName.setText( jobEntry.getUserName() ); if ( jobEntry.getPassword() != null ) { wPassword.setText( jobEntry.getPassword() ); wUseSSL.setSelection( jobEntry.isUseSSL() ); wGetMessage.setSelection( jobEntry.isSaveMessage() ); wGetAttachment.setSelection( jobEntry.isSaveAttachment() ); wDifferentFolderForAttachment.setSelection( jobEntry.isDifferentFolderForAttachment() ); if ( jobEntry.getAttachmentFolder() != null ) { wAttachmentFolder.setText( jobEntry.getAttachmentFolder() ); if ( jobEntry.getPort() != null ) { wPort.setText( jobEntry.getPort() ); if ( jobEntry.getOutputDirectory() != null ) { wOutputDirectory.setText( jobEntry.getOutputDirectory() ); if ( jobEntry.getFilenamePattern() != null ) { wFilenamePattern.setText( jobEntry.getFilenamePattern() ); if ( jobEntry.getAttachmentWildcard() != null ) {
public String getRealFilenamePattern() { return environmentSubstitute( getFilenamePattern() ); }
public String getRealAttachmentFolder() { return environmentSubstitute( getAttachmentFolder() ); }
private void initVariables() { // Attachment wildcard attachementPattern = null; String realAttachmentWildcard = environmentSubstitute( getAttachmentWildcard() ); if ( !Utils.isEmpty( realAttachmentWildcard ) ) { attachementPattern = Pattern.compile( realAttachmentWildcard ); } }
boolean usePOP3 = getProtocol().equals( MailConnectionMeta.PROTOCOL_STRING_POP3 ); boolean moveafter = false; int nbrmailtoretrieve = usePOP3 ? ( getRetrievemails() == 2 ? Const.toInt( getFirstMails(), 0 ) : 0 ) : Const.toInt( getFirstIMAPMails(), 0 ); String realOutputFolder = createOutputDirectory( JobEntryGetPOP.FOLDER_OUTPUT ); String targetAttachmentFolder = createOutputDirectory( JobEntryGetPOP.FOLDER_ATTACHMENTS ); String realMoveToIMAPFolder = environmentSubstitute( getMoveToIMAPFolder() ); if ( getProtocol().equals( MailConnectionMeta.PROTOCOL_STRING_IMAP ) && ( getActionType() == MailConnectionMeta.ACTION_TYPE_MOVE ) || ( getActionType() == MailConnectionMeta.ACTION_TYPE_GET && getAfterGetIMAP() == MailConnectionMeta.AFTER_GET_IMAP_MOVE ) ) { if ( Utils.isEmpty( realMoveToIMAPFolder ) ) { throw new KettleException( BaseMessages switch ( getConditionOnReceivedDate() ) { case MailConnectionMeta.CONDITION_DATE_EQUAL: case MailConnectionMeta.CONDITION_DATE_GREATER: case MailConnectionMeta.CONDITION_DATE_SMALLER: String realBeginDate = environmentSubstitute( getReceivedDate1() ); if ( Utils.isEmpty( realBeginDate ) ) { throw new KettleException( BaseMessages.getString( break; case MailConnectionMeta.CONDITION_DATE_BETWEEN: realBeginDate = environmentSubstitute( getReceivedDate1() ); if ( Utils.isEmpty( realBeginDate ) ) {
/** * PDI-11943 - Get Mail Job Entry: Attachments folder not created * * Test that the Attachments folder is created when the entry is * configured to save attachments and messages in different folders * * @throws IOException */ @Test public void testCreateDifferentAttachmentsFolder() throws IOException { File outputDir = new File( TestUtils.createTempDir() ); File attachmentsDir = new File( TestUtils.createTempDir() ); entry.setCreateLocalFolder( true ); entry.setSaveAttachment( true ); entry.setOutputDirectory( outputDir.getAbsolutePath() ); entry.setDifferentFolderForAttachment( true ); entry.setAttachmentFolder( attachmentsDir.getAbsolutePath() ); String outputFolderName = ""; String attachmentsFolderName = ""; try { outputFolderName = entry.createOutputDirectory( JobEntryGetPOP.FOLDER_OUTPUT ); attachmentsFolderName = entry.createOutputDirectory( JobEntryGetPOP.FOLDER_ATTACHMENTS ); } catch ( Exception e ) { fail( "Could not create folder: " + e.getLocalizedMessage() ); } assertTrue( "Output Folder should be a local path", !Utils.isEmpty( outputFolderName ) ); assertTrue( "Attachment Folder should be a local path", !Utils.isEmpty( attachmentsFolderName ) ); assertFalse( "Output and Attachment Folder should not match", outputFolderName.equals( attachmentsFolderName ) ); }
if ( isDetailed() ) { logDetailed( BaseMessages.getString( PKG, "JobGetMailsFromPOP.TotalMessagesFolder.Label", "" + messagesCount, Const.NVL( mailConn.getFolderName(), MailConnectionMeta.INBOX_FOLDER ) ) ); switch ( getActionType() ) { case MailConnectionMeta.ACTION_TYPE_DELETE: if ( nbrmailtoretrieve > 0 ) { if ( isDebug() ) { logDebug( BaseMessages.getString( PKG, "JobGetMailsFromPOP.MessageDeleted", "" + i ) ); if ( isDebug() ) { logDebug( BaseMessages.getString( PKG, "JobGetMailsFromPOP.MessagesDeleted", "" + messagesCount ) ); if ( isDebug() ) { logDebug( BaseMessages.getString( PKG, "JobGetMailsFromPOP.MessageMoved", "" + i, realMoveToIMAPFolder ) ); if ( isDebug() ) { logDebug( BaseMessages.getString( PKG, "JobGetMailsFromPOP.MessagesMoved", "" + messagesCount, realMoveToIMAPFolder ) ); if ( isDebug() && mailConn.getMessage() != null ) { logDebug( "--------------------------------------------------" ); logDebug( BaseMessages.getString( PKG, "JobGetMailsFromPOP.MessageNumber.Label", "" + messagenumber ) ); if ( mailConn.getMessage().getReceivedDate() != null ) { logDebug( BaseMessages.getString( PKG, "JobGetMailsFromPOP.ReceivedDate.Label", df .format( mailConn.getMessage().getReceivedDate() ) ) );
String attachmentVariableName = "myAttachmentVar"; String attachmentVariableValue = "myOutputFolder"; entry.setVariable( outputVariableName, outputVariableValue ); entry.setVariable( attachmentVariableName, attachmentVariableValue ); entry.setOutputDirectory( outputDirWithVariable ); entry.setAttachmentFolder( attachmentDirWithVariable ); outputDir.toString().equals( entry.getRealOutputDirectory() ) ); assertTrue( "Error in Direct substitute test for attachment directory", attachmentDir.toString().equals( entry.getRealAttachmentFolder() ) ); String outputRes = entry.createOutputDirectory( JobEntryGetPOP.FOLDER_OUTPUT ); assertTrue( "Variables not working in createOutputDirectory: output directory", outputRes.equals( outputDir.toString() ) ); String attachOutputRes = entry.createOutputDirectory( JobEntryGetPOP.FOLDER_ATTACHMENTS ); assertTrue( "Variables not working in createOutputDirectory: attachment with options false", attachOutputRes.equals( outputDir.toString() ) ); entry.setSaveAttachment( true ); entry.setDifferentFolderForAttachment( true ); String attachRes = entry.createOutputDirectory( JobEntryGetPOP.FOLDER_ATTACHMENTS ); assertTrue( "Variables not working in createOutputDirectory: attachment with options true", attachRes.equals( outputDir.toString() ) );
/** * PDI-10942 - Job get emails JobEntry does not mark emails as 'read' when load emails content. * * Test that we always open remote folder in rw mode, and after email attachment is loaded email is marked as read. * Set for openFolder rw mode if this is pop3. * * @throws KettleException * @throws MessagingException */ @Test public void testFetchOneFolderModePop3() throws KettleException, MessagingException { entry.fetchOneFolder( mailConn, true, "junitImapFolder", "junitRealOutputFolder", "junitTargetAttachmentFolder", "junitRealMoveToIMAPFolder", "junitRealFilenamePattern", 0, Mockito.mock( SimpleDateFormat.class ) ); Mockito.verify( mailConn ).openFolder( true ); Mockito.verify( message ).setFlag( Flag.SEEN, true ); }
/** * PDI-11943 - Get Mail Job Entry: Attachments folder not created * * Test that the Attachments folder is created when the entry is * configured to save attachments and messages in the same folder * * @throws IOException */ @Test public void testCreateSameAttachmentsFolder() throws IOException { File attachmentsDir = new File( TestUtils.createTempDir() ); attachmentsDir.deleteOnExit(); entry.setCreateLocalFolder( true ); entry.setSaveAttachment( true ); entry.setOutputDirectory( attachmentsDir.getAbsolutePath() ); entry.setDifferentFolderForAttachment( false ); String outputFolderName = ""; String attachmentsFolderName = ""; try { outputFolderName = entry.createOutputDirectory( JobEntryGetPOP.FOLDER_OUTPUT ); attachmentsFolderName = entry.createOutputDirectory( JobEntryGetPOP.FOLDER_ATTACHMENTS ); } catch ( Exception e ) { fail( "Could not create folder " + e.getLocalizedMessage() ); } assertTrue( "Output Folder should be a local path", !Utils.isEmpty( outputFolderName ) ); assertTrue( "Attachment Folder should be a local path", !Utils.isEmpty( attachmentsFolderName ) ); assertTrue( "Output and Attachment Folder should match", outputFolderName.equals( attachmentsFolderName ) ); }
/** * PDI-10942 - Job get emails JobEntry does not mark emails as 'read' when load emails content. * * Test that we always open remote folder in rw mode, and after email attachment is loaded email is marked as read. * protocol IMAP and default remote folder is overridden * * @throws KettleException * @throws MessagingException */ @Test public void testFetchOneFolderModeIMAPWithNonDefFolder() throws KettleException, MessagingException { entry.fetchOneFolder( mailConn, false, "junitImapFolder", "junitRealOutputFolder", "junitTargetAttachmentFolder", "junitRealMoveToIMAPFolder", "junitRealFilenamePattern", 0, Mockito.mock( SimpleDateFormat.class ) ); Mockito.verify( mailConn ).openFolder( "junitImapFolder", true ); Mockito.verify( message ).setFlag( Flag.SEEN, true ); }
attachmentsDir.delete(); entry.setCreateLocalFolder( false ); entry.setSaveAttachment( true ); entry.setOutputDirectory( outputDir.getAbsolutePath() ); entry.setDifferentFolderForAttachment( true ); entry.setAttachmentFolder( attachmentsDir.getAbsolutePath() ); entry.createOutputDirectory( JobEntryGetPOP.FOLDER_OUTPUT ); fail( "A KettleException should have been thrown" ); } catch ( Exception e ) { entry.createOutputDirectory( JobEntryGetPOP.FOLDER_ATTACHMENTS ); fail( "A KettleException should have been thrown" ); } catch ( Exception e ) {
/** * PDI-10942 - Job get emails JobEntry does not mark emails as 'read' when load emails content. * * Test that we always open remote folder in rw mode, and after email attachment is loaded email is marked as read. * protocol IMAP and default remote folder is NOT overridden * * @throws KettleException * @throws MessagingException */ @Test public void testFetchOneFolderModeIMAPWithIsDefFolder() throws KettleException, MessagingException { entry.fetchOneFolder( mailConn, false, null, "junitRealOutputFolder", "junitTargetAttachmentFolder", "junitRealMoveToIMAPFolder", "junitRealFilenamePattern", 0, Mockito.mock( SimpleDateFormat.class ) ); Mockito.verify( mailConn ).openFolder( true ); Mockito.verify( message ).setFlag( Flag.SEEN, true ); }