{"record":{"id":"78835ea1f035c614","repo":"pentaho/pentaho-kettle","slug":"mailconnection-error-countingattachedfiles","errorCode":null,"errorMessage":"MailConnection.Error.CountingAttachedFiles","messagePattern":"MailConnection\\.Error\\.CountingAttachedFiles","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"plugins/email-messages/impl/src/main/java/org/pentaho/di/job/entries/getpop/MailConnection.java","lineNumber":1653,"sourceCode":"          if ( ( disposition != null )\n            && ( disposition.equalsIgnoreCase( Part.ATTACHMENT ) || disposition.equalsIgnoreCase( Part.INLINE ) ) ) {\n            String MimeText = null;\n            try {\n              MimeText = MimeUtility.decodeText( part.getFileName() );\n            } catch ( Exception e ) {\n              // Ignore errors\n            }\n            if ( MimeText != null ) {\n              String filename = MimeUtility.decodeText( part.getFileName() );\n              if ( isWildcardMatch( filename, pattern ) ) {\n                retval++;\n              }\n            }\n          }\n        }\n      }\n    } catch ( Exception e ) {\n      throw new KettleException( BaseMessages.getString( PKG, \"MailConnection.Error.CountingAttachedFiles\", \"\"\n        + this.message.getMessageNumber() ), e );\n    } finally {\n      if ( content != null ) {\n        content = null;\n      }\n    }\n    return retval;\n  }\n\n  private Message[] loadMboxMessages() throws KettleException {\n    String mboxPath = getSourceMboxPath();\n    File mboxFile = new File( mboxPath );\n\n    if ( mboxFile.exists() && mboxFile.length() == 0 ) {\n      return new Message[0];\n    }\n\n    mboxMessageNumbers.clear();","sourceCodeStart":1635,"sourceCodeEnd":1671,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/email-messages/impl/src/main/java/org/pentaho/di/job/entries/getpop/MailConnection.java#L1635-L1671","documentation":"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.","triggerScenarios":"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).","commonSituations":"Malformed or virus-scanner-quarantined messages; server connection lost while lazy-loading body parts; messages with unusual MIME structures.","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"],"exampleFix":"// before\nint count = connection.countAttachedFiles(); // throws on malformed message\n// after\ntry {\n  int count = connection.countAttachedFiles();\n} catch ( KettleException e ) {\n  logBasic( \"Skipping message \" + msgNum + \": \" + e.getMessage() );\n  count = 0;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"boolean isMultipart = ( data.message instanceof javax.mail.internet.MimeMessage )\n  && ( (MimeMessage) data.message ).getContent() instanceof javax.mail.Multipart;","tryCatchPattern":"try {\n  count = connection.countAttachedFiles();\n} catch ( KettleException e ) {\n  logBasic( \"Attachment count failed for message #\" + msgNum + \": \" + e.getCause() );\n  count = -1; // treat as unknown and continue\n}","preventionTips":["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"],"tags":["kettle","pdi","email","mime","attachments"],"backgroundTag":"unexpected-response-shape","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}