summaryrefslogtreecommitdiffstats
path: root/examples/tools/mail.sh
blob: 4e0e9c1e5b00bf420f51993372e0f571329c1b43 (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
#!/bin/bash
# desktop-assistant tool: unread mail summary through mailctl (read-only).
# Copyright (C) 2026 Danilo M. <danix@danix.xyz>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# mail.sh [QUERY]: thread count and the 10 newest threads for a notmuch
# query, default unread mail in the inbox, across every account. Only
# mailctl's search runs here: nothing is tagged, moved or synced.
# MAILCTL overrides the command (default mailctl.py on PATH).

set -uo pipefail

query="${1:-tag:unread and tag:inbox}"
json=$("${MAILCTL:-mailctl.py}" search "$query" --json) || { echo "mail search failed" >&2; exit 1; }
jq -r 'length as $n
    | if $n == 0 then "no threads match"
      else "\($n) threads", (.[:10][] | "\(.date_relative), \(.authors): \(.subject)")
      end' <<<"$json"