pentaho/pentaho-kettle · error · KettleException
MailConnection.Error.CountingAttachedFiles
Error message
MailConnection.Error.CountingAttachedFiles
What it means
Thrown while counting attachments of the current message: any Exception raised walking the message content (Part/Multipart traversal) is wrapped in a KettleException with this message including the message number. It indicates the message body could not be read or parsed.
Solutions
- Check the wrapped cause to see if it is an IO problem (connection) or MIME parsing problem
- Re-fetch the message or reopen the folder and retry
- Skip messages with unparsable content by logging and continuing (set messages not downloaded / limit fields)
- Update the mail server/Jakarta Mail version if a specific MIME structure fails
Example fix
// before
int count = connection.countAttachedFiles(); // throws on malformed message
// after
try {
int count = connection.countAttachedFiles();
} catch ( KettleException e ) {
logBasic( "Skipping message " + msgNum + ": " + e.getMessage() );
count = 0;
} Defensive patterns
Strategy: try-catch
Type guard
boolean isMultipart = ( data.message instanceof javax.mail.internet.MimeMessage ) && ( (MimeMessage) data.message ).getContent() instanceof javax.mail.Multipart;
Try / catch
try {
count = connection.countAttachedFiles();
} catch ( KettleException e ) {
logBasic( "Attachment count failed for message #" + msgNum + ": " + e.getCause() );
count = -1; // treat as unknown and continue
} Prevention
- Skip or quarantine messages with malformed MIME content
- Keep the mail session connected while iterating messages
- Test with problematic emails from the actual mailbox before production runs
When it happens
Trigger: Calling countAttachedFiles (attachment counting during MailInput processing) on a message whose content is not a Multipart, or whose content throws IOException/MessagingException when accessed (corrupt message, connection drop).
Common situations: Malformed or virus-scanner-quarantined messages; server connection lost while lazy-loading body parts; messages with unusual MIME structures.
Related errors
- Error adding values to row!
- MailConnection.Error.MovingMessages
- MailConnection.Error.SavingAttachedFiles
- MailConnection.Error.WriteMboxFile
- MailInput.Error.ReceivedDateSearchTermEmpty
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/78835ea1f035c614.
Report an issue: GitHub.
Appendix: source
Thrown at plugins/email-messages/impl/src/main/java/org/pentaho/di/job/entries/getpop/MailConnection.java:1653
if ( ( disposition != null )
&& ( disposition.equalsIgnoreCase( Part.ATTACHMENT ) || disposition.equalsIgnoreCase( Part.INLINE ) ) ) {
String MimeText = null;
try {
MimeText = MimeUtility.decodeText( part.getFileName() );
} catch ( Exception e ) {
// Ignore errors
}
if ( MimeText != null ) {
String filename = MimeUtility.decodeText( part.getFileName() );
if ( isWildcardMatch( filename, pattern ) ) {
retval++;
}
}
}
}
}
} catch ( Exception e ) {
throw new KettleException( BaseMessages.getString( PKG, "MailConnection.Error.CountingAttachedFiles", ""
+ this.message.getMessageNumber() ), e );
} finally {
if ( content != null ) {
content = null;
}
}
return retval;
}
private Message[] loadMboxMessages() throws KettleException {
String mboxPath = getSourceMboxPath();
File mboxFile = new File( mboxPath );
if ( mboxFile.exists() && mboxFile.length() == 0 ) {
return new Message[0];
}
mboxMessageNumbers.clear();View on GitHub (pinned to f3058517a1)