From 5afbf3d5b8ab6cea33057123730e5c55d27fe8d4 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 6 Sep 2018 17:45:56 +0200 Subject: cleanup --- ymir/mlmmj-expose/mlmmj-expose.hs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'ymir') diff --git a/ymir/mlmmj-expose/mlmmj-expose.hs b/ymir/mlmmj-expose/mlmmj-expose.hs index a7b9ec48..4ad9a201 100644 --- a/ymir/mlmmj-expose/mlmmj-expose.hs +++ b/ymir/mlmmj-expose/mlmmj-expose.hs @@ -14,6 +14,8 @@ import Data.Char import Control.Monad import Control.Monad.State +import Control.Exception (bracket_) + import Crypto.Hash import qualified Data.ByteString.Lazy as LBS @@ -66,7 +68,7 @@ main = do subscribers <- getSubscribers let hashes = filter ((==) extension . snd) [((siIdent, siEmail), hashIdent SubscriberIdent{..}) | siIdent <- identities, siEmail <- subscribers ] case hashes of - [((_, recipient), _)] -> do + [((_, siEmail), _)] -> do uuid <- UUID.nextRandom let fName = "queue" "exposed" <.> uuidTrans uuid uuidTrans = uuidTrans' . UUID.toString @@ -74,10 +76,11 @@ main = do uuidTrans' [] = [] uuidTrans' ('-':xs) = uuidTrans' xs uuidTrans' (x:xs) = x : uuidTrans' xs - getContents >>= writeFile fName - hPrintf stdout "Forwarding mail to <%s>, subscribed to %s\n" recipient (takeBaseName listDir) - callProcess "@mlmmj@/bin/mlmmj-send" ["-L", listDir, "-l", "6", "-m", fName, "-T", recipient] - removeFile fName + writeQueueFile = getContents >>= writeFile fName + removeQueueFile = removeFile fName + hPrintf stdout "Forwarding mail for %s to <%s>, subscribed to %s\n" siIdent siEmail siList + bracket_ writeQueueFile removeQueueFile $ + callProcess "@mlmmj@/bin/mlmmj-send" ["-L", listDir, "-l", "6", "-m", fName, "-T", siEmail] [] -> die "Unknown extension" _ -> die "Ambiguous extension" _ -> hPutStrLn stderr ("Called without expected arguments ( )") >> exitWith (ExitFailure 2) -- cgit v1.2.3