-
-
Save ZsBT/2b057442dca6b38d2aaa04abf0bcb36a to your computer and use it in GitHub Desktop.
PHP class 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 /* | |
encode/decode Outlook thread index. | |
GUID must be 32 bytes long | |
forked from brettp/thread-index.php | |
*/ | |
abstract class outlook_thread_index { | |
static function build($guid, $timestamp=NULL){ // create one | |
if(strlen($guid)!=32)throw new Exception("guid is not 32 bytes"); | |
$t = ($timestamp ? $timestamp : 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); | |
// 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); | |
return $thread_enc; | |
} | |
static function get_guid($thread_enc){ // return GUID | |
$thread_bin = base64_decode($thread_enc); | |
$thread_ascii = bin2hex($thread_bin); | |
return | |
$guid = substr($thread_ascii,12); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment