Gmail is very special when it comes to IMAP. Gmail uses labels, not folders, and there is simply no one-to-one mapping to IMAP. For example: putting a message in the Trash actually kind of assigns the label "Deleted". When labeled as such, any other label for that same message no longer applies.
Be sure to understand the implications of this. Like if you think you copied a message to some IMAP folder, then actually Gmail will only have assigned an additional label to the very same message. Now, if you've (wrongly) set up Mail to move deleted messages to the Trash, then after "deletion" of either of the two occurrences of that single message, the other is removed as well.
So, if your rules move messages to specific folders on the Gmail server, then beware! When moving to a local folder on your Mac, then deleting from the Gmail server may not harm you.
To get the full picture when using IMAP for Gmail, one should unfortunately at least read all of the following from Google's help:
Finally, see Google Labs Advanced IMAP Controls, which allows you to set When a message is deleted from the last visible IMAP folder: Move the message to the Gmail Trash.
And while we're at the subject of Gmail:
- The Gmail SMTP server automatically moves a copy to your Sent Items. So, when using that server, be sure to set up Mail.app to Use only this server. If you don't, then when Mail falls back to another server, you won't have a copy in your Sent Items.
- If you want to use another Sender address, then see Adding a custom 'From' address; if you don't then Gmail will change it into your gmail.com address. For fine tuning see this week's new feature Send mail from another address without "on behalf of".
- Be sure to create a backup. If messages are somehow deleted form either your computer or Gmail's servers, then after the first IMAP synchronisation they're removed everywhere. When using Time Machine: first activate Mail and then enter Time Machine. This will give you the galaxy and star field with, instead of the default Finder, the Mail interface. Here you can even restore message from accounts you've deleted altogether.
Too bad there's no automatic set up, despite of the fact that Mail knows you're using Gmail, indicated by For support, visit Gmail Help Center in Mail's preferences: