This repository has been archived on 2023-01-25. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
mail-config/astroid/hooks/unspam

29 lines
1.0 KiB
Plaintext
Raw Normal View History

2017-04-13 12:28:53 +02:00
#!/bin/bash
#
2017-07-24 15:29:34 +02:00
# Removes the spam tag from a mail, and moves it back to the INBOX if necessary
2017-04-13 12:28:53 +02:00
#
2017-07-24 15:29:34 +02:00
# $1 = message id
2017-04-13 12:28:53 +02:00
2017-07-24 15:29:34 +02:00
TAG="spam"
2017-04-13 12:28:53 +02:00
DIR_JUNK="INBOX.Junk"
DIR_INBOX="INBOX"
LOG="/home/$USER/.config/astroid/hooks/hook.log"
ID=$1
2017-07-24 15:29:34 +02:00
FILE=$(notmuch search --exclude=false --output=files id:"${ID}") # get actual file path of MID
2017-04-13 12:28:53 +02:00
2017-07-24 15:29:34 +02:00
if [[ $(notmuch search id:"${ID}" and tag:${TAG}) ]]; then # only do something if mail is tagged "spam"
notmuch tag -${TAG} -- id:"${ID}" # unspam mail
echo "[unspam] [SUCCESS] \"${TAG}\" removed from ${ID}" >> $LOG
2017-04-13 12:28:53 +02:00
else
2017-07-24 15:29:34 +02:00
echo "[unspam] [ERROR] not tagged as \"${TAG}\": ${ID}" >> $LOG
2017-04-13 12:28:53 +02:00
fi
2017-07-24 15:29:34 +02:00
if $(echo ${FILE} | grep -q ${DIR_JUNK}); then # if mail is in spam dir
FILE_NEW=$(echo ${FILE} | sed "s|${DIR_JUNK}/|${DIR_INBOX}/|")
mv "${FILE}" "${FILE_NEW}" # move from spamdir to inbox
echo "[unspam] [SUCCESS] moved ${FILE} to ${FILE_NEW}" >> $LOG
2017-04-13 12:28:53 +02:00
else
2017-07-24 15:29:34 +02:00
echo "[unspam] [ERROR] not in \"${TAG}\"\'s folder: ${FILE}" >> $LOG
2017-04-13 12:28:53 +02:00
fi