예제 #1
0
    public function testResolveCids()
    {
        $parser = new ezcMailParser();
        $set = new ezcMailFileSet(array(dirname(__FILE__) . '/parser/data/various/test-html-inline-images'));
        $mail = $parser->parseMail($set);
        $relatedParts = $mail[0]->body->getParts();
        $alternativeParts = $relatedParts[0]->getParts();
        $html = $alternativeParts[1]->getMainPart();
        $convertArray = array('consoletools-table.png@1421450' => 'foo', 'consoletools-table.png@1421452' => 'bar');
        $htmlBody = ezcMailTools::replaceContentIdRefs($html->text, $convertArray);
        $expected = <<<EOFE
<html>
Here is the HTML version of your mail
with an image: <img src='foo'/>
with an image: <img src='cid:consoletools-table.png@1421451'/>
</html>
EOFE;
        self::assertSame($expected, $htmlBody);
    }
예제 #2
0
            $newFile = tempnam($this->dir, 'mail');
            copy($mailPart->fileName, $newFile);
            // save location and setup ID array
            $this->cids[$mailPart->contentId] = $this->webDir . '/' . basename($newFile);
        }
        // if we find a text part and if the sub-type is HTML (no plain text)
        // we store that in the classes' htmlText property.
        if ($mailPart instanceof ezcMailText) {
            if ($mailPart->subType == 'html') {
                $this->htmlText = $mailPart->text;
            }
        }
    }
}
// create the collector class and set the filesystem path, and the webserver's
// path to find the attached files (images) in.
$collector = new collector();
$collector->dir = "/home/httpd/html/test/ezc";
$collector->webDir = '/test/ezc';
// We use the saveMailPart() method of the $collector object function as a
// callback in walkParts().
$context = new ezcMailPartWalkContext(array($collector, 'saveMailPart'));
// only call the callback for file and text parts.
$context->filter = array('ezcMailFile', 'ezcMailText');
// use walkParts() to iterate over all parts in the first parsed e-mail
// message.
$mail[0]->walkParts($context, $mail[0]);
// display the html text with the content IDs replaced with references to the
// file in the webroot.
echo ezcMailTools::replaceContentIdRefs($collector->htmlText, $collector->cids);