import Control.Monad (forever)
import qualified Data.ByteString.Lazy.Char8 as BL
import qualified Data.Text as T
+import Data.List (isSuffixOf)
import Data.Time
import Data.Time.Clock.POSIX
import Data.Version (showVersion)
inotify
[CloseWrite, MoveIn]
(inputFile args)
- (handleEvent publishOneMsg)
+ (handleEvent publishOneMsg (suffix args))
hr $ "watching " ++ (inputFile args)
_ <- forever $ threadDelay 1000000
removeWatch wd
(show ackType))
-- | Hotfolder event handler
-handleEvent :: (Maybe String -> BL.ByteString -> IO ()) -> Event -> IO ()
+handleEvent :: (Maybe String -> BL.ByteString -> IO ()) -> [ String ] -> Event -> IO ()
-- just handle closewrite and movedin events
-handleEvent f (Closed False (Just x) True) = handleFile f x
-handleEvent f (MovedIn False x _) = handleFile f x
-handleEvent _ _ = return ()
+handleEvent f s (Closed False (Just x) True) = handleFile f s x
+handleEvent f s (MovedIn False x _) = handleFile f s x
+handleEvent _ _ _ = return ()
-- | Hotfolder file handler
-handleFile :: (Maybe String -> BL.ByteString -> IO ()) -> FilePath -> IO ()
-handleFile _ ('.':_) = return () -- ignore hidden files
-handleFile f x =
+handleFile :: (Maybe String -> BL.ByteString -> IO ()) -> [String] -> FilePath -> IO ()
+handleFile _ _ ('.':_) = return () -- ignore hidden files
+handleFile f s@(_:_) x = if any (flip isSuffixOf x) s then handleFile f [] x else return ()
+handleFile f [] x =
X.catch
(hr ("sending " ++ x) >> BL.readFile x >>= f (Just x))
(\exception ->
, msgTimestamp = Just now
, msgID = msgid a
, msgType = msgtype a
- , msgUserID = msguserid a
- , msgApplicationID = msgappid a
- , msgClusterID = msgclusterid a
- , msgContentType = msgcontenttype a
- , msgContentEncoding = msgcontentencoding a
- , msgReplyTo = msgreplyto a
- , msgPriority = msgprio a
- , msgCorrelationID = msgcorrid a
+ , msgUserID = userid a
+ , msgApplicationID = appid a
+ , msgClusterID = clusterid a
+ , msgContentType = contenttype a
+ , msgContentEncoding = contentencoding a
+ , msgReplyTo = replyto a
+ , msgPriority = prio a
+ , msgCorrelationID = corrid a
, msgExpiration = msgexp a
, msgHeaders = substheader (fnheader a) fn $ msgheader a
}
printparam "sent" $ fmap show r
where
- substheader ::
- Maybe String -> Maybe String -> Maybe FieldTable -> Maybe FieldTable
- substheader (Just fnh) (Just fname) old = addheader old (fnh ++ "=" ++ fname)
+ substheader :: [String] -> Maybe String -> Maybe FieldTable -> Maybe FieldTable
+ substheader (s:r) (Just fname) old =
+ substheader r (Just fname) (addheader old (s ++ "=" ++ fname))
substheader _ _ old = old