2017-02-06 12:33:43 +00:00
|
|
|
module Main where
|
|
|
|
|
|
|
|
import Lib
|
2017-02-10 19:36:41 +00:00
|
|
|
import Data.Time.Clock
|
|
|
|
import Data.Time.Calendar
|
2017-02-06 14:57:43 +00:00
|
|
|
import System.Environment
|
2017-02-10 19:36:41 +00:00
|
|
|
import Data.Monoid
|
|
|
|
import Network.Mail.Mime hiding (mailFrom, mailTo)
|
|
|
|
import Options.Applicative
|
|
|
|
|
|
|
|
data CLIOptions = CLIOptions
|
|
|
|
{ filename :: String
|
|
|
|
, mailTo :: String
|
|
|
|
, mailFrom :: String
|
|
|
|
, mailFromName :: String
|
|
|
|
}
|
|
|
|
|
|
|
|
options :: Parser CLIOptions
|
|
|
|
options = CLIOptions
|
|
|
|
<$> strOption
|
|
|
|
( long "filename"
|
|
|
|
<> short 'f'
|
|
|
|
<> metavar "FILE"
|
|
|
|
<> help "Filename of Markdown-File"
|
|
|
|
)
|
|
|
|
<*> strOption
|
|
|
|
( long "to"
|
|
|
|
<> short 't'
|
|
|
|
<> metavar "TO"
|
|
|
|
<> help "Mail-address to send the reminder to"
|
|
|
|
)
|
|
|
|
<*> strOption
|
|
|
|
( long "from"
|
|
|
|
<> short 'f'
|
|
|
|
<> metavar "FROM"
|
|
|
|
<> help "Mail-address of the reminder"
|
|
|
|
)
|
|
|
|
<*> strOption
|
|
|
|
( long "name"
|
|
|
|
<> short 'n'
|
|
|
|
<> metavar "NAME"
|
|
|
|
<> help "Name in the reminder-mails"
|
|
|
|
)
|
|
|
|
|
|
|
|
opts = info (options <**> helper)
|
|
|
|
( fullDesc
|
|
|
|
<> progDesc "Send reminder from FILE to mail TO using FROM and NAME as identification for the sender"
|
|
|
|
<> header "md2mail - a small program for sending out reminder-mails from markdown"
|
|
|
|
)
|
2017-02-06 12:33:43 +00:00
|
|
|
|
|
|
|
main :: IO ()
|
2017-02-06 14:45:50 +00:00
|
|
|
main = do
|
2017-02-10 19:36:41 +00:00
|
|
|
args <- execParser opts
|
|
|
|
md <- readFile $ filename args
|
|
|
|
(UTCTime today _) <- getCurrentTime
|
|
|
|
sequence_ $ sequence . fmap (renderSendMail . snd) . filter (filterToday today) <$> getMails md (mailTo args) (mailFrom args) (mailFromName args)
|
|
|
|
|
|
|
|
|
|
|
|
filterToday :: Day -> (Day, Mail) -> Bool
|
2017-02-10 19:38:18 +00:00
|
|
|
filterToday d (d2,_) = day1 == day2 && m1 == m2
|
2017-02-10 19:36:41 +00:00
|
|
|
where
|
|
|
|
(_,m1,day1) = toGregorian d
|
|
|
|
(_,m2,day2) = toGregorian d2
|