increase speed heavily

This was possible by removing the step to tag mails in the inbox and move them directly instead; by removing a few unnecessary for loops; and interrupting the while loop if there is not even a thread to search in
This commit is contained in:
2018-07-04 09:26:14 +02:00
parent 3b366b4a17
commit 1f153edaec

View File

@@ -5,7 +5,7 @@
CURDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
DEBUG=false # use 'true' to echo verbose debug messages
DEBUG=true # use 'true' to echo verbose debug messages
CSV="$CURDIR"/tag-list.csv # Table of tags/folders
MAILDIR="$HOME/Mails/FSFE" # Maildir
@@ -46,10 +46,10 @@ function debugmsg {
# Set date until when files are searched for, depending on current connection status
if [ "${var_conn}" == "off" ]; then
DATELIMIT="1d"
logrun echo "Datelimit for search set to $DATELIMIT"
echo "Datelimit for search set to $DATELIMIT"
else
DATELIMIT="14d"
logrun echo "Datelimit for search set to $DATELIMIT"
echo "Datelimit for search set to $DATELIMIT"
fi
while read line; do
@@ -85,34 +85,23 @@ 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}.. | cut -d" " -f1 | cut -d":" -f2)
THREADS=$(notmuch search --exclude=false --output=threads tag:$TAG and date:${DATELIMIT}..)
if [[ -z $THREADS ]]; then debugmsg "Tag $TAG finished. No thread within ${DATELIMIT} found."; debugmsg ""; continue; fi
# 2. Get message ids of all messages in these threads
debugmsg "search for all IDs of these threads"
MID=
for t in $THREADS; do
MID="$MID "$(notmuch search --output=messages --exclude=false thread:$t)
# MID consists of many something like "id:5XXX0CD1.305516@fsfe.org"
done
debugmsg "search for all IDs of these "$(echo "$THREADS" | wc -w)" threads"
MID=$(notmuch search --output=messages --exclude=false $THREADS)
# MID consists of many something like "id:5XXX0CD1.305516@fsfe.org"
# 3. Tag all message ids of messages which are still in INBOX
debugmsg "tag all these IDs if they are in INBOX:" $(echo "$MID" | wc -w) "files"
for m in $MID; do
if $(notmuch search --exclude=false --output=files "$m" | grep -q "$MAILDIR/INBOX/"); then
debugmsg "tag $m with $TAG"
logrun notmuch tag +"$TAG" -- "$m"
fi
done
# Search for these lone messages in INBOX
debugmsg "search for these messages which are still in INBOX"
HITFILES=$(notmuch search --output=files --exclude=false path:INBOX/** and tag:$TAG | grep "$MAILDIR/INBOX/")
# 3. Mark all files of messages if they are still in INBOX
debugmsg "mark all files of "$(echo "$MID" | wc -w)" IDs if they are in INBOX"
HITFILES=$(notmuch search --output=files --exclude=false "$MID" | grep "$MAILDIR/INBOX/")
fi
fi
# Move files to their destination folders
debugmsg "move the files of tag $TAG"
debugmsg "move "$(echo "$HITFILES" | wc -w)" files of tag $TAG from INBOX"
for m in $HITFILES; do
# Destination folder is derived from the current location