@Test public void testInitSetGetFirstForIMAP() { MailInput step = new MailInput( mockHelper.stepMeta, mockHelper.stepDataInterface, 0, mockHelper.transMeta, mockHelper.trans ); MailInputData data = new MailInputData(); MailInputMeta meta = mock( MailInputMeta.class ); when( meta.isDynamicFolder() ).thenReturn( false ); when( meta.getProtocol() ).thenReturn( MailConnectionMeta.PROTOCOL_STRING_IMAP ); when( meta.getFirstIMAPMails() ).thenReturn( "2" ); when( meta.getFirstMails() ).thenReturn( "3" ); step.init( meta, data ); Assert.assertEquals( "Row Limit is set up to 2 rows.", 2, data.rowlimit ); }
public boolean init( StepMetaInterface smi, StepDataInterface sdi ) { meta = (MailInputMeta) smi; data = (MailInputData) sdi; if ( !super.init( smi, sdi ) ) { return false; } if ( !meta.isDynamicFolder() ) { try { data.outputRowMeta = new RowMeta(); meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore ); } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "MailInput.ErrorInit", e.toString() ) ); logError( Const.getStackTracker( e ) ); return false; } } data.usePOP = meta.getProtocol().equals( MailConnectionMeta.PROTOCOL_STRING_POP3 ); String realserver = environmentSubstitute( meta.getServerName() ); if ( meta.getProtocol().equals( MailConnectionMeta.PROTOCOL_STRING_MBOX ) && StringUtils.startsWith( realserver, "file: realserver = StringUtils.remove( realserver, "file: } String realusername = environmentSubstitute( meta.getUserName() ); String realpassword = Utils.resolvePassword( variables, meta.getPassword() ); int realport = Const.toInt( environmentSubstitute( meta.getPort() ), -1 ); String realProxyUsername = environmentSubstitute( meta.getProxyUsername() ); if ( !meta.isDynamicFolder() ) { String reallimitrow = environmentSubstitute( meta.getRowLimit() ); int limit = Const.toInt( reallimitrow, 0 ); if ( limit == 0 ) { limit = getReadFirst( meta.getProtocol() ); } data.rowlimit = limit; } Date beginDate = null; Date endDate = null; SimpleDateFormat df = new SimpleDateFormat( MailInputMeta.DATE_PATTERN ); try { switch ( meta.getConditionOnReceivedDate() ) { case MailConnectionMeta.CONDITION_DATE_EQUAL: case MailConnectionMeta.CONDITION_DATE_GREATER: case MailConnectionMeta.CONDITION_DATE_SMALLER: String realBeginDate = environmentSubstitute( meta.getReceivedDate1() ); if ( Utils.isEmpty( realBeginDate ) ) { throw new KettleException( BaseMessages.getString( PKG, "MailInput.Error.ReceivedDateSearchTermEmpty" ) ); } beginDate = df.parse( realBeginDate ); break; case MailConnectionMeta.CONDITION_DATE_BETWEEN: realBeginDate = environmentSubstitute( meta.getReceivedDate1() ); if ( Utils.isEmpty( realBeginDate ) ) { throw new KettleException( BaseMessages.getString( PKG, "MailInput.Error.ReceivedDatesSearchTermEmpty" ) ); } beginDate = df.parse( realBeginDate ); String realEndDate = environmentSubstitute( meta.getReceivedDate2() ); if ( Utils.isEmpty( realEndDate ) ) { throw new KettleException( BaseMessages.getString( PKG, "MailInput.Error.ReceivedDatesSearchTermEmpty" ) ); } endDate = df.parse( realEndDate ); break; default: break; } } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "MailInput.Error.SettingSearchTerms", e.getMessage() ) ); setErrors( 1 ); stopAll(); } try { data.mailConn = new MailConnection( log, MailConnectionMeta.getProtocolFromString( meta.getProtocol(), MailConnectionMeta.PROTOCOL_IMAP ), realserver, realport, realusername, realpassword, meta.isUseSSL(), meta.isUseProxy(), realProxyUsername ); data.mailConn.connect(); applySearch( beginDate, endDate ); if ( !meta.isDynamicFolder() ) { String realIMAPFolder = environmentSubstitute( meta.getIMAPFolder() ); data.folders = getFolders( realIMAPFolder ); } } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "MailInput.Error.OpeningConnection", e.getMessage() ) ); setErrors( 1 ); stopAll(); } data.nrFields = meta.getInputFields() != null ? meta.getInputFields().length : 0; return true; }
MailInput extends BaseStep implements StepInterface { public boolean init( StepMetaInterface smi, StepDataInterface sdi ) { meta = (MailInputMeta) smi; data = (MailInputData) sdi; if ( !super.init( smi, sdi ) ) { return false; } if ( !meta.isDynamicFolder() ) { try { data.outputRowMeta = new RowMeta(); meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore ); } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "MailInput.ErrorInit", e.toString() ) ); logError( Const.getStackTracker( e ) ); return false; } } data.usePOP = meta.getProtocol().equals( MailConnectionMeta.PROTOCOL_STRING_POP3 ); String realserver = environmentSubstitute( meta.getServerName() ); if ( meta.getProtocol().equals( MailConnectionMeta.PROTOCOL_STRING_MBOX ) && StringUtils.startsWith( realserver, "file: realserver = StringUtils.remove( realserver, "file: } String realusername = environmentSubstitute( meta.getUserName() ); String realpassword = Utils.resolvePassword( variables, meta.getPassword() ); int realport = Const.toInt( environmentSubstitute( meta.getPort() ), -1 ); String realProxyUsername = environmentSubstitute( meta.getProxyUsername() ); if ( !meta.isDynamicFolder() ) { String reallimitrow = environmentSubstitute( meta.getRowLimit() ); int limit = Const.toInt( reallimitrow, 0 ); if ( limit == 0 ) { limit = getReadFirst( meta.getProtocol() ); } data.rowlimit = limit; } Date beginDate = null; Date endDate = null; SimpleDateFormat df = new SimpleDateFormat( MailInputMeta.DATE_PATTERN ); try { switch ( meta.getConditionOnReceivedDate() ) { case MailConnectionMeta.CONDITION_DATE_EQUAL: case MailConnectionMeta.CONDITION_DATE_GREATER: case MailConnectionMeta.CONDITION_DATE_SMALLER: String realBeginDate = environmentSubstitute( meta.getReceivedDate1() ); if ( Utils.isEmpty( realBeginDate ) ) { throw new KettleException( BaseMessages.getString( PKG, "MailInput.Error.ReceivedDateSearchTermEmpty" ) ); } beginDate = df.parse( realBeginDate ); break; case MailConnectionMeta.CONDITION_DATE_BETWEEN: realBeginDate = environmentSubstitute( meta.getReceivedDate1() ); if ( Utils.isEmpty( realBeginDate ) ) { throw new KettleException( BaseMessages.getString( PKG, "MailInput.Error.ReceivedDatesSearchTermEmpty" ) ); } beginDate = df.parse( realBeginDate ); String realEndDate = environmentSubstitute( meta.getReceivedDate2() ); if ( Utils.isEmpty( realEndDate ) ) { throw new KettleException( BaseMessages.getString( PKG, "MailInput.Error.ReceivedDatesSearchTermEmpty" ) ); } endDate = df.parse( realEndDate ); break; default: break; } } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "MailInput.Error.SettingSearchTerms", e.getMessage() ) ); setErrors( 1 ); stopAll(); } try { data.mailConn = new MailConnection( log, MailConnectionMeta.getProtocolFromString( meta.getProtocol(), MailConnectionMeta.PROTOCOL_IMAP ), realserver, realport, realusername, realpassword, meta.isUseSSL(), meta.isUseProxy(), realProxyUsername ); data.mailConn.connect(); applySearch( beginDate, endDate ); if ( !meta.isDynamicFolder() ) { String realIMAPFolder = environmentSubstitute( meta.getIMAPFolder() ); data.folders = getFolders( realIMAPFolder ); } } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "MailInput.Error.OpeningConnection", e.getMessage() ) ); setErrors( 1 ); stopAll(); } data.nrFields = meta.getInputFields() != null ? meta.getInputFields().length : 0; return true; } }
MailInput extends BaseStep implements StepInterface { public boolean init( StepMetaInterface smi, StepDataInterface sdi ) { meta = (MailInputMeta) smi; data = (MailInputData) sdi; if ( !super.init( smi, sdi ) ) { return false; } if ( !meta.isDynamicFolder() ) { try { data.outputRowMeta = new RowMeta(); meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore ); } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "MailInput.ErrorInit", e.toString() ) ); logError( Const.getStackTracker( e ) ); return false; } } data.usePOP = meta.getProtocol().equals( MailConnectionMeta.PROTOCOL_STRING_POP3 ); String realserver = environmentSubstitute( meta.getServerName() ); if ( meta.getProtocol().equals( MailConnectionMeta.PROTOCOL_STRING_MBOX ) && StringUtils.startsWith( realserver, "file: realserver = StringUtils.remove( realserver, "file: } String realusername = environmentSubstitute( meta.getUserName() ); String realpassword = Utils.resolvePassword( variables, meta.getPassword() ); int realport = Const.toInt( environmentSubstitute( meta.getPort() ), -1 ); String realProxyUsername = environmentSubstitute( meta.getProxyUsername() ); if ( !meta.isDynamicFolder() ) { String reallimitrow = environmentSubstitute( meta.getRowLimit() ); int limit = Const.toInt( reallimitrow, 0 ); if ( limit == 0 ) { limit = getReadFirst( meta.getProtocol() ); } data.rowlimit = limit; } Date beginDate = null; Date endDate = null; SimpleDateFormat df = new SimpleDateFormat( MailInputMeta.DATE_PATTERN ); try { switch ( meta.getConditionOnReceivedDate() ) { case MailConnectionMeta.CONDITION_DATE_EQUAL: case MailConnectionMeta.CONDITION_DATE_GREATER: case MailConnectionMeta.CONDITION_DATE_SMALLER: String realBeginDate = environmentSubstitute( meta.getReceivedDate1() ); if ( Utils.isEmpty( realBeginDate ) ) { throw new KettleException( BaseMessages.getString( PKG, "MailInput.Error.ReceivedDateSearchTermEmpty" ) ); } beginDate = df.parse( realBeginDate ); break; case MailConnectionMeta.CONDITION_DATE_BETWEEN: realBeginDate = environmentSubstitute( meta.getReceivedDate1() ); if ( Utils.isEmpty( realBeginDate ) ) { throw new KettleException( BaseMessages.getString( PKG, "MailInput.Error.ReceivedDatesSearchTermEmpty" ) ); } beginDate = df.parse( realBeginDate ); String realEndDate = environmentSubstitute( meta.getReceivedDate2() ); if ( Utils.isEmpty( realEndDate ) ) { throw new KettleException( BaseMessages.getString( PKG, "MailInput.Error.ReceivedDatesSearchTermEmpty" ) ); } endDate = df.parse( realEndDate ); break; default: break; } } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "MailInput.Error.SettingSearchTerms", e.getMessage() ) ); setErrors( 1 ); stopAll(); } try { data.mailConn = new MailConnection( log, MailConnectionMeta.getProtocolFromString( meta.getProtocol(), MailConnectionMeta.PROTOCOL_IMAP ), realserver, realport, realusername, realpassword, meta.isUseSSL(), meta.isUseProxy(), realProxyUsername ); data.mailConn.connect(); applySearch( beginDate, endDate ); if ( !meta.isDynamicFolder() ) { String realIMAPFolder = environmentSubstitute( meta.getIMAPFolder() ); data.folders = getFolders( realIMAPFolder ); } } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "MailInput.Error.OpeningConnection", e.getMessage() ) ); setErrors( 1 ); stopAll(); } data.nrFields = meta.getInputFields() != null ? meta.getInputFields().length : 0; return true; } MailInput( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
    Trans trans ); }
