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

Fails on very long filenames #18

Open
gvoncken opened this issue Dec 3, 2021 · 2 comments
Open

Fails on very long filenames #18

gvoncken opened this issue Dec 3, 2021 · 2 comments

Comments

@gvoncken
Copy link

gvoncken commented Dec 3, 2021

First of all, many thanks for ripmime!

I sometimes encounter files containing attachments with very long filenames. "Very long" means longer than 255 characters (on my Linux system). This is an error message I recently got:

mime.c:2337:MIME_generate_multiple_hardlink_filenames:WARNING: While trying to create '(...)' link to '(...)' (File name too long)

On non Linux filesystems (HFS, FAT, ...) the maximum filename length can even be less than 255 characters.

Suggestion for handling the problem:

  • Query the max. file name size with the help of function pathconf (see http://www.gnu.org/software/libc/manual/html_node/Pathconf.html, parameter _PC_NAME_MAX)
  • If a file is to be created with a name longer than that value: Shorten the filename to the max value minus some spare characters.
  • Those spare characters are needed if a file with that name already exists. In that case, renaming could be done according to the options --overwrite, --unique-names, --prefix, --postfix and --infix.
  • Optionally, the spare characters could include some string hinting that the filename was shortened and does not correspond to the original filename. For example: "AttachmentThatReallyHasSomeVeryLongFilename" would become "AttachmentThatReallyHasSomeVe_shortened".
  • If a filename needs to be shortened, ripmime could inform about it on stdout (the message would include the original filename) .
  • ripmime could even refuse to work on file systems whose maximum filename length is less then a certain value.

Thanks again for this great tool and best greetings!

@inflex
Copy link
Owner

inflex commented Dec 3, 2021 via email

@gvoncken
Copy link
Author

gvoncken commented Dec 3, 2021

Thanks for the very fast answer, Paul.

I re-read my message; there's one point where I wasn't precise: The max. Linux filename length is not expressed in characters. It's a number of bytes!

Example: The filename Привет.jpg has 10 characters and is 16 bytes long. A 5 character filename like 𓂀𓁆𓀽𓀿𓃀 even consumes 20 bytes in UTF-8 (and with only 64 ancient Egypt symbols you get a "filename too long" error).

As ripmime is looking at filenames as char[], truncation could become tricky. There is the risk of cutting the filename in the middle of a multi-byte UTF-8 sequence, probably leading to new problems.

Maybe, the best way for treating too long filenames is not truncation. Replacing the whole name would be much easier and safer: Renamed_file_1, Renamed_file_2 etc.

The main thing is extracting the file. In case I need the original filename I easily can grep it if ripmime puts an info message on stdout.

Guy

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

2 participants