Mac OS X 10.5: Broken Spotlight indexing for mail messages caused by presence of older Mail applicationPosted by Pierre Igot in: Mail
March 28th, 2008 • 5:21 pm
I first wrote a post about a problem I had with broken Spotlight searches in Mac OS X 10.5′s Mail application.
I then wrote a post about the feedback I had received from Apple on this problem and how it had enabled me to fix the problem on my machine. In that post, I indicated that, based on Apple’s feedback and on the resolution, the cause of the problem on my machine was probably the presence of an older version of Mac OS X’s Mail application on one of my other (non-startup) partitions.
I have since received more feedback from Betalogue readers by e-mail, including the following message, which provides a pretty clear and convincing explanation of the problem. Since this reader sent it to me privately and agreed to let me share it with Betalogue readers, I thought I would post it here in order to further clarify the problem’s cause and solution:
Launch Services maintains a list of file metadata and applications, to map files to concrete types and the applications that can handle them. It has a fairly decent mechanism for preferring specific applications for specific metadata (file extension, HFS type and creator codes, etc), using hints from the user if necessary (e.g. via Finder’s Get Info -> Open With). Unfortunately it’s not as robust about mapping metadata to concrete types, when more than one application is known to handle a specific set of metadata.
The Launch Services database is built by scanning standard locations (/Applications etc) on startup and login, and Finder registers applications on demand as it discovers them in new locations (e.g. when you mount a network drive, disk image, or browse to a folder containing an application bundle).
Spotlight uses Launch Services to find the concrete type for each file and folder it walks, and then maps that type to a registered Metadata Importer. If it encounters something there is no Importer for, that item is skipped.
In pre-Tiger versions of Mail.app, messages in a given mailbox were stored in single-file database format, contained in bundles using the file extension .mbox. The type of that bundle, “mbox”, was defined by Mail.app when Launch Services scanned it.
Tiger introduced a new mechanism within Launch Services for declaring concrete file types, in an effort to make things work better.
In Tiger and onward, the message storage format used by Mail.app was changed to use individual files, so that Spotlight could index them easily. The .mbox extension was given a new type (“com.apple.mail.box”) by Mail.app using the Tiger+ mechanism, with standard folder behavior instead of being an opaque bundle, and individual messages are stored as files in a Messages folder within it.
When I upgraded, the old /Applications folder was stored under /Previous Systems, and naturally I have been visiting there often while I collect all my previous applications, check for new versions, etc. Whenever I open it, Finder realizes it contains applications, and promptly registers them all with Launch Services. Including the old Mail.app, which maps the .mbox extension to type “mbox”.
This is where the unfortunate (and possibly “just plain stupid”) part of Launch Services comes in: the old way the Panther Mail.app mapped the extension .mbox is actually prioritized above the new way the Leopard Mail.app maps it. When Spotlight’s scanner gets a notice that a file changed, it walks each folder in the path to it, asking for the type of each. When it gets to a .mbox bundle, Launch Services tells it “mbox” instead of “com.apple.mail.mbox” like it should have. Spotlight has no Metadata Importer for “mbox”, and this type is not declared as behaving like a folder, so it stops without going inside it to find the actual messages.
This problem also shows up in Finder by having the .mbox things in ~/Library/Mail/Messages look like files with “house-front mail box” icons, instead of as folders with “office mail tray” icons.
Resetting the Launch Services database lets Spotlight properly import my Mail directory now, but whenever I browse to the old Applications folder, it will stop indexing any changes (like new email).
I’m still not done retrieving my old applications, but when I am, I plan to fix this problem by deleting all the old apps, reset the Launch Services database, and have Spotlight reindex the entire drive. Then it should have correct metadata for everything, and properly keep up when I get new Mail messages.
I’ve yet to find a way to fix Launch Services’ priorities, or have Finder stop telling it about those apps.
Hopefully something in this description will help you too. And hopefully I’ll get enough time to navigate my way around Apple’s bug reporting site to make sure they’re aware of the problem. I know people have filed bugs on these things individually, but I don’t know if anyone else has put it all together…