diff --git a/src/Config/Main.hs b/src/Config/Main.hs index 84b1396b..89ddc6bb 100644 --- a/src/Config/Main.hs +++ b/src/Config/Main.hs @@ -30,7 +30,6 @@ import Control.Monad.Except (runExceptT) import System.Environment (lookupEnv) import System.Directory (getHomeDirectory) import Data.Maybe (fromMaybe) -import Data.List.NonEmpty (fromList) import System.Exit (ExitCode(..)) import Control.Lens (set) @@ -290,9 +289,11 @@ defaultConfig = , _mvToKeybindings = mailviewComposeToKeybindings , _mvMailcap = [ ( matchContentType "text" (Just "html") - , MailcapHandler (Shell (fromList "elinks -force-html")) CopiousOutput DiscardTempfile) + , MailcapHandler (\fp -> proc "elinks" ["-force-html", fp]) CopiousOutput DiscardTempfile) + , ( matchContentType "application" (Just "pdf") + , MailcapHandler (\fp -> proc "pdftotext" [fp, "-"]) CopiousOutput DiscardTempfile) , ( const True - , MailcapHandler (Process (fromList "xdg-open") []) IgnoreOutput KeepTempfile) + , MailcapHandler (\fp -> proc "xdg-open" [fp]) IgnoreOutput KeepTempfile) ] } , _confIndexView = IndexViewSettings diff --git a/src/Purebred/System/Process.hs b/src/Purebred/System/Process.hs index ae2d0ae8..2764f3d6 100644 --- a/src/Purebred/System/Process.hs +++ b/src/Purebred/System/Process.hs @@ -26,7 +26,6 @@ module Purebred.System.Process , tmpfileResource , draftFileResoure , emptyResource - , toProcessConfigWithTempfile , runEntityCommand , createDraftFilePath , createSentFilePath @@ -54,7 +53,6 @@ import System.Directory (removeFile, createDirectoryIfMissing) import qualified Data.ByteString.Lazy as LB import qualified Data.ByteString as B import Data.Char (isControl, isSpace) -import Data.Foldable (toList) import Data.List (intercalate) import Data.Time.Clock (getCurrentTime) import Data.Time.Format (formatTime, defaultTimeLocale) @@ -166,10 +164,6 @@ draftFileResoure maildir = (tryIO . removeFile) (\fp -> tryIO . B.writeFile fp) -toProcessConfigWithTempfile :: MakeProcess -> FilePath -> ProcessConfig () () () -toProcessConfigWithTempfile (Shell cmd) fp = shell (toList cmd <> " " <> fp) -toProcessConfigWithTempfile (Process cmd args) fp = proc (toList cmd) (args <> [fp]) - -- | Generates a Maildir filename -- see https://cr.yp.to/proto/maildir.html maildirMessageFileTemplate :: MonadIO m => m FilePath diff --git a/src/Storage/ParsedMail.hs b/src/Storage/ParsedMail.hs index 3186ffd8..24b498da 100644 --- a/src/Storage/ParsedMail.hs +++ b/src/Storage/ParsedMail.hs @@ -51,7 +51,6 @@ import Data.Text.Lens (packed) import Control.Monad.Except (MonadError, throwError) import Control.Monad.IO.Class (MonadIO, liftIO) import Control.Monad.Catch (MonadMask) -import Data.Foldable (toList) import qualified Data.ByteString as B import qualified Data.CaseInsensitive as CI import qualified Data.Text as T @@ -67,7 +66,7 @@ import Purebred.System (tryIO) import Purebred.Types.IFC (sanitiseText) import Purebred.Parsing.Text (parseMailbody) import Purebred.System.Process - (runEntityCommand, tmpfileResource, toProcessConfigWithTempfile, + (runEntityCommand, tmpfileResource, tryReadProcessStdout, handleExitCodeThrow) {- $synopsis @@ -160,10 +159,11 @@ bodyToDisplay s textwidth charsets prefCT msg = maybe (pure $ parseMailbody textwidth "Internal Viewer" $ entityToText charsets entity) (\handler -> - parseMailbody textwidth (showHandler handler) <$> + parseMailbody textwidth (showCommand handler) <$> entityPiped handler entity) (findAutoview s entity) - showHandler = view (mhMakeProcess . mpCommand . to (T.pack . toList)) + showCommand :: MailcapHandler -> T.Text + showCommand h = T.pack $ show $ view mhMakeProcess h mempty in (msg, ) <$> output @@ -233,7 +233,7 @@ mkConfig cmd = EntityCommand handleExitCodeThrow (tmpfileResource (view mhKeepTemp cmd)) - (\_ fp -> toProcessConfigWithTempfile (view mhMakeProcess cmd) fp) + (\_ fp -> view mhMakeProcess cmd fp) tryReadProcessStdout quoteText :: T.Text -> T.Text diff --git a/src/Types.hs b/src/Types.hs index 199daf56..dee7d1e8 100644 --- a/src/Types.hs +++ b/src/Types.hs @@ -1132,7 +1132,7 @@ data TempfileOnExit deriving (Generic, NFData) data MailcapHandler = MailcapHandler - { _mhMakeProcess :: MakeProcess + { _mhMakeProcess :: FilePath -> ProcessConfig () () () , _mhCopiousoutput :: CopiousOutput -- ^ output should be paged or made scrollable , _mhKeepTemp :: TempfileOnExit @@ -1140,7 +1140,7 @@ data MailcapHandler = MailcapHandler -- exits immediately (e.g. Firefox) } deriving (Generic, NFData) -mhMakeProcess :: Lens' MailcapHandler MakeProcess +mhMakeProcess :: Lens' MailcapHandler (FilePath -> ProcessConfig () () ()) mhMakeProcess = lens _mhMakeProcess (\h x -> h { _mhMakeProcess = x }) mhCopiousoutput :: Lens' MailcapHandler CopiousOutput diff --git a/src/UI/Actions.hs b/src/UI/Actions.hs index 757e8c03..a1be36f6 100644 --- a/src/UI/Actions.hs +++ b/src/UI/Actions.hs @@ -876,8 +876,8 @@ openWithCommand = cmd <- uses (asMailView . mvOpenCommand . E.editContentsL) (T.unpack . currentLine) case cmd of [] -> lift . Brick.continue . setUserMessage (makeWarning StatusBar "Empty command") =<< get - (x:xs) -> stateSuspendAndResume $ - openCommand' (MailcapHandler (Process (x :| xs) []) IgnoreOutput KeepTempfile) + cmd' -> stateSuspendAndResume $ + openCommand' (MailcapHandler (\_ -> proc cmd' []) IgnoreOutput KeepTempfile) } -- | Wrapper for 'Brick.suspendAndResume' that reads state from @@ -1613,7 +1613,7 @@ openCommand' cmd = do let con = EntityCommand handleExitCodeThrow (tmpfileResource (view mhKeepTemp cmd)) - (\_ fp -> toProcessConfigWithTempfile (view mhMakeProcess cmd) fp) + (\_ fp -> view mhMakeProcess cmd fp) tryReadProcessStderr in fmap con . entityToBytes selectedItemHelper (asMailView . mvAttachments) $ \ent ->