@@ -7,47 +7,47 @@ |
||
7 | 7 | |
8 | 8 | class Object implements Arrayable |
9 | 9 | { |
10 | - /** |
|
11 | - * Attributes |
|
12 | - */ |
|
13 | - protected $attributes = array(); |
|
10 | + /** |
|
11 | + * Attributes |
|
12 | + */ |
|
13 | + protected $attributes = array(); |
|
14 | 14 | |
15 | - /** |
|
16 | - * Constructor |
|
17 | - */ |
|
18 | - public function __construct($email, $name = null, $mailboxHash = null) |
|
19 | - { |
|
20 | - $this->attributes['email'] = $email; |
|
21 | - $this->attributes['name'] = $name; |
|
22 | - $this->attributes['mailboxHash'] = $mailboxHash; |
|
23 | - } |
|
15 | + /** |
|
16 | + * Constructor |
|
17 | + */ |
|
18 | + public function __construct($email, $name = null, $mailboxHash = null) |
|
19 | + { |
|
20 | + $this->attributes['email'] = $email; |
|
21 | + $this->attributes['name'] = $name; |
|
22 | + $this->attributes['mailboxHash'] = $mailboxHash; |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * Setter |
|
27 | - */ |
|
28 | - public function __set($name, $value) |
|
29 | - { |
|
30 | - $this->attributes[$name] = $value; |
|
31 | - } |
|
25 | + /** |
|
26 | + * Setter |
|
27 | + */ |
|
28 | + public function __set($name, $value) |
|
29 | + { |
|
30 | + $this->attributes[$name] = $value; |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Getter |
|
35 | - */ |
|
36 | - public function __get($name) |
|
37 | - { |
|
38 | - if ( ! array_key_exists($name, $this->attributes)) |
|
39 | - throw new MissingAttributeException("The attribute $name does not exists.", 1); |
|
33 | + /** |
|
34 | + * Getter |
|
35 | + */ |
|
36 | + public function __get($name) |
|
37 | + { |
|
38 | + if ( ! array_key_exists($name, $this->attributes)) |
|
39 | + throw new MissingAttributeException("The attribute $name does not exists.", 1); |
|
40 | 40 | |
41 | - return $this->attributes[$name]; |
|
42 | - } |
|
41 | + return $this->attributes[$name]; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Get the instance as an array. |
|
46 | - * |
|
47 | - * @return array |
|
48 | - */ |
|
49 | - public function toArray() |
|
50 | - { |
|
51 | - return $this->attributes; |
|
52 | - } |
|
44 | + /** |
|
45 | + * Get the instance as an array. |
|
46 | + * |
|
47 | + * @return array |
|
48 | + */ |
|
49 | + public function toArray() |
|
50 | + { |
|
51 | + return $this->attributes; |
|
52 | + } |
|
53 | 53 | } |
@@ -11,239 +11,239 @@ |
||
11 | 11 | |
12 | 12 | class PostmarkappParser extends AbstractParser implements EmailParserInterface |
13 | 13 | { |
14 | - /** |
|
15 | - * Parse the request and return itself |
|
16 | - * |
|
17 | - * @return ParserInterface |
|
18 | - */ |
|
19 | - public function parse() : ParserInterface |
|
20 | - { |
|
21 | - $this->from = $this->from(); |
|
22 | - $this->replyTo = $this->replyTo(); |
|
23 | - |
|
24 | - $this->to = $this->to(); |
|
25 | - $this->cc = $this->cc(); |
|
26 | - $this->bcc = $this->bcc(); |
|
27 | - |
|
28 | - $this->subject = $this->subject(); |
|
29 | - $this->body = $this->body(); |
|
30 | - |
|
31 | - $this->attachements = $this->attachements(); |
|
32 | - |
|
33 | - return $this; |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * Return an Address object from an input |
|
38 | - * |
|
39 | - * @param Array $input |
|
40 | - * @return Address |
|
41 | - */ |
|
42 | - protected function address(Array $input) : Address |
|
43 | - { |
|
44 | - return new Address($input['Email'], $input['Name'], $input['MailboxHash']); |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Parse an array of addresses |
|
49 | - * |
|
50 | - * @param Array $input |
|
51 | - * @return Collection |
|
52 | - */ |
|
53 | - protected function foreachAddress(Array $input) : Collection |
|
54 | - { |
|
55 | - $collection = new Collection; |
|
56 | - |
|
57 | - foreach ($input as $address) |
|
58 | - $collection->push($this->address($address)); |
|
59 | - |
|
60 | - return $collection; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * From property |
|
65 | - * |
|
66 | - * @return Address |
|
67 | - */ |
|
68 | - public function from() : Address |
|
69 | - { |
|
70 | - return $this->address($this->input('FromFull')); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Reply-to property |
|
75 | - * |
|
76 | - * @todo: edit this to handler the reply-to parameter |
|
77 | - * |
|
78 | - * @return Address |
|
79 | - */ |
|
80 | - public function replyTo() : Address |
|
81 | - { |
|
82 | - return $this->address($this->input('FromFull')); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * To property |
|
87 | - * |
|
88 | - * @return Collection<Address> |
|
89 | - */ |
|
90 | - public function to() : Collection |
|
91 | - { |
|
92 | - return $this->foreachAddress($this->input('ToFull')); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * CC property |
|
97 | - * |
|
98 | - * @return Collection<Address> |
|
99 | - */ |
|
100 | - public function cc() : Collection |
|
101 | - { |
|
102 | - return $this->foreachAddress($this->input('CcFull')); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * BCC property |
|
107 | - * |
|
108 | - * @return Collection<Address> |
|
109 | - */ |
|
110 | - public function bcc() : Collection |
|
111 | - { |
|
112 | - return $this->foreachAddress($this->input('BccFull')); |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Subject property |
|
117 | - * |
|
118 | - * @return String |
|
119 | - */ |
|
120 | - public function subject() |
|
121 | - { |
|
122 | - return $this->input('Subject'); |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Body |
|
127 | - * |
|
128 | - * @return String |
|
129 | - */ |
|
130 | - public function body() |
|
131 | - { |
|
132 | - $body = $this->bodyHtml(); |
|
133 | - |
|
134 | - if ($this->bodyIsText()) |
|
135 | - $body = $this->bodyText(); |
|
136 | - |
|
137 | - return $body; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Return the body html |
|
142 | - * |
|
143 | - * @return String |
|
144 | - */ |
|
145 | - public function bodyHtml() |
|
146 | - { |
|
147 | - return $this->input('HtmlBody'); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Return the body text |
|
152 | - * |
|
153 | - * @return String |
|
154 | - */ |
|
155 | - public function bodyText() |
|
156 | - { |
|
157 | - return $this->input('TextBody'); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * IsText |
|
162 | - * |
|
163 | - * @return Boolean |
|
164 | - */ |
|
165 | - public function bodyIsText() |
|
166 | - { |
|
167 | - return ! $this->bodyIsHtml(); |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * IsHtml |
|
172 | - * |
|
173 | - * @return Boolean |
|
174 | - */ |
|
175 | - public function bodyIsHtml() |
|
176 | - { |
|
177 | - return ! is_null($this->input('HtmlBody')) || $this->input('HtmlBody') !== ''; |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Get email headers |
|
182 | - * |
|
183 | - * @return Collection |
|
184 | - */ |
|
185 | - public function headers() : Collection |
|
186 | - { |
|
187 | - $collection = new Collection; |
|
188 | - |
|
189 | - foreach ($this->input('Headers') as $header) |
|
190 | - $collection->push(new Header($header['Name'], $header['Value'])); |
|
191 | - |
|
192 | - return $collection; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * retrieve a email header |
|
197 | - * |
|
198 | - * return Array |
|
199 | - */ |
|
200 | - public function header($name) : Header |
|
201 | - { |
|
202 | - return $this->headers()->filter(function ($header) use ($name) { |
|
203 | - return $header->name === $name; |
|
204 | - })->first(); |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Determinate if the email is marked as spam |
|
209 | - * |
|
210 | - * @return Boolean |
|
211 | - */ |
|
212 | - public function isSpam() |
|
213 | - { |
|
214 | - $header = $this->header('X-Spam-Flag'); |
|
215 | - return $header->value === 'NO' ? false : true; |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * Has attachements |
|
220 | - * |
|
221 | - * @return Boolean |
|
222 | - */ |
|
223 | - public function hasAttachements() |
|
224 | - { |
|
225 | - return $this->attachements->isEmpty(); |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * Attachments |
|
230 | - * |
|
231 | - * @return Collection<File> |
|
232 | - */ |
|
233 | - public function attachements() : Collection |
|
234 | - { |
|
235 | - $collection = new Collection; |
|
236 | - |
|
237 | - foreach ($this->input('Attachments') as $attachment) |
|
238 | - $collection->push( |
|
239 | - new Attachment( |
|
240 | - $attachment['Name'], |
|
241 | - ( isset($attachment['Content']) ? $attachment['Content'] : '' ), |
|
242 | - $attachment['ContentType'], |
|
243 | - $attachment['ContentLength'] |
|
244 | - ) |
|
245 | - ); |
|
246 | - |
|
247 | - return $collection; |
|
248 | - } |
|
14 | + /** |
|
15 | + * Parse the request and return itself |
|
16 | + * |
|
17 | + * @return ParserInterface |
|
18 | + */ |
|
19 | + public function parse() : ParserInterface |
|
20 | + { |
|
21 | + $this->from = $this->from(); |
|
22 | + $this->replyTo = $this->replyTo(); |
|
23 | + |
|
24 | + $this->to = $this->to(); |
|
25 | + $this->cc = $this->cc(); |
|
26 | + $this->bcc = $this->bcc(); |
|
27 | + |
|
28 | + $this->subject = $this->subject(); |
|
29 | + $this->body = $this->body(); |
|
30 | + |
|
31 | + $this->attachements = $this->attachements(); |
|
32 | + |
|
33 | + return $this; |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * Return an Address object from an input |
|
38 | + * |
|
39 | + * @param Array $input |
|
40 | + * @return Address |
|
41 | + */ |
|
42 | + protected function address(Array $input) : Address |
|
43 | + { |
|
44 | + return new Address($input['Email'], $input['Name'], $input['MailboxHash']); |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Parse an array of addresses |
|
49 | + * |
|
50 | + * @param Array $input |
|
51 | + * @return Collection |
|
52 | + */ |
|
53 | + protected function foreachAddress(Array $input) : Collection |
|
54 | + { |
|
55 | + $collection = new Collection; |
|
56 | + |
|
57 | + foreach ($input as $address) |
|
58 | + $collection->push($this->address($address)); |
|
59 | + |
|
60 | + return $collection; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * From property |
|
65 | + * |
|
66 | + * @return Address |
|
67 | + */ |
|
68 | + public function from() : Address |
|
69 | + { |
|
70 | + return $this->address($this->input('FromFull')); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Reply-to property |
|
75 | + * |
|
76 | + * @todo: edit this to handler the reply-to parameter |
|
77 | + * |
|
78 | + * @return Address |
|
79 | + */ |
|
80 | + public function replyTo() : Address |
|
81 | + { |
|
82 | + return $this->address($this->input('FromFull')); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * To property |
|
87 | + * |
|
88 | + * @return Collection<Address> |
|
89 | + */ |
|
90 | + public function to() : Collection |
|
91 | + { |
|
92 | + return $this->foreachAddress($this->input('ToFull')); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * CC property |
|
97 | + * |
|
98 | + * @return Collection<Address> |
|
99 | + */ |
|
100 | + public function cc() : Collection |
|
101 | + { |
|
102 | + return $this->foreachAddress($this->input('CcFull')); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * BCC property |
|
107 | + * |
|
108 | + * @return Collection<Address> |
|
109 | + */ |
|
110 | + public function bcc() : Collection |
|
111 | + { |
|
112 | + return $this->foreachAddress($this->input('BccFull')); |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Subject property |
|
117 | + * |
|
118 | + * @return String |
|
119 | + */ |
|
120 | + public function subject() |
|
121 | + { |
|
122 | + return $this->input('Subject'); |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Body |
|
127 | + * |
|
128 | + * @return String |
|
129 | + */ |
|
130 | + public function body() |
|
131 | + { |
|
132 | + $body = $this->bodyHtml(); |
|
133 | + |
|
134 | + if ($this->bodyIsText()) |
|
135 | + $body = $this->bodyText(); |
|
136 | + |
|
137 | + return $body; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Return the body html |
|
142 | + * |
|
143 | + * @return String |
|
144 | + */ |
|
145 | + public function bodyHtml() |
|
146 | + { |
|
147 | + return $this->input('HtmlBody'); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Return the body text |
|
152 | + * |
|
153 | + * @return String |
|
154 | + */ |
|
155 | + public function bodyText() |
|
156 | + { |
|
157 | + return $this->input('TextBody'); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * IsText |
|
162 | + * |
|
163 | + * @return Boolean |
|
164 | + */ |
|
165 | + public function bodyIsText() |
|
166 | + { |
|
167 | + return ! $this->bodyIsHtml(); |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * IsHtml |
|
172 | + * |
|
173 | + * @return Boolean |
|
174 | + */ |
|
175 | + public function bodyIsHtml() |
|
176 | + { |
|
177 | + return ! is_null($this->input('HtmlBody')) || $this->input('HtmlBody') !== ''; |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Get email headers |
|
182 | + * |
|
183 | + * @return Collection |
|
184 | + */ |
|
185 | + public function headers() : Collection |
|
186 | + { |
|
187 | + $collection = new Collection; |
|
188 | + |
|
189 | + foreach ($this->input('Headers') as $header) |
|
190 | + $collection->push(new Header($header['Name'], $header['Value'])); |
|
191 | + |
|
192 | + return $collection; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * retrieve a email header |
|
197 | + * |
|
198 | + * return Array |
|
199 | + */ |
|
200 | + public function header($name) : Header |
|
201 | + { |
|
202 | + return $this->headers()->filter(function ($header) use ($name) { |
|
203 | + return $header->name === $name; |
|
204 | + })->first(); |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Determinate if the email is marked as spam |
|
209 | + * |
|
210 | + * @return Boolean |
|
211 | + */ |
|
212 | + public function isSpam() |
|
213 | + { |
|
214 | + $header = $this->header('X-Spam-Flag'); |
|
215 | + return $header->value === 'NO' ? false : true; |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * Has attachements |
|
220 | + * |
|
221 | + * @return Boolean |
|
222 | + */ |
|
223 | + public function hasAttachements() |
|
224 | + { |
|
225 | + return $this->attachements->isEmpty(); |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * Attachments |
|
230 | + * |
|
231 | + * @return Collection<File> |
|
232 | + */ |
|
233 | + public function attachements() : Collection |
|
234 | + { |
|
235 | + $collection = new Collection; |
|
236 | + |
|
237 | + foreach ($this->input('Attachments') as $attachment) |
|
238 | + $collection->push( |
|
239 | + new Attachment( |
|
240 | + $attachment['Name'], |
|
241 | + ( isset($attachment['Content']) ? $attachment['Content'] : '' ), |
|
242 | + $attachment['ContentType'], |
|
243 | + $attachment['ContentLength'] |
|
244 | + ) |
|
245 | + ); |
|
246 | + |
|
247 | + return $collection; |
|
248 | + } |
|
249 | 249 | } |