There are a few tricks to getting IMAP on Apple Mail to behave correctly with Gmail. Rather than me spelling this information out, here’s a link to just one of the many articles which explain the steps:

http://bit.ly/jKfSgH