summaryrefslogtreecommitdiffstats
path: root/src/Data/MIME/Untweaked.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data/MIME/Untweaked.hs')
-rw-r--r--src/Data/MIME/Untweaked.hs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/Data/MIME/Untweaked.hs b/src/Data/MIME/Untweaked.hs
new file mode 100644
index 0000000..56acd43
--- /dev/null
+++ b/src/Data/MIME/Untweaked.hs
@@ -0,0 +1,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
+
+