From c843cccf9b880d20c0c93a921f4089a5376a37be Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 13 Feb 2023 15:37:11 -0500 Subject: [PATCH] Plain text attachment might be body of MMS --- MMS.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/MMS.hs b/MMS.hs index 70ba72a..273579c 100644 --- a/MMS.hs +++ b/MMS.hs @@ -12,6 +12,7 @@ import Control.Lens (firstOf) import Data.Aeson ((.=)) import qualified Data.Aeson as Aeson import qualified Data.Attoparsec.Text as Atto +import qualified Data.Text as T import qualified Data.IPLD.CID as CID import qualified Data.MIME as MIME @@ -83,10 +84,13 @@ emailToMMS attachmentUrl ownerT email = do owner' <- addressTel $ AddressLax ownerT return (MMS mid' time' to' from' owner' text' media', files) where + text' = firstOf plainTextBody email <|> + fmap (\(_, _, bytes) -> decodeUtf8 bytes) (headZ texts) media' = map (\(_, uri, _) -> uri) attachments files = map (\(cid, _, bytes) -> (cid, bytes)) attachments - attachments = getAttachments attachmentUrl email - text' = firstOf plainTextBody email + (texts, attachments) = + partition (\(_, uri, _) -> T.isSuffixOf (s".txt") $ tshow uri) $ + getAttachments attachmentUrl email to' = mapMaybe addressTel $ recipientHeader "to" email ++ recipientHeader "cc" email header h = firstOf (MIME.headers . MIME.header (fromString h)) email -- 2.38.5