remailback

send email reminders after a time period
git clone https://a3nm.net/git/remailback/
Log | Files | Refs

delete.sh (1074B)


      1 #!/bin/bash
      2 
      3 # Mark all reminders about a message as deleted.
      4 # Usage: cat message | ./delet.sh
      5 
      6 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
      7 cd "$DIR"
      8 
      9 TEMPFILE=$(mktemp)
     10 cat > $TEMPFILE
     11 
     12 # get_email_header command from https://a3nm.net/git/mybin
     13 
     14 MESSAGEID=$(~/bin/get_email_header message-id < "$TEMPFILE")
     15 
     16 # adapted from https://stackoverflow.com/a/169969
     17 (
     18   # Wait for lock on /var/lock/.myscript.exclusivelock (fd 200) for 10 seconds
     19   flock -x -w 10 200 || exit 1
     20 
     21   echo "Currently scheduled reminders:"
     22   ./show.sh < $TEMPFILE
     23 
     24   mkdir -p deleted
     25 
     26   echo "SELECT * FROM reminders WHERE messageid='$MESSAGEID' AND status='scheduled'" |
     27     sqlite3 remailback.sqlite | while read l; do 
     28     ID=$(echo "$l" | cut -d\| -f1)
     29     FILE=$(echo "$l" | cut -d\| -f5)
     30     mv "scheduled/$FILE" "deleted/$FILE"
     31     echo "UPDATE reminders SET status='deleted' WHERE id='$ID'" |
     32       sqlite3 remailback.sqlite
     33     echo "Deleted reminder $ID"
     34   done
     35 
     36   echo "Scheduled reminders are now:"
     37   ./show.sh < $TEMPFILE
     38 ) 200>lock.flock
     39 
     40 rm -f "$TEMPFILE"
     41 
     42