module CreateMail where import Graphics.UI.WX import Graphics.UI.WXCore import Text.Estraier.Misc (estIconv) import QDBM.Cabin (mimeEncode) import Data.Maybe import Network.SMTP import ParseMail import Config iconvert toenc str = estIconv str "UTF-8" toenc ctype "" = "Content-Type: text/plain" ctype enc = "Content-Type: text/plain; charset=" ++ enc send f r subj body config = do receiver <- get r text mailbody <- get body text subject <- get subj text doSMTPPort host port (sendMail (head $ getAddrs sender) (getAddrs receiver) $ unlines ([field "From" sender, field "To" receiver, field "Subject" subject, ctype (encode config)] ++ mailheader config ++ ["", iconv mailbody])) close f where iconv = iconvert (encode config) field f v = prettyField f (iconv v) (encode config) sender = mailaddr config host = hostname $ smtphost $ config port = fromMaybe 25 (portNum $ smtphost $ config) createMail p config = do c <- frameTool [ text := "hazakura - create new mail" , clientSize := sz 640 480 ] p panel <- panel c [] receiverE <- textEntry panel [ enabled := True ] subjectE <- textEntry panel [ enabled := True ] b <- textCtrl panel [ alignment := AlignLeft , wrap := WrapWord , enabled := True ] menu <- menuPane [ text := "&File" ] menuSend <- menuItem menu [ text := "&Send mail" , on command := send c receiverE subjectE b config ] menuClose <- menuItem menu [ text := "&Close" , on command := close c ] set c [ layout := container panel $ margin 0 $ column 2 $ [ row 5 [ label "To: " , hfill $ widget receiverE ] , row 5 [ label "Subject: " , hfill $ widget subjectE ] , fill $ widget b ] , menuBar := [menu] , clientSize := sz 640 480 ] focusOn receiverE return ()