Advertisement

Prevent Spotlight from resurrecting your deleted emails on iPhone

Note: The problem discussed below behaves differently depending on the type of email account being used. Users of POP mail accounts are indeed noticing a problem with deleted email messages appearing in Spotlight search results. Please see this post for updated information.

Our friends over at Engadget have highlighted a Cult of Mac post that, at first glance, appears to have found a bug in Spotlight's caching of email search results on the iPhone. The idea is that after you delete an email from your inbox in the iPhone's Mail.app client, you can still locate and open the e-mail using Spotlight search, if you know the subject of the message.

What's really happening, though, is what Apple might otherwise call "user confusion." When you delete an e-mail message in most mail clients, the message isn't magically deleted, but instead moved to a "trash" or "deleted messages" folder. Being a folder, it is indexed by Mail to provide an unread count, as well as by Spotlight so that you can easily find messages in the folder. When you search for the email, it shows up in Spotlight and opens in Mail because the message still exists in your trash folder.

All right, so what can you do to avoid this? Well, you need to empty the trash folder from your email. With many providers, you can just go to the trash folder, and delete the message from there to permanently remove it. The problem there is that, if you use a service like Gmail, the message doesn't really get deleted when you do this because of the way Gmail translates its labels into folders. Gmail's Trash folder is also set to purge itself after 30 days by default.

Your options? You either have to use the Gmail web interface in Safari, or if you don't mind tweaking your Gmail settings, you can enable the Advanced IMAP Controls Lab and then change your Gmail settings to immediately delete messages instead of using the trash folder. (Note that if you have your "All Mail" label configured to show up in IMAP, you will need to either disable it, or delete the message from that folder on the iPhone as well. See this thread for more information.) Once you've deleted the message, go in to the Trash folder and hit the refresh button to ensure that the message is no longer listed, which will remove it from the local mail cache. This should also clear up Spotlight's index so that the message no longer appears.

By now, you're probably wondering if this is really something to worry about. In my opinion, it really depends on how you manage your email. If you rarely delete messages, or you just delete things that are not of interest to you, they will most likely disappear from your trash folder after a specified time period that is set by your email provider (usually somewhere between 7 and 30 days.) However, if you intentionally delete messages with the idea that the message is unretreivable, then you should probably consider testing this out for yourself to see if it affects you. Again, with many providers, just periodically deleting the contents of the trash folder will do the trick. If you use Gmail, or your company's email services are hosted by Google, then you may need to log in to the web interface periodically to empty the trash, or you can look into the available configuration options, if you feel comfortable doing so.

So in reality, this isn't really a bug as much as it is what I would call "intended, but unexpected behavior." Many people simply forget that the trash folder exists, particularly on the iPhone where you don't always see it sitting off to the left hand side of your inbox. Checking your trash folder for any unintentionally deleted items, and cleaning out the old messages periodically, isn't really a bad habit to get into. With that said, however, I do think that Apple could improve this behavior by implementing some simple changes like adding an "Empty Trash" button to the trash folder, showing the count of all messages in the trash instead of just unread messages (so that it's easier to notice there are messages in there), and having Spotlight either ignore deleted messages like Leopard's Spotlight does, or at least indicate that they were found in the trash.

What are your thoughts on this? Do you consider this to be a bug, or do you think it's just a place that Apple could improve the experience on? Let us know in the comments!

Update: Leander Kahney has posted an update to the original Cult of Mac post that clarifies this issue a bit more. It seems that accounts using POP are configured by default to remove messages after one day or one week, thus causing them to continue to appear in Spotlight search results. Unfortunately, there isn't an option to remove them immediately, however, only after a day, one week, one month, or never. Because of this, Spotlight still sees them in the index, and Mail still contains a cached copy of the message until the time limit configured in the settings is reached.

If you'd like to check out this setting for yourself, go to the Settings app, tap on Mail, Contacts & Calendars, and choose the POP mail account you want to modify. Scroll down and choose Advanced, and the retention settings will be at the top of that page under Deleted Messages. It appears the default for a new account is to retain messages up to one week. So this is still the OS doing what it's configured to do, but there really should be an option to remove messages immediately here. If Apple were to add an option there, and/or remove Spotlight's ability to index deleted messages, the problem would be solved.

Update 2: After further investigation, it appears that some messages deleted on POP accounts do disappear from Spotlight, while others show up long after the message is deleted. I have conducted several tests on this situation, including on different versions of the iPhone OS, and have posted an update with details.