Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

msgconvert ignores subdirectory in file path #68

Open
dingens opened this issue Feb 21, 2025 · 4 comments
Open

msgconvert ignores subdirectory in file path #68

dingens opened this issue Feb 21, 2025 · 4 comments

Comments

@dingens
Copy link

dingens commented Feb 21, 2025

When calling msgconvert dir/mail.msg, output is written to ./mail.eml, instead of the expected dir/mail.msg. (Same with absolute paths: msgconvert /some/where/mail.msg also creates mail.eml in the current working directory.)

The behavior of overriding existing files (which is documented) in combination with this (not documented) can result in data loss even when people are aware of the "normal" overriding, because one would not reasonably expect that files in the current working directory might be overridden as well.

Bug observed in 0.921, but I could not find a matching commit since, so I strongly assume it is still present.

@sandbro
Copy link

sandbro commented Feb 22, 2025

@dingens try this (generated by GPT...)

#!/bin/bash

# Define a recursive function to process directories
process_directory() {
  local dir="$1"  # Local variable to store the directory path
  pushd "$dir" > /dev/null  # Change directory and suppress output

  # Find and convert .msg files in the current directory
  if [[ -n $(find . -maxdepth 1 -name "*.msg") ]]; then
    msgconvert *.msg  # Convert .msg files
    echo "Processed directory: $dir" # Display the directory processed
  else
    echo "Directory: $dir has no .msg files" # Display no .msg files were found.
  fi

  # Recursively process subdirectories
  for subdir in */; do
    if [[ -d "$subdir" ]]; then
      process_directory "$subdir" # Recursive call for subdirectories
    fi
  done

  popd > /dev/null # Return to the previous directory and suppress output
}

# Start processing from the current directory
process_directory "." # Start the recursive process

echo "Processing complete." # Display completion message

@mvz
Copy link
Owner

mvz commented Feb 22, 2025

@sandbro please don't post untested GPT output.

@sandbro
Copy link

sandbro commented Feb 22, 2025

Hi @mvz, I tried this Bash command on my computer, and it works.
The script recursively searches for .msg files in the current directory and all its subdirectories, using the msgconvert command to process them. After processing, it outputs the status of each directory and a final completion message.

@dingens
Copy link
Author

dingens commented Feb 23, 2025

@sandbro I appreciate your intention to help, however I think that this is a bug in msgconvert that should be fixed (or, at least, it's unexpected behavior that should be documented). Your script does not solve this.

If however somebody urgently needs a workaround, they could just use find's -execdir option, no need for such a huge script:

find -type f -name "*.msg" -execdir msgconvert {} +

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants