summaryrefslogtreecommitdiffstats
path: root/src/Data/MIME/Untweaked.hs
blob: 56acd43c86eb12e9a25a3d225cb560ae55584856 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{-# LANGUAGE OverloadedStrings #-}
module Data.MIME.Untweaked where

import Data.Foldable (fold)
import Data.List.NonEmpty (intersperse)
import Data.MIME
import qualified Data.ByteString.Builder as Builder



newtype Untweaked = Untweaked MIME


toUntweaked :: Message ctx MIME -> Message ctx Untweaked
toUntweaked (Message h b) = Message h (Untweaked b)


instance RenderMessage Untweaked where
  buildBody _h (Untweaked z) = Just $ case z of
    Part partbody -> Builder.byteString partbody
    Encapsulated msg -> buildMessage . toUntweaked $ msg
    Multipart _sub b xs ->
      let
        boundary = "--" <> Builder.byteString (unBoundary b)
      in
        boundary <> "\r\n"
        <> fold (intersperse ("\r\n" <> boundary <> "\r\n") (fmap (buildMessage . toUntweaked) xs))
        <> "\r\n" <> boundary <> "--\r\n"
    FailedParse _ bs -> Builder.byteString bs