@@ -10,6 +10,10 @@ import Data.Char
10import Data.Time
10import Data.Time
11import Control.Applicative
11import Control.Applicative
12import System.Locale (defaultTimeLocale)
12import System.Locale (defaultTimeLocale)
14+import qualified Data.Map as Map
15+import qualified Data.ByteString as B
16+import qualified Data.ByteString.Base64 as Base64
13import qualified Data.Text as T
17import qualified Data.Text as T
14import qualified Data.Text.Lazy as TL
18import qualified Data.Text.Lazy as TL
15import Control.Lens
19import Control.Lens
@@ -123,6 +127,61 @@ instance FromJSON MandrillHtml where
123instance Arbitrary MandrillHtml where
127instance Arbitrary MandrillHtml where
124 arbitrary = pure $ mkMandrillHtml "<p><b>FooBar</b></p>"
128 arbitrary = pure $ mkMandrillHtml "<p><b>FooBar</b></p>"
130+--------------------------------------------------------------------------------
131+type MandrillTags = T.Text
134+--------------------------------------------------------------------------------
135+type MandrillHeader = Map T.Text T.Text
138+--------------------------------------------------------------------------------
139+type MandrillVars = Map T.Text T.Text
142+--------------------------------------------------------------------------------
143+data MandrillMergeVars = MandrillMergeVars {
144+ _mmvr_rcpt :: !T.Text
145+ , _mmvr_vars :: [MandrillVars]
148+makeLenses ''MandrillMergeVars
149+deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillMergeVars
151+--------------------------------------------------------------------------------
152+data MandrillMetadata = MandrillMetadata {
153+ _mmdt_rcpt :: !T.Text
154+ , _mmdt_values :: [MandrillVars]
157+makeLenses ''MandrillMetadata
158+deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillMetadata
161+newtype Base64ByteString = B64BS !B.ByteString
163+instance ToJSON Base64ByteString where
164+ toJSON (B64BS bs) = Base64.encode bs
166+instance FromJSON Base64ByteString where
167+ parseJSON (String v) = case Base64.decode v of
170+ parseJSON rest = typeMismatch "Base64ByteString must be a String." rest
172+--------------------------------------------------------------------------------
173+data MandrillWebContent = MandrillWebContent {
174+ _mwct_type :: !T.Text
175+ , _mwct_name :: !T.Text
176+ -- ^ [for images] the Content ID of the image
177+ -- - use <img src="cid:THIS_VALUE"> to reference the image
178+ -- in your HTML content
179+ , _mwct_content :: !Base64ByteString
182+makeLenses ''MandrillWebContent
183+deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillWebContent
126--------------------------------------------------------------------------------
185--------------------------------------------------------------------------------
127-- | The information on the message to send
186-- | The information on the message to send
128data MandrillMessage = MandrillMessage {
187data MandrillMessage = MandrillMessage {
@@ -138,6 +197,74 @@ data MandrillMessage = MandrillMessage {
138 -- ^ Optional from name to be used
197 -- ^ Optional from name to be used
139 , _mmsg_to :: [MandrillRecipient]
198 , _mmsg_to :: [MandrillRecipient]
140 -- ^ A list of recipient information
199 -- ^ A list of recipient information
200+ , _mmsg_headers :: [MandrillHeader]
201+ -- ^ optional extra headers to add to the message (most headers are allowed)
202+ , _mmsg_important :: Maybe Bool
203+ -- ^ whether or not this message is important, and should be delivered ahead
204+ -- of non-important messages
205+ , _mmsg_track_opens :: Maybe Bool
206+ -- ^ whether or not to turn on open tracking for the message
207+ , _mmsg_track_clicks :: Maybe Bool
208+ -- ^ whether or not to turn on click tracking for the message
209+ , _mmsg_auto_text :: Maybe Bool
210+ -- ^ whether or not to automatically generate a text part for messages that are not given text
211+ , _mmsg_auto_html :: Maybe Bool
212+ -- ^ whether or not to automatically generate an HTML part for messages that are not given HTML
213+ , _mmsg_inline_css :: Maybe Bool
214+ -- ^ whether or not to automatically inline all CSS styles provided in the message HTML
215+ -- - only for HTML documents less than 256KB in size
216+ , _mmsg_url_strip_qs :: Maybe Bool
217+ -- ^ whether or not to strip the query string from URLs when aggregating tracked URL data
218+ , _mmsg_preserve_recipients :: Maybe Bool
219+ -- ^ whether or not to expose all recipients in to "To" header for each email
220+ , _mmsg_view_content_link :: Maybe Bool
221+ -- ^ set to false to remove content logging for sensitive emails
222+ , _mmsg_bcc_address :: Maybe T.Text
223+ -- ^ an optional address to receive an exact copy of each recipient's email
224+ , _mmsg_tracking_domain :: Maybe T.Text
225+ -- ^ a custom domain to use for tracking opens and clicks instead of mandrillapp.com
226+ , _mmsg_signing_domain :: Maybe Bool
227+ -- ^ a custom domain to use for SPF/DKIM signing instead of mandrill
228+ -- (for "via" or "on behalf of" in email clients)
229+ , _mmsg_return_path_domain :: Maybe Bool
230+ -- ^ a custom domain to use for the messages's return-path
231+ , _mmsg_merge :: Maybe Bool
232+ -- ^ whether to evaluate merge tags in the message.
233+ -- Will automatically be set to true if either merge_vars
234+ -- or global_merge_vars are provided.
235+ , _mmsg_global_merge_vars :: [MandrillVars]
236+ -- ^ global merge variables to use for all recipients. You can override these per recipient.
237+ , _mmsg_merge_vars :: [MandrillMergeVars]
238+ -- ^ per-recipient merge variables, which override global merge variables with the same name.
239+ , _mmsg_tags :: [MandrillTags]
240+ -- ^ 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
242+ -- or change frequently. Tags should be 50 characters or less.
243+ -- Any tags starting with an underscore are reserved for internal use
244+ -- and will cause errors.
245+ , _mmsg_subaccount :: Maybe T.Text
246+ -- ^ the unique id of a subaccount for this message
247+ -- - must already exist or will fail with an error
248+ , _mmsg_google_analytics_domains :: [T.Text]
249+ -- ^ an array of strings indicating for which any matching URLs
250+ -- will automatically have Google Analytics parameters appended
251+ -- to their query string automatically.
252+ , _mmsg_google_analytics_campaign :: Maybe T.Text
253+ -- ^ optional string indicating the value to set for the utm_campaign
254+ -- tracking parameter. If this isn't provided the email's from address
255+ -- will be used instead.
256+ , _mmsg_metadata :: [MandrillVars]
257+ -- ^ metadata an associative array of user metadata. Mandrill will store
258+ -- this metadata and make it available for retrieval.
259+ -- In addition, you can select up to 10 metadata fields to index
260+ -- and make searchable using the Mandrill search api.
261+ , _mmsg_recipient_metadata :: [MandrillMetadata]
262+ -- ^ Per-recipient metadata that will override the global values
263+ -- specified in the metadata parameter.
264+ , _mmsg_attachments :: [MandrillWebContent]
265+ -- ^ an array of supported attachments to add to the message
266+ , _mmsg_images :: [MandrillWebContent]
267+ -- ^ an array of embedded images to add to the message
141 } deriving Show
268 } deriving Show
143makeLenses ''MandrillMessage
270makeLenses ''MandrillMessage
@@ -150,6 +277,31 @@ instance Arbitrary MandrillMessage where
150 <*> pure "sender@example.com"
277 <*> pure "sender@example.com"
151 <*> pure Nothing
278 <*> pure Nothing
152 <*> resize 2 arbitrary
279 <*> resize 2 arbitrary
154--------------------------------------------------------------------------------
306--------------------------------------------------------------------------------
155type MandrillKey = T.Text
307type MandrillKey = T.Text