add script for putting emails in pending state
This commit is contained in:
1
astroid/.gitignore
vendored
1
astroid/.gitignore
vendored
@@ -1,4 +1,5 @@
|
||||
*.log
|
||||
scripts/pending.save
|
||||
scripts/tag-folder-rules.sh
|
||||
scripts/tag-list.csv
|
||||
searches
|
||||
|
||||
@@ -53,6 +53,10 @@ echo "[DEBUG] Tag mails based on their folder (tag-folder.sh)"
|
||||
bash "$CURDIR"/scripts/tag-folder.sh # generates commands from tag-folder.csv
|
||||
bash "$CURDIR"/scripts/tag-folder-rules.sh # executes generated commands
|
||||
|
||||
# Handle pending days (tag:/pend*/)
|
||||
echo "[DEBUG] Handle pending tags (pending.sh)"
|
||||
bash "$CURDIR"/scripts/pending.sh
|
||||
|
||||
# Mark mails in certain folders read
|
||||
echo "[DEBUG] Mark mails in trash folders read"
|
||||
notmuch tag -unread -- path:Trash/**
|
||||
|
||||
63
astroid/scripts/pending.sh
Executable file
63
astroid/scripts/pending.sh
Executable file
@@ -0,0 +1,63 @@
|
||||
#!/bin/bash
|
||||
|
||||
CURDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
|
||||
SAVEFILE="$CURDIR"/pending.save # Location of logfile
|
||||
BASETAG="pend"
|
||||
UNPENDTAG="unpend"
|
||||
|
||||
function pdate {
|
||||
DATE=$(date +%y-%m-%d_%H:%M:%S)
|
||||
echo "[$DATE]"
|
||||
}
|
||||
|
||||
function debugmsg {
|
||||
if ${DEBUG}; then
|
||||
echo "$(pdate) $*"
|
||||
fi
|
||||
}
|
||||
|
||||
function datediff {
|
||||
d1=$(date -d "$1" +%s)
|
||||
d2=$(date -d "$2" +%s)
|
||||
echo $(( (d1 - d2) / 86400 ))
|
||||
}
|
||||
|
||||
|
||||
# Load the values from the last run
|
||||
touch "$SAVEFILE"
|
||||
# shellcheck source=/dev/null
|
||||
source "$SAVEFILE"
|
||||
# Get the current day
|
||||
CURDATE=$(date +%Y-%m-%d)
|
||||
# Populate $LASTDATE if empty
|
||||
if [[ -z "$LASTDATE" ]]; then
|
||||
LASTDATE="$CURDATE"
|
||||
echo "LASTDATE=$LASTDATE" > "$SAVEFILE"
|
||||
fi
|
||||
|
||||
# Get pending tags
|
||||
pending_tags=$(notmuch search --output=tags '*' | grep "^$BASETAG")
|
||||
|
||||
# Reduce pending dates if current date not last saved date
|
||||
if [[ "$CURDATE" != "$LASTDATE" ]]; then
|
||||
ddiff=$(datediff "$CURDATE" "$LASTDATE")
|
||||
for tag in $pending_tags; do
|
||||
# Get day element
|
||||
day=$(grep -Eo '[0-9]*$' <<< "$tag")
|
||||
|
||||
# Calculate new day for pending tag
|
||||
day=$(( day - ddiff ))
|
||||
|
||||
# if new pending days more than 1
|
||||
if [[ $day -ge 1 ]]; then
|
||||
notmuch tag -"$tag" +"${BASETAG}${day}" -- tag:"$tag"
|
||||
# otherwise, delete pending tag and set unpending tag
|
||||
else
|
||||
notmuch tag -"$tag" +"$UNPENDTAG" -- tag:"$tag"
|
||||
fi
|
||||
done
|
||||
|
||||
# Write the current date in the file
|
||||
sed -i "s/LASTDATE\=.*/LASTDATE=$CURDATE/" "$SAVEFILE"
|
||||
fi
|
||||
Reference in New Issue
Block a user