Skip to content

Commit

Permalink
Merge pull request #63 from obendev/master
Browse files Browse the repository at this point in the history
Enhancements to Mail Filesize/Filename Fixer Script
  • Loading branch information
obendev authored Apr 10, 2024
2 parents 341c380 + d62743e commit 45ee866
Showing 1 changed file with 11 additions and 8 deletions.
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

0 comments on commit 45ee866

Please sign in to comment.