MailInput extends BaseStep implements StepInterface { public boolean init( StepMetaInterface smi, StepDataInterface sdi ) { meta = (MailInputMeta) smi; data = (MailInputData) sdi; if ( !super.init( smi, sdi ) ) { return false; } if ( !meta.isDynamicFolder() ) { try { data.outputRowMeta = new RowMeta(); meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore ); } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "MailInput.ErrorInit", e.toString() ) ); logError( Const.getStackTracker( e ) ); return false; } } data.usePOP = meta.getProtocol().equals( MailConnectionMeta.PROTOCOL_STRING_POP3 ); String realserver = environmentSubstitute( meta.getServerName() ); if ( meta.getProtocol().equals( MailConnectionMeta.PROTOCOL_STRING_MBOX ) && StringUtils.startsWith( realserver, "file: realserver = StringUtils.remove( realserver, "file: } String realusername = environmentSubstitute( meta.getUserName() ); String realpassword = Utils.resolvePassword( variables, meta.getPassword() ); int realport = Const.toInt( environmentSubstitute( meta.getPort() ), -1 ); String realProxyUsername = environmentSubstitute( meta.getProxyUsername() ); if ( !meta.isDynamicFolder() ) { String reallimitrow = environmentSubstitute( meta.getRowLimit() ); int limit = Const.toInt( reallimitrow, 0 ); if ( limit == 0 ) { limit = getReadFirst( meta.getProtocol() ); } data.rowlimit = limit; } Date beginDate = null; Date endDate = null; SimpleDateFormat df = new SimpleDateFormat( MailInputMeta.DATE_PATTERN ); try { switch ( meta.getConditionOnReceivedDate() ) { case MailConnectionMeta.CONDITION_DATE_EQUAL: case MailConnectionMeta.CONDITION_DATE_GREATER: case MailConnectionMeta.CONDITION_DATE_SMALLER: String realBeginDate = environmentSubstitute( meta.getReceivedDate1() ); if ( Utils.isEmpty( realBeginDate ) ) { throw new KettleException( BaseMessages.getString( PKG, "MailInput.Error.ReceivedDateSearchTermEmpty" ) ); } beginDate = df.parse( realBeginDate ); break; case MailConnectionMeta.CONDITION_DATE_BETWEEN: realBeginDate = environmentSubstitute( meta.getReceivedDate1() ); if ( Utils.isEmpty( realBeginDate ) ) { throw new KettleException( BaseMessages.getString( PKG, "MailInput.Error.ReceivedDatesSearchTermEmpty" ) ); } beginDate = df.parse( realBeginDate ); String realEndDate = environmentSubstitute( meta.getReceivedDate2() ); if ( Utils.isEmpty( realEndDate ) ) { throw new KettleException( BaseMessages.getString( PKG, "MailInput.Error.ReceivedDatesSearchTermEmpty" ) ); } endDate = df.parse( realEndDate ); break; default: break; } } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "MailInput.Error.SettingSearchTerms", e.getMessage() ) ); setErrors( 1 ); stopAll(); } try { data.mailConn = new MailConnection( log, MailConnectionMeta.getProtocolFromString( meta.getProtocol(), MailConnectionMeta.PROTOCOL_IMAP ), realserver, realport, realusername, realpassword, meta.isUseSSL(), meta.isUseProxy(), realProxyUsername ); data.mailConn.connect(); applySearch( beginDate, endDate ); if ( !meta.isDynamicFolder() ) { String realIMAPFolder = environmentSubstitute( meta.getIMAPFolder() ); data.folders = getFolders( realIMAPFolder ); } } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "MailInput.Error.OpeningConnection", e.getMessage() ) ); setErrors( 1 ); stopAll(); } data.nrFields = meta.getInputFields() != null ? meta.getInputFields().length : 0; return true; } MailInput( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
    Trans trans ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); String[] getFolders( String realIMAPFolder ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); }
