<< Blog Index

ActiveSync Hell
June 5, 2021

I was recently tasked with diagnosing a problem pertaining to ActiveSync synchronization. ActiveSync is an email
synchronization protocol developed by Microsoft, wonderfully described in several lengthy PDF documents. Here’s the HTTP spec to get started.

I had to help a client figure out just why some mail had went missing, and this involved:

  • Reading an understanding the MS ActiveSync protocol (much like RFC text)
  • Compiling libwbxml and Expat to encode/decode WBXML.
    • Not just for implementing the protocol, this was also paramount for decoding server logs and protocol data to inspect the original device’s behavior.
  • Implement a small portion of the protocol in Python, along with diagnostic functions. Diagnose a bunch of old C++ code to narrow down scope/suspicions.
  • Test and find the bug!

After reading through the AS spec, I put together some Python code which provides a (very) partial implementation to run diagnostic tests on a mail server. This script sets up some basics and drops the user into a Python shell in order to run test commands.

Basic usage

>>> # Set the account to use
>>> set_account( "server", "username", "password" )

>>> # Connect a "device" for testing
>>> provision_device() 

>>> # Test folder tree synchronization
>>> folder_sync() 

>>> # Prime folder synchronization
>>> test_sync_reset()

>>> # Test syncing mail
>>> test_sync()

>>> # Print emails received
>>> print_emails() 

activesync-hell-1.png

Suffice to say this was quite difficult to diagnose, but I’m so relieved to say that we did find something – it had to do with the server’s processing of client changes in tandem with server changes.

Hopefully you don’t find yourself in a similar situation needing advanced/complex diagnostics like this, but if you do, you might find some of the code in the script useful as a basis to work with (though there is a high chance of it not even working with some implementations).

<< Blog Index