blob: 4889a592adec1ce675b67a460d82316360600815 (
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
|
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
--module Main (main) where
import Control.Applicative
import qualified Data.Text.Lazy as LT
import qualified Data.Tree as Tree
import MBox (MBox)
import qualified MBox
import System.Environment
import System.Process
notmuchShowMBox :: String -> IO MBox
notmuchShowMBox searchTerm =
MBox.parseMBox . LT.pack <$> readProcess
"notmuch"
[ "show"
, "--format=mbox"
, "--entire-thread=true"
, searchTerm
]
""
renderMessage :: MBox.Message -> String
renderMessage msg =
LT.unpack (MBox.getMessageId $ MBox.headers msg)
++ " "
++ drop (length ("From " :: String)) (LT.unpack $ MBox.fromLine msg)
main :: IO ()
main = do
-- load-env hack
maybe (return ()) (setEnv "HOME") =<< lookupEnv "OLDHOME"
notmuchShowMBox "tree1" >>=
putStrLn . Tree.drawTree .
Tree.Node "subject:tree-test" .
map (fmap renderMessage) .
MBox.toForest
|