This commit is contained in:
Markus Birth 2016-08-04 22:48:44 +02:00
parent 99870d94c4
commit 4993a29013
5 changed files with 38 additions and 23 deletions

View File

@ -84,9 +84,9 @@ class MailOutput extends GenericOutput
$this->setHeadersFromString($headers);
$recipients = implode(', ', $this->recipients);
// TODO: Check if any recipients in the first place
$this->transport->setRecipients($recipients);
$this->transport->setSubject($this->subject);
$this->transport->setHeaders($this->headers);
$this->transport->setParam('to', $recipients);
$this->transport->setParam('subject', $this->subject);
$this->transport->setParam('headers', $this->headers);
$this->transport->setContent($mailbody);
return $this->transport->transmit();
}

View File

@ -20,19 +20,21 @@ class GmailTransport implements TransportInterface
$this->content = $content;
}
public function setRecipients($recipients)
public function setParam($key, $value)
{
$this->recipients = $recipients;
}
switch ($key) {
case 'to':
$this->recipients = $value;
break;
public function setSubject($subject)
{
$this->subject = $subject;
}
case 'subject':
$this->subject = $value;
break;
public function setHeaders($headers)
{
$this->headers = $headers;
case 'headers':
$this->headers = $value;
break;
}
}
/**
@ -42,7 +44,7 @@ class GmailTransport implements TransportInterface
* @param string $data Date to encode
* @return string Encoded data
*/
private function b64url_encode($data)
private function base64UrlEncode($data)
{
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
@ -57,7 +59,7 @@ class GmailTransport implements TransportInterface
$mime->setSubject($this->subject);
$message_body = $mime->getMessage(null, null, $this->headers);
$encoded_message = $this->b64url_encode($message_body);
$encoded_message = $this->base64UrlEncode($message_body);
$postBody = new \Google_Service_Gmail_Message();
$postBody->setRaw($encoded_message);

View File

@ -14,17 +14,24 @@ class MailTransport implements TransportInterface
$this->content = $content;
}
public function setRecipients($recipients)
public function setParam($key, $value)
{
$this->recipients = $recipients;
switch ($key) {
case 'to':
$this->recipients = $value;
break;
case 'subject':
$this->subject = $value;
break;
case 'headers':
$this->setHeaders($value);
break;
}
}
public function setSubject($subject)
{
$this->subject = $subject;
}
public function setHeaders($headers)
private function setHeaders($headers)
{
$this->headers = '';
foreach ($headers as $key=>$value) {

View File

@ -6,6 +6,10 @@ class StdoutTransport implements TransportInterface
{
private $content;
public function setParam($key, $value)
{
}
public function setContent($content)
{
$this->content = $content;

View File

@ -4,6 +4,8 @@ namespace Frs\Output\Transport;
interface TransportInterface
{
public function setParam($key, $value);
public function setContent($content);
public function transmit();