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

Enhancements to Mail Filesize/Filename Fixer Script #63

Merged
merged 5 commits into from
Apr 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions fix-mail-filesize-filename/fix-mail-filesize-filename.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ if [ ! -d "${dir}" ] || [ ! -r "${dir}" ]; then
fi

# Get the total number of files that match the expected filename format
total_files=$(find ${dir} -type f | grep -E 'S=[0-9]+:' | wc -l)
total_files=0
count=0
mismatch_count=0

Expand All @@ -70,13 +70,16 @@ declare -a mismatches

# Function to check filenames
check_filenames() {
for file in $(find ${dir} -type f | grep -E 'S=[0-9]+:'); do
while IFS= read -r -d '' file; do
# Extract the expected size from the filename
expected_size=$(echo ${file} | grep -oP 'S=\K[0-9]+')
expected_size=$(echo ${file} | grep -oP ',S=\K[0-9]+')

# Get the actual size
actual_size=$(stat -c%s "${file}")

# Increment the total_files counter
total_files=$((total_files+1))

# Check if the sizes match
if [ "${expected_size}" != "${actual_size}" ]; then
echo "Mismatch found in file: ${file}"
Expand All @@ -88,16 +91,16 @@ check_filenames() {
fi

# Show the progress
count=$((count+1))
echo -ne "Progress: ${count}/${total_files} files checked\r"
done
echo -ne "Progress: ${total_files} files checked\\r"
done < <(find ${dir} -type f -print0 | grep -zE ',S=[0-9]+')
echo "" # Move to a new line after the loop
}


# Function to export mismatches
export_mismatches() {
for mismatch in "${mismatches[@]}"; do
IFS read -r -a array <<< "$mismatch"
IFS= read -r -a array <<< "$mismatch"
file="${array[0]}"
echo "${file}" >> "${domain}_${username}_mismatches.txt"
done
Expand All @@ -106,7 +109,7 @@ export_mismatches() {
# Function to fix mismatches
fix_mismatches() {
for mismatch in "${mismatches[@]}"; do
IFS read -r -a array <<< "$mismatch"
IFS= read -r -a array <<< "$mismatch"
file="${array[0]}"
expected_size="${array[1]}"
actual_size="${array[2]}"
Expand Down