Created
December 6, 2009 19:36
-
-
Save soeren/250367 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Haskell GMail Count | |
-- soeren openfoo.org | |
import System.Directory | |
import System.FilePath | |
import Network.Curl | |
import qualified Text.Feed.Import as F | |
import qualified Text.Feed.Types as T | |
import qualified Text.XML.Light as X | |
-- Config file with username:password in home directory | |
conf = ".hgmc.conf" | |
-- Google Apps: set your domain | |
url = "https://mail.google.com/a/yourdomain.com/feed/atom" | |
-- GMail | |
--url = "https://mail.google.com/mail/feed/atom" | |
newMsgs (T.XMLFeed e) = case count of | |
Nothing -> error "no message counter found" | |
Just e' -> if null c | |
then error "no fullcount content" | |
else X.showContent $ head c | |
where | |
c = X.elContent e' | |
where | |
count = X.findElement fullcount e | |
fullcount = X.QName "fullcount" (Just "http://purl.org/atom/ns#") Nothing | |
newMsgs _ = error "wrong feed type" | |
main = withCurlDo $ do { | |
home <- getHomeDirectory; | |
userpw <- readFile $ combine home conf; | |
(c, b) <- curlGetString url [CurlUserPwd userpw]; | |
if c /= CurlOK then | |
do error ("http error: " ++ show c) | |
else | |
do case F.parseFeedString b of | |
Nothing -> error "unable to parse feed" | |
Just b' -> putStrLn $ newMsgs b' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment