/** * @depends test_get * @depends test_set * @covers ::createMimeMessage * @covers ::_createMimeMessageWithAddresses * @covers ::_addBodyWithoutInlineAttachments * @covers ::_addBodyWithInlineAttachments */ public function test_createMimeMessage() { $this->generateMessage(); # Inline attachments $this->assertInstanceof('\\BLW\\Type\\MIME\\IMessage', $this->Message->createMimeMessage(), 'IMessage::createMimeMessage() returned an invalid value'); # No Inline attachments $Attachments = $this->readAttribute($this->Message, '_InlineAttachments'); unset($Attachments[0]); $this->assertInstanceof('\\BLW\\Type\\MIME\\IMessage', $this->Message->createMimeMessage(), 'IMessage::createMimeMessage() returned an invalid value'); # Invalid attachment $Attachments[0] = new GenericFile('z:\\undefined\\!!!'); try { $this->Message->createMimeMessage(); $this->fail('Failed to generate exception with invalid arguments'); } catch (FileException $e) { } # No recipient $x = $this->Message->To[0]; unset($this->Message->To[0]); try { $this->Message->createMimeMessage(); $this->fail('Failed to generate exception with invalid arguments'); } catch (ClassException $e) { } # No sender $this->Message->To[0] = $x; $x = $this->Message->From[0]; unset($this->Message->From[0]); try { $this->Message->createMimeMessage(); $this->fail('Failed to generate exception with invalid arguments'); } catch (ClassException $e) { } # No subject $this->Message->From[0] = $x; $x = $this->Message->Subject; unset($this->Message->Subject); try { $this->Message->createMimeMessage(); $this->fail('Failed to generate exception with invalid arguments'); } catch (ClassException $e) { } # No Body $this->Message->Subject = $x; $x = $this->Message->Text; unset($this->Message->Text); try { $this->Message->createMimeMessage(); $this->fail('Failed to generate exception with invalid arguments'); } catch (ClassException $e) { } }
/** * Does the actual work of sending the message. * * @codeCoverageIgnore * * @param \BLW\Type\MIME\IMessage $Message * Message to send. * @return integer ITransport::RESULT_FLAGS */ public function doSend(IMessage $Message) { // Convert Message to MIME format if (is_callable(array($Message, 'createMimeMessage'))) { $MimeMessage = $Message->createMimeMessage(); $this->_Recipients = $this->parseRecipients($Message); $this->_Header = $MimeMessage->getHeader(); $this->_Body = $MimeMessage->getBody(); return ITransport::SUCCESS; } // Invalid $VARIABLE return ITransport::ERROR; }
/** * Does the actual work of sending the message. * * @codeCoverageIgnore * * @link http://www.php.net/manual/en/function.mail.php mail() * * @throws \BLW\Model\ErrorException If there is an error sending the mail. * * @param \BLW\Type\Mail\IMessage $Message * Message to send. * @return integer ITransport::RESULT_FLAGS */ public function doSend(IMessage $Message) { $MimeMessage = $Message->createMimeMessage(); $To = array(); // Gather recipients foreach ($this->parseRecipients($Message) as $Recipient) { // Is current entry an email address? if ($Recipient instanceof IEmailAddress) { // Add it to recipients $To[] = strval($Address); } } $To = implode(', ', $To); // Try to send message if (!@mail($To, $Message->getSubject(), strval($MimeMessage->getBody()), strval($MimeMessage->getHeader()))) { throw new ErrorException(error_get_last()); } // Success return ITransport::SUCCESS; }