import qualified Data.ByteString.Lazy.Char8 as BL
import System.IO
--- log cmdline options
+-- | log cmdline options
listToMaybeUnwords :: [String] -> Maybe String
listToMaybeUnwords [] = Nothing
listToMaybeUnwords x = Just $ unwords x
--- Strings or ByteStrings with label, oder nothing at all
+-- | Strings or ByteStrings with label, oder nothing at all
printwithlabel :: String -> Maybe (IO ()) -> IO ()
printwithlabel _ Nothing =
return ()
i
hFlush stdout
--- optional parameters
+-- | optional parameters
printparam :: String -> Maybe String -> IO ()
printparam labl ms = printwithlabel labl $
fmap putStrLn ms
--- required parameters
+-- | required parameters
printparam' :: String -> String -> IO ()
printparam' d s = printparam d (Just s)
--- head chars of body
+-- | head chars of body
printbody :: (String, Maybe BL.ByteString) -> IO ()
printbody (labl, ms) = printwithlabel labl $
fmap (\s -> putStrLn "" >> BL.putStrLn s) ms
--- log marker
+-- | log marker
hr :: String -> IO ()
hr x = putStrLn hr' >> hFlush stdout
where
show (exception :: X.SomeException))
closeConnection conn
--- exclusive temp queue
+-- | exclusive temp queue
tempQueue :: Channel -> String -> [(String, String)] -> String -> IO T.Text
tempQueue chan tmpqname bindlist x = do
(q, _, _) <- declareQueue chan
(if null bindlist then [ (x, "#") ] else bindlist)
return q
--- process received message
+-- | process received message
myCallback :: Maybe Int
-> Maybe String
-> Maybe String
tid)
hr $ "END " ++ numstring
--- if the message is to be saved
+-- | if the message is to be saved
-- and maybe processed further
optionalFileStuff :: (Message, Envelope)
-> [String]
return ())
callbackcmdline
--- save message into temp file
+-- | save message into temp file
saveFile :: Maybe String -> String -> BL.ByteString -> IO (Maybe String)
saveFile Nothing _ _ = return Nothing
saveFile (Just tempD) numstring body = do
hClose h
return $ Just p
--- construct cmdline for callback script
+-- | construct cmdline for callback script
constructCallbackCmdLine :: [String]
-> [String]
-> String
constructCallbackCmdLine opts addi num exe path =
exe : "-f" : path : "-n" : num : opts ++ addi
--- call callback script
+-- | call callback script
doProc :: String -> Envelope -> [String] -> IO ()
doProc numstring envi (exe : args) = do
(_, _, _, processhandle) <- createProcess (proc exe args) { std_out = Inherit
formatheaders f (FieldTable ll) =
concat $ map f $ M.toList ll
--- log formatting
+-- | log formatting
fieldshow :: (T.Text, FieldValue) -> String
fieldshow (k, v) = "\n " ++ T.unpack k ++ ": " ++ valueshow v
--- callback cmdline formatting
+-- | callback cmdline formatting
fieldshow' :: (T.Text, FieldValue) -> [String]
fieldshow' (k, v) = [ "-h", T.unpack k ++ "=" ++ valueshow v ]
--- showing a FieldValue
+-- | showing a FieldValue
valueshow :: FieldValue -> String
valueshow (FVString value) =
T.unpack value
show value
valueshow value = show value
--- skip showing body head if binary type
+-- | skip showing body head if binary type
isimage :: Maybe String -> Bool
isimage Nothing = False
isimage (Just ctype)
False
| otherwise = any (flip isPrefixOf ctype) [ "application", "image" ]
--- show the first bytes of message body
+-- | show the first bytes of message body
anriss' :: Maybe Int -> BL.ByteString -> BL.ByteString
anriss' x = case x of
Nothing -> id
Just y -> BL.take (fromIntegral y)
--- callback cmdline with optional parameters
+-- | callback cmdline with optional parameters
printopt :: (String, Maybe String) -> [String]
printopt (_, Nothing) = []
printopt (opt, Just s) =
[ opt, s ]
--- prints header and head on STDOUT and returns cmdline options to callback
+-- | prints header and head on STDOUT and returns cmdline options to callback
printmsg :: (Message, Envelope) -> Maybe Int -> ZonedTime -> IO [String]
printmsg (msg, envi) anR now = do
mapM_ (uncurry printparam)
timestamp'
timediff
+-- | timestamp conversion
zonedTimeToUTCFLoor :: ZonedTime -> UTCTime
zonedTimeToUTCFLoor x = posixSecondsToUTCTime $
realToFrac ((floor .
utcTimeToPOSIXSeconds .
zonedTimeToUTC) x :: Timestamp)
+-- | show the timestamp
showtime :: TimeZone -> Maybe UTCTime -> Maybe String
showtime tz = fmap (show . (utcToZonedTime tz))
+-- | show difference between two timestamps
difftime :: UTCTime -> UTCTime -> String
difftime now msg
| now == msg = "now"