Search code examples
zend-frameworkimapgmail-imap

How to fetch a GMail message using GMail URL Hash in Zend Framework


I am using Zend Framework for fetching GMail messages. I have been able to authenticate and fetch all the messages using the zend framework using following code:

$storage = new Zend_Mail_Storage_Imap($imap);

for ($i = 1; $i <= $storage->countMessages() && $i <=10; $i++ ){ 
    echo htmlentities($storage->getMessage($i)->subject);
    echo $storage->getMessage($i)->getContent();
}

But I want to fetch mail using the hash which usually appears in the GMail URL when we read a message. For example in following URL:

https://mail.google.com/mail/?shva=1#inbox/137261701dcae0a6 The part after the last slash is the hash (137261701dcae0a6) which I suppose is in hex. How can I use this hash to fetch the message using Zend Framework? Please help.


Solution

  • The Google link you provided (https://mail.google.com/mail/?shva=1#inbox/137261701dcae0a6) points to the whole conversation (entire thread).

    137261701dcae0a6 is Gmail's thread-id in hex.

    It is possible to use X-GM-THRID Gmail's IMAP extension to search for messages in this thread.

    I don't know Zend, so I can't help you with the code, but IMAP communication looks as follows:

    C: 20eeec4bb07a44be UID SEARCH X-GM-THRID 1401511523692802395
    S: * SEARCH 13622
    S: 20eeec4bb07a44be OK SEARCH completed (Success)