Archive for February, 2009

I’ve decided to create an application launch platform called Beetle Labs. The purpose is to have a public staging area where I can get feedback on different ideas. Whatever gains traction, I’ll spin off into a separate site with a new UX. Most of the stuff I put out there, I expect to fail. Failing applications just won’t receive the attention that more prominent ones do. It’ll be a sort of survival of the fittest. The first app probably won’t launch for another week or so, but I’ll announce it at that time.

I usually use find/xargs quite a bit, such as removing .svn directories when I forget to export. This wouldn’t work in this situation, because I needed to use the result of the find as an argument within my next command and the pipe wouldn’t do. So the -exec flag of find will pass the match as an argument that can be used with the syntax {}. The semi-colon denotes the end of the command and I’m escaping it with a backslash. So this reads “find all files in the current directory that end in _1.jpg and move them to ../xx/.”

The second command I ran within the “xx” directory. The basename string manipulation let me strip the _1.jpg from the name, then I re-added .jpg and this is all within the quotes so it comes out as a single file name. So this reads “for every file in this directory that ends in *_1.jpg, rename by removing _1.jpg then adding .jpg to the end.”

When Safari 4 Public Beta came out, there was a mad rush to find the applications hidden preferences. Some used it to bring back the aqua loading bar, others used it to bring back tabs on bottom, and others were just curious. I’m leaving S4PB the way it is because I want to give it a chance to win me over. Here are three ways that I know of to find these hidden preferences.

Right click (control-click) on an application and select “Show Package Contents” from the popup. Open up the Info.plist and see if there is anything interesting to change. Also, it’s fun to poke around the Resources folder, there are all kinds of neato icons and other goodies.

Find all the strings in the application binary. From the command line, run this “# strings /Applications/Safari.app/Contents/MacOS/Safari”. You have to target the binary file and “Safari.app” is just a package (a glorified folder). You’ll get back a bunch of junk, but if you look closely there are gems in there like “IncludeDebugMenu” which you can modify with the “defaults” utility. If you want to turn on the debug menu, you would do “# defaults write com.apple.Safari IncludeDebugMenu -bool YES”, restart Safari and you’ll see the debug menu.

Read the defaults. So run “# defaults read com.apple.Safari” and you’ll get back a bunch of preferences. You can change these by using write or delete. Check out “# man defaults” for all the info.

Use getmail – this has been the best archiver I’ve run across. There are other applications – isync, OfflineIMAP, Fetchmail, etc. – that probably do a decent job, but getmail is still the best in my view. There are other hacks – use Mail.app to synch the Gmail IMAP directory, then convert emlx to maildir; same for Thunderbird and mbox; etc – but we wanted something a little more straightforward – Occam’s razor, right?

Install getmail – On my dev machine, I used macports (port install python25; port install getmail) to install the latest getmail which had dependencies on Python 2.5. After this was done, I set up the getmailrc config file and fired off an attempt using SimpleIMAPSSLRetriever… which failed due to a lack of SSL in the newly installed Python. I had to go back and install Readline (port install py25-readline), then install SSL for Python (port install py25-socket-ssl).

Patch Python – There is a malloc bug in imaplib when fetching large documents using SSL. So open up imaplib.py from your Python lib dir (in my case /opt/local/lib/python2.5/) and replace:

data = self.sslobj.read(size-read)

with

data = self.sslobj.read(min(size-read, 16384))

to maintain a 15MB memory block if necessary.

Configure getmail – Now that most of the fun is taken care of, we need to set up a configuration file for getmail (~/.getmail/getmailrc) and create the proper local destination. First the getmailrc file:

First of all, we are using IMAP to retrieve mail as POP has a limit of 99 documents per access and that would take forever.

Second, we are using the Maildir format for the destination so we need to make sure the target directories have been created (~/Maildir/cur, ~/Maildir/new, ~/Maildir/tmp).

Third, we need to specify a mailbox or mailboxes to download or the INBOX will be the default.

Fourth, we need a trailing comma on the list of mailboxes to download due to a parsing error in getmail (actually the mailboxes option needs to be a tuple, but the trailing comma negates that).

Fifth, we need to know the syntax of Gmail’s internal IMAP structure to pull down discrete folders. Non-label folders (Starred, Sent Mail, Drafts, etc.) are accessed with “[Gmail]/Starred” (as in the above config) and labels are accessed directly. For example, the label “Important Project” would have this in the config:

mailboxes = ("Important Project",)

Download your Gmail – For every folder/label I had within Gmail, I downloaded to a separate folder so I could import into dovecot IMAP without hassle. This entailed changing the mailboxes option in getmailrc, running getmail, renaming Maildir to label/directory name, rinsing, repeating.

Retain Times – Because maildir uses the modification time of every file to determine the sent date, all emails pulled by the above method will basically lose their sense of time. The below PHP script will restore the modification times: