Replace newlines in this part's contents with those specified by either
the given newline sequence or the part's current EOL setting.
public replaceEOL ( mixed $text, string $eol = null, boolean $stream = false ) : string | ||
$text | mixed | The text to replace. Either a string or a stream resource. If a stream, and returning a string, will close the stream when done. |
$eol | string | The EOL sequence to use. If not present, uses the part's current EOL setting. |
$stream | boolean | If true, returns a stream resource. |
리턴 | string | The text with the newlines replaced by the desired newline sequence (returned as a stream resource if $stream is true). |
$textpart->setType('text/plain'); $textpart->setCharset('UTF-8'); $textpart->setContents(_("You have been sent an Ecard. To view the Ecard, you must be able to view text/html messages in your mail reader. If you are viewing this message, then most likely your mail reader does not support viewing text/html messages.")); /* Create the multipart/related part. */ $related = new Horde_Mime_Part(); $related->setType('multipart/related'); /* Create the HTML part. */ $htmlpart = new Horde_Mime_Part(); $htmlpart->setType('text/html'); $htmlpart->setCharset('UTF-8'); /* The image part */ $imgpart = new Horde_Mime_Part(); $imgpart->setType($image->getType('screen')); $imgpart->setContents($image->raw('screen')); $img_tag = '<img src="cid:' . $imgpart->setContentID() . '" /><p />'; $comments = $htmlpart->replaceEOL(Horde_Util::getFormData('ecard_comments')); if (!Horde_Util::getFormData('rtemode')) { $comments = '<pre>' . htmlspecialchars($comments, ENT_COMPAT, 'UTF-8') . '</pre>'; } $htmlpart->setContents('<html>' . $img_tag . $comments . '</html>'); $related->setContentTypeParameter('start', $htmlpart->setContentID()); $related->addPart($htmlpart); $related->addPart($imgpart); /* Create the multipart/alternative part. */ $alternative = new Horde_Mime_Part(); $alternative->setType('multipart/alternative'); $alternative->addPart($textpart); $alternative->addPart($related); /* Add them to the mail message */ $alt = new Horde_Mime_Mail(array('Subject' => _("Ecard - ") . Horde_Util::getFormData('image_desc'), 'To' => $to, 'From' => $from)); $alt->setBasePart($alternative);
/** * Attempts to obtain the raw text of a MIME part. * * @param mixed $text The full text of the MIME message. The text is * assumed to be MIME data (no MIME-Version checking * is performed). It can be either a stream or a * string. * @param string $type Either 'header' or 'body'. * @param string $id The MIME ID. * * @return string The raw text. * @throws Horde_Mime_Exception */ public static function getRawPartText($text, $type, $id) { /* Mini-hack to get a blank Horde_Mime part so we can call * replaceEOL(). From an API perspective, getRawPartText() should be * static since it is not working on MIME part data. */ $part = new Horde_Mime_Part(); $rawtext = $part->replaceEOL($text, self::RFC_EOL); /* We need to carry around the trailing "\n" because this is needed * to correctly find the boundary string. */ $hdr_pos = self::_findHeader($rawtext, self::RFC_EOL); $curr_pos = $hdr_pos + 3; if ($id == 0) { switch ($type) { case 'body': return substr($rawtext, $curr_pos + 1); case 'header': return trim(substr($rawtext, 0, $hdr_pos)); } } $hdr_ob = Horde_Mime_Headers::parseHeaders(trim(substr($rawtext, 0, $hdr_pos))); /* If this is a message/rfc822, pass the body into the next loop. * Don't decrement the ID here. */ if (($ct = $hdr_ob['Content-Type']) && $ct == 'message/rfc822') { return self::getRawPartText(substr($rawtext, $curr_pos + 1), $type, $id); } $base_pos = strpos($id, '.'); $orig_id = $id; if ($base_pos !== false) { $id = substr($id, $base_pos + 1); $base_pos = substr($orig_id, 0, $base_pos); } else { $base_pos = $id; $id = 0; } if ($ct && !isset($ct->params['boundary'])) { if ($orig_id == '1') { return substr($rawtext, $curr_pos + 1); } throw new Horde_Mime_Exception('Could not find MIME part.'); } $b_find = self::_findBoundary($rawtext, $curr_pos, $ct->params['boundary'], $base_pos); if (!isset($b_find[$base_pos])) { throw new Horde_Mime_Exception('Could not find MIME part.'); } return self::getRawPartText(substr($rawtext, $b_find[$base_pos]['start'], $b_find[$base_pos]['length'] - 1), $type, $id); }