MailInput extends BaseStep implements StepInterface { public boolean init( StepMetaInterface smi, StepDataInterface sdi ) { meta = (MailInputMeta) smi; data = (MailInputData) sdi; if ( !super.init( smi, sdi ) ) { return false; } if ( !meta.isDynamicFolder() ) { try { data.outputRowMeta = new RowMeta(); meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore ); } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "MailInput.ErrorInit", e.toString() ) ); logError( Const.getStackTracker( e ) ); return false; } } data.usePOP = meta.getProtocol().equals( MailConnectionMeta.PROTOCOL_STRING_POP3 ); String realserver = environmentSubstitute( meta.getServerName() ); if ( meta.getProtocol().equals( MailConnectionMeta.PROTOCOL_STRING_MBOX ) && StringUtils.startsWith( realserver, "file: realserver = StringUtils.remove( realserver, "file: } String realusername = environmentSubstitute( meta.getUserName() ); String realpassword = Utils.resolvePassword( variables, meta.getPassword() ); int realport = Const.toInt( environmentSubstitute( meta.getPort() ), -1 ); String realProxyUsername = environmentSubstitute( meta.getProxyUsername() ); if ( !meta.isDynamicFolder() ) { String reallimitrow = environmentSubstitute( meta.getRowLimit() ); int limit = Const.toInt( reallimitrow, 0 ); if ( limit == 0 ) { limit = getReadFirst( meta.getProtocol() ); } data.rowlimit = limit; } Date beginDate = null; Date endDate = null; SimpleDateFormat df = new SimpleDateFormat( MailInputMeta.DATE_PATTERN ); try { switch ( meta.getConditionOnReceivedDate() ) { case MailConnectionMeta.CONDITION_DATE_EQUAL: case MailConnectionMeta.CONDITION_DATE_GREATER: case MailConnectionMeta.CONDITION_DATE_SMALLER: String realBeginDate = environmentSubstitute( meta.getReceivedDate1() ); if ( Utils.isEmpty( realBeginDate ) ) { throw new KettleException( BaseMessages.getString( PKG, "MailInput.Error.ReceivedDateSearchTermEmpty" ) ); } beginDate = df.parse( realBeginDate ); break; case MailConnectionMeta.CONDITION_DATE_BETWEEN: realBeginDate = environmentSubstitute( meta.getReceivedDate1() ); if ( Utils.isEmpty( realBeginDate ) ) { throw new KettleException( BaseMessages.getString( PKG, "MailInput.Error.ReceivedDatesSearchTermEmpty" ) ); } beginDate = df.parse( realBeginDate ); String realEndDate = environmentSubstitute( meta.getReceivedDate2() ); if ( Utils.isEmpty( realEndDate ) ) { throw new KettleException( BaseMessages.getString( PKG, "MailInput.Error.ReceivedDatesSearchTermEmpty" ) ); } endDate = df.parse( realEndDate ); break; default: break; } } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "MailInput.Error.SettingSearchTerms", e.getMessage() ) ); setErrors( 1 ); stopAll(); } try { data.mailConn = new MailConnection( log, MailConnectionMeta.getProtocolFromString( meta.getProtocol(), MailConnectionMeta.PROTOCOL_IMAP ), realserver, realport, realusername, realpassword, meta.isUseSSL(), meta.isUseProxy(), realProxyUsername ); data.mailConn.connect(); applySearch( beginDate, endDate ); if ( !meta.isDynamicFolder() ) { String realIMAPFolder = environmentSubstitute( meta.getIMAPFolder() ); data.folders = getFolders( realIMAPFolder ); } } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "MailInput.Error.OpeningConnection", e.getMessage() ) ); setErrors( 1 ); stopAll(); } data.nrFields = meta.getInputFields() != null ? meta.getInputFields().length : 0; return true; } MailInput( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
    Trans trans ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); String[] getFolders( String realIMAPFolder ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi );  }