@@ 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