]> git.madduck.net Git - etc/mailfilter.git/blob - bin/process-delayed-queue

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

e978a40aacc9125166a658b7544d095390748fb8
[etc/mailfilter.git] / bin / process-delayed-queue
1 #!/bin/sh
2 set -eu
3
4 MAILDIR=$HOME/.maildir
5
6 SQLITE=/usr/bin/sqlite3
7 RESUBMIT=$HOME/.etc/mailfilter/bin/resubmit
8
9 DELAYED_QUEUE_DB=$HOME/.var/procmail/delayed-queue.sqlite
10
11 QUERY='select * from messages where release_ts < strftime("%s", "now")'
12
13 $SQLITE -list -separator ' ' $DELAYED_QUEUE_DB "$QUERY" \
14   | while read msgid basefile ts; do
15
16     file="$MAILDIR/$basefile"
17     files="$file ${file}:2,"
18
19     basename="${file##*/}"
20     dirname="${file%/*}"
21     case "${dirname##*/}" in
22       cur)
23         files="$files ${file}:2,S"
24         file="${dirname%/cur}/new/$basename"
25         files="$files $file ${file}:2,"
26         ;;
27       new)
28         file="${dirname%/new}/cur/$basename"
29         files="$files ${file}:2, ${file}:2,S"
30         ;;
31     esac
32
33     found=0
34     for file in $files; do
35       if [ -f "$file" ]; then
36         $RESUBMIT "$file"
37         echo "I: resubmitted $msgid"
38         found=1
39         break
40       fi
41     done
42
43     $SQLITE $DELAYED_QUEUE_DB "delete from messages where msgid = '$msgid'"
44
45     if [ $found -eq 0 ]; then
46       echo "E: message $msgid not found in $basefile" >&2
47     fi
48
49 done