The following scenario occurs regularly on several of my e-mail accounts (all IMAP accounts):

  • I receive a valid e-mail, but it is marked as spam and shows up in my Junk folder (though not usually actually marked as spam)
  • I click “Move to Inbox” to move it out into my inbox since it’s not spam
  • The e-mail shows up in my inbox, but then within a minute or two vanishes, sometimes before my very eyes, while I’m actually reading it

If I log on using a webmail system which shows items marked for deletion using strikethrough, I can see the missing e-mail, so it appears that Mail, for some reason, is flagging it for deletion, but without actually moving it to the Bin folder where delete-flagged items would normally be.

Unfortunately, the webmail systems I have access to don’t seem to offer any way to add or remove IMAP delete flags, and I can’t find any way to do so in Apple Mail either.

On a few of the accounts, I have access to the MailEnable Administration, but while I can see the message (as a .mai file) in the user’s inbox there, I can’t figure out how to see or edit IMAP flags on messages, aside from editing the raw XML index file (which is risky, since it may lead to corruption if an e-mail arrives while the file is being edited). And it also happens with other accounts that I have no admin access to, anyway.

Short of nuke-style approaches like rebuilding/reinstalling entire mailboxes, is there some way to retrieve items that Mail flags for deletion without moving?

(This has been happening regularly for years, across several Macs (Intel Mac mini, M1 MacBook Pro, M1 Mac Studio) running at least macOS Catalina/10.15 to Ventura/13.3.)

  • Without knowing the system it's hard to say, but "Move to Inbox" does not, in itself, remove the spam flag. You should do that first.
    – Tetsujin
    Commented Apr 15, 2022 at 18:01
  • @Tetsujin Oops, forgot system info; edited. Most of the time, e-mails that appear in the Junk folder don’t appear to actually be marked as spam – at least, the “Not Spam” button doesn’t appear. I don’t recall whether that’s usually the case for the disappearing e-mails, but I just had it happen a moment ago, and I’m fairly sure there was no “Not Spam” button on that one. Commented Apr 15, 2022 at 18:05
  • I just had this happen to me and in my case I don't have a webmail system to find the messages in. Curious if anyone has found a solution for this or a way to retrieve the messages. Thanks. Commented May 17, 2022 at 4:38
  • @JonSteinmetz I finally managed to find a (somewhat cumbersome but working) way to retrieve these mysteriously delete-marked e-mails. See my answer below. Commented May 2, 2023 at 14:21

1 Answer 1


I finally managed to find a solution for this. Not an ideal one, but a solution nonetheless. This is based on this SuperUser answer and some subsequent digging.

It uses imapfilter, which is a CLI package that allows you to communicate with IMAP servers in a more flexible way than e-mail clients allow. The package is written in Lua, which is completely foreign territory to me, but luckily, it is also supported by Homebrew, so I used that to install it. I got it to work this way:

Install imapfilter

(This assumes that you don’t know how to install a Lua package directly, but that you do have Homebrew installed.)

Open a terminal window and type:

brew install imapfilter

Once it’s installed, run it by typing imapfilter in the terminal window. That should create a hidden folder called .imapfilter in your home directory (~/.imapfilter, that is, /Users/yourname/.imapfilter).

Make a config file

The config file for imapfilter is really more of an instruction file than a config file. It sets up some general configurations (timeout, etc.), defines the IMAP account you want to connect to, and then defines the actual actions you want to perform once you’re connected to the account.

The default location for the config file is at ~/.imapfilter/config.lua, so create that file and copy-paste the following into it:

--  Options  --

options.timeout = 120
options.subscribe = true

--  Accounts  --

-- Connects to "imap1.mail.server", as user "user1" with "secret1" as
-- password.
account = IMAP {
    server = 'mail.example.com',
    username = '[email protected]',
    password = 'Password123',
    port = 993,
    ssl = 'ssl3',

--  Actions   --

msgs = account.INBOX:is_deleted()

Make sure to switch the values in the account section out for the appropriate values for your e-mail account. The port and ssl keys are optional; if you connect to your server without SSL, just delete that key. If you delete the port key, it uses the default, which is 143 without SSL and 993 for IMAP with SSL.

The actions section first selects all messages that are located in your account’s inbox and are marked as deleted; then it removes the \Deleted mark.

Here is an-depth description of the config file’s structure, if you need more flexibility.

Run the program

Save your config file, go back to your terminal window and type:


If everything worked as expected, you should get a message like this:

X messages unmarked deleted in [email protected]@imap.example.com/INBOX.

Note that this is a one-off, so you will have to open a terminal window and run the program again every time an e-mail gets mysteriously delete-marked.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .