Permalink
Browse files

Used HTML mode and added a Mail structure.

  • Loading branch information...
koral
koral committed Dec 23, 2011
1 parent 1446919 commit ff65e751f0e4afc0aecae106dbf518aa7c7dd891
Showing with 55 additions and 15 deletions.
  1. +16 −13 Imm/Core.hs
  2. +24 −0 Imm/Mail.hs
  3. +13 −0 Imm/Types.hs
  4. +2 −2 imm.cabal
View
@@ -1,6 +1,7 @@
module Imm.Core where
-- {{{ Imports
+import Imm.Mail
import Imm.Types
import Imm.Util
@@ -9,18 +10,19 @@ import Config.Dyre.Paths
import Data.Foldable
import Data.Maybe
+import qualified Data.String.UTF8 as U
import Data.Time.Clock
import Data.Time.Clock.POSIX
import Data.Time.Format
import Network.BSD
import Network.HTTP hiding(Response)
-import Network.Mail.Mime
import Network.URI
import System.Console.CmdArgs
import System.Directory
import System.IO
+import qualified System.IO.UTF8 as U
import System.IO.Error
import System.Locale
import System.Random
@@ -177,6 +179,7 @@ getUniqueName = do
processItem :: Parameters -> Maybe UTCTime -> Item -> IO (Maybe UTCTime)
processItem parameters@Parameters{ mMailBox = directory } threshold item = do
+ putStrLn $ " Item author: " ++ (maybe "" id $ getItemAuthor item)
putStrLn $ " Item title: " ++ (maybe "" id $ getItemTitle item)
putStrLn $ " Item URI: " ++ (maybe "" id $ getItemLink item)
@@ -197,18 +200,18 @@ processItem parameters@Parameters{ mMailBox = directory } threshold item = do
addItemToMailDir :: FilePath -> Item -> IO ()
-addItemToMailDir filePath item = withFile filePath WriteMode $ \handle -> do
- hPutStrLn handle "Return-Path: <noreply@anonymous.net>"
- hPutStrLn handle $ "Date: " ++ (maybe "" id $ getItemDate item)
- hPutStrLn handle $ "From: " ++ (maybe "Anonymous" id $ getItemAuthor item)
- hPutStrLn handle $ "Subject: " ++ (maybe "Untitled" id $ getItemTitle item)
- hPutStrLn handle $ "Content-Type: text/plain; charset=utf-8"
- hPutStrLn handle $ "Content-Disposition: inline"
- hPutStrLn handle $ ""
- hPutStrLn handle $ ""
- hPutStrLn handle $ (maybe "Empty" id $ getItemDescription item)
-
-
+addItemToMailDir filePath item = U.writeFile filePath $ show (itemToMail item)
+
+itemToMail :: Item -> Mail
+itemToMail item = defaultMail {
+ mReturnPath = "<noreply@anonymous.net>",
+ mDate = stringToUTC $ (maybe "" id $ getItemDate item),
+ mFrom = maybe "Anonymous" id $ getItemAuthor item,
+ mSubject = maybe "Untitled" id $ getItemTitle item,
+ mCharset = "utf-8",
+ mContentDisposition = "inline",
+ mContent = maybe "Empty" id $ getItemDescription item
+}
stringToUTC :: String -> Maybe UTCTime
View
@@ -0,0 +1,24 @@
+module Imm.Mail where
+
+import Imm.Types
+
+import Data.Time.LocalTime
+
+
+instance Show Mail where
+ show mail = unlines [
+ "Return-Path: " ++ mReturnPath mail,
+ "Date: " ++ (maybe "" show (mDate mail)),
+ "From: " ++ mFrom mail,
+ "Subject: " ++ mSubject mail,
+ "Content-Type: " ++ mMIME mail ++ "; charset=" ++ mCharset mail,
+ "Content-Disposition: " ++ mContentDisposition mail,
+ "",
+ mContent mail
+ ]
+
+
+defaultMail :: Mail
+defaultMail = Mail {
+ mMIME = "text/html"
+}
View
@@ -4,6 +4,8 @@ module Imm.Types where
-- {{{ Imports
import Network.URI
+import Data.Time.Clock
+
import System.Console.CmdArgs
import Text.Feed.Types
@@ -27,4 +29,15 @@ data Parameters = Parameters {
data ImmFeed = ImmFeed {
mURI :: URI,
mFeed :: Feed
+}
+
+data Mail = Mail {
+ mReturnPath :: String,
+ mDate :: Maybe UTCTime,
+ mFrom :: String,
+ mSubject :: String,
+ mMIME :: String,
+ mCharset :: String,
+ mContentDisposition :: String,
+ mContent :: String
}
View
@@ -44,10 +44,10 @@ Cabal-version: >=1.8
Library
-- Modules exported by the library.
- Exposed-modules: Imm.Core, Imm.Types, Imm.Util
+ Exposed-modules: Imm.Core, Imm.Types, Imm.Util, Imm.Mail
-- Packages needed in order to build this package.
- Build-depends: base == 4.*, directory, dyre, time, HTTP, xml, feed, old-locale, random, bytestring, mime-mail, text, cmdargs, network, pureMD5
+ Build-depends: base == 4.*, directory, dyre, time, HTTP, xml, feed, old-locale, random, bytestring, mime-mail, text, cmdargs, network, pureMD5, utf8-string
-- Modules not exported by this package.
-- Other-modules:

0 comments on commit ff65e75

Please sign in to comment.