better tag selection and blacklists; some speedup
This commit is contained in:
@@ -14,10 +14,11 @@ SPAMFOL="INBOX.Junk" # Spam folder
|
|||||||
ARCHTAG="archive" # Archive tag
|
ARCHTAG="archive" # Archive tag
|
||||||
ARCHFOL="ARCHIVE" # Archive folder
|
ARCHFOL="ARCHIVE" # Archive folder
|
||||||
LOG="$CURDIR"/move-tag.log # Location of logfile
|
LOG="$CURDIR"/move-tag.log # Location of logfile
|
||||||
USETAGS="P\.[[:alnum:]]+?|org-de|staff|ticket|del|spam|archive" # List of tags which shall be moved
|
USETAGS=".+" # List of tags which shall be moved
|
||||||
THREADTAG="P\.[[:alnum:]]+?|org-de|staff|ticket" # List of tags for which single, but connected messages in INBOX shall be tagged
|
THREADTAGS=".+" # List of tags for which single, but connected messages in INBOX shall be tagged
|
||||||
|
|
||||||
BLACKLIST=
|
BL_USETAGS=""
|
||||||
|
BL_THREADTAGS="$TRASHTAG|$SPAMTAG|$ARCHTAG"
|
||||||
touch "$LOG" # Create logfile or update time stamp
|
touch "$LOG" # Create logfile or update time stamp
|
||||||
|
|
||||||
|
|
||||||
@@ -29,15 +30,15 @@ function pdate {
|
|||||||
function logrun {
|
function logrun {
|
||||||
# Write command itself to log, and pipe errors to log
|
# Write command itself to log, and pipe errors to log
|
||||||
echo "$(pdate) $@" >> "$LOG"
|
echo "$(pdate) $@" >> "$LOG"
|
||||||
eval "$@" 2>> "$LOG"
|
# eval "$@" 2>> "$LOG"
|
||||||
}
|
}
|
||||||
|
|
||||||
while read line; do
|
while read line; do
|
||||||
TAG=$(echo $line | cut -d";" -f1)
|
TAG=$(echo $line | cut -d";" -f1)
|
||||||
FOL=$(echo $line | cut -d";" -f2)
|
FOL=$(echo $line | cut -d";" -f2)
|
||||||
|
|
||||||
if ! $(echo $BLACKLIST | grep -q "$TAG,") && $(echo $TAG | grep -qE "$USETAGS"); then
|
if ! $(echo $BL_USETAGS | grep -q "$TAG,") && $(echo $TAG | grep -qE "$USETAGS"); then
|
||||||
BLACKLIST="$TAG,$BLACKLIST" # Add current tag to list of tags which do not have to be searched for another time
|
BL_USETAGS="$TAG,$BL_USETAGS" # Add current tag to list of tags which do not have to be searched for another time
|
||||||
|
|
||||||
# TRASH tag "del"
|
# TRASH tag "del"
|
||||||
if [ "$TAG" = "$TRASHTAG" ]; then
|
if [ "$TAG" = "$TRASHTAG" ]; then
|
||||||
@@ -57,11 +58,11 @@ while read line; do
|
|||||||
# DEFAULT
|
# DEFAULT
|
||||||
else
|
else
|
||||||
# For some tags, also tag its threads
|
# For some tags, also tag its threads
|
||||||
if $(echo $TAG | grep -qE "$THREADTAG"); then
|
if ! $(echo $BL_THREADTAGS | grep -q "$TAG,") && $(echo $TAG | grep -qE "$THREADTAGS"); then
|
||||||
# If one file is tagged (except del, spam, archive), also tag the other mails of its thread respectively, IF they are located in INBOX [TODO: is this the best approach?]. Only then they can be moved by this script
|
# If one file is tagged (except del, spam, archive), also tag the other mails of its thread respectively, IF they are located in INBOX [TODO: is this the best approach?]. Only then they can be moved by this script
|
||||||
|
|
||||||
# 1. Get thread ids of all entries with the searched tag
|
# 1. Get thread ids of all entries with the searched tag
|
||||||
THREADS=$(notmuch search --exclude=false tag:$TAG and date:$(date -d "-2 months" +%Y-%m-%d)..$(date -d "+1 year" +%Y-%m-%d) | cut -d" " -f1 | cut -d":" -f2)
|
THREADS=$(notmuch search --exclude=false tag:$TAG and date:$(date -d "-6 weeks" +%Y-%m-%d)..$(date -d "+1 year" +%Y-%m-%d) | cut -d" " -f1 | cut -d":" -f2)
|
||||||
|
|
||||||
# 2. Get message ids of all messages in these threads
|
# 2. Get message ids of all messages in these threads
|
||||||
MID=
|
MID=
|
||||||
@@ -72,14 +73,14 @@ while read line; do
|
|||||||
|
|
||||||
# 3. Tag all message ids of messages which are still in INBOX
|
# 3. Tag all message ids of messages which are still in INBOX
|
||||||
for m in $MID; do
|
for m in $MID; do
|
||||||
if $(notmuch search --exclude=false --output=files "$m" | grep -q "$MAILDIR/INBOX"); then
|
if $(notmuch search --exclude=false --output=files "$m" | grep -q "$MAILDIR/INBOX/"); then
|
||||||
logrun notmuch tag +"$TAG" -- "$m"
|
logrun notmuch tag +"$TAG" -- "$m"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Search for these lone messages in INBOX
|
# Search for these lone messages in INBOX
|
||||||
HITFILES=$(notmuch search --output=files --exclude=false path:INBOX/** and tag:$TAG | grep "$MAILDIR/INBOX")
|
HITFILES=$(notmuch search --output=files --exclude=false path:INBOX/** and tag:$TAG | grep "$MAILDIR/INBOX/")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Move files to their destination folders
|
# Move files to their destination folders
|
||||||
@@ -93,10 +94,8 @@ while read line; do
|
|||||||
DESTFOL="$MAILDIR/$FOL/cur"
|
DESTFOL="$MAILDIR/$FOL/cur"
|
||||||
if [ ! -e "$DESTFOL" ]; then
|
if [ ! -e "$DESTFOL" ]; then
|
||||||
logrun mkdir -p "$DESTFOL"
|
logrun mkdir -p "$DESTFOL"
|
||||||
#logrun echo "mkdir -p" "$DESTFOL"
|
|
||||||
fi
|
fi
|
||||||
logrun mv "$m" "$DESTFOL"
|
logrun mv "$m" "$DESTFOL"
|
||||||
#logrun echo "mv" "$m" "$DESTFOL"
|
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user