Previously posted on on March 25, 2010

The idea for having an encrypted drive is to secure information. What information is more important that email? Really, I don’t think much other information is quite as personal and important. So, with that I guess I’ve given away the reason I started looking at encryption for drives. I want to encrypt my emails in case some baddy takes my laptop. One negative that’s come of this is I the ability to search through the body of the email in has stopped working. This is very disappointing and quite crippling for someone like me that believes in using search instead of infinite number of folder-inside-folder hierarchy to keep things organized. After much work I found a solution that works for me. I can’t promise it’ll work for you.

Let me start at the beginning and we’ll work our way to the actual fix. Make you\’re you are not running The first part is to move your directory into an encrypted drive. From the previous post we will use the hdiutil but in a slightly different way. It has a flag to take an existing directory and create an image out of it. We will take our mail directory ~/Library/Mail and create a 4GB image out of it on to our Documents directory called MailDrive.sparseimage.

~]# cd ~/Documents ~]# hdiutil create -size 4G -srcfolder ~/Library/Mail -format SPARSE -encryption -stdinpass MailDrive

You should be prompted for a password. Every-time you mount this drive you will be prompted for this password.

Now move the old Mail directory out of the way. Don’t delete until after everything is working. Then mount the image you just created in it’s place. Again we will use the hdiutilcommand to mount the image where we want it to be mounted. You will be prompted for the password you set in the previous step. ~]# cd ~/Library/Mail ~]# mv Mail Mail.bak ~]# mkdir Mail ~]# hdiutil attach -mountpoint ~/Library/Mail ~/Documents/MailDrive.sparseimage

With this done, start up Everything should looks like it did before but, under the covers, your email is now encrypted! The problem is, most likely, your search function for “Entire Message” is probably broken now. So we can get to the crux of the matter. relied on Spotlight for it’s search. Spotlight does not scan thought mounted drives. I don’t know the reasoning as I don’t work at Apple but my guess is they don’t want the index to glow to infinity every time you connect a little USB device or other things of the sort. But this is your email! You want to search though it! We can ask Spotlight to do exactly that. The mditul command seems to be the the way to plug into Spotlight, at least for drives.

The following first command will tell Spotlight to index the drive. While this is running you will see the Spotlight magnifying glass on the top right of your screen pulsating and thinking. Once this is done you will be able to search though your emails. The second command will just confirm the indexing is on. does not need to be restarted for this to work which I think is pretty cool. ~]# mdutil ~/Library/Mail -i on ~]# mdutil ~/Library/Mail -s