Created
August 7, 2017 18:04
-
-
Save stekan/afadc9b97a297b6f879d09627e3e5a7e to your computer and use it in GitHub Desktop.
Copy emails to directory year/month/day
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SRC=/path/to/eml/src | |
DEST=/path/to/eml/dest | |
SAVEIFS=$IFS | |
IFS=$(echo -en "\n\b") | |
cd "$SRC" | |
for file in $(find -type f -name "*.eml") | |
do | |
EMAILDATE=$(grep -m 1 "^Date: " < "$file" | sed -e "s/Date://g") | |
y=$(date --date="$EMAILDATE" +%Y) | |
m=$(date --date="$EMAILDATE" +%m) | |
d=$(date --date="$EMAILDATE" +%d) | |
[ -d "$DEST/$y/$m/$d" ] || mkdir -p "$DEST/$y/$m/$d" | |
cp "$file" "$DEST/$y/$m/$d/" | |
done | |
IFS=$SAVEIFS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment