packages feed

email-postmark (empty) → 0.1

raw patch · 4 files changed

+125/−0 lines, 4 filesdep +HTTPdep +aesondep +attoparsecsetup-changed

Dependencies added: HTTP, aeson, attoparsec, base, bytestring, containers, network

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2011, Daniel Patterson++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Daniel Patterson nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ email-postmark.cabal view
@@ -0,0 +1,47 @@+Name:                email-postmark+Version:             0.1+Synopsis:            A simple wrapper to send emails via the api of the service postmark (http://postmarkapp.com/)+-- Description:         +License:             BSD3+License-file:        LICENSE+Author:              Daniel Patterson+Maintainer:          dbp@riseup.net+-- Copyright:           +Category:            Email+Build-type:          Simple++-- Extra files to be distributed with the package, such as examples or+-- a README.+-- Extra-source-files:  ++-- Constraint on the version of Cabal needed to build this package.+Cabal-version:       >=1.2+++Library+  hs-source-dirs: src+  -- Modules exported by the library.+  Exposed-modules:     +    Network.Mail.Postmark+    +  -- Packages needed in order to build this package.+  Build-depends:+    base >= 4 && < 5,+    network >= 2 && < 3,+    HTTP >= 4000 && < 4001,+    bytestring >= 0.9.1 && < 0.10,+    containers >= 0.2 && < 0.5,+    attoparsec >= 0.8 && < 0.10,+    aeson >= 0.3 && < 0.4+    --     mtl >= 2 && < 3,+    --     text >= 0.11 && < 0.12,+    --     time >= 1.1 && < 1.3,+    --     transformers,+    --     bson >= 0.1 && < 0.2+    -- +  -- Modules not exported by this package.+  -- Other-modules:       +  +  -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.+  -- Build-tools:         +  
+ src/Network/Mail/Postmark.hs view
@@ -0,0 +1,46 @@+{-# LANGUAGE OverloadedStrings #-}++module Network.Mail.Postmark+  (postmark)+  where++import Data.Aeson+import Data.Aeson.Types+import qualified Data.Attoparsec as A+import qualified Data.Map as M+import qualified Data.ByteString.Lazy as LBS +import qualified Data.ByteString as BS+import Data.Maybe (fromJust)+import Network.HTTP hiding (getRequest)+import Network.HTTP.Base+import Network.HTTP.Headers+import Network.URI (parseURI)+++maybeAesonResult (Error _) = Nothing+maybeAesonResult (Success a) = Just a++strictifyBS = BS.concat . LBS.toChunks++-- | The main function, sends an email with the provided+-- from, to, tag, body, and to address. Token is your Postmark token.+-- It returns a boolean depending on whether it succeeded or note.+postmark token from subject tag body to = do+        resp <- simpleHTTP (Request +                              (fromJust $ parseURI "http://api.postmarkapp.com/email")+                              POST+                              [ mkHeader HdrAccept "application/json"+                              , mkHeader HdrContentType "application/json"+                              , mkHeader (HdrCustom "X-Postmark-Server-Token") token+                              , mkHeader HdrContentLength (show $ LBS.length rqbdy)]+                              rqbdy) >>= getResponseBody+        -- there has to be a cleaner way to do this...+        let val = (parseMaybe (.: "Message")) =<< (maybeAesonResult.fromJSON) =<< (A.maybeResult $ A.parse json $ strictifyBS resp)+        return $ maybe False (== ("OK"::BS.ByteString)) val+  where rqbdy = encode $ M.fromList +                        [ ("From" :: BS.ByteString, from)+                        , ("To", to)+                        , ("Subject", subject)+                        , ("Tag", tag)+                        , ("TextBody", body)+                        ]