Compare commits

...

6 Commits

Author SHA1 Message Date
925cee9839
Päivitä channels.scm 2023-09-02 14:43:28 +03:00
6ff0765cfb
Korjaa updateListBy 2023-09-02 14:42:22 +03:00
5862f87add
Lisää komento palvelimen tilan tulostamiseen 2023-09-02 14:42:22 +03:00
a1fb59a5ad
Siisti koodia 2023-09-02 14:41:47 +03:00
2e526fe122
Vastaa webhook-ilmoituksiin välittömästi
Tämä korjaa ongelman, jossa gitean webhookin http-kysely ehtii vanhentua
ennen kuin siihen on vastattu. Ilmoituksia lähettävän järjestelmän ei
myöskään tarvitse tietää kauanko ilmoitusten prosessointi kestää.
2023-09-02 13:36:42 +03:00
f708ef1348
Siirrä HTML-versio sähköpostissa viimeiseksi
Jotkin huonot sähköpostiohjelmat (ainakin Applen) eivät osaa valita sitä
vaihtoehtoa, jonka ne osaisivat näyttää, vaan käyttävät sokeasti
viimeistä vaihtoehtoa. Huonot sähköpostiohjelmat osaavat myös
todennäköisemmin näyttää HTML-version järkevästi kuin raakatekstin tai
markdownin.
2023-09-02 13:35:08 +03:00
6 changed files with 26 additions and 7 deletions

View File

