module Main (main) where import System(getArgs) server = "news.studfb.unibw-muenchen.de" port = "119" prefix = "#!/usr/local/bin/expect\n"++ "spawn /usr/bin/telnet "++server++' ':port++"\n"++ "expect 200\n"++ "send \"POST\\r\"\n"++ "expect 340\n" postfix = "\n"++ "send \"\\r\"\n"++ "send \".\\r\"\n"++ "expect 240\n"++ "send \"q\\r\"\n" main = getArgs >>= runMain runMain :: [String] -> IO () runMain args = do let source = args!!0 let destination = source++".sh" c<-readFile source let text = prefix ++ (unlines.walkThrough.lines $ c) ++ postfix writeFile destination text walkThrough::[String]->[String] walkThrough [] = [] walkThrough (x:xs) | x=="" = map (\x->"send \""++tagSpecialChars x++"\\r\"") (x:xs) | startsWith x "From:" || startsWith x "Newsgroups:" || startsWith x "Subject:" = ("send \""++handle x++"\\r\""):walkThrough xs | otherwise = walkThrough xs --omit other headers startsWith x [] = True startsWith (x:xs) (y:ys) | x == y = startsWith xs ys | otherwise = False --unfortunately there are some problems with signatures, they are not accepted --will look at the protocol spec later tagSpecialChars ('-':'-':xs) = [] --a point represents end of message -> must not occur in the message tagSpecialChars (".") = ("..") tagSpecialChars xs = handle xs --probably some special cases are still missing --tag brackets handle [] = [] handle ('[':xs) = "\\["++handle xs handle (']':xs) = "\\]"++handle xs handle ('\"':xs) = "\\\""++handle xs handle (x:xs) = x:handle xs