blob: 90877bd13e068476998e9cad9e522c226fdce02b (
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
|
#!/bin/bash
#
# 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.
#
# Opens qtmaildir on an account, or on a thread's newest unread message.
# Shared by the drawer's mail page and mail-notify.sh, so both open mail the
# same way.
#
# mail-open.sh <account-key> [thread-id]
#
# A running qtmaildir takes the selectors over its socket and raises, so this
# never opens a second window.
#
# The message is looked up at click time rather than when the row or the
# notification was built: by then it may have been read, and an unread-only
# lookup that finds nothing falls back to the whole thread instead of a miss.
# Newest, because that is the message the row's date and the notification
# are about.
set -u
key="${1:?usage: mail-open.sh <account-key> [thread-id]}"
tid="${2:-}"
args=(--account "$key")
# notmuch thread ids are hex; anything else never reaches a query.
if [[ "$tid" =~ ^[0-9a-f]+$ ]]; then
id="$(notmuch search --format=json --output=messages --sort=newest-first --limit=1 \
"thread:$tid and tag:unread and tag:inbox" 2>/dev/null | jq -r '.[0] // empty' 2>/dev/null)"
if [[ -n "$id" ]]; then
args+=(--message "$id")
else
args+=(--thread "$tid")
fi
fi
exec "$HOME/bin/qtmaildir" "${args[@]}"
|