blob: bd7219d833f8fd2db7d22de927ff37e18dde3cef (
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
|
#!/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}"
mailctl="${MAILCTL:-mailctl.py}"
json=$("$mailctl" search "$query" --json) || { echo "mail search failed" >&2; exit 1; }
# Messages and threads both: the model otherwise calls threads "emails".
msgs=$("$mailctl" count "$query" | awk '{print $1}') || { echo "mail count failed" >&2; exit 1; }
jq -r --arg msgs "$msgs" 'length as $n
| if $n == 0 then "no messages match"
else "\($msgs) messages in \($n) threads", (.[:10][] | "\(.date_relative), \(.authors): \(.subject)")
end' <<<"$json"
|