From 01f23590e4840624fd1a840c67de55765f3d2f75 Mon Sep 17 00:00:00 2001 From: nikkel Date: Fri, 20 Mar 2020 01:45:50 +0700 Subject: [PATCH] Upload files to 'src' --- src/Error.php | 8 ++++ src/Message.php | 21 ++++++++++ src/SendMessage.php | 93 ++++++++++++++++++++++++++++++++++++++++++ src/SendRawMessage.php | 38 +++++++++++++++++ src/SendResult.php | 34 +++++++++++++++ 5 files changed, 194 insertions(+) create mode 100644 src/Error.php create mode 100644 src/Message.php create mode 100644 src/SendMessage.php create mode 100644 src/SendRawMessage.php create mode 100644 src/SendResult.php diff --git a/src/Error.php b/src/Error.php new file mode 100644 index 0000000..92739d7 --- /dev/null +++ b/src/Error.php @@ -0,0 +1,8 @@ +client = $client; + $this->attributes = $attributes; + } + + public function id() + { + return $this->attributes->id; + } + + public function token() + { + return $this->attributes->token; + } +} diff --git a/src/SendMessage.php b/src/SendMessage.php new file mode 100644 index 0000000..0fa0c7f --- /dev/null +++ b/src/SendMessage.php @@ -0,0 +1,93 @@ +client = $client; + $this->attributes['to'] = []; + $this->attributes['cc'] = []; + $this->attributes['bcc'] = []; + $this->attributes['headers'] = null; + $this->attributes['attachments'] = []; + } + + public function to($address) + { + $this->attributes['to'][] = $address; + } + + public function cc($address) + { + $this->attributes['cc'][] = $address; + } + + public function bcc($address) + { + $this->attributes['bcc'][] = $address; + } + + public function from($address) + { + $this->attributes['from'] = $address; + } + + public function sender($address) + { + $this->attributes['sender'] = $address; + } + + public function subject($subject) + { + $this->attributes['subject'] = $subject; + } + + public function tag($tag) + { + $this->attributes['tag'] = $tag; + } + + public function replyTo($replyTo) + { + $this->attributes['reply_to'] = $replyTo; + } + + public function plainBody($content) + { + $this->attributes['plain_body'] = $content; + } + + public function htmlBody($content) + { + $this->attributes['html_body'] = $content; + } + + public function header($key, $value) + { + $this->attributes['headers'][$key] = $value; + } + + public function attach($filename, $content_type, $data) + { + $attachment = [ + 'name' => $filename, + 'content_type' => $content_type, + 'data' => base64_encode($data), + ]; + + $this->attributes['attachments'][] = $attachment; + } + + + public function send() + { + $result = $this->client->makeRequest('send', 'message', $this->attributes); + + return new SendResult($this->client, $result); + } +} diff --git a/src/SendRawMessage.php b/src/SendRawMessage.php new file mode 100644 index 0000000..8ef8415 --- /dev/null +++ b/src/SendRawMessage.php @@ -0,0 +1,38 @@ +client = $client; + $this->attributes['rcpt_to'] = []; + } + + public function mailFrom($address) + { + $this->attributes['mail_from'] = $address; + } + + public function rcptTo($address) + { + $this->attributes['rcpt_to'][] = $address; + } + + public function data($data) + { + $this->attributes['data'] = base64_encode($data); + } + + public function send() + { + $result = $this->client->makeRequest('send', 'raw', $this->attributes); + + return new SendResult($this->client, $result); + } +} diff --git a/src/SendResult.php b/src/SendResult.php new file mode 100644 index 0000000..2e7098d --- /dev/null +++ b/src/SendResult.php @@ -0,0 +1,34 @@ +client = $client; + $this->result = $result; + } + + public function recipients() + { + if ($this->recipients != null) { + return $this->recipients; + } else { + $this->recipients = []; + + foreach ($this->result->messages as $key => $value) { + $this->recipients[strtolower($key)] = new Message($this->client, $value); + } + + return $this->recipients; + } + } + + public function size() + { + return count($this->recipients()); + } +}