I am planning a Haskell project and I need to access files. Since the program will be automatically started whenever a mail comes in I will need to be able to lock the access to files. Is there any support for this in some library?
Yes, the Posix library distributed with GHC has support for file locking. See http://www.haskell.org/ghc/docs/latest/html/hslibs/sec-posix.html This library is currently undergoing a rewrite - the functionality will be available under System.Posix in future releases of GHC (and possibly Hugs & NHC).
The second option that I have is to use a daemon and let the programs that get started by mail connect via some sort of socket. Is there any socket support in Haskell?
Yes: http://www.haskell.org/ghc/docs/latest/html/network/index.html (currently only available with GHC). Cheers, Simon