summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ParseMail.hs6
-rw-r--r--nix/mime-mail.nix4
-rw-r--r--test5.hs28
3 files changed, 30 insertions, 8 deletions
diff --git a/ParseMail.hs b/ParseMail.hs
index 7ce0674..c4db5fd 100644
--- a/ParseMail.hs
+++ b/ParseMail.hs
@@ -29,9 +29,9 @@ data Address = Mailbox M.Address | Group T.Text [M.Address]
-readMail :: FilePath -> IO M.Mail
-readMail p =
- fromMIMEValue . parseMIMEMessage <$> T.readFile p
+readMail :: T.Text -> M.Mail
+readMail =
+ fromMIMEValue . parseMIMEMessage
fromMIMEValue :: MIMEValue -> M.Mail
diff --git a/nix/mime-mail.nix b/nix/mime-mail.nix
index e855038..699a1b6 100644
--- a/nix/mime-mail.nix
+++ b/nix/mime-mail.nix
@@ -7,8 +7,8 @@ mkDerivation {
version = "0.4.6.2";
src = fetchgit {
url = "https://github.com/4z3/mime-mail";
- sha256 = "fa2ecb7ca0f71513a8f4dde897ff910d94a205c4a81c6b5e107e4712438b0446";
- rev = "3d0f060fb4c58b69c72ce3b4911bff32df7329a7";
+ sha256 = "00xlibw1rdaj71y1r7qhb8ypw5prbzyz4z3rynmv9gbxrp1kz0hw";
+ rev = "be4ec1958dac85bde01ae3433cb387810585c5fd";
};
buildDepends = [
base base64-bytestring blaze-builder bytestring filepath process
diff --git a/test5.hs b/test5.hs
index 76e8ec6..1709be5 100644
--- a/test5.hs
+++ b/test5.hs
@@ -9,6 +9,7 @@ import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Tree as Tree
import qualified Data.Tree.Zipper as Z
+import qualified Network.Mail.Mime as M
import qualified Notmuch
import qualified Notmuch.Message as Notmuch
import qualified Notmuch.SearchResult as Notmuch
@@ -22,6 +23,7 @@ import Data.Maybe
import Data.Monoid
import Data.Time
import Event
+import ParseMail (readMail)
import RenderTreeView (renderTreeView)
import Scanner (scan)
import System.Directory
@@ -29,6 +31,7 @@ import System.Console.Docopt (getArgWithDefault, optionsWithUsage, shortOption)
import System.Environment
import System.Exit
import System.IO
+import System.Locale (defaultTimeLocale, rfc822DateFormat)
import System.Posix.Files
import System.Posix.Signals
import System.Process
@@ -493,7 +496,13 @@ replyToAll q@State{..} = case getMessage (Z.label cursor) of
ExitFailure code ->
return q { flashMessage = Plain $ "editor exit code = " ++ show code }
ExitSuccess -> do
- x <- LBS.readFile path
+ -- TODO check if path has been written to,
+ -- else abort
+ draft <-
+ M.renderMail' =<<
+ addDateHeader =<<
+ return . readMail =<<
+ T.readFile path
-- TODO use TagOps
Notmuch.notmuchWithInput
[ "insert"
@@ -503,8 +512,7 @@ replyToAll q@State{..} = case getMessage (Z.label cursor) of
, "-inbox"
, "-unread"
]
- -- TODO rename to draftPath
- x >>= \case
+ draft >>= \case
(ExitFailure code, _, _) ->
return q { flashMessage =
Plain $ "notmuch insert exit code = " ++ show code
@@ -660,3 +668,17 @@ withTempFile' s f = do
logname <- getEnv "LOGNAME"
tmpdir <- getTemporaryDirectory
withTempFile tmpdir (logname ++ "_much_" ++ s) f
+
+
+addDateHeader m@M.Mail{..} = do
+ t <- getCurrentTime
+ return m
+ { M.mailHeaders =
+ ( "Date"
+ , T.pack $
+ formatTime defaultTimeLocale
+ rfc822DateFormat
+ t
+ ) :
+ mailHeaders
+ }