{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.SESV2.Types.RawMessage
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.SESV2.Types.RawMessage where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents the raw content of an email message.
--
-- /See:/ 'newRawMessage' smart constructor.
data RawMessage = RawMessage'
  { -- | The raw email message. The message has to meet the following criteria:
    --
    -- -   The message has to contain a header and a body, separated by one
    --     blank line.
    --
    -- -   All of the required header fields must be present in the message.
    --
    -- -   Each part of a multipart MIME message must be formatted properly.
    --
    -- -   Attachments must be in a file format that the Amazon SES supports.
    --
    -- -   The entire message must be Base64 encoded.
    --
    -- -   If any of the MIME parts in your message contain content that is
    --     outside of the 7-bit ASCII character range, you should encode that
    --     content to ensure that recipients\' email clients render the message
    --     properly.
    --
    -- -   The length of any single line of text in the message can\'t exceed
    --     1,000 characters. This restriction is defined in
    --     <https://tools.ietf.org/html/rfc5321 RFC 5321>.
    RawMessage -> Base64
data' :: Core.Base64
  }
  deriving (RawMessage -> RawMessage -> Bool
(RawMessage -> RawMessage -> Bool)
-> (RawMessage -> RawMessage -> Bool) -> Eq RawMessage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RawMessage -> RawMessage -> Bool
$c/= :: RawMessage -> RawMessage -> Bool
== :: RawMessage -> RawMessage -> Bool
$c== :: RawMessage -> RawMessage -> Bool
Prelude.Eq, ReadPrec [RawMessage]
ReadPrec RawMessage
Int -> ReadS RawMessage
ReadS [RawMessage]
(Int -> ReadS RawMessage)
-> ReadS [RawMessage]
-> ReadPrec RawMessage
-> ReadPrec [RawMessage]
-> Read RawMessage
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RawMessage]
$creadListPrec :: ReadPrec [RawMessage]
readPrec :: ReadPrec RawMessage
$creadPrec :: ReadPrec RawMessage
readList :: ReadS [RawMessage]
$creadList :: ReadS [RawMessage]
readsPrec :: Int -> ReadS RawMessage
$creadsPrec :: Int -> ReadS RawMessage
Prelude.Read, Int -> RawMessage -> ShowS
[RawMessage] -> ShowS
RawMessage -> String
(Int -> RawMessage -> ShowS)
-> (RawMessage -> String)
-> ([RawMessage] -> ShowS)
-> Show RawMessage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RawMessage] -> ShowS
$cshowList :: [RawMessage] -> ShowS
show :: RawMessage -> String
$cshow :: RawMessage -> String
showsPrec :: Int -> RawMessage -> ShowS
$cshowsPrec :: Int -> RawMessage -> ShowS
Prelude.Show, (forall x. RawMessage -> Rep RawMessage x)
-> (forall x. Rep RawMessage x -> RawMessage) -> Generic RawMessage
forall x. Rep RawMessage x -> RawMessage
forall x. RawMessage -> Rep RawMessage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RawMessage x -> RawMessage
$cfrom :: forall x. RawMessage -> Rep RawMessage x
Prelude.Generic)

-- |
-- Create a value of 'RawMessage' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'data'', 'rawMessage_data' - The raw email message. The message has to meet the following criteria:
--
-- -   The message has to contain a header and a body, separated by one
--     blank line.
--
-- -   All of the required header fields must be present in the message.
--
-- -   Each part of a multipart MIME message must be formatted properly.
--
-- -   Attachments must be in a file format that the Amazon SES supports.
--
-- -   The entire message must be Base64 encoded.
--
-- -   If any of the MIME parts in your message contain content that is
--     outside of the 7-bit ASCII character range, you should encode that
--     content to ensure that recipients\' email clients render the message
--     properly.
--
-- -   The length of any single line of text in the message can\'t exceed
--     1,000 characters. This restriction is defined in
--     <https://tools.ietf.org/html/rfc5321 RFC 5321>.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
newRawMessage ::
  -- | 'data''
  Prelude.ByteString ->
  RawMessage
newRawMessage :: ByteString -> RawMessage
newRawMessage ByteString
pData_ =
  RawMessage' :: Base64 -> RawMessage
RawMessage' {$sel:data':RawMessage' :: Base64
data' = Tagged ByteString (Identity ByteString)
-> Tagged Base64 (Identity Base64)
Iso' Base64 ByteString
Core._Base64 (Tagged ByteString (Identity ByteString)
 -> Tagged Base64 (Identity Base64))
-> ByteString -> Base64
forall t b. AReview t b -> b -> t
Lens.# ByteString
pData_}

-- | The raw email message. The message has to meet the following criteria:
--
-- -   The message has to contain a header and a body, separated by one
--     blank line.
--
-- -   All of the required header fields must be present in the message.
--
-- -   Each part of a multipart MIME message must be formatted properly.
--
-- -   Attachments must be in a file format that the Amazon SES supports.
--
-- -   The entire message must be Base64 encoded.
--
-- -   If any of the MIME parts in your message contain content that is
--     outside of the 7-bit ASCII character range, you should encode that
--     content to ensure that recipients\' email clients render the message
--     properly.
--
-- -   The length of any single line of text in the message can\'t exceed
--     1,000 characters. This restriction is defined in
--     <https://tools.ietf.org/html/rfc5321 RFC 5321>.--
-- -- /Note:/ This 'Lens' automatically encodes and decodes Base64 data.
-- -- The underlying isomorphism will encode to Base64 representation during
-- -- serialisation, and decode from Base64 representation during deserialisation.
-- -- This 'Lens' accepts and returns only raw unencoded data.
rawMessage_data :: Lens.Lens' RawMessage Prelude.ByteString
rawMessage_data :: (ByteString -> f ByteString) -> RawMessage -> f RawMessage
rawMessage_data = (RawMessage -> Base64)
-> (RawMessage -> Base64 -> RawMessage)
-> Lens RawMessage RawMessage Base64 Base64
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RawMessage' {Base64
data' :: Base64
$sel:data':RawMessage' :: RawMessage -> Base64
data'} -> Base64
data') (\s :: RawMessage
s@RawMessage' {} Base64
a -> RawMessage
s {$sel:data':RawMessage' :: Base64
data' = Base64
a} :: RawMessage) ((Base64 -> f Base64) -> RawMessage -> f RawMessage)
-> ((ByteString -> f ByteString) -> Base64 -> f Base64)
-> (ByteString -> f ByteString)
-> RawMessage
-> f RawMessage
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (ByteString -> f ByteString) -> Base64 -> f Base64
Iso' Base64 ByteString
Core._Base64

instance Prelude.Hashable RawMessage

instance Prelude.NFData RawMessage

instance Core.ToJSON RawMessage where
  toJSON :: RawMessage -> Value
toJSON RawMessage' {Base64
data' :: Base64
$sel:data':RawMessage' :: RawMessage -> Base64
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Data" Text -> Base64 -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Base64
data')]
      )