#! /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: ' ) (( 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