Horde_Imap_Client_Data_Fetch::setBodyPart PHP Method

setBodyPart() public method

Set a body part entry.
public setBodyPart ( string $id, mixed $text, string $decode = null )
$id string The MIME ID.
$text mixed The body part text, as either a string or stream resource.
$decode string Either '8bit', 'binary', or null.
    public function setBodyPart($id, $text, $decode = null)
    {
        $this->_data[Horde_Imap_Client::FETCH_BODYPART][$id] = array('d' => $decode, 't' => $this->_setMixed($text));
    }

Usage Example

Beispiel #1
0
 public function testIconvHtmlMessage()
 {
     $conn = $this->getMockBuilder('Horde_Imap_Client_Socket')->disableOriginalConstructor()->setMethods(['fetch'])->getMock();
     $urlGenerator = $this->getMockBuilder('\\OCP\\IURLGenerator')->disableOriginalConstructor()->getMock();
     //linkToRoute 'mail.proxy.proxy'
     $urlGenerator->expects($this->any())->method('linkToRoute')->will($this->returnCallback(function ($url) {
         return "https://docs.example.com/server/go.php?to={$url}";
     }));
     $htmlService = new \OCA\Mail\Service\Html($urlGenerator);
     // mock first fetch
     $firstFetch = new Horde_Imap_Client_Data_Fetch();
     $firstPart = Horde_Mime_Part::parseMessage(file_get_contents(__DIR__ . '/data/mail-message-123.txt'), ['level' => 1]);
     $firstFetch->setStructure($firstPart);
     $firstFetch->setBodyPart(1, $firstPart->getPart(1)->getContents());
     $firstFetch->setBodyPart(2, $firstPart->getPart(2)->getContents());
     $firstResult = new Horde_Imap_Client_Fetch_Results();
     $firstResult[123] = $firstFetch;
     $conn->expects($this->any())->method('fetch')->willReturn($firstResult);
     $message = new \OCA\Mail\Message($conn, 'INBOX', 123, null, true, $htmlService);
     $htmlBody = $message->getHtmlBody(0, 0, 123, function () {
         return null;
     });
     $this->assertTrue(strlen($htmlBody) > 1000);
     $plainTextBody = $message->getPlainBody();
     $this->assertTrue(strlen($plainTextBody) > 1000);
 }