roundcubemail/program/lib/Roundcube/rcube_imap_generic.php
public function fetchMIMEHeaders($mailbox, $uid, $parts, $mime = true)
    {
        if (!$this->select($mailbox)) {
            return false;
        }

        $result = false;
        $parts  = (array) $parts;
        $key    = $this->nextTag();
        $peeks  = array();
        $type   = $mime ? 'MIME' : 'HEADER';

        // format request
        foreach ($parts as $part) {
            $peeks[] = "BODY.PEEK[$part.$type]";
        }

        $request = "$key UID FETCH $uid (" . implode(' ', $peeks) . ')';

        // send request
        if (!$this->putLine($request)) {
            $this->setError(self::ERROR_COMMAND, "Failed to send UID FETCH command");
            return false;
        }

        do {
            $line = $this->readLine(1024);

            if (preg_match('/^\* [0-9]+ FETCH [0-9UID( ]+/', $line, $m)) {
                $line = ltrim(substr($line, strlen($m[0])));
                while (preg_match('/^BODY\[([0-9\.]+)\.'.$type.'\]/', $line, $matches)) {
                    $line = substr($line, strlen($matches[0]));
                    $result[$matches[1]] = trim($this->multLine($line));
                    $line = $this->readLine(1024);
                }
            }
        }
        while (!$this->startsWith($line, $key, true));

        return $result;
    }
public function fetchMIMEHeaders($mailbox, $uid, $parts, $mime = true)
    {
        if (!$this->select($mailbox)) {
            return false;
        }

        $result = false;
        $parts  = (array) $parts;
        $key    = $this->nextTag();
        $peeks  = array();
        $type   = $mime ? 'MIME' : 'HEADER';

        // format request
        foreach ($parts as $part) {
            $peeks[] = "BODY.PEEK[$part.$type]";
        }

        $request = "$key UID FETCH $uid (" . implode(' ', $peeks) . ')';

        // send request
        if (!$this->putLine($request)) {
            $this->setError(self::ERROR_COMMAND, "Failed to send UID FETCH command");
            return false;
        }

        do {
            $line = $this->readLine(1024);

            if (preg_match('/^\* [0-9]+ FETCH [0-9UID( ]+/', $line, $m)) {
                $line = ltrim(substr($line, strlen($m[0])));
                while (preg_match('/^BODY\[([0-9\.]+)\.'.$type.'\]/', $line, $matches)) {
                    $line = substr($line, strlen($matches[0]));
                    $result[$matches[1]] = trim($this->multLine($line));
                    $line = $this->readLine(1024);
                }
            }
        }
        while (!$this->startsWith($line, $key, true));

        return $result;
    }
public function fetchMIMEHeaders ( $ mailbox , $ uid , $ parts , $ mime = true ) { if ( ! $ this -> select ( $ mailbox ) ) { return false ; } $ result = false ; $ parts = ( array ) $ parts ; $ key = $ this -> nextTag ( ) ; $ peeks = array ( ) ; $ type = $ mime ? 'MIME' : 'HEADER' ; // format request foreach ( $ parts as $ part ) { $ peeks [ ] = "BODY.PEEK[$part.$type]" ; } $ request = "$key UID FETCH $uid (" . implode ( ' ' , $ peeks ) . ')' ; // send request if ( ! $ this -> putLine ( $ request ) ) { $ this -> setError ( self :: ERROR_COMMAND , "Failed to send UID FETCH command" ) ; return false ; } do { $ line = $ this -> readLine ( 1024 ) ; if ( preg_match ( '/^\* [0-9]+ FETCH [0-9UID( ]+/' , $ line , $ m ) ) { $ line = ltrim ( substr ( $ line , strlen ( $ m [ 0 ] ) ) ) ; while ( preg_match ( '/^BODY\[([0-9\.]+)\.' . $ type . '\]/' , $ line , $ matches ) ) { $ line = substr ( $ line , strlen ( $ matches [ 0 ] ) ) ; $ result [ $ matches [ 1 ] ] = trim ( $ this -> multLine ( $ line ) ) ; $ line = $ this -> readLine ( 1024 ) ; } } } while ( ! $ this -> startsWith ( $ line , $ key , true ) ) ; return $ result ; }
Fetch MIME headers of specified message parts

@param string $mailbox Mailbox name
@param int    $uid     Message UID
@param array  $parts   Message part identifiers
@param bool   $mime    Use MIME instad of HEADER

@return array|bool Array containing headers string for each specified body
False on failure.
Fetch MIME headers of specified message parts