~singpolyma/cheogram-smtp

fdd71cf68dee52dcd4ad1535154951cf9cd669c2 — Stephen Paul Weber 2 years ago 217288d
Send nick from email From header
2 files changed, 11 insertions(+), 3 deletions(-)

M Email.hs
M test/EmailTest.hs
M Email.hs => Email.hs +8 -3
@@ 86,19 86,24 @@ emailToStanza ::
	-> XMPP.Message
emailToStanza toJid email =
	(XMPP.emptyMessage XMPP.MessageNormal) {
		XMPP.messageFrom = Just from,
		XMPP.messageFrom = toJid fromMailbox,
		XMPP.messagePayloads = [
			XML.Element (s"{jabber:component:accept}subject") []
				[XML.NodeContent $ XML.ContentText subject],
			XML.Element (s"{jabber:component:accept}body") []
				[XML.NodeContent $ XML.ContentText textBody]
		]
		] ++ nick
	}
	where
	nick = maybeToList $ fmap (\n ->
			XML.Element (s"{http://jabber.org/protocol/nick}nick")
				[] [XML.NodeContent $ XML.ContentText n]
		) fn
	Just textBody = firstOf plainTextBody email
	Just subject = MIME.decodeEncodedWords MIME.defaultCharsets <$>
		firstOf (MIME.headers . MIME.header (s"subject")) email
	Just from = toJid =<< headZ =<< firstOf MIME.headerFrom email
	Just fromMailbox@(MIME.Mailbox fn _) =
		headZ =<< firstOf MIME.headerFrom email


defaultSubject :: XMPP.Message -> Maybe Text

M test/EmailTest.hs => test/EmailTest.hs +3 -0
@@ 50,6 50,9 @@ unit_emailToStanzaSimple =
			],
			XML.Element (s"{jabber:component:accept}body") [] [
				XML.NodeContent $ XML.ContentText $ s"Hello\n"
			],
			XML.Element (s"{http://jabber.org/protocol/nick}nick") [] [
				XML.NodeContent $ XML.ContentText $ s"Human"
			]
		]
	}