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:
parent
6479f9ae5e
commit
eeba67de1c
2 changed files with 16 additions and 11 deletions
|
|
@ -17,16 +17,15 @@ MkDirP ← •file.CreateDir⍟(¬•file.Exists)
|
|||
|
||||
AsciiDown ← ('A'-'a')⊸(⊢-×⟜('A'⊸≤∧≤⟜'Z'))
|
||||
|
||||
nl ← @+10
|
||||
_join ← {(∾⟜(𝕗⊸∾))´𝕩;𝕨∾𝕗∾𝕩}
|
||||
|
||||
nl ← @+10
|
||||
SplitChar ← ((=(¯1˙⍟⊣)¨+`∘=)⊔⊢)
|
||||
Lines ← nl⊸SplitChar
|
||||
|
||||
ReadPosInt ← {(𝕨⊸×+⊣)´∘⌽-⟜'0'𝕩} # ty leah2
|
||||
ReadPosDec ← 10⊸ReadPosInt
|
||||
|
||||
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,≠headerNames⟩⥊headerNames Hdrs ms
|
||||
dh ← Dates ms
|
||||
ah ← (("com.apple.mail-note"⊸≡⊑)˘/⊢) ⍉th∾dh≍ms
|
||||
{𝕊 ·‿id‿title‿date‿path:
|
||||
⟨AsciiDown id, title, date, {"execline-cd"‿𝕩‿"mshow"‿"-x"‿path ⋄ R "mn2html"‿path}⟩
|
||||
}˘ ah
|
||||
}
|
||||
}
|
||||
|
||||
# Rendering
|
||||
|
|
|
|||
|
|
@ -19,3 +19,5 @@ Xor ⇐ (¬⊸∧∨∧⟜¬)
|
|||
|
||||
# To get all Diagonals (⊢∾○Diagonals⌽)
|
||||
Diagonals ⇐ {(0‿0⊸⍉ ↓⟜𝕩)¨ (↕≠𝕩)}
|
||||
|
||||
ApplyMany ← {fs 𝕊 arg: {𝕏 arg}¨ fs}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue