Deleting messages in IMAP accounts
From MozillaZine Knowledge Base
It is perfectly appropriate for a deleted message in a IMAP account to be visible in webmail or other email clients. Deleting a message just sets a flag, and it's up to the GUI what it should do when there is a message with that flag set. However, once Thunderbird compacts (expunges) that folder, the deleted message shouldn't be visible any more from webmail or any email client because it has been physically deleted.
IMAP accounts provide several options to delete messages that aren't available in POP accounts. Tools -> Account Settings -> Server Settings -> "When I delete a message" has choices for "Move it to the Trash folder", "Mark it as deleted" and "Remove it immediately".
Move it to the Trash folder
"Move it to the Trash folder" is very similar to deleting a message in a POP account. The main difference is that if you set mail.imap.expunge_after_delete to true using the Config editor Thunderbird will compact the folder after it successfully copies the message to the trash folder.  The same thing occurs if you move a message to another folder since moving a message deletes a message and then copies it.
Shift+Delete deletes the message without copying it to the trash folder, and is also supposed to compact the folder (if you have that preference set). However, some users report that Shift+Delete doesn't always compact the folder. 
If you want Thunderbird to ask for confirmation when emptying a trash folder, set mail.imap.confirm_emptyTrashFolderDeletion to true.
Remove it immediately
"Remove it immediately" doesn't actually remove the message despite its name. It just hides it from view and flags the message as deleted. That appears to be because Thunderbird doesn't support the optional UID Expunge command, which requires the server to support the optional UIDPLUS capability. It will be physically deleted when you compact the folder.
Mark it as deleted
The main difference between "Mark it as deleted" and "Remove it immediately" is that it doesn't hide the message, and disables automatic expunging of the account (if its enabled) . It draws a line through the message in the folder listing. You can undelete the message by deleting the message again.
Tools -> Account Settings -> Server Settings -> Clean up ("Expunge") Inbox on Exit will compact the Inbox folder when you exit Thunderbird. If you check "Empty Trash on Exit" it will also empty and compact the Trash folder when you exit.
Some IMAP email providers (such as Yahoo ) periodically remove any messages in your Trash folder, and don't let you control when this happens.