Created
March 21, 2016 10:24
-
-
Save xdbr/b009a39efbcf541c0c0d to your computer and use it in GitHub Desktop.
This file contains 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 | |
# set -x | |
VERSION="0.1.0" | |
GREP= | |
SENT= | |
DAYS=30 | |
HOSTNAME=`hostname` | |
MAILDIR=$HOME/Maildir | |
version.display() { | |
echo "$VERSION" | |
} | |
help.display() { | |
cat <<-EOF | |
Usage: mailstats [args] | |
Options: | |
-V, --version Output current version | |
-h, --help Display help | |
-m, --maildir set different maildir (default: ~/Maildir) | |
-H, --hostname set different hostname (default: hostname) | |
-d, --days last X days (in days, default: 30) | |
-s, --sent-only count only sent emails (default: all) | |
-S, --no-sent don't count sent emails (default: all) | |
EOF | |
} | |
while test $# -ne 0; do | |
case $1 in | |
-V|--version) version.display; exit ;; | |
-h|--help) help.display; exit ;; | |
-d|--directory) MAILDIR=$1 ;; | |
-H|--hostname) HOSTNAME=$1 ;; | |
-d|--days) shift; DAYS=$1 ;; | |
-s|--sent-only) SENT=true ;; | |
-S|--no-sent) SENT=false ;; | |
esac | |
shift | |
done | |
if [[ ! -z $SENT && $SENT == true ]]; then GREP='grep .Sent' | |
elif [[ ! -z $SENT && $SENT == false ]]; then GREP='grep -v .Sent' | |
else GREP='cat ' | |
fi | |
main() { | |
find $MAILDIR -type f -not -empty -ctime -$DAYS -ls | grep $HOSTNAME | eval "$GREP" | |
} | |
main; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment