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

Mail Filesize/Filename Fixer Script #46

Merged
merged 14 commits into from
Jan 18, 2024
Merged

Conversation

obendev
Copy link
Contributor

@obendev obendev commented Jan 16, 2024

This pull request introduces the Mail Filesize/Filename Fixer script I coded. The script validates and corrects discrepancies between actual and reported file sizes in mail files.

There was an earlier draft (not present in this repo).
Improvements include better handling of file size discrepancies and options to fix these discrepancies by renaming the files or exporting the mismatched filenames to a text file.

For more details on usage, requirements and functionality of the updated script, please see the README.md in this pull request.

Before the script tries to find files in the directory, it now checks if the directory exists and is readable. If the directory does not exist or is not readable, the script will print an error message and exit with status 1.
I added a sanitize_filename function that removes potentially harmful characters from the filename. This function is called to sanitize the filename before it’s used in the check_and_fix function.
In this version, the check_and_fix function has been split into three separate functions: check_filenames, export_mismatches, and fix_mismatches. The check_filenames function is always run, and the export_mismatches and fix_mismatches functions are run if the corresponding flags are set. This makes the script more modular and easier to understand and maintain.
The check_filenames function stores the mismatch information in an array called mismatches. Each element of the array is a string containing the filename, expected size, and actual size, separated by commas. The export_mismatches and fix_mismatches functions then iterate over this array to perform their respective actions. This allows the script to remember the mismatches found during the initial check and use this information later if the user decides to fix or export the mismatches.
Removed the sanitize_filename function, as the risk of filename manipulation is negligible
Commas are used in the filenames
@sibprogrammer sibprogrammer self-requested a review January 18, 2024 14:42
@sibprogrammer sibprogrammer merged commit f2f8c38 into plesk:master Jan 18, 2024
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

Successfully merging this pull request may close these issues.

2 participants