summaryrefslogtreecommitdiff
path: root/ymir/mlmmj-expose.nix
diff options
context:
space:
mode:
Diffstat (limited to 'ymir/mlmmj-expose.nix')
-rw-r--r--ymir/mlmmj-expose.nix15
1 files changed, 9 insertions, 6 deletions
diff --git a/ymir/mlmmj-expose.nix b/ymir/mlmmj-expose.nix
index aca8aeb1..b3eab046 100644
--- a/ymir/mlmmj-expose.nix
+++ b/ymir/mlmmj-expose.nix
@@ -37,14 +37,17 @@ let
37 "mlmmj-exposed" -> do 37 "mlmmj-exposed" -> do
38 args <- getArgs 38 args <- getArgs
39 case args of 39 case args of
40 [listDir, extension] -> do 40 [listDir, (map toLower -> extension)] -> do
41 setCurrentDirectory listDir 41 setCurrentDirectory listDir
42 identities <- getIdentities 42 identities <- getIdentities
43 subscribers <- getSubscribers 43 subscribers <- getSubscribers
44 let hashes = [(ident, sub, take len $ hash' (ident, sub)) | ident <- identities, sub <- subscribers] 44 let hashes = filter ((==) extension . snd) [((ident, sub), take len $ hash' (ident, sub)) | ident <- identities, sub <- subscribers]
45 unless (extension `elem` map (\(_, _, s) -> s) hashes) $ die "Unknown extension" 45 case hashes of
46 getContents >>= writeFile "queue/exposed" 46 [(_, recipient)] -> do
47 callProcess "${pkgs.mlmmj}/bin/mlmmj-send" ["-L", listDir, "-l", "6", "-m", "queue/exposed", "-T", recipient] 47 getContents >>= writeFile "queue/exposed"
48 callProcess "${pkgs.mlmmj}/bin/mlmmj-send" ["-L", listDir, "-l", "6", "-m", "queue/exposed", "-T", recipient]
49 [] -> die "Unknown extension"
50 _ -> die "Ambiguous extension"
48 _ -> hPutStrLn stderr ("Called without expected arguments (<listDirectory> <recipientExtension>)") >> exitWith (ExitFailure 2) 51 _ -> hPutStrLn stderr ("Called without expected arguments (<listDirectory> <recipientExtension>)") >> exitWith (ExitFailure 2)
49 "mlmmj-expose" -> do 52 "mlmmj-expose" -> do
50 args <- getArgs 53 args <- getArgs
@@ -79,7 +82,7 @@ let
79 readDir dir = concat <$> (mapM (fmap lines . readFile) . map (dir </>) . filter (not . (`elem` [".", ".."]))=<< (getDirectoryContents dir)) 82 readDir dir = concat <$> (mapM (fmap lines . readFile) . map (dir </>) . filter (not . (`elem` [".", ".."]))=<< (getDirectoryContents dir))
80 83
81 hash' :: Show a => a -> String 84 hash' :: Show a => a -> String
82 hash' = show . (hash :: BS.ByteString -> Digest SHA256) . CBS.pack . map toLower . show 85 hash' = map toLower . show . (hash :: BS.ByteString -> Digest SHA256) . CBS.pack . map toLower . show
83 86
84 len :: Int 87 len :: Int
85 len = 16 88 len = 16