Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
PHP implementation for Outlook's bogus proprietary thread-index for message threading
* Generates strings appropriate to use as values for Microsoft's annoying Thread-Index email header.
* This is how Outlook groups email threads in conversation view.
* These headers are base64 encoded 22-byte binary strings in the format:
* 6 bytes: The first 6 significant bytes from a FILETIME timestamp.
* 16 bytes: A unique GUID in hex.
* There are optional 5-byte suffixes that indicate time skew and references other messages in the same thread.
* This does not implement these suffixes.
* See
// get the current timestamp in FILETIME format (seconds since 1601)
$t = time();
$ft = ($t * 10000000) + 116444736000000000;
// convert to hex and 0-pad to 8 bytes
$ft_hex = base_convert($ft, 10, 16);
$ft_hex = str_pad($ft_hex, 16, 0, STR_PAD_LEFT);
// fake the guid that Outlook assigns
// I've been using the same value as the standard In-Reply-To header
// this is what determines the threading, so should be unique per thread
$guid = md5("The message-id of normal headers");
// combine first 6 bytes of timestamp with hashed guid, convert to bin, then encode
$thread_ascii = substr($ft_hex, 0, 12) . $guid;
$thread_bin = hex2bin($thread_ascii);
$thread_enc = base64_encode($thread_bin);
echo $thread_enc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.