@@ -1,38 +1,59 @@
1−{-# LANGUAGE TemplateHaskell #-}
1+{-# LANGUAGE CPP #-}
2+{-# LANGUAGE DeriveFoldable #-}
3+{-# LANGUAGE DeriveFunctor #-}
4+{-# LANGUAGE DeriveTraversable #-}
5+{-# LANGUAGE OverloadedStrings #-}
2−{-# LANGUAGE RankNTypes #-}
6+{-# LANGUAGE RankNTypes #-}
3{-# LANGUAGE ScopedTypeVariables #-}
7{-# LANGUAGE ScopedTypeVariables #-}
4−{-# LANGUAGE OverloadedStrings #-}
8+{-# LANGUAGE TemplateHaskell #-}
5module Network.API.Mandrill.Types where
9module Network.API.Mandrill.Types where
7−import Network.API.Mandrill.Utils
11+import Control.Applicative
8−import Test.QuickCheck
12+import Control.Monad (mzero)
9import Data.Char
13import Data.Char
10import Data.Time
15import Data.Time
11−import Control.Applicative
16+import Lens.Micro.TH (makeLenses)
17+import Network.API.Mandrill.Utils
18+import Test.QuickCheck
19+import Text.Email.Validate
20+#if MIN_VERSION_time(1,5,0)
21+import Data.Time.Format (TimeLocale, defaultTimeLocale)
12−import System.Locale (defaultTimeLocale)
23+import System.Locale (TimeLocale, defaultTimeLocale)
13−import Data.Map (Map)
24+#endif
14−import qualified Data.Map as Map
15−import qualified Data.ByteString as B
16−import qualified Data.ByteString.Base64 as Base64
17−import qualified Data.Text as T
18−import qualified Data.Text.Lazy as TL
22import Data.Aeson
25import Data.Aeson
23−import Data.Aeson.Types
24import Data.Aeson.TH
26import Data.Aeson.TH
27+import Data.Aeson.Types
28+import qualified Data.ByteString as B
29+import qualified Data.ByteString.Base64 as Base64
30+#if !MIN_VERSION_base(4,8,0)
32+import Data.Traversable
34+import qualified Data.HashMap.Strict as H
36+import qualified Data.Text as T
37+import qualified Data.Text.Encoding as TL
38+import qualified Data.Text.Lazy as TL
25−import qualified Text.Blaze.Html as Blaze
39+import qualified Text.Blaze.Html as Blaze
26import qualified Text.Blaze.Html.Renderer.Text as Blaze
40import qualified Text.Blaze.Html.Renderer.Text as Blaze
41+import qualified Text.Email.Validate as TEV
43+timeParse :: ParseTime t => TimeLocale -> String -> String -> Maybe t
44+#if MIN_VERSION_time(1,5,0)
45+timeParse = parseTimeM True
29--------------------------------------------------------------------------------
50--------------------------------------------------------------------------------
30data MandrillError = MandrillError {
51data MandrillError = MandrillError {
31− _merr_status :: !T.Text
52+ _merr_status :: !T.Text
32− , _merr_code :: !Int
53+ , _merr_code :: !Int
33− , _merr_name :: !T.Text
54+ , _merr_name :: !T.Text
34 , _merr_message :: !T.Text
55 , _merr_message :: !T.Text
35− } deriving Show
56+ } deriving (Show, Eq)
37makeLenses ''MandrillError
58makeLenses ''MandrillError
38deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillError
59deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillError
@@ -57,6 +78,7 @@ data MandrillRejectReason = RR_HardBounce
57 | RR_InvalidSender
78 | RR_InvalidSender
58 | RR_Invalid
79 | RR_Invalid
59 | RR_TestModeLimit
80 | RR_TestModeLimit
60 | RR_Rule deriving Show
82 | RR_Rule deriving Show
62deriveJSON defaultOptions {
84deriveJSON defaultOptions {
@@ -69,7 +91,7 @@ deriveJSON defaultOptions {
69-- which can be either a success or a failure.
91-- which can be either a success or a failure.
70data MandrillResponse k =
92data MandrillResponse k =
71 MandrillSuccess k
93 MandrillSuccess k
72− | MandrillFailure MandrillError deriving Show
94+ | MandrillFailure MandrillError deriving (Show, Eq, Functor, Foldable, Traversable)
74instance FromJSON k => FromJSON (MandrillResponse k) where
96instance FromJSON k => FromJSON (MandrillResponse k) where
75 parseJSON v = case (parseMaybe parseJSON v) :: Maybe k of
97 parseJSON v = case (parseMaybe parseJSON v) :: Maybe k of
@@ -87,14 +109,27 @@ data MandrillRecipientTag = To | Cc | Bcc deriving Show
87deriveJSON defaultOptions { constructorTagModifier = map toLower } ''MandrillRecipientTag
109deriveJSON defaultOptions { constructorTagModifier = map toLower } ''MandrillRecipientTag
112+--------------------------------------------------------------------------------
113+newtype MandrillEmail = MandrillEmail EmailAddress deriving Show
115+instance ToJSON MandrillEmail where
116+ toJSON (MandrillEmail e) = String . TL.decodeUtf8 . toByteString $ e
118+instance FromJSON MandrillEmail where
119+ parseJSON (String s) = case validate (TL.encodeUtf8 s) of
120+ Left err -> fail err
121+ Right v -> return . MandrillEmail $ v
122+ parseJSON o = typeMismatch "Expecting a String for MandrillEmail." o
90--------------------------------------------------------------------------------
125--------------------------------------------------------------------------------
91-- | An array of recipient information.
126-- | An array of recipient information.
92data MandrillRecipient = MandrillRecipient {
127data MandrillRecipient = MandrillRecipient {
93− _mrec_email :: !T.Text
128+ _mrec_email :: MandrillEmail
94 -- ^ The email address of the recipient
129 -- ^ The email address of the recipient
95− , _mrec_name :: Maybe T.Text
130+ , _mrec_name :: Maybe T.Text
96 -- ^ The optional display name to use for the recipient
131 -- ^ The optional display name to use for the recipient
97− , _mrec_type :: Maybe MandrillRecipientTag
132+ , _mrec_type :: Maybe MandrillRecipientTag
98 -- ^ The header type to use for the recipient.
133 -- ^ The header type to use for the recipient.
99 -- defaults to "to" if not provided
134 -- defaults to "to" if not provided
100 } deriving Show
135 } deriving Show
@@ -102,17 +137,35 @@ data MandrillRecipient = MandrillRecipient {
102makeLenses ''MandrillRecipient
137makeLenses ''MandrillRecipient
103deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillRecipient
138deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillRecipient
140+newRecipient :: EmailAddress -> MandrillRecipient
141+newRecipient email = MandrillRecipient (MandrillEmail email) Nothing Nothing
105instance Arbitrary MandrillRecipient where
143instance Arbitrary MandrillRecipient where
106− arbitrary = pure $ MandrillRecipient "test@example.com" Nothing Nothing
144+ arbitrary = pure MandrillRecipient {
145+ _mrec_email = MandrillEmail $ fromJust (emailAddress "test@example.com")
146+ , _mrec_name = Nothing
147+ , _mrec_type = Nothing
108--------------------------------------------------------------------------------
150--------------------------------------------------------------------------------
109newtype MandrillHtml = MandrillHtml Blaze.Html
151newtype MandrillHtml = MandrillHtml Blaze.Html
111−mkMandrillHtml :: T.Text -> MandrillHtml
153+unsafeMkMandrillHtml :: T.Text -> MandrillHtml
112−mkMandrillHtml = MandrillHtml . Blaze.toHtml
154+unsafeMkMandrillHtml = MandrillHtml . Blaze.preEscapedToHtml
156+-- This might be slightly hairy because it violates
157+-- the nice encapsulation that newtypes offer.
114−mkMandrillHtml' :: Blaze.Html -> MandrillHtml
158+mkMandrillHtml :: Blaze.Html -> MandrillHtml
115−mkMandrillHtml' = MandrillHtml
159+mkMandrillHtml = MandrillHtml
161+#if MIN_VERSION_base(4,11,0)
162+instance Semigroup MandrillHtml where
163+ MandrillHtml m1 <> MandrillHtml m2 = MandrillHtml (m1 <> m2)
166+instance Monoid MandrillHtml where
167+ mempty = MandrillHtml mempty
168+ mappend (MandrillHtml m1) (MandrillHtml m2) = MandrillHtml (m1 <> m2)
117instance Show MandrillHtml where
170instance Show MandrillHtml where
118 show (MandrillHtml h) = show $ Blaze.renderHtml h
171 show (MandrillHtml h) = show $ Blaze.renderHtml h
@@ -121,7 +174,7 @@ instance ToJSON MandrillHtml where
121 toJSON (MandrillHtml h) = String . TL.toStrict . Blaze.renderHtml $ h
174 toJSON (MandrillHtml h) = String . TL.toStrict . Blaze.renderHtml $ h
123instance FromJSON MandrillHtml where
176instance FromJSON MandrillHtml where
124− parseJSON (String h) = return $ MandrillHtml (Blaze.toHtml h)
177+ parseJSON (String h) = return $ MandrillHtml (Blaze.preEscapedToHtml h)
125 parseJSON v = typeMismatch "Expecting a String for MandrillHtml" v
178 parseJSON v = typeMismatch "Expecting a String for MandrillHtml" v
127instance Arbitrary MandrillHtml where
180instance Arbitrary MandrillHtml where
@@ -132,17 +185,23 @@ type MandrillTags = T.Text
134--------------------------------------------------------------------------------
187--------------------------------------------------------------------------------
135−type MandrillHeader = Map T.Text T.Text
188+type MandrillHeaders = Object
138--------------------------------------------------------------------------------
191--------------------------------------------------------------------------------
139−type MandrillVars = Map T.Text T.Text
193+data MergeVar = MergeVar {
195+ , _mv_content :: Value
198+makeLenses ''MergeVar
199+deriveJSON defaultOptions { fieldLabelModifier = drop 4 } ''MergeVar
142--------------------------------------------------------------------------------
201--------------------------------------------------------------------------------
143data MandrillMergeVars = MandrillMergeVars {
202data MandrillMergeVars = MandrillMergeVars {
144 _mmvr_rcpt :: !T.Text
203 _mmvr_rcpt :: !T.Text
145− , _mmvr_vars :: [MandrillVars]
204+ , _mmvr_vars :: [MergeVar]
146 } deriving Show
205 } deriving Show
148makeLenses ''MandrillMergeVars
207makeLenses ''MandrillMergeVars
@@ -150,29 +209,33 @@ deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillMergeVars
151--------------------------------------------------------------------------------
210--------------------------------------------------------------------------------
152data MandrillMetadata = MandrillMetadata {
211data MandrillMetadata = MandrillMetadata {
153− _mmdt_rcpt :: !T.Text
212+ _mmdt_rcpt :: !T.Text
154− , _mmdt_values :: [MandrillVars]
213+ , _mmdt_values :: Object
155 } deriving Show
214 } deriving Show
157makeLenses ''MandrillMetadata
216makeLenses ''MandrillMetadata
158deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillMetadata
217deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillMetadata
161−newtype Base64ByteString = B64BS !B.ByteString
220+data Base64ByteString =
221+ EncodedB64BS B.ByteString
222+ -- ^ An already-encoded Base64 ByteString.
223+ | PlainBS B.ByteString
224+ -- ^ A plain Base64 ByteString which requires encoding.
163instance ToJSON Base64ByteString where
227instance ToJSON Base64ByteString where
164− toJSON (B64BS bs) = Base64.encode bs
228+ toJSON (PlainBS bs) = String . TL.decodeUtf8 . Base64.encode $ bs
229+ toJSON (EncodedB64BS bs) = String . TL.decodeUtf8 $ bs
166instance FromJSON Base64ByteString where
231instance FromJSON Base64ByteString where
167− parseJSON (String v) = case Base64.decode v of
232+ parseJSON (String v) = pure $ EncodedB64BS (TL.encodeUtf8 v)
170 parseJSON rest = typeMismatch "Base64ByteString must be a String." rest
233 parseJSON rest = typeMismatch "Base64ByteString must be a String." rest
172--------------------------------------------------------------------------------
235--------------------------------------------------------------------------------
173data MandrillWebContent = MandrillWebContent {
236data MandrillWebContent = MandrillWebContent {
174− _mwct_type :: !T.Text
237+ _mwct_type :: !T.Text
175− , _mwct_name :: !T.Text
238+ , _mwct_name :: !T.Text
176 -- ^ [for images] the Content ID of the image
239 -- ^ [for images] the Content ID of the image
177 -- - use <img src="cid:THIS_VALUE"> to reference the image
240 -- - use <img src="cid:THIS_VALUE"> to reference the image
178 -- in your HTML content
241 -- in your HTML content
@@ -185,67 +248,67 @@ deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillWebContent
185--------------------------------------------------------------------------------
248--------------------------------------------------------------------------------
186-- | The information on the message to send
249-- | The information on the message to send
187data MandrillMessage = MandrillMessage {
250data MandrillMessage = MandrillMessage {
188− _mmsg_html :: MandrillHtml
251+ _mmsg_html :: MandrillHtml
189 -- ^ The full HTML content to be sent
252 -- ^ The full HTML content to be sent
190− , _mmsg_text :: Maybe T.Text
253+ , _mmsg_text :: Maybe T.Text
191 -- ^ Optional full text content to be sent
254 -- ^ Optional full text content to be sent
192− , _mmsg_subject :: !T.Text
255+ , _mmsg_subject :: !T.Text
193 -- ^ The message subject
256 -- ^ The message subject
194− , _mmsg_from_email :: !T.Text
257+ , _mmsg_from_email :: MandrillEmail
195 -- ^ The sender email address
258 -- ^ The sender email address
196− , _mmsg_from_name :: Maybe T.Text
259+ , _mmsg_from_name :: Maybe T.Text
197 -- ^ Optional from name to be used
260 -- ^ Optional from name to be used
198− , _mmsg_to :: [MandrillRecipient]
261+ , _mmsg_to :: [MandrillRecipient]
199 -- ^ A list of recipient information
262 -- ^ A list of recipient information
200− , _mmsg_headers :: [MandrillHeader]
263+ , _mmsg_headers :: MandrillHeaders
201 -- ^ optional extra headers to add to the message (most headers are allowed)
264 -- ^ optional extra headers to add to the message (most headers are allowed)
202− , _mmsg_important :: Maybe Bool
265+ , _mmsg_important :: Maybe Bool
203 -- ^ whether or not this message is important, and should be delivered ahead
266 -- ^ whether or not this message is important, and should be delivered ahead
204 -- of non-important messages
267 -- of non-important messages
205− , _mmsg_track_opens :: Maybe Bool
268+ , _mmsg_track_opens :: Maybe Bool
206 -- ^ whether or not to turn on open tracking for the message
269 -- ^ whether or not to turn on open tracking for the message
207− , _mmsg_track_clicks :: Maybe Bool
270+ , _mmsg_track_clicks :: Maybe Bool
208 -- ^ whether or not to turn on click tracking for the message
271 -- ^ whether or not to turn on click tracking for the message
209− , _mmsg_auto_text :: Maybe Bool
272+ , _mmsg_auto_text :: Maybe Bool
210 -- ^ whether or not to automatically generate a text part for messages that are not given text
273 -- ^ whether or not to automatically generate a text part for messages that are not given text
211− , _mmsg_auto_html :: Maybe Bool
274+ , _mmsg_auto_html :: Maybe Bool
212 -- ^ whether or not to automatically generate an HTML part for messages that are not given HTML
275 -- ^ whether or not to automatically generate an HTML part for messages that are not given HTML
213− , _mmsg_inline_css :: Maybe Bool
276+ , _mmsg_inline_css :: Maybe Bool
214 -- ^ whether or not to automatically inline all CSS styles provided in the message HTML
277 -- ^ whether or not to automatically inline all CSS styles provided in the message HTML
215 -- - only for HTML documents less than 256KB in size
278 -- - only for HTML documents less than 256KB in size
216− , _mmsg_url_strip_qs :: Maybe Bool
279+ , _mmsg_url_strip_qs :: Maybe Bool
217 -- ^ whether or not to strip the query string from URLs when aggregating tracked URL data
280 -- ^ whether or not to strip the query string from URLs when aggregating tracked URL data
218− , _mmsg_preserve_recipients :: Maybe Bool
281+ , _mmsg_preserve_recipients :: Maybe Bool
219 -- ^ whether or not to expose all recipients in to "To" header for each email
282 -- ^ whether or not to expose all recipients in to "To" header for each email
220− , _mmsg_view_content_link :: Maybe Bool
283+ , _mmsg_view_content_link :: Maybe Bool
221 -- ^ set to false to remove content logging for sensitive emails
284 -- ^ set to false to remove content logging for sensitive emails
222− , _mmsg_bcc_address :: Maybe T.Text
285+ , _mmsg_bcc_address :: Maybe T.Text
223 -- ^ an optional address to receive an exact copy of each recipient's email
286 -- ^ an optional address to receive an exact copy of each recipient's email
224− , _mmsg_tracking_domain :: Maybe T.Text
287+ , _mmsg_tracking_domain :: Maybe T.Text
225 -- ^ a custom domain to use for tracking opens and clicks instead of mandrillapp.com
288 -- ^ a custom domain to use for tracking opens and clicks instead of mandrillapp.com
226− , _mmsg_signing_domain :: Maybe Bool
289+ , _mmsg_signing_domain :: Maybe Bool
227− -- ^ a custom domain to use for SPF/DKIM signing instead of mandrill
290+ -- ^ a custom domain to use for SPF/DKIM signing instead of mandrill
228 -- (for "via" or "on behalf of" in email clients)
291 -- (for "via" or "on behalf of" in email clients)
229− , _mmsg_return_path_domain :: Maybe Bool
292+ , _mmsg_return_path_domain :: Maybe Bool
230 -- ^ a custom domain to use for the messages's return-path
293 -- ^ a custom domain to use for the messages's return-path
231− , _mmsg_merge :: Maybe Bool
294+ , _mmsg_merge :: Maybe Bool
232 -- ^ whether to evaluate merge tags in the message.
295 -- ^ whether to evaluate merge tags in the message.
233 -- Will automatically be set to true if either merge_vars
296 -- Will automatically be set to true if either merge_vars
234 -- or global_merge_vars are provided.
297 -- or global_merge_vars are provided.
235− , _mmsg_global_merge_vars :: [MandrillVars]
298+ , _mmsg_global_merge_vars :: [MergeVar]
236 -- ^ global merge variables to use for all recipients. You can override these per recipient.
299 -- ^ global merge variables to use for all recipients. You can override these per recipient.
237− , _mmsg_merge_vars :: [MandrillMergeVars]
300+ , _mmsg_merge_vars :: [MandrillMergeVars]
238 -- ^ per-recipient merge variables, which override global merge variables with the same name.
301 -- ^ per-recipient merge variables, which override global merge variables with the same name.
239− , _mmsg_tags :: [MandrillTags]
302+ , _mmsg_tags :: [MandrillTags]
240 -- ^ an array of string to tag the message with. Stats are accumulated using tags,
303 -- ^ an array of string to tag the message with. Stats are accumulated using tags,
241 -- though we only store the first 100 we see, so this should not be unique
304 -- though we only store the first 100 we see, so this should not be unique
242 -- or change frequently. Tags should be 50 characters or less.
305 -- or change frequently. Tags should be 50 characters or less.
243 -- Any tags starting with an underscore are reserved for internal use
306 -- Any tags starting with an underscore are reserved for internal use
244 -- and will cause errors.
307 -- and will cause errors.
245− , _mmsg_subaccount :: Maybe T.Text
308+ , _mmsg_subaccount :: Maybe T.Text
246 -- ^ the unique id of a subaccount for this message
309 -- ^ the unique id of a subaccount for this message
247 -- - must already exist or will fail with an error
310 -- - must already exist or will fail with an error
248− , _mmsg_google_analytics_domains :: [T.Text]
311+ , _mmsg_google_analytics_domains :: [T.Text]
249 -- ^ an array of strings indicating for which any matching URLs
312 -- ^ an array of strings indicating for which any matching URLs
250 -- will automatically have Google Analytics parameters appended
313 -- will automatically have Google Analytics parameters appended
251 -- to their query string automatically.
314 -- to their query string automatically.
@@ -253,17 +316,17 @@ data MandrillMessage = MandrillMessage {
253 -- ^ optional string indicating the value to set for the utm_campaign
316 -- ^ optional string indicating the value to set for the utm_campaign
254 -- tracking parameter. If this isn't provided the email's from address
317 -- tracking parameter. If this isn't provided the email's from address
255 -- will be used instead.
318 -- will be used instead.
256− , _mmsg_metadata :: [MandrillVars]
319+ , _mmsg_metadata :: Object
257 -- ^ metadata an associative array of user metadata. Mandrill will store
320 -- ^ metadata an associative array of user metadata. Mandrill will store
258 -- this metadata and make it available for retrieval.
321 -- this metadata and make it available for retrieval.
259 -- In addition, you can select up to 10 metadata fields to index
322 -- In addition, you can select up to 10 metadata fields to index
260 -- and make searchable using the Mandrill search api.
323 -- and make searchable using the Mandrill search api.
261− , _mmsg_recipient_metadata :: [MandrillMetadata]
324+ , _mmsg_recipient_metadata :: [MandrillMetadata]
262 -- ^ Per-recipient metadata that will override the global values
325 -- ^ Per-recipient metadata that will override the global values
263 -- specified in the metadata parameter.
326 -- specified in the metadata parameter.
264− , _mmsg_attachments :: [MandrillWebContent]
327+ , _mmsg_attachments :: [MandrillWebContent]
265 -- ^ an array of supported attachments to add to the message
328 -- ^ an array of supported attachments to add to the message
266− , _mmsg_images :: [MandrillWebContent]
329+ , _mmsg_images :: [MandrillWebContent]
267 -- ^ an array of embedded images to add to the message
330 -- ^ an array of embedded images to add to the message
268 } deriving Show
331 } deriving Show
@@ -274,10 +337,10 @@ instance Arbitrary MandrillMessage where
274 arbitrary = MandrillMessage <$> arbitrary
337 arbitrary = MandrillMessage <$> arbitrary
275 <*> pure Nothing
338 <*> pure Nothing
276 <*> pure "Test Subject"
339 <*> pure "Test Subject"
277− <*> pure "sender@example.com"
340+ <*> pure (MandrillEmail . fromJust $ emailAddress "sender@example.com")
278 <*> pure Nothing
341 <*> pure Nothing
279 <*> resize 2 arbitrary
342 <*> resize 2 arbitrary
280− <*> pure []
343+ <*> pure H.empty
281 <*> pure Nothing
344 <*> pure Nothing
282 <*> pure Nothing
345 <*> pure Nothing
283 <*> pure Nothing
346 <*> pure Nothing
@@ -298,13 +361,24 @@ instance Arbitrary MandrillMessage where
298 <*> pure Nothing
361 <*> pure Nothing
299 <*> pure []
362 <*> pure []
300 <*> pure Nothing
363 <*> pure Nothing
301 <*> pure []
365 <*> pure []
302 <*> pure []
366 <*> pure []
303 <*> pure []
367 <*> pure []
369+--------------------------------------------------------------------------------
370+-- | Key value pair for replacing content in templates via 'Editable Regions'
371+data MandrillTemplateContent = MandrillTemplateContent {
373+ , _mtc_content :: T.Text
376+makeLenses ''MandrillTemplateContent
377+deriveJSON defaultOptions { fieldLabelModifier = drop 5 } ''MandrillTemplateContent
306--------------------------------------------------------------------------------
379--------------------------------------------------------------------------------
307type MandrillKey = T.Text
380type MandrillKey = T.Text
381+type MandrillTemplate = T.Text
309newtype MandrillDate = MandrillDate {
383newtype MandrillDate = MandrillDate {
310 fromMandrillDate :: UTCTime
384 fromMandrillDate :: UTCTime
@@ -315,6 +389,6 @@ instance ToJSON MandrillDate where
316instance FromJSON MandrillDate where
390instance FromJSON MandrillDate where
317 parseJSON = withText "MandrillDate" $ \t ->
391 parseJSON = withText "MandrillDate" $ \t ->
318− case parseTime defaultTimeLocale "%Y-%m-%d %I:%M:%S%Q" (T.unpack t) of
392+ case timeParse defaultTimeLocale "%Y-%m-%d %I:%M:%S%Q" (T.unpack t) of
319 Just d -> pure $ MandrillDate d
393 Just d -> pure $ MandrillDate d
320 _ -> fail "could not parse Mandrill date"
394 _ -> fail "could not parse Mandrill date"