aboutsummaryrefslogtreecommitdiff
path: root/src/Email.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Email.hs')
-rw-r--r--src/Email.hs31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/Email.hs b/src/Email.hs
index a0b9174..89e361f 100644
--- a/src/Email.hs
+++ b/src/Email.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module Email
@@ -9,12 +10,10 @@ module Email
, printFeedEntries
) where
+import Protolude
import Network.Mail.Mime
-import qualified Data.ByteString.Lazy as B
import qualified Data.Text as T
-import qualified Data.Text.Encoding as TE
import Data.Text.Manipulate ( toPascal, toTrain )
-import Control.Monad.IO.Class ( MonadIO, liftIO )
import Control.Monad.Logger ( MonadLogger, logWarn )
import Types
import Date
@@ -25,11 +24,11 @@ configAddressToAddress :: ConfigAddress -> Address
configAddressToAddress (ConfigAddress name email) = Address name email
entryToMail :: MonadLogger m => ConfigAddress -> ConfigAddress -> Int -> Feed -> Entry -> m Mail
-entryToMail from to tlength f e = do
+entryToMail from' to' tlength f e = do
ps <- parts (entryContent e)
return Mail
- { mailFrom = configAddressToAddress from
- , mailTo = [configAddressToAddress to]
+ { mailFrom = configAddressToAddress from'
+ , mailTo = [configAddressToAddress to']
, mailCc = []
, mailBcc = []
, mailHeaders =
@@ -49,17 +48,17 @@ entryToMail from to tlength f e = do
, formatFieldContent $ linkHref l
)
where
- formatFieldName mrel = TE.encodeUtf8 $
- "X-Perfeed-EntryLink" `T.append` maybe "" (\r -> "-" `T.append` toPascal r) mrel
- formatFieldContent l = "<" `T.append` l `T.append` ">"
+ formatFieldName mrel = toS $
+ "X-Perfeed-EntryLink" <> maybe "" (\r -> "-" <> toPascal r) mrel
+ formatFieldContent l = "<" <> l <> ">"
authorHeaders = map $ \a ->
( "X-Perfeed-EntryAuthor"
- , escapeHeader $ personName a `T.append` formatEmail (personEmail a) `T.append` formatURI (personURI a)
+ , escapeHeader $ personName a <> formatEmail (personEmail a) <> formatURI (personURI a)
)
where
- formatEmail = maybe "" (\u -> " <" `T.append` u `T.append` ">")
- formatURI = maybe "" (\u -> " [" `T.append` u `T.append` "]")
+ formatEmail = maybe "" (\u -> " <" <> u <> ">")
+ formatURI = maybe "" (\u -> " [" <> u <> "]")
parts Nothing = do
-- work around Network.Mime.Mail error with empty parts
@@ -75,13 +74,13 @@ entryToMail from to tlength f e = do
parts (Just (TextContent content)) = return [ [ plainPart content ] ]
topic _ "" s = s
- topic l t s = "[" `T.append` short t `T.append` "] " `T.append` s
+ topic l t s = "[" <> short t <> "] " <> s
where
short t'
| T.length t <= l = t'
- | otherwise = T.take (l - 1) t' `T.append` "…"
+ | otherwise = T.take (l - 1) t' <> "…"
-escapeHeader :: T.Text -> T.Text
+escapeHeader :: Text -> Text
escapeHeader = T.strip . T.intercalate " - " . T.lines
mapFeedEntries :: MonadLogger m => ConfigAddress -> ConfigAddress -> Int -> Feed -> (Mail -> m ()) -> [Entry] -> m ()
@@ -101,4 +100,4 @@ sendMail :: MonadIO m => Mail -> m ()
sendMail = liftIO . renderSendMail
printMail :: MonadIO m => Mail -> m ()
-printMail m = liftIO $ B.putStr =<< renderMail' m
+printMail m = liftIO $ putStr =<< renderMail' m