Showing posts with label Scripting. Show all posts
Showing posts with label Scripting. Show all posts

Tuesday, September 05, 2006

Archiving AND compressing Mail.app messages

OK - so I was wanting to compress and archive my old messages - but I wanted to still have fairly easy access to them. I think I found a really nice way of doing this. I just put all the messages that I wanted to archive into their own folders (I did it by year - messages from 2000, 2001, etc). Then, for each folder I wanted to archive, I did the following:

  1. Open ~/Library/Mail/Mailboxes/[ARCHIVEFOLDER].mbox in BOTH finder and terminal

  2. In the Finder window, I copied the "Messages" folder to the desktop - and renamed it something a bit more descriptive (ie. "MailArchive-2000" or "MailArchive-2001")

  3. In the terminal window, I entered: ln -s /Volumes/[DESCRIPTIVENAME] Messages, ie. ln -s /Volumes/MailArchive-2000 Messages

  4. I opened DiskUtility, and created a New disk image from the folder on my desktop (File | New | Disk Image from Folder...). I made sure it was compressed.

Now, what this ended up doing was put all my messages in a compressed disk image on my hard drive. In Mail, the folder still shows up, and the message headers are all there cached - so I can even still search for messages based on "From", "To", or "Subject"... When I try to open a message in an archived folder, I get a message saying that I need to take the account online in order to read the message. When this happens, I simply double-click the corresponding image file, and it gets mounted, and I can access my messages easily.

Pretty Slick! If it weren't for Mail's smart way of handling offline folders, I think it would have been quite a bit harder. In addition, since I use compressed disk images, my old email messages end up taking up less than 50% of the original space on my disk....emails - being plain text - compress very nicely!

Maybe one day, if I'm REALLY ambitious, I'll write some kind of applescript that can do the whole thing for you....shouldn't be too hard. But I just don't have the time for it right now.

Converting kmail messages to Mac Mail.app messages

I wasn't able to find an easy way to convert Kmail messages to mac os Mail.app - without having to export to mbox format. For me, that wasn't an option.

I did, however, find a workaround.

  1. Create a new mailbox in mail.app (ie "Import"

  2. move your mail messages from kdemail/cur into ~/Library/Mail/Mailboxes/Import.mbox/Messages

  3. run the following: let num=9999; for i in `ls`; do cat $i | wc -c | sed -e 's/\t//g' | sed -e 's/ //g' > $num.emlx; cat $i >> $num.emlx; let num=$num+1; rm $i; done in a terminal window within the new "Messages" directory you have

  4. in Mail, choose to Rebuild the mailbox (Mailbox | Rebuild)

This seems to work because mail just stores its information in a modified maildir format (I'm guessing this only works for Tiger).

Tuesday, July 04, 2006

Syncing iTunes library between Mac and PC

I searched around quite a bit on Google to try and find a way to sync my iTunes library between my laptop (Mac) and my desktop (PC).  After reading quite a bit about messing with the Library.xml file and stuff that I didn't want to deal with (I just wanted it to work quickly - something that I could script, and maybe use something like rsync), I decided to just play around a little bit...

What I found was really interesting - it's quite easy to sync your iTunes library, if you have things set up just right.

If you have both your Mac and your PC set to "Keep iTunes Music Folder Organized", then most of the work is done for you.

All you need to do is copy the "iTunes Music" folder from the Mac to the PC, and copy the "iTunes Library" file from the Mac to the PC, but rename it as "iTunes Library.itl"

To make things even easier, you can rename the "iTunes Library" file to "iTunes Library.itl" on your mac, and it will work just fine - then you can do a simple rsync and get everything you need synced across.

The rsync command I use is:
rsync -avz --force --delete --stats --size-only -e ssh --exclude="iTunes Music Library.xml" --exclude=".DS_Store" ~/Music/iTunes/* user@desktop:'~/My\ Music/iTunes/'

You can modify your rsync command yourself.  Of note, DO NOT copy the xml file (it's "--exclude"ed), because iTunes on Windows will just recreate it based off of the .itl file.  Also, I didn't want to mess up my Windows file structure with all the .DS_Store files (so they are "--exclude"ed as well)

Since I don't care about two-way synchronization (I just want my Windows machine to be a clone of my Mac), this works for me.  Hopefully, it's helpful for someone else as well.