curl-and-php
PHP curl not returning data in all cases for IMAP
Date: Fri, 17 Jun 2016 14:40:26 -0700
I am implementing a basic IMAP client that supports multiple connection
libraries - php_imap, sockets and php-curl.
The php_imap and sockets methods work fine. The curl method works for all
commands except FETCH so I know I don't have an error in my code. If I send
the same command via sockets it works, so I also know that I don't have an
error in my command. Additionally if I enable verbose output I can see that
the message is actually sent back.
function write($command) {
$url = ($this->type == 'imap' ? 'imap' : 'pop3') . ($this->secure
? 's' : '') . '://' . $this->host . '/INBOX';
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERPWD, "$this->username:$this->password");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PORT, $this->port);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
$fp = tmpfile();
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$verbose = fopen('php://temp', 'w+');
curl_setopt($ch, CURLOPT_STDERR, $verbose);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $command);
$res = curl_exec($ch);
rewind($verbose);
$verboseLog = stream_get_contents($verbose);
echo($verboseLog);
fclose($verbose);
return $res;
}
This works:
write('STATUS "INBOX" (MESSAGES)');
This returns empty string (UID is valid - works with socket)
$uid = 181;
write('UID FETCH ' . $uid . ' (BODY[])');
Is there is bug in the curl IMAP implementation? I've tested with curl
7.30.0 and 7.35.0
http://stackoverflow.com/questions/37870022/php-curl-not-returning-data-in-all-cases
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2016-06-18