{"record":{"id":"418d1320fa23bdf8","repo":"pentaho/pentaho-kettle","slug":"mailconnection-error-foldernotfound","errorCode":null,"errorMessage":"MailConnection.Error.FolderNotFound","messagePattern":"MailConnection\\.Error\\.FolderNotFound","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":1118,"sourceCode":"    } catch ( Exception e ) {\n      throw new KettleException( BaseMessages.getString( PKG, ERROR_SET_DESTINATION, foldername ), e );\n    }\n  }\n\n  private String prepareMboxDestinationPath( String foldername, boolean createFolder ) throws KettleException {\n    String resolvedPath = resolveMboxFolderPath( foldername );\n    File destinationFile = new File( resolvedPath );\n    File parentDirectory = destinationFile.getParentFile();\n    if ( parentDirectory == null ) {\n      return resolvedPath;\n    }\n\n    if ( parentDirectory.exists() && !parentDirectory.isDirectory() ) {\n      throw new KettleException( BaseMessages.getString( PKG, ERROR_CREATE_FOLDER, resolvedPath ) );\n    }\n    if ( !parentDirectory.exists() ) {\n      if ( !createFolder ) {\n        throw new KettleException( BaseMessages.getString( PKG, ERROR_FOLDER_NOT_FOUND, foldername ) );\n      }\n      if ( !parentDirectory.mkdirs() ) {\n        throw new KettleException( BaseMessages.getString( PKG, ERROR_CREATE_FOLDER, resolvedPath ) );\n      }\n    }\n    return resolvedPath;\n  }\n\n  private Folder getOrCreateImapDestinationFolder( String foldername, boolean createFolder )\n    throws MessagingException, KettleException {\n    String[] folderparts = foldername.split( \"/\" );\n    Folder destinationFolder = this.getStore().getDefaultFolder();\n    for ( String folderPart : folderparts ) {\n      destinationFolder = destinationFolder.getFolder( folderPart );\n      if ( destinationFolder.exists() ) {\n        continue;\n      }\n      if ( !createFolder ) {","sourceCodeStart":1100,"sourceCodeEnd":1136,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/email-messages/impl/src/main/java/org/pentaho/di/job/entries/getpop/MailConnection.java#L1100-L1136","documentation":"Thrown from prepareMboxDestinationPath() when the parent directory of the resolved MBOX destination path does not exist and createFolder is false. It uses key MailConnection.Error.FolderNotFound with the requested folder name. The method refuses to auto-create directories unless the caller opted in.","triggerScenarios":"Calling setDestinationFolder(foldername, createFolder=false) with MBOX protocol where the destination path's parent directory (e.g. /data/mail/INBOX) does not exist on disk.","commonSituations":"Destination mbox folder moved or deleted between runs; environment migration where the mail directory was not recreated; typo in the configured path; create/dry-run mode left unchecked.","solutions":["Pass createFolder=true to setDestinationFolder so the parent directory is created via mkdirs().","Pre-create the parent directory on the filesystem (mkdir -p).","Fix the configured folder path to point at an existing directory."],"exampleFix":"// before\nconnection.setDestinationFolder(\"/data/mail/archive/2024\", false); // parent missing\n// after\nconnection.setDestinationFolder(\"/data/mail/archive/2024\", true);","handlingStrategy":"validation","validationCode":"File f = new File(resolvedPath);\nif (f.getParentFile() != null && !f.getParentFile().exists() && !createFolder) { throw new IllegalArgumentException(\"Parent directory missing and createFolder=false\"); }","typeGuard":null,"tryCatchPattern":"try { connection.setDestinationFolder(path, true); } catch (KettleException e) { logError(\"Folder not found: \" + e.getMessage(), e); }","preventionTips":["Pre-create destination directories in provisioning scripts (mkdir -p)","Use createFolder=true unless you intentionally want strict existence checks","Keep destination paths stable across environments"],"tags":["mbox","filesystem","folder-not-found"],"backgroundTag":"directory-not-found","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"}