public function send($email, $headers, Horde_Mail_Transport $mailer, array $opts = array())
{
$old_status = $this->_status;
$this->isBasePart(true);
/* Does the SMTP backend support 8BITMIME (RFC 1652)? */
$canonical = true;
$encode = self::ENCODE_7BIT;
if (isset($opts['encode'])) {
/* Always allow 7bit encoding. */
$encode |= $opts['encode'];
} elseif ($mailer instanceof Horde_Mail_Transport_Smtp) {
try {
$smtp_ext = $mailer->getSMTPObject()->getServiceExtensions();
if (isset($smtp_ext['8BITMIME'])) {
$encode |= self::ENCODE_8BIT;
}
} catch (Horde_Mail_Exception $e) {
}
$canonical = false;
} elseif ($mailer instanceof Horde_Mail_Transport_Smtphorde) {
try {
if ($mailer->getSMTPObject()->data_8bit) {
$encode |= self::ENCODE_8BIT;
}
} catch (Horde_Mail_Exception $e) {
}
$canonical = false;
}
$msg = $this->toString(array('canonical' => $canonical, 'encode' => $encode, 'headers' => false, 'stream' => true));
/* Add MIME Headers if they don't already exist. */
if (!isset($headers['MIME-Version'])) {
$headers = $this->addMimeHeaders(array('encode' => $encode, 'headers' => $headers));
}
if (!empty($this->_temp['toString'])) {
$headers->addHeader('Content-Transfer-Encoding', $this->_temp['toString']);
switch ($this->_temp['toString']) {
case '8bit':
if ($mailer instanceof Horde_Mail_Transport_Smtp) {
$mailer->addServiceExtensionParameter('BODY', '8BITMIME');
}
break;
}
}
$this->_status = $old_status;
$rfc822 = new Horde_Mail_Rfc822();
try {
$mailer->send($rfc822->parseAddressList($email)->writeAddress(array('encode' => $this->getHeaderCharset() ?: true, 'idn' => true)), $headers->toArray(array('broken_rfc2231' => !empty($opts['broken_rfc2231']), 'canonical' => $canonical, 'charset' => $this->getHeaderCharset())), $msg);
} catch (InvalidArgumentException $e) {
// Try to rebuild the part in case it was due to
// an invalid line length in a rfc822/message attachment.
if ($this->_failed) {
throw $e;
}
$this->_failed = true;
$this->_sanityCheckRfc822Attachments();
try {
$this->send($email, $headers, $mailer, $opts);
} catch (Horde_Mail_Exception $e) {
throw new Horde_Mime_Exception($e);
}
} catch (Horde_Mail_Exception $e) {
throw new Horde_Mime_Exception($e);
}
}