Search code examples
phpoauth-2.0imap

IMAP Command with PHP VivOAuthIMAP


I am using the following lib : https://github.com/vmuthal/VivOAuthIMAP

I would like to add a function call Search From that would enable me to search mails from a specific sender. Here's the additional function :

public function searchfrom($expeditor) {
    $this->writeCommannd("A" . $this->codeCounter, " UID SEARCH FROM \"".$expeditor."\" ");
    $response = $this->readResponse("A" . $this->codeCounter); 
    return $this->modifyResponse($response);

}

The result from the server is : "BAD" (nothing else).


Solution

  •    /**
        * Search in FROM ie. Email Address
        * @param string $email
        * @return Array
        */
        public function searchFrom($email) {
            $this->writeCommannd("A" . $this->codeCounter, "SEARCH FROM \"$email\"");
            $response = $this->readResponse("A" . $this->codeCounter);      
            //Fetch by ids got in response
            $ids = explode(" ", trim($response[0][1]));     
            unset($ids[0]);
            unset($ids[1]);     
            $ids = array_values($ids);
            $stringIds = implode(",",$ids);     
            $mails = $this->getMessage($stringIds);         
            return $mails;
        }
    

    I have added this to the Library. Check if it works for you. https://github.com/vmuthal/VivOAuthIMAP/blob/master/src/VivOAuthIMAP.php