more intelligent way to set limit for date

This commit is contained in:
2018-02-05 17:47:43 +01:00
parent fb0d1665d6
commit 3cbdab7c13

View File

@@ -1,7 +1,7 @@
#!/bin/bash
# Script moves tagged mails to their respective folders if they are still lying around in INBOX
# It also moved mails tagged with "del" to the Trash folder, "archive" to Archive, and "spam" to Spam folder
# It also moves mails tagged with "del" to the Trash folder, "archive" to Archive, and "spam" to Spam folder
CURDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
@@ -24,7 +24,6 @@ BL_THREADTAGS="$TRASHTAG|$SPAMTAG|$ARCHTAG|draft" # Tags for which their whole
touch "$LOG" # Create logfile or update time stamp
LASTRUN="$CURDIR"/move-tag-lastrun.log # file where the date of the last successful run of this script is saved
var_conn=$1 # supposed to be "on" or "off"
function pdate {
@@ -46,10 +45,10 @@ function debugmsg {
# Set date until when files are searched for, depending on current connection status
if [ "${var_conn}" == "off" ]; then
DATELIMIT=$(date -d "$(cat ${LASTRUN}) - 1 days" +%Y-%m-%d)
DATELIMIT="1d"
logrun echo "Datelimit for search set to $DATELIMIT"
else
DATELIMIT=$(date -d "$(cat ${LASTRUN}) - 1 weeks" +%Y-%m-%d)
DATELIMIT="7d"
logrun echo "Datelimit for search set to $DATELIMIT"
fi
@@ -86,7 +85,7 @@ while read line; do
# 1. Get thread ids of all entries with the searched tag
debugmsg "search for all threads tagged with $TAG"
THREADS=$(notmuch search --exclude=false tag:$TAG and date:$DATELIMIT..$(date -d "+1 year" +%Y-%m-%d) | cut -d" " -f1 | cut -d":" -f2)
THREADS=$(notmuch search --exclude=false tag:$TAG and date:${DATELIMIT}.. | cut -d" " -f1 | cut -d":" -f2)
# 2. Get message ids of all messages in these threads
debugmsg "search for all IDs of these threads"
@@ -133,5 +132,3 @@ while read line; do
debugmsg ""
done < "$CSV"
echo $(date +%Y-%m-%d) > ${LASTRUN}