From 4474762dae817d81ab0e28ed39363d21405b2a26 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 2 Jun 2016 02:43:32 +0200 Subject: massage because email --- ymir/mlmmj-expose.nix | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/ymir/mlmmj-expose.nix b/ymir/mlmmj-expose.nix index fbc66ef0..4973b50a 100644 --- a/ymir/mlmmj-expose.nix +++ b/ymir/mlmmj-expose.nix @@ -37,7 +37,7 @@ let "mlmmj-exposed" -> do args <- getArgs case args of - [listDir, (LBS.fromStrict . Base64.decodeLenient . CBS.pack -> extension)] -> do + [listDir, (LBS.fromStrict . Base64.decodeLenient . unmassage . CBS.pack -> extension)] -> do setCurrentDirectory listDir key <- (BS.readFile "exposed.key") `catchIOError` (\e -> if isDoesNotExistError e then randomKey >>= (\k -> BS.writeFile "exposed.key" k >> return k) else ioError e) let ((map toLower -> ident), (map toLower -> recipient)) = read . CLBS.unpack $ decryptMsg CBC key extension @@ -61,21 +61,37 @@ let "mlmmj-get-exposed" -> do args <- getArgs case args of - [listDir, (map toLower -> ident), (map toLower -> recipient)] -> do + [listDir, (map toLower -> ident)] : (map (map toLower) -> recipients) -> do setCurrentDirectory listDir key <- (BS.readFile "exposed.key") `catchIOError` (\e -> if isDoesNotExistError e then randomKey >>= (\k -> BS.writeFile "exposed.key" k >> return k) else ioError e) identities <- (lines <$> readFile "exposed.ids") `catchIOError` (\e -> if isDoesNotExistError e then return [] else ioError e) unless (ident `elem` identities) . die $ "Unknown sender: ‘" ++ ident ++ "’" subscribers <- getSubscribers - unless (recipient `elem` subscribers) . die $ "Unknown recipient: ‘" ++ recipient ++ "’" - encryptMsg CBC key (CLBS.pack . show $ (ident, recipient)) >>= CBS.putStrLn . Base64.encode . LBS.toStrict - _ -> hPutStrLn stderr ("Called without expected arguments ( )") >> exitWith (ExitFailure 2) + for_ recipients (\recipient -> do + unless (recipient `elem` subscribers) . die $ "Unknown recipient: ‘" ++ recipient ++ "’" + encryptMsg CBC key (CLBS.pack . show $ (ident, recipient)) >>= putStrLn . (\ext -> takeDirectory listDir ++ "+" ++ ext ++ "@subs.lists.yggdrasil.li") . CBS.unpack . massage . Base64.encode . LBS.toStrict + ) + _ -> hPutStrLn stderr ("Called without expected arguments ( [ [...]])") >> exitWith (ExitFailure 2) _ -> hPutStrLn stderr ("Called under unsupported name ‘" ++ progName ++ "’") >> exitWith (ExitFailure 2) getSubscribers :: IO [String] getSubscribers = map (map toLower) . concat <$> mapM (flip catchIOError (\e -> if isDoesNotExistError e then return [] else ioError e) . readDir) ["subscribers.d", "digesters.d"] where readDir dir = concat <$> (mapM (fmap lines . readFile) . map (dir ) . filter (not . (`elem` [".", ".."]))=<< (getDirectoryContents dir)) + + massage :: BS.ByteString -> BS.ByteString + massage = CBS.pack . map massage' . CBS.unpack + where + massage' '+' = '-' + massage' '/' = '_' + massage' c = c + + unmassage :: BS.ByteString -> BS.ByteString + unmassage = CBS.pack . map massage' . CBS.unpack + where + massage' '-' = '+' + massage' '_' = '/' + massage' c = c ''; buildCommand = '' mkdir -p $out/bin -- cgit v1.2.3