@ -3,7 +3,7 @@
(url "https://git.savannah.gnu.org/git/guix.git") (url "https://git.savannah.gnu.org/git/guix.git")
(branch "master") (branch "master")
(commit (commit
"4547bc6fa3142dca77f7fc912368aeff31bd6e53") "7309da3ba64a191f074807275d8c5661a25c035c")
(introduction (introduction
(make-channel-introduction (make-channel-introduction
"9edb3f66fd807b096b48283debdcddccfea34bad" "9edb3f66fd807b096b48283debdcddccfea34bad"

View File

@ -7,6 +7,7 @@ module Main where
import Control.Concurrent (forkIO) import Control.Concurrent (forkIO)
import Control.Exception (onException) import Control.Exception (onException)
import Control.Exception (throwIO) import Control.Exception (throwIO)
import Control.Monad (void)
import Data.Acid (openLocalState) import Data.Acid (openLocalState)
import Data.Acid.Remote (skipAuthenticationCheck, acidServerSockAddr, openRemoteStateSockAddr, skipAuthenticationPerform) import Data.Acid.Remote (skipAuthenticationCheck, acidServerSockAddr, openRemoteStateSockAddr, skipAuthenticationPerform)
import Data.IMF (Mailbox, parse, mailbox) import Data.IMF (Mailbox, parse, mailbox)
@ -21,7 +22,6 @@ import System.Exit.Codes (codeTempFail)
import System.Posix.User (getRealUserID, userName, getUserEntryForID) import System.Posix.User (getRealUserID, userName, getUserEntryForID)
import Web.Scotty (scotty, post, liftAndCatchIO, defaultHandler) import Web.Scotty (scotty, post, liftAndCatchIO, defaultHandler)
import qualified Data.Text as T import qualified Data.Text as T
import qualified Data.Text.Lazy.IO as LT import qualified Data.Text.Lazy.IO as LT
@ -30,6 +30,7 @@ import TiedoteMD.Review
import TiedoteMD.Send import TiedoteMD.Send
import TiedoteMD.State import TiedoteMD.State
import TiedoteMD.Types import TiedoteMD.Types
import TiedoteMD.Debug
serverMain :: SockAddr -> Mailbox -> FilePath -> FilePath -> IO () serverMain :: SockAddr -> Mailbox -> FilePath -> FilePath -> IO ()
serverMain socket mail repoPath sendmailPath = do serverMain socket mail repoPath sendmailPath = do
@ -38,7 +39,7 @@ serverMain socket mail repoPath sendmailPath = do
queueMessages acid queueMessages acid
_ <- forkIO $ scotty 3000 $ do _ <- forkIO $ scotty 3000 $ do
defaultHandler $ liftAndCatchIO . LT.putStrLn -- Don't return exceptions to clients defaultHandler $ liftAndCatchIO . LT.putStrLn -- Don't return exceptions to clients
post "/" $ liftAndCatchIO $ updateMessages acid repoPath post "/" $ liftAndCatchIO $ void $ forkIO $ updateMessages acid repoPath
updateMessages acid repoPath updateMessages acid repoPath
_ <- forkIO $ manageQueueingMessages acid _ <- forkIO $ manageQueueingMessages acid
_ <- forkIO $ managePreviews acid mail sendmailPath _ <- forkIO $ managePreviews acid mail sendmailPath
@ -50,8 +51,15 @@ clientMain socket mail sendmailPath = do
`onException` exitWith codeTempFail `onException` exitWith codeTempFail
manageIncomingEmail acid mail sendmailPath manageIncomingEmail acid mail sendmailPath
printStateMain :: SockAddr -> IO ()
printStateMain socket = do
acid <- openRemoteStateSockAddr skipAuthenticationPerform socket
`onException` openLocalState emptyState
`onException` exitWith codeTempFail
printState acid
data Config = Config { socketPath :: FilePath, mail :: Mailbox, sendmailCommand :: String, runMode :: RunMode } deriving Show data Config = Config { socketPath :: FilePath, mail :: Mailbox, sendmailCommand :: String, runMode :: RunMode } deriving Show
data RunMode = Server { repoPath :: FilePath } | Recieve deriving Show data RunMode = Server { repoPath :: FilePath } | Recieve | Print deriving Show
config :: Maybe Mailbox -> Parser Config config :: Maybe Mailbox -> Parser Config
config mail = Config config mail = Config
@ -59,7 +67,8 @@ config mail = Config
<*> option readMailbox (long "address" <> short 'a' <> metavar "EMAIL" <> maybe mempty value mail <> help "Email address to send and recieve mail") <*> option readMailbox (long "address" <> short 'a' <> metavar "EMAIL" <> maybe mempty value mail <> help "Email address to send and recieve mail")
<*> strOption (long "sendmail" <> short 'm' <> metavar "FILE" <> value "sendmail" <> help "Sendmail command") <*> strOption (long "sendmail" <> short 'm' <> metavar "FILE" <> value "sendmail" <> help "Sendmail command")
<*> hsubparser (command "server" (info serverCommand (progDesc "Run the server")) <*> hsubparser (command "server" (info serverCommand (progDesc "Run the server"))
<> command "recieve" (info (pure Recieve) (progDesc "Recieve an email"))) <> command "recieve" (info (pure Recieve) (progDesc "Recieve an email"))
<> command "state" (info (pure Print) (progDesc "Print the server's current state")))
serverCommand :: Parser RunMode serverCommand :: Parser RunMode
serverCommand = Server <$> strOption (long "repository" <> short 'r' <> metavar "DIRECTORY" <> value "/var/lib/tiedote.md/git-repo" <> showDefault <> help "Path to git repository") serverCommand = Server <$> strOption (long "repository" <> short 'r' <> metavar "DIRECTORY" <> value "/var/lib/tiedote.md/git-repo" <> showDefault <> help "Path to git repository")
@ -78,4 +87,5 @@ main = do
findExecutable (sendmailCommand args) findExecutable (sendmailCommand args)
case args of case args of
Config {runMode = Recieve, ..} -> clientMain (SockAddrUnix socketPath) mail sendmailPath Config {runMode = Recieve, ..} -> clientMain (SockAddrUnix socketPath) mail sendmailPath
Config {runMode = Print, ..} -> printStateMain (SockAddrUnix socketPath)
Config {runMode = Server {..}, ..} -> serverMain (SockAddrUnix socketPath) mail repoPath sendmailPath Config {runMode = Server {..}, ..} -> serverMain (SockAddrUnix socketPath) mail repoPath sendmailPath

8
src/TiedoteMD/Debug.hs Normal file
View File

@ -0,0 +1,8 @@
module TiedoteMD.Debug where
import Data.Acid (AcidState, query)
import TiedoteMD.State
printState :: AcidState State -> IO ()
printState acid = query acid GetState >>= print

View File

@ -70,8 +70,8 @@ renderMessage' subjectPrefix maybeMailID (Message {messageContent = MessageConte
set (headerFrom defaultCharsets) [Single sender] $ set (headerFrom defaultCharsets) [Single sender] $
IMF.Message (Headers []) $ Multipart Alternative boundary $ NE.fromList IMF.Message (Headers []) $ Multipart Alternative boundary $ NE.fromList
[ createTextPlainMessage plainTextMessage [ createTextPlainMessage plainTextMessage
, createTextHtmlMessage htmlMessage
, createTextMarkdownMessage markdownMessage , createTextMarkdownMessage markdownMessage
, createTextHtmlMessage htmlMessage
] ]
createTextMarkdownMessage :: T.Text -> MIMEMessage createTextMarkdownMessage :: T.Text -> MIMEMessage

View File

@ -35,7 +35,7 @@ emptyState = State
updateListBy :: (a -> a -> Bool) -> [a] -> [a] -> [a] updateListBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
updateListBy f old new = olds <> news updateListBy f old new = olds <> news
where news = differenceBy f new old where news = differenceBy f new old
olds = intersectBy f old news olds = intersectBy f old new
elemBy :: (a -> b -> Bool) -> a -> [b] -> Bool elemBy :: (a -> b -> Bool) -> a -> [b] -> Bool
elemBy = (.) any elemBy = (.) any

View File

@ -55,6 +55,7 @@ executable tiedote.md
utf8-string utf8-string
main-is: Main.hs main-is: Main.hs
other-modules: other-modules:
TiedoteMD.Debug
TiedoteMD.Git TiedoteMD.Git
TiedoteMD.Read TiedoteMD.Read
TiedoteMD.Review TiedoteMD.Review