gmail-simple 0.1.0.2 → 0.1.0.4
raw patch · 3 files changed
+23/−1 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- README.md +7/−0
- gmail-simple.cabal +1/−1
- src/Network/GMail/Simple.hs +15/−0
README.md view
@@ -12,3 +12,10 @@ Feel free to open an issue if you are interested in the addition of some specific feature.++## Required scopes++In order to use the Google API, you need to enable scopes on your account.+Here are the ones you'll need for this library, depending on what you want to do.++* For sending mails: `https://www.googleapis.com/auth/gmail.send`.
gmail-simple.cabal view
@@ -1,5 +1,5 @@ name: gmail-simple-version: 0.1.0.2+version: 0.1.0.4 synopsis: Simple library for Google Mail (GMail). description: Easy-to-use library to interact with the Google Mail API.
src/Network/GMail/Simple.hs view
@@ -2,6 +2,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE CPP #-} -- | Interactions with GMail made simple. --@@ -60,6 +61,7 @@ , GMailException (..) ) where +-- TODO: Better organize the import list import Control.Monad (unless) import Control.Exception (Exception, throwIO) import Control.Concurrent (MVar, newMVar, modifyMVar)@@ -72,6 +74,9 @@ import qualified Web.JWT as JWT import qualified Data.HashMap.Strict as HashMap import qualified Data.Aeson as JSON+#if MIN_VERSION_aeson(2,0,0)+import qualified Data.Aeson.KeyMap as KeyMap+#endif import qualified Network.HTTP.Simple as HTTP import Data.ByteString.Base64 (encodeBase64) import Network.HTTP.Media (MediaType)@@ -179,7 +184,11 @@ , JWT.jti = Nothing } -- Signed JWT+#if MIN_VERSION_jwt(0,11,0)+ jwt = JWT.encodeSigned (JWT.EncodeRSAPrivateKey $ private_key k) h c+#else jwt = JWT.encodeSigned (JWT.RSAPrivateKey $ private_key k) h c+#endif -- HTTP request body body :: ByteString body = URLEncoded.urlEncodeForm $ URLEncoded.Form $ HashMap.fromList@@ -243,7 +252,11 @@ (,) oauthw' <$> f oauth' renderMail :: forall a . ToMailBody a => MailAddress -> Mail a -> JSON.Value+#if MIN_VERSION_aeson(2,0,0)+renderMail sender mail = JSON.Object $ KeyMap.singleton "raw" $ JSON.String+#else renderMail sender mail = JSON.Object $ HashMap.singleton "raw" $ JSON.String+#endif $ Text.replace "+" "-" $ Text.replace "/" "_" $ encodeBase64@@ -269,6 +282,8 @@ instance Exception GMailException -- | Send mail using a session. It might throw a 'FailedToSend' exception.+--+-- In order for this to work, the user must have permissions for the @https://www.googleapis.com/auth/gmail.send@ scope. sendMail :: ToMailBody a => Session -> Mail a -> IO () sendMail session mail = withOAuth session $ \oauth -> do let mailReq :: HTTP.Request