/** Loads the mail configuration. */
  public static void loadMailConfiguration() {
    try {
      DATFileReader reader = new DATFileReader(MAIL_PATH);
      reader.setCommentChar('#');
      reader.ignoreWhitespaces(true);

      // Read file line by line
      while (reader.loadNextLine()) {
        // Read data from current line
        String systemName = reader.nextField();
        String userName = reader.nextField();
        String sender = reader.nextField();
        String date = reader.nextField();
        String subject = reader.nextField();
        String resourceName = reader.nextField();

        Server system = Terminal.getServer(systemName);
        UserAccount user = system.getUser(userName);
        Mail m = new Mail(sender, date, subject, resourceName);
        user.getMailbox().addMail(m);

        Logger.info(
            "Loaded mail: subject: %s (user: %s, system: %s%s)\n",
            subject.isEmpty() ? "<no subject>" : subject,
            userName,
            systemName,
            resourceName.isEmpty() ? "" : ", resource: " + resourceName);
      }
    } catch (IOException ex) {
      Logger.stackTrace(ex);
      showConfigFileErrorMessage(ex);
    }
  }
  /**
   * Loads user configuration
   *
   * @return the last loaded user account
   */
  public static UserAccount loadUserConfiguration() {
    UserAccount u = null;

    try {
      DATFileReader reader = new DATFileReader(USERS_PATH);
      reader.setCommentChar('#');
      reader.ignoreWhitespaces(true);

      // Read file line by line
      while (reader.loadNextLine()) {
        // Read data from current line
        String systemName = reader.nextField();
        String username = reader.nextField();
        String password = reader.nextField();
        int homeDirID = Integer.parseInt(reader.nextField());
        boolean isUnlisted = Boolean.parseBoolean(reader.nextField());

        Server system = Terminal.getServer(systemName);
        HomeDirectory homeDir =
            (HomeDirectory) system.getFileSystem().getFileSystemObject(homeDirID);
        homeDir.setUnlisted(isUnlisted);
        u = new UserAccount(username, password, homeDir);
        system.addUser(u);

        Logger.info("Loaded user: %s (system: %s)\n", username, systemName);
      }
    } catch (IOException ex) {
      Logger.stackTrace(ex);
      showConfigFileErrorMessage(ex);
    }

    return u;
  }
  /**
   * Loads the filesystem configuration.
   *
   * @param exes a Map containing classes representing executable files and their corresponding
   *     names
   */
  public static void loadFileSystemConfiguration(
      Map<String, Class<? extends ExecutableFile>> exes) {
    /* Load files into temporary filesystem. The temporary filesytem is used
       to access files while the actual filesystem is being built.
    */
    FileSystem tempFileSystem = loadFiles(exes);

    try {
      DATFileReader reader = new DATFileReader(FILESYSTEM_PATH);
      reader.setCommentChar('#');
      reader.ignoreWhitespaces(true);

      // Read file line by line
      while (reader.loadNextLine()) {
        // Read data from current line
        int id = Integer.parseInt(reader.nextField());
        String systemName = reader.nextField();
        String dirName = reader.nextField();
        int parentID = Integer.parseInt(reader.nextField());
        String files = "";
        if (reader.hasNextField()) {
          files = reader.nextField();
        }

        Server system = Terminal.getServer(systemName);

        Directory dir;
        if (parentID == -1 || (id > 600 && id < 700)) {
          // Load directory, set it as root on the current system
          dir = new Directory(id, dirName);
          system.setFileSystem(new FileSystem(dir));
        } else if (id > 800 && id < 900) {
          // Load directory as as user's home directory
          dir = new HomeDirectory(id, dirName);
        } else {
          // Load generic directory
          dir = new Directory(id, dirName);
        }

        /* Place the directory in the correct location in the filesystem
           tree
        */
        FileSystemObject parent = system.getFileSystem().getFileSystemObject(parentID);
        if (parent != null) {
          parent.addChild(dir);
        }

        // Populate directory with files (if it has any)
        String[] fileIDList = files.split(" ");
        for (String fileIDStr : fileIDList) {
          if (fileIDStr.isEmpty()) {
            continue;
          }
          int fileID = Integer.parseInt(fileIDStr);

          // Get file from temporary filesystem based on file ID
          File file = (File) tempFileSystem.getFileSystemObject(fileID);
          if (file == null) {
            Logger.error(
                "Unresolved file ID: %d " + "(dir: %s, system: %s)\n", fileID, dirName, systemName);
            continue;
          }

          // Place the file in the directory
          dir.addChild(file);
        }

        Logger.info(
            "Loaded directory: %s (system: %s, id: ID)\n",
            dirName.isEmpty() ? "<no name, root?>" : dirName, systemName, id);
      }
    } catch (IOException ex) {
      Logger.stackTrace(ex);
      showConfigFileErrorMessage(ex);
    }
  }