use of com.helger.smtp.transport.ESMTPErrorCode in project ph-web by phax.
the class FailedMailDataMicroTypeConverter method convertToNative.
@Nullable
public FailedMailData convertToNative(@Nonnull final IMicroElement eFailedMail) {
final String sID = eFailedMail.getAttributeValue(ATTR_ID);
if (sID == null) {
LOGGER.error("Failed to read ID");
return null;
}
// Read error date/time
final String sErrorDT = eFailedMail.getAttributeValue(ATTR_ERRORDT);
if (sErrorDT == null) {
LOGGER.error("Failed to read error date/time");
return null;
}
LocalDateTime aErrorDT = PDTWebDateHelper.getLocalDateTimeFromXSD(sErrorDT);
if (aErrorDT == null)
aErrorDT = TypeConverter.convert(sErrorDT, LocalDateTime.class);
if (aErrorDT == null) {
if (LOGGER.isErrorEnabled())
LOGGER.error("Failed to parse error date '" + sErrorDT + "'");
return null;
}
// read original sent date/time
final String sOriginalSentDT = eFailedMail.getAttributeValue(ATTR_ORIGINALSENT_DT);
LocalDateTime aOriginalSentDT = null;
if (sOriginalSentDT != null) {
aOriginalSentDT = PDTWebDateHelper.getLocalDateTimeFromXSD(sOriginalSentDT);
if (aOriginalSentDT == null)
aOriginalSentDT = TypeConverter.convert(sOriginalSentDT, LocalDateTime.class);
}
// SMTP settings
final IMicroElement eSMTPSettings = eFailedMail.getFirstChildElement(ELEMENT_SMTP_SETTINGS);
if (eSMTPSettings == null) {
LOGGER.error("Failed to get child element of SMTP settings!");
return null;
}
final ISMTPSettings aSMTPSettings = MicroTypeConverter.convertToNative(eSMTPSettings, SMTPSettings.class);
// email data (may be null)
final IMicroElement eEmailData = eFailedMail.getFirstChildElement(ELEMENT_EMAIL_DATA);
final IMutableEmailData aEmailData = MicroTypeConverter.convertToNative(eEmailData, EmailData.class);
// error message
final String sErrorMessage = MicroHelper.getChildTextContent(eFailedMail, ELEMENT_ERROR_MSG);
final Exception aException = StringHelper.hasNoText(sErrorMessage) ? null : new Exception(sErrorMessage);
MailTransportError aError = null;
if (aException != null) {
final ICommonsList<MailSendDetails> aDetails = new CommonsArrayList<>();
for (final IMicroElement eDetails : eFailedMail.getAllChildElements(ELEMENT_DETAILS)) {
final boolean bAddressValid = StringParser.parseBool(eDetails.getAttributeValue(ATTR_ADDRESS_VALID));
final String sAddress = eDetails.getAttributeValue(ATTR_ADDRESS);
final String sCommand = eDetails.getAttributeValue(ATTR_COMMAND);
final String sDetailsErrorMessage = eDetails.getAttributeValue(ATTR_ERROR_MESSAGE);
final int nErrorCode = StringParser.parseInt(eDetails.getAttributeValue(ATTR_ERROR_CODE), -1);
final ESMTPErrorCode eErrorCode = ESMTPErrorCode.getFromIDOrDefault(nErrorCode, ESMTPErrorCode.FALLBACK);
aDetails.add(new MailSendDetails(bAddressValid, sAddress, sCommand, sDetailsErrorMessage, eErrorCode));
}
aError = new MailTransportError(aException, aDetails);
}
return new FailedMailData(sID, aErrorDT, aSMTPSettings, aOriginalSentDT, aEmailData, aError);
}
Aggregations