Created
August 21, 2015 22:35
-
-
Save brettp/7e8e450b0d200279323c to your computer and use it in GitHub Desktop.
PHP implementation for Outlook's bogus proprietary thread-index for message threading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* 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 http://www.meridiandiscovery.com/how-to/e-mail-conversation-index-metadata-computer-forensics/ | |
*/ | |
// 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