summaryrefslogtreecommitdiff
path: root/labs_change_detector
blob: 1c0db34d46215ca11bb8028530b7e6131d791e86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#! /bin/bash

if ! which inotifywait &> /dev/null
then
    echo 'inotify is a dep. fail'
    exit
fi

bot_ipc="/tmp/un-provoked-message-store"
maildir="/home/pbot/Maildir/new"

shopt -s extglob

next_line_is_url=0

inotifywait -m --format '%w%f' -e create "${maildir}" 2>/dev/null |
    while read email
    do
        while read line
        do
            case "${line}" in
                'Subject: ['* )
                    lp1="${line#Subject: [}"
                    lp="${lp1%% - *}"
                    echo -n "${lp}"
                    ;;
                'Issue #'* )
                    echo -n " - ${line}"
                    ;;
                *' #'+([[:digit:]])': '* )
                    echo -n " (${line#'Bug #'+([[:digit:]])': '})"
                    next_line_is_url=1
                    ;;
                'https://labs.parabola.nu/issues/'* )
                    (( next_line_is_url )) &&
                        echo -n " ${line}"
                    break
                    ;;
            esac
        done < "${email}"

        echo
    done |
        while read message
        do
            echo "${message}" >> "${bot_ipc}"
        done