refactor(sterni/blërg): avoid calling mhdr once per header

We can actually get all the headers we are interested in just one call
of mhdr(1) since it can query multiple headers in multiple messages in
just one call. With BQNs reshape / two dimensional array facilities it
is easy to group the lines of headers by their originating message and
append the original path to the result array.

We still use a separate mhdr(1) call for the Date header since we rely
on the -D option for parsing the header.

Change-Id: Iaaf8f21fa22ab3e32e6900df4ae164e72c722cd3
Reviewed-on: https://cl.tvl.fyi/c/depot/+/13016
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Autosubmit: sterni <sternenseemann@systemli.org>
This commit is contained in:
sterni 2025-01-06 17:03:02 +01:00 committed by clbot
parent 6479f9ae5e
commit eeba67de1c
2 changed files with 16 additions and 11 deletions

View file

@ -17,16 +17,15 @@ MkDirP ← •file.CreateDir⍟(¬•file.Exists)
AsciiDown ('A'-'a')(-×('A''Z'))
nl @+10
_join {((𝕗))´𝕩;𝕨𝕗𝕩}
nl @+10
SplitChar ((=(¯1˙)¨+`=))
Lines nlSplitChar
ReadPosInt {(𝕨×+)´-'0'𝕩} # ty leah2
ReadPosDec 10ReadPosInt
ApplyMany {fs 𝕊 arg: {𝕏 arg}¨ fs}
Chomp {nl¯1𝕩? ¯1𝕩; 𝕩}
Run {
@ -43,16 +42,20 @@ LR ← Lines∘R
# (Apple) Mail Notes Backend
# TODO(sterni): avoid argv limit by chunking
Hdr {LR "mhdr""-dh"𝕨𝕩}
Date {ReadPosDec¨ LR "mhdr""-Dh""Date"𝕩}
Hdrs {LR "mhdr""-dh"(':' _join 𝕨)𝕩}
Dates {ReadPosDec¨ LR "mhdr""-Dh""Date"𝕩}
headerNames "X-Uniform-Type-Identifier""X-Universally-Unique-Identifier""Subject"
MailNotesBackend {𝕊 mailDir:
Filter {𝕩 ("com.apple.mail-note"¨/) "X-Uniform-Type-Identifier" Hdr 𝕩}
Id AsciiDown "X-Universally-Unique-Identifier"Hdr
Title "Subject"Hdr
MkRenderer {𝕊 p: {R "execline-cd"𝕩"mshow""-x"p R "mn2html"p}}
# TODO(sterni): entries could become namespaces
Entries {𝕊: >Id,Title,Date,MkRenderer¨ApplyMany Filter LR "mlist"mailDir}
Entries {𝕊:
ms LR "mlist"mailDir
th ms,headerNamesheaderNames Hdrs ms
dh Dates ms
ah (("com.apple.mail-note")˘/) thdhms
{𝕊 ·idtitledatepath:
AsciiDown id, title, date, {"execline-cd"𝕩"mshow""-x"path R "mn2html"path}
}˘ ah
}
}
# Rendering

View file

@ -19,3 +19,5 @@ Xor ⇐ (¬⊸∧∨∧⟜¬)
# To get all Diagonals (⊢∾○Diagonals⌽)
Diagonals {(00 𝕩)¨ (𝕩)}
ApplyMany {fs 𝕊 arg: {𝕏 arg}¨ fs}