warbo-utilities: 9bae5374720aaab51bfed15ad8ef5c287545b1a4
1: #!/usr/bin/env bash
2: set -e
3:
4: # Mark the given filename as read, in mu's database and mu4e's Emacs buffers
5:
6: function fail {
7: echo "$*" 1>&2
8: exit 1
9: }
10:
11: [[ -e "$1" ]] || fail "Maildir file '$1' not found"
12: F=$(readlink -f "$1")
13: [[ -f "$F" ]] || fail "File '$F' not found"
14:
15: # We need the msgid from mu's database. Getting this is convoluted, since mu
16: # doesn't seem to allow querying by filename, so we use the sender instead
17: FROM=$(grep '^From:' < "$F" | head -n1 | sed -e 's/^From: //')
18: [[ -n "$FROM" ]] || fail "No From line in '$F'"
19:
20: # If the From address has the form '"Foo Bar" <foo@bar>' then get just the
21: # address (foo@bar)
22: if echo "$FROM" | grep -q '<[^>]*>'
23: then
24: FROM=$(echo "$FROM" | grep -o '<[^>]*>' | grep -o '[^<>]*')
25: fi
26:
27: # Look for messages with this subject line and print their filename and msgid
28: FOUND=0
29: MSGID=""
30: while read -r PAIR
31: do
32: LOCATION=$(echo "$PAIR" | cut -f2)
33: [[ "$LOCATION" = "$F" ]] || continue
34:
35: FOUND=1
36: MSGID=$(echo "$PAIR" | cut -f1)
37: break
38: done < <(mu find "from:$FROM" --fields 'i l')
39:
40: [[ "$FOUND" -eq 1 ]] || fail "Couldn't find '$F' in mu DB (from '$FROM')"
41: [[ -n "$MSGID" ]] || fail "No msgid for '$F'"
42:
43: # We set the flags via mu4e, rather than calling 'mu server' ourselves, since
44: # it will automatically update any mu4e displays to show it as read
45: OUT=$(emacsclient -e "(mu4e~proc-move \"$MSGID\" nil \"+S-u-N\")") ||
46: fail "Emacs gave an error, aborting (stdout: $OUT)"
47:
48: # We expect the output 'nil', otherwise alert the user
49: [[ "$OUT" = "nil" ]] || fail "Unexpected response from Emacs: $OUT"
Generated by git2html.