Archive for May, 2008

Offline Support Finished

Well, I finally finished adding offline support, so it will should work well offline.  It just sets text in the status bar to let the user know the sync cannot be completed while offline.  Once the user is back online it works like normal.  Any changes made while offline are synced since the listener still adds the last modified date to the custom4 property.  My next goals are to handle errors more smoothly, get some refactoring and additional commenting, and to add support for locales in the scripts.  Once these are done it might be ready for an alpha release.  Let me know if you are interested.

I have been busy the last few days and will be busy for the next day or two because there is a wedding in my family.

, , ,

No Comments

May 27, 2008

I was attempting to change my sync process today when I opened the Address Book and was greeted with 925 new Address Books.  In the end, cleaning obj directory and rebuilding fixed the problem.  Strange, but at least my extension wasn’t the direct cause of the problem.

I found and fixed an error that would sometimes occur when trying to sync after adding several new contacts.

After fixing that error, I re-defined what two cards must have in common for the sync function to consider them identical.  Since Google only allows one contact/e-mail address, it first checks if the cards have any e-mail address in common (primaryEmail or secondEmail).  If there aren’t any e-mail addresses (which is allowed in Thunderbird and Google) it checks the name.

I rewrote my old method to sync individual cards now that I use custom4 for the last modified date.  It checks to see first if both have changed (and will eventually have a preference that can ask the user what to do in this case or pick one to always update) and then checks to see which (if any) changed and updates it.  Unfortunately, updating a Thunderbird card isn’t as efficient as it could be.  I kept getting NS_NOINTERFACE errors while trying to call the modifyCard function in the address book, so I have to actually delete the card and then add the card from Google…  Updating a Google contact needs to be re-done soon, too.

In my casual tests I didn’t find any other errors.  It now works well offline and syncs every 30 minutes by default or manually.  Out of the 11 average contacts I added on one computer, every one synced perfectly with Google and with my other computer.

The only catch so far is that it has to use the card’s custom4 property to store the lastModifiedDate.

, , , ,

No Comments

An overview of my extension

The extension that I am working on for GSoC synchronizes an Address Book in Mozilla Thunderbird with Google Contacts. This is going to be a quick overview of how it works so far. This post assumes some basic knowledge of the Hypertext Transfer Protocol (HTTP), Thunderbird, and programming.

Basically, my extension adds an overlay to the Thunderbird Address Book, so when the Address Book opens, it starts going.

Authentication Check

When it starts, it registers a preferences observer (so it can modify behavior as preferences change) and obtains the current preferences. I will explain preferences in more detail later. It then checks to see if there is a valid authentication token in the extension directory. If not, it shows a login prompt. When OK is pressed, it attempts to authenticate the user using Google’s Client Login method of authentication. So, it sends an HTTPS POST request to Google which then returns an authentication token that can be used repeatedly and does not expire. This token (not the username and password) is stored in a textfile in the extension directory.

Initialization

Once it gets or finds a valid authentication token, adds a listener (nsIAbListener) to the Address Book Manager (nsIAbManager), sets up the file that stores the date and time of the last synchronization, and begins the synchronization process.

Preparing for Synchronization

The sync process is the longest and the one that I change most often. Right now, it gets the Address Book first (does this every time in case it was deleted, changed, etc.). Then, it gets the time of the last sync (if any) to be used later and sends an HTTP GET request to Google using the authentication token to obtain all of the user’s contacts. Once it has these, it also obtains all contacts in the specified Address Book.

Synchronization

Right now this process is costly in terms of asymptotic analysis (or Big O notation) with a nested for loop.

The outer for loop iterates through every contact from Google while the inner for loop iterates through every unmatched card in the address book. When it finds two cards that it considers “identical,” if the current card from Google hasn’t been matched then it sets the TB card to null (so the loop knows it was ‘matched’ and calls a method that checks the cards’ last modified date to see if any of them is new since the last sync.  If so, it replaces the old card with the new one.

If the card from Google was already matched, however, that means that the card from the Address Book is a duplicate and my current implementation removes the card. In the future I may add a prompt asking the user what to do about it.

Once the inner loop is finished, if the card from Google wasn’t matched it means one of two things. Either the card is new and should be added to Thunderbird (the card’s last modified date is more recent than the last sync) or it was deleted from Thunderbird and should be removed from Google.

Once that is done, it checks any unmatched cards from Thunderbird and figures out if they should be deleted from TB or added to Google, and then does that. Due to some timing issues with HTTP Requests, there are three helper methods. There are three global arrays treated as queues for cards to delete, update, and remove.  The sync method adds cards to the arrays as necessary.  When the sync method is done, it calls the delete method, which then calls the add method, which in turn calls the update method.

Finishing up the sync

When the hard part is over, it writes the current date/time to a file (the last sync time), schedules another sync after the preferred interval and sets a synced boolean to true (which is checked by the listener to make sure it doesn’t act during synchronization)

Address Book Listener

Since TB 3 doesn’t have the lastModifiedDate property, I made my own rough version with an Address Book Listener. The address book listener updates the card’s ‘custom2’ property whenver a contact is modified or added to the Google Contacts address book. Using this approach, my extension should work offline.  I am working on adding last modified date to Thunderbird 3, so soon an address book listener and some of the booleans required by it may become unnecessary.

, , , , , , ,

No Comments

alert(“Hello World!”);

This is my first blog.  I chose JavaScript for the title since that is the language I used most often today (started with JS then moved on to Java, then XUL, then back to JS).  I don’t have much to say yet, but my goal for this blog is not to rant–even though it might happen–or to write much about me; I plan on blogging about my Google Summer of Code (GSoC) project that still doesn’t have a name, Thunderbird, any/all programs that I am working on, Linux, and more.  I’ll probably be changing the theme and layout several times.

GSoC update:

Today I rewrote the Address Book listener portion of my code to hopefully make it work more smoothly and to fix a few bugs with it.  Basically, in TB 3 so far, an Address Book Listener is called when an event occurs in the Address Book.  It can handle onItemAdded, onItemRemoved, and/or onItemChanged events and specify what to do in each circumstance.

My previous implementation didn’t work well if multiple items were added or removed by the user simultaneously but now it should work just fine.  I had some timing issues with all the HTTP requests, so I added a command parameter to most of the methods that send them.  The parameter is an array of strings that contain commands.  When the HTTP request gets a 201 response it then evaluates each command in the array.  Right now the onItemChanged is still rough and requires another request be sent after the first, so I had to send commands to make another command array into the first request.  That will hopefully be changed soon.

Then, I decided to finally add a preference to my pref dialog for changing the Address Book name.  It should work with the Personal Address Book, but for now the default will be Google Contacts.

After that was done, I realized that my current initialization/sync process was more complicated than it should be, so I re-wrote that.  It will still require another re-write, but this method is better.  I might expand on this idea soon.

Time to go to bed and hopefully fall asleep within a few hours…  If you made it this far without falling asleep you probably have the same problem falling asleep that I have.

<!ENTITY goodNight.label “Good Night” >

No Comments