#!/bin/bash
#
# Moves a file to the INBOX directory
#
# $1 = message id

MAIL_ROOT=`notmuch config get database.path`
DIR_INBOX="INBOX"
LOG="/home/$USER/.config/astroid/hooks/hook.log"

ID=$1
FILE=$(notmuch search --exclude=false --output=files id:"${ID}")    # get actual file path of MID

if ! $(echo ${FILE} | grep -q "${MAIL_ROOT}/${DIR_INBOX}/"); then     # if mail is not in INBOX already
  mv "${FILE}" "${MAIL_ROOT}/${DIR_INBOX}/cur/"
  echo "[move2inbox] [SUCCESS] moved ${FILE} to ${MAIL_ROOT}/${DIR_INBOX}/cur/" >> $LOG
else
  echo "[move2inbox] [ERROR] already in \"${DIR_INBOX}\" directory: ${FILE}" >> $LOG
fi
