Restructuring the repo
This commit is contained in:
parent
21e3cf65e6
commit
3d67598c27
45 changed files with 368 additions and 77 deletions
75
bin/newmails
75
bin/newmails
|
@ -1,75 +0,0 @@
|
|||
#!/bin/zsh
|
||||
|
||||
DEFAULT=raw
|
||||
ICON=/usr/share/icons/Adwaita/48x48/actions/mail-message-new.png
|
||||
|
||||
opt() {
|
||||
if [ -n "$1" ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
contains() {
|
||||
arr=$1
|
||||
value=$2
|
||||
[[ ${${(P)arr}[(ie)$value]} -lt ${#${(P)arr}} ]]
|
||||
}
|
||||
|
||||
zparseopts -D -E h=help -help=help \
|
||||
r=raw -raw=raw \
|
||||
n=number -number=number \
|
||||
p=pretty -pretty=pretty
|
||||
|
||||
if [ -n "$help" ]; then
|
||||
cat <<HELP
|
||||
Usage: newmails [OPTIONS] [MAILDIR]
|
||||
|
||||
Options:
|
||||
-h --help Show this help
|
||||
-r --raw Show full paths to new mail files (default)
|
||||
-n --number Only show number of new mails
|
||||
-p --pretty Show formatted output of new mails (TODO)
|
||||
|
||||
HELP
|
||||
fi
|
||||
|
||||
|
||||
local md=${MAILDIR:-${MAIL:-$HOME/Mail}}
|
||||
local cache=${XDG_CACHE_HOME:-$HOME/.cache}/seen-mails
|
||||
|
||||
newmails=$(find $md/ -type f -a \
|
||||
\( -regex ".*:2,[PRTDF]*" \) -exec realpath \{\} \;)
|
||||
|
||||
decode(){
|
||||
perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | \
|
||||
sed -e 's/&/\&/' -e 's/</\</' -e 's/>/\>/'
|
||||
}
|
||||
|
||||
from() { formail -zcb -xFrom | tail -n 1 | decode }
|
||||
subject() { formail -zcb -xSubject | decode }
|
||||
|
||||
|
||||
if opt $number; then
|
||||
echo -n $newmails | wc -l
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if opt $pretty; then
|
||||
touch $cache
|
||||
seen=$(<$cache)
|
||||
truncate --size 0 $cache
|
||||
notify-send --icon=$ICON "$(
|
||||
echo -n $newmails | while read mail; do
|
||||
if ! contains seen $mail; then
|
||||
echo -n "<b>$(from < $mail):</b> $(subject < $mail)<br>"
|
||||
fi
|
||||
echo $mail >> $cache
|
||||
done
|
||||
)"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
#otherwise
|
||||
echo -n $newmails
|
Loading…
Add table
Add a link
Reference in a new issue