git.iko.soy/typeable/mandrill
on master help sign in
Code won't build until new release on base64
1c23e1aAlfredo Di Napoli
mandrill.cabal+3
@@ -28,6 +28,9 @@ library
28 -- other-extensions:
28 -- other-extensions:
29 build-depends:
29 build-depends:
30 base >=4.6 && < 5
30 base >=4.6 && < 5
31+ , containers >= 0.5.0.0
32+ , bytestring >= 0.9.0
33+ , bytestring-base64 > 1.0.0.1
31 , text >= 1.0.0.0 && < 1.2
34 , text >= 1.0.0.0 && < 1.2
32 , wreq >= 0.1.0.1
35 , wreq >= 0.1.0.1
33 , aeson >= 0.7.0.3 && < 0.8
36 , aeson >= 0.7.0.3 && < 0.8
src/Network/API/Mandrill/Types.hs+152
@@ -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)
13+import Data.Map (Map)
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>"
125
129
130+--------------------------------------------------------------------------------
131+type MandrillTags = T.Text
132+
133+
134+--------------------------------------------------------------------------------
135+type MandrillHeader = Map T.Text T.Text
136+
137+
138+--------------------------------------------------------------------------------
139+type MandrillVars = Map T.Text T.Text
140+
141+
142+--------------------------------------------------------------------------------
143+data MandrillMergeVars = MandrillMergeVars {
144+ _mmvr_rcpt :: !T.Text
145+ , _mmvr_vars :: [MandrillVars]
146+ } deriving Show
147+
148+makeLenses ''MandrillMergeVars
149+deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillMergeVars
150+
151+--------------------------------------------------------------------------------
152+data MandrillMetadata = MandrillMetadata {
153+ _mmdt_rcpt :: !T.Text
154+ , _mmdt_values :: [MandrillVars]
155+ } deriving Show
156+
157+makeLenses ''MandrillMetadata
158+deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillMetadata
159+
160+
161+newtype Base64ByteString = B64BS !B.ByteString
162+
163+instance ToJSON Base64ByteString where
164+ toJSON (B64BS bs) = Base64.encode bs
165+
166+instance FromJSON Base64ByteString where
167+ parseJSON (String v) = case Base64.decode v of
168+ Left err = fail err
169+ Right rs = B64BS rs
170+ parseJSON rest = typeMismatch "Base64ByteString must be a String." rest
171+
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
180+ } deriving Show
181+
182+makeLenses ''MandrillWebContent
183+deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillWebContent
184+
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
142
269
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
280+ <*> pure []
281+ <*> pure Nothing
282+ <*> pure Nothing
283+ <*> pure Nothing
284+ <*> pure Nothing
285+ <*> pure Nothing
286+ <*> pure Nothing
287+ <*> pure Nothing
288+ <*> pure Nothing
289+ <*> pure Nothing
290+ <*> pure Nothing
291+ <*> pure Nothing
292+ <*> pure Nothing
293+ <*> pure Nothing
294+ <*> pure Nothing
295+ <*> pure []
296+ <*> pure []
297+ <*> pure []
298+ <*> pure Nothing
299+ <*> pure []
300+ <*> pure Nothing
301+ <*> pure []
302+ <*> pure []
303+ <*> pure []
304+ <*> pure []
153
305
154--------------------------------------------------------------------------------
306--------------------------------------------------------------------------------
155type MandrillKey = T.Text
307type MandrillKey = T.Text