Skip to content

Instantly share code, notes, and snippets.

@soeren
Created December 6, 2009 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soeren/250367 to your computer and use it in GitHub Desktop.
Save soeren/250367 to your computer and use it in GitHub Desktop.
-- 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