Search in sources :

Example 1 with MailValidationResult

use of org.pentaho.di.trans.steps.mailvalidator.MailValidationResult in project pentaho-kettle by pentaho.

the class JobEntryMailValidator method execute.

/**
 * Execute this job entry and return the result. In this case it means, just set the result boolean in the Result
 * class.
 *
 * @param previousResult
 *          The result of the previous execution
 * @return The Result of the execution.
 */
public Result execute(Result previousResult, int nr) {
    Result result = previousResult;
    result.setNrErrors(1);
    result.setResult(false);
    String realEmailAddress = environmentSubstitute(emailAddress);
    if (Utils.isEmpty(realEmailAddress)) {
        logError(BaseMessages.getString(PKG, "JobEntryMailValidator.Error.EmailEmpty"));
        return result;
    }
    String realSender = environmentSubstitute(emailSender);
    if (smtpCheck) {
        // check sender
        if (Utils.isEmpty(realSender)) {
            logError(BaseMessages.getString(PKG, "JobEntryMailValidator.Error.EmailSenderEmpty"));
            return result;
        }
    }
    String realDefaultSMTP = environmentSubstitute(defaultSMTP);
    int timeOut = Const.toInt(environmentSubstitute(timeout), 0);
    // Split the mail-address: separated by space
    String[] mailsCheck = realEmailAddress.split(" ");
    boolean exitloop = false;
    boolean mailIsValid = false;
    String MailError = null;
    for (int i = 0; i < mailsCheck.length && !exitloop; i++) {
        String email = mailsCheck[i];
        if (log.isDetailed()) {
            logDetailed(BaseMessages.getString(PKG, "JobEntryMailValidator.CheckingMail", email));
        }
        // Check if address is valid
        MailValidationResult resultValidator = MailValidation.isAddressValid(log, email, realSender, realDefaultSMTP, timeOut, smtpCheck);
        mailIsValid = resultValidator.isValide();
        MailError = resultValidator.getErrorMessage();
        if (log.isDetailed()) {
            if (mailIsValid) {
                logDetailed(BaseMessages.getString(PKG, "JobEntryMailValidator.MailValid", email));
            } else {
                logDetailed(BaseMessages.getString(PKG, "JobEntryMailValidator.MailNotValid", email));
                logDetailed(MailError);
            }
        }
        // invalid mail? exit loop
        if (!resultValidator.isValide()) {
            exitloop = true;
        }
    }
    result.setResult(mailIsValid);
    if (mailIsValid) {
        result.setNrErrors(0);
    }
    return result;
}
Also used : MailValidationResult(org.pentaho.di.trans.steps.mailvalidator.MailValidationResult) Result(org.pentaho.di.core.Result) MailValidationResult(org.pentaho.di.trans.steps.mailvalidator.MailValidationResult)

Aggregations

Result (org.pentaho.di.core.Result)1 MailValidationResult (org.pentaho.di.trans.steps.mailvalidator.MailValidationResult)1