public function getHeader() { $header = new Header(); return $header->getHeader(); }
/** * Encode and generate MDN from attributes and message (if exists) * * @param object $message The refering message */ public function encode($message = null) { // container $container = new Horde_MIME_Part('multipart/report', ' '); // first part $text = new Horde_MIME_Part('text/plain', $this->getMessage(), MIME_DEFAULT_CHARSET, null, '7bit'); // add human readable message $container->addPart($text); // second part $lines = new Header(); $lines->addHeader('Reporting-UA', 'AS2Secure - PHP Lib for AS2 message encoding / decoding'); if ($this->getPartnerFrom()) { $lines->addHeader('Original-Recipient', 'rfc822; "' . $this->getPartnerFrom()->id . '"'); $lines->addHeader('Final-Recipient', 'rfc822; "' . $this->getPartnerFrom()->id . '"'); } $lines->addHeader('Original-Message-ID', $this->getAttribute('original-message-id')); $lines->addHeader('Disposition', $this->getAttribute('action-mode') . '/' . $this->getAttribute('sending-mode') . '; ' . $this->getAttribute('disposition-type')); if ($this->getAttribute('disposition-type') != self::TYPE_PROCESSED) { $lines->addHeader('Disposition', $lines->getHeader('Disposition') . ': ' . $this->getAttribute('disposition-modifier')); } if ($this->getAttribute('received-content-mic')) { $lines->addHeader('Received-Content-MIC', $this->getAttribute('received-content-mic')); } // build computer readable message $mdn = new Horde_MIME_Part('message/disposition-notification', $lines, MIME_DEFAULT_CHARSET, null, '7bit'); $container->addPart($mdn); $this->setMessageId(self::generateMessageID($this->getPartnerFrom())); // headers setup $this->headers = new Header(array('AS2-Version' => '1.0', 'Message-ID' => $this->getMessageId(), 'Mime-Version' => '1.0', 'Server' => 'AS2Secure - PHP Lib for AS2 message encoding / decoding', 'User-Agent' => 'AS2Secure - PHP Lib for AS2 message encoding / decoding')); $this->headers->addHeaders($container->header()); if ($this->getPartnerFrom()) { $headers_from = array('AS2-From' => '"' . $this->getPartnerFrom()->id . '"', 'From' => $this->getPartnerFrom()->email, 'Subject' => $this->getPartnerFrom()->mdn_subject, 'Disposition-Notification-To' => $this->getPartnerFrom()->send_url); $this->headers->addHeaders($headers_from); } if ($this->getPartnerTo()) { $headers_to = array('AS2-To' => '"' . $this->getPartnerTo()->id . '"', 'Recipient-Address' => $this->getPartnerTo()->send_url); $this->headers->addHeaders($headers_to); } if ($message && ($url = $message->getHeader('Receipt-Delivery-Option')) && $this->getPartnerFrom()) { $this->url = $url; $this->headers->addHeader('Recipient-Address', $this->getPartnerFrom()->send_url); } $this->path = Adapter::getTempFilename(); // signing if requested if ($message && $message->getHeader('Disposition-Notification-Options')) { file_put_contents($this->path, $container->toCanonicalString(true)); $this->path = $this->adapter->sign($this->path); $content = file_get_contents($this->path); $this->headers->addHeadersFromMessage($content); // TODO : replace with futur AS2MimePart to separate content from header if (strpos($content, "\n\n") !== false) { $content = substr($content, strpos($content, "\n\n") + 2); } file_put_contents($this->path, ltrim($content)); } else { file_put_contents($this->path, $container->toCanonicalString(false)); $content = $container->toString(); } }