~singpolyma/cheogram-smtp

c843cccf9b880d20c0c93a921f4089a5376a37be — Stephen Paul Weber 1 year, 17 days ago 99b426b
Plain text attachment might be body of MMS
1 files changed, 6 insertions(+), 2 deletions(-)

M MMS.hs
M MMS.hs => MMS.hs +6 -2
@@ 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