summaryrefslogtreecommitdiff
path: root/labs_change_detector
blob: 16a440d4b540bd786e3a36b488956bb7a691fec0 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#! /bin/bash

source ./bot_settings.sh
source ./lib/send.sh
shopt -s extglob


if ! which inotifywait &> /dev/null
then
    log_error "[LABS]: ERROR: cannot find the \`inotify\` program"
    exit
elif [[ ! -d "${BOT_MAIL_DIR}" ]]
then
    log_error "[LABS]: ERROR: no such directory set in \$BOT_MAIL_DIR: '${BOT_MAIL_DIR}'"
    exit
fi


inotifywait -m --format '%w%f' -e create "${BOT_MAIL_DIR}" 2>/dev/null |
    while read email
    do
        is_forum=0
        is_reply=0
        thread=''
        next_line_is_url=0

        while read line
        do
            case "${line}" in
                'Subject: ['* )
                    lp1="${line#Subject: [}"
                    lp="${lp1%% - *}"
                    [[ "$lp" == 'Parabola Community Forum' ]] && is_forum=1 || is_forum=0
                    (( is_forum )) && line=$(echo ${line##*]})
                    next_line_continues_subject=${is_forum}

                    echo -n "${lp}"
                    ;;
                'Mime-Version: '* )
                    next_line_continues_subject=0
                    [[ "${thread#RE:}" != "${thread}" ]] && is_reply=1 || is_reply=0
                    ;;

                'Issue #'* )
                    nick=${line}
                    echo -n " - ${nick}"
                    ;;
                'X-Redmine-Sender: '* )
                    nick=${line##*: }

                    (( is_forum )) && ! (( is_reply )) && echo -n " - ${nick} started: \"${thread#RE:*}\""
                    (( is_forum )) &&   (( is_reply )) && echo -n " - ${nick} commented on: \"${thread#RE:*}\""
                    ;;

                *' #'+([[:digit:]])': '* )
                    echo -n " (${line#'Bug #'+([[:digit:]])': '})"
                    ! (( is_forum )) && next_line_is_url=1
                    ;;
                'List-Id: <labs.parabola.nu>' )
                    (( is_forum )) && next_line_is_url=1
                    ;;

                'https://labs.parabola.nu/issues/'* | \
                'https://labs.parabola.nu/boards/'* )
                    (( next_line_is_url )) && echo -n " - <${line}>"
                    break
                    ;;
            esac

            (( next_line_continues_subject )) && thread+="${line}"
        done < "${email}"

        echo
    done |
        while read message
        do
            send_ipc_msg '0' "${message}"
        done