Completed
Push — master ( 987613...8e6cf9 )
by Jacob
02:35
created
src/Archangel.php 2 patches
Doc Comments   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
      * @param string $address email address for the recipient
84 84
      * @param string $title   name of the recipient (optional)
85 85
 
86
-     * @return object instantiated $this
86
+     * @return Archangel instantiated $this
87 87
      */
88 88
     public function addTo($address, $title = '')
89 89
     {
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
      * @param string $address email address for the cc recipient
102 102
      * @param string $title   name of the cc recipient (optional)
103 103
      *
104
-     * @return object instantiated $this
104
+     * @return Archangel instantiated $this
105 105
      */
106 106
     public function addCC($address, $title = '')
107 107
     {
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
      * @param string $address email address for the bcc recipient
120 120
      * @param string $title   name of the bcc recipient (optional)
121 121
      *
122
-     * @return object instantiated $this
122
+     * @return Archangel instantiated $this
123 123
      */
124 124
     public function addBCC($address, $title = '')
125 125
     {
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
      * @param string $address email address for the sender
138 138
      * @param string $title   name of the sender (optional)
139 139
      *
140
-     * @return object instantiated $this
140
+     * @return Archangel instantiated $this
141 141
      */
142 142
     public function setFrom($address, $title = '')
143 143
     {
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
      * @param string $address email address for the reply-to
156 156
      * @param string $title   name of the reply-to (optional)
157 157
      *
158
-     * @return object instantiated $this
158
+     * @return Archangel instantiated $this
159 159
      */
160 160
     public function setReplyTo($address, $title = '')
161 161
     {
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
      *
173 173
      * @param string $subject subject for the email
174 174
      *
175
-     * @return object instantiated $this
175
+     * @return Archangel instantiated $this
176 176
      */
177 177
     public function setSubject($subject)
178 178
     {
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
      *
187 187
      * @param string $message the plain-text message
188 188
      *
189
-     * @return object instantiated $this
189
+     * @return Archangel instantiated $this
190 190
      */
191 191
     public function setPlainMessage($message)
192 192
     {
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
      *
201 201
      * @param string $message the html message
202 202
      *
203
-     * @return object instantiated $this
203
+     * @return Archangel instantiated $this
204 204
      */
205 205
     public function setHTMLMessage($message)
206 206
     {
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
      * @param string $type  mime type of the file
217 217
      * @param string $title the title of the attachment (optional)
218 218
      *
219
-     * @return object instantiated $this
219
+     * @return Archangel instantiated $this
220 220
      */
221 221
     public function addAttachment($path, $type, $title = '')
222 222
     {
Please login to merge, or discard this patch.
Indentation   +403 added lines, -404 removed lines patch added patch discarded remove patch
@@ -16,410 +16,409 @@
 block discarded – undo
16 16
 class Archangel implements LoggerAwareInterface
17 17
 {
18 18
 
19
-    /** @var string $subject */
20
-    protected $subject;
21
-
22
-    /** @var array $toAddresses */
23
-    protected $toAddresses = array();
24
-
25
-    /** @var array $ccAddresses */
26
-    protected $ccAddresses = array();
27
-
28
-    /** @var array $bccAddresses */
29
-    protected $bccAddresses = array();
30
-
31
-    /** @var array $headers */
32
-    protected $headers = array();
33
-
34
-    /** @var string $plainMessage */
35
-    protected $plainMessage;
36
-
37
-    /** @var string $htmlMessage */
38
-    protected $htmlMessage;
39
-
40
-    /** @var array $attachments */
41
-    protected $attachments = array();
42
-
43
-    /** @var string $boundary */
44
-    protected $boundary;
45
-
46
-    /** @var string $alternativeBoundary */
47
-    protected $alternativeBoundary;
48
-
49
-    /** @var LoggerInterface */
50
-    protected $logger;
51
-
52
-    /** @var string LINE_BREAK */
53
-    const LINE_BREAK = "\r\n";
54
-
55
-    /**
56
-     * @param string $mailer
57
-     */
58
-    public function __construct($mailer = null)
59
-    {
60
-        if (is_null($mailer)) {
61
-            $mailer = sprintf('PHP/%s', phpversion());
62
-        }
63
-        $this->headers['X-Mailer'] = $mailer;
64
-
65
-        $this->logger = new NullLogger();
66
-    }
67
-
68
-    /**
69
-     * @param LoggerInterface $logger
70
-     *
71
-     * @return $this;
72
-     */
73
-    public function setLogger(LoggerInterface $logger)
74
-    {
75
-        $this->logger = $logger;
76
-
77
-        return $this;
78
-    }
79
-
80
-    /**
81
-     * Setter method for adding recipients
82
-     *
83
-     * @param string $address email address for the recipient
84
-     * @param string $title   name of the recipient (optional)
85
-
86
-     * @return object instantiated $this
87
-     */
88
-    public function addTo($address, $title = '')
89
-    {
90
-        if (!empty($title)) {
91
-            $address = sprintf('"%s" <%s>', $title, $address);
92
-        }
93
-        array_push($this->toAddresses, $address);
94
-
95
-        return $this;
96
-    }
97
-
98
-    /**
99
-     * Setter method for adding cc recipients
100
-     *
101
-     * @param string $address email address for the cc recipient
102
-     * @param string $title   name of the cc recipient (optional)
103
-     *
104
-     * @return object instantiated $this
105
-     */
106
-    public function addCC($address, $title = '')
107
-    {
108
-        if (!empty($title)) {
109
-            $address = sprintf('"%s" <%s>', $title, $address);
110
-        }
111
-        array_push($this->ccAddresses, $address);
112
-
113
-        return $this;
114
-    }
115
-
116
-    /**
117
-     * Setter method for adding bcc recipients
118
-     *
119
-     * @param string $address email address for the bcc recipient
120
-     * @param string $title   name of the bcc recipient (optional)
121
-     *
122
-     * @return object instantiated $this
123
-     */
124
-    public function addBCC($address, $title = '')
125
-    {
126
-        if (!empty($title)) {
127
-            $address = sprintf('"%s" <%s>', $title, $address);
128
-        }
129
-        array_push($this->bccAddresses, $address);
130
-
131
-        return $this;
132
-    }
133
-
134
-    /**
135
-     * Setter method for setting the single 'from' field
136
-     *
137
-     * @param string $address email address for the sender
138
-     * @param string $title   name of the sender (optional)
139
-     *
140
-     * @return object instantiated $this
141
-     */
142
-    public function setFrom($address, $title = '')
143
-    {
144
-        if (!empty($title)) {
145
-            $address = sprintf('"%s" <%s>', $title, $address);
146
-        }
147
-        $this->headers['From'] = $address;
148
-
149
-        return $this;
150
-    }
151
-
152
-    /**
153
-     * Setter method for setting the single 'reply-to' field
154
-     *
155
-     * @param string $address email address for the reply-to
156
-     * @param string $title   name of the reply-to (optional)
157
-     *
158
-     * @return object instantiated $this
159
-     */
160
-    public function setReplyTo($address, $title = '')
161
-    {
162
-        if (!empty($title)) {
163
-            $address = sprintf('"%s" <%s>', $title, $address);
164
-        }
165
-        $this->headers['Reply-To'] = $address;
166
-
167
-        return $this;
168
-    }
169
-
170
-    /**
171
-     * Setter method for setting a subject
172
-     *
173
-     * @param string $subject subject for the email
174
-     *
175
-     * @return object instantiated $this
176
-     */
177
-    public function setSubject($subject)
178
-    {
179
-        $this->subject = $subject;
180
-
181
-        return $this;
182
-    }
183
-
184
-    /**
185
-     * Setter method for the plain text message
186
-     *
187
-     * @param string $message the plain-text message
188
-     *
189
-     * @return object instantiated $this
190
-     */
191
-    public function setPlainMessage($message)
192
-    {
193
-        $this->plainMessage = $message;
194
-
195
-        return $this;
196
-    }
197
-
198
-    /**
199
-     * Setter method for the html message
200
-     *
201
-     * @param string $message the html message
202
-     *
203
-     * @return object instantiated $this
204
-     */
205
-    public function setHTMLMessage($message)
206
-    {
207
-        $this->htmlMessage = $message;
208
-
209
-        return $this;
210
-    }
211
-
212
-    /**
213
-     * Setter method for adding attachments
214
-     *
215
-     * @param string $path  the full path of the attachment
216
-     * @param string $type  mime type of the file
217
-     * @param string $title the title of the attachment (optional)
218
-     *
219
-     * @return object instantiated $this
220
-     */
221
-    public function addAttachment($path, $type, $title = '')
222
-    {
223
-        array_push($this->attachments, array(
224
-          'path' => $path,
225
-          'type' => $type,
226
-          'title' => $title,
227
-        ));
228
-
229
-        return $this;
230
-    }
231
-
232
-    /**
233
-     * The executing step, the actual sending of the email
234
-     * First checks to make sure the minimum fields are set (returns false if they are not)
235
-     * Second it attempts to send the mail with php's mail() (returns false if it fails)
236
-     *
237
-     * return boolean whether or not the email was valid & sent
238
-     */
239
-    public function send()
240
-    {
241
-        if (!$this->checkRequiredFields()) {
242
-            return false;
243
-        }
244
-
245
-        $recipients = $this->buildTo();
246
-        $subject = $this->subject;
247
-        $message = $this->buildMessage();
248
-        $headers = $this->buildHeaders();
249
-
250
-        return mail($recipients, $subject, $message, $headers);
251
-    }
252
-
253
-    /**
254
-     * Call to check the minimum required fields
255
-     *
256
-     * @return boolean whether or not the email meets the minimum required fields
257
-     */
258
-    protected function checkRequiredFields()
259
-    {
260
-        if (empty($this->toAddresses)) {
261
-            return false;
262
-        }
263
-        if (empty($this->subject)) {
264
-            return false;
265
-        }
266
-
267
-        if (empty($this->plainMessage) && empty($this->htmlMessage) && empty($this->attachments)) {
268
-            return false;
269
-        }
270
-
271
-        return true;
272
-    }
273
-
274
-    /**
275
-     * Build the recipients from 'to'
276
-     *
277
-     * @return string comma-separated lit of recipients
278
-     */
279
-    protected function buildTo()
280
-    {
281
-        return implode(', ', $this->toAddresses);
282
-    }
283
-
284
-    /**
285
-     * Long, nasty creater of the actual message, with all the multipart logic you'd never want to see
286
-     *
287
-     * @return string email message
288
-     */
289
-    protected function buildMessage()
290
-    {
291
-        $messageString = '';
19
+	/** @var string $subject */
20
+	protected $subject;
21
+
22
+	/** @var array $toAddresses */
23
+	protected $toAddresses = array();
24
+
25
+	/** @var array $ccAddresses */
26
+	protected $ccAddresses = array();
27
+
28
+	/** @var array $bccAddresses */
29
+	protected $bccAddresses = array();
30
+
31
+	/** @var array $headers */
32
+	protected $headers = array();
33
+
34
+	/** @var string $plainMessage */
35
+	protected $plainMessage;
36
+
37
+	/** @var string $htmlMessage */
38
+	protected $htmlMessage;
39
+
40
+	/** @var array $attachments */
41
+	protected $attachments = array();
42
+
43
+	/** @var string $boundary */
44
+	protected $boundary;
45
+
46
+	/** @var string $alternativeBoundary */
47
+	protected $alternativeBoundary;
48
+
49
+	/** @var LoggerInterface */
50
+	protected $logger;
51
+
52
+	/** @var string LINE_BREAK */
53
+	const LINE_BREAK = "\r\n";
54
+
55
+	/**
56
+	 * @param string $mailer
57
+	 */
58
+	public function __construct($mailer = null)
59
+	{
60
+		if (is_null($mailer)) {
61
+			$mailer = sprintf('PHP/%s', phpversion());
62
+		}
63
+		$this->headers['X-Mailer'] = $mailer;
64
+
65
+		$this->logger = new NullLogger();
66
+	}
67
+
68
+	/**
69
+	 * @param LoggerInterface $logger
70
+	 *
71
+	 * @return $this;
72
+	 */
73
+	public function setLogger(LoggerInterface $logger)
74
+	{
75
+		$this->logger = $logger;
76
+
77
+		return $this;
78
+	}
79
+
80
+	/**
81
+	 * Setter method for adding recipients
82
+	 *
83
+	 * @param string $address email address for the recipient
84
+	 * @param string $title   name of the recipient (optional)
85
+	 * @return object instantiated $this
86
+	 */
87
+	public function addTo($address, $title = '')
88
+	{
89
+		if (!empty($title)) {
90
+			$address = sprintf('"%s" <%s>', $title, $address);
91
+		}
92
+		array_push($this->toAddresses, $address);
93
+
94
+		return $this;
95
+	}
96
+
97
+	/**
98
+	 * Setter method for adding cc recipients
99
+	 *
100
+	 * @param string $address email address for the cc recipient
101
+	 * @param string $title   name of the cc recipient (optional)
102
+	 *
103
+	 * @return object instantiated $this
104
+	 */
105
+	public function addCC($address, $title = '')
106
+	{
107
+		if (!empty($title)) {
108
+			$address = sprintf('"%s" <%s>', $title, $address);
109
+		}
110
+		array_push($this->ccAddresses, $address);
111
+
112
+		return $this;
113
+	}
114
+
115
+	/**
116
+	 * Setter method for adding bcc recipients
117
+	 *
118
+	 * @param string $address email address for the bcc recipient
119
+	 * @param string $title   name of the bcc recipient (optional)
120
+	 *
121
+	 * @return object instantiated $this
122
+	 */
123
+	public function addBCC($address, $title = '')
124
+	{
125
+		if (!empty($title)) {
126
+			$address = sprintf('"%s" <%s>', $title, $address);
127
+		}
128
+		array_push($this->bccAddresses, $address);
129
+
130
+		return $this;
131
+	}
132
+
133
+	/**
134
+	 * Setter method for setting the single 'from' field
135
+	 *
136
+	 * @param string $address email address for the sender
137
+	 * @param string $title   name of the sender (optional)
138
+	 *
139
+	 * @return object instantiated $this
140
+	 */
141
+	public function setFrom($address, $title = '')
142
+	{
143
+		if (!empty($title)) {
144
+			$address = sprintf('"%s" <%s>', $title, $address);
145
+		}
146
+		$this->headers['From'] = $address;
147
+
148
+		return $this;
149
+	}
150
+
151
+	/**
152
+	 * Setter method for setting the single 'reply-to' field
153
+	 *
154
+	 * @param string $address email address for the reply-to
155
+	 * @param string $title   name of the reply-to (optional)
156
+	 *
157
+	 * @return object instantiated $this
158
+	 */
159
+	public function setReplyTo($address, $title = '')
160
+	{
161
+		if (!empty($title)) {
162
+			$address = sprintf('"%s" <%s>', $title, $address);
163
+		}
164
+		$this->headers['Reply-To'] = $address;
165
+
166
+		return $this;
167
+	}
168
+
169
+	/**
170
+	 * Setter method for setting a subject
171
+	 *
172
+	 * @param string $subject subject for the email
173
+	 *
174
+	 * @return object instantiated $this
175
+	 */
176
+	public function setSubject($subject)
177
+	{
178
+		$this->subject = $subject;
179
+
180
+		return $this;
181
+	}
182
+
183
+	/**
184
+	 * Setter method for the plain text message
185
+	 *
186
+	 * @param string $message the plain-text message
187
+	 *
188
+	 * @return object instantiated $this
189
+	 */
190
+	public function setPlainMessage($message)
191
+	{
192
+		$this->plainMessage = $message;
193
+
194
+		return $this;
195
+	}
196
+
197
+	/**
198
+	 * Setter method for the html message
199
+	 *
200
+	 * @param string $message the html message
201
+	 *
202
+	 * @return object instantiated $this
203
+	 */
204
+	public function setHTMLMessage($message)
205
+	{
206
+		$this->htmlMessage = $message;
207
+
208
+		return $this;
209
+	}
210
+
211
+	/**
212
+	 * Setter method for adding attachments
213
+	 *
214
+	 * @param string $path  the full path of the attachment
215
+	 * @param string $type  mime type of the file
216
+	 * @param string $title the title of the attachment (optional)
217
+	 *
218
+	 * @return object instantiated $this
219
+	 */
220
+	public function addAttachment($path, $type, $title = '')
221
+	{
222
+		array_push($this->attachments, array(
223
+		  'path' => $path,
224
+		  'type' => $type,
225
+		  'title' => $title,
226
+		));
227
+
228
+		return $this;
229
+	}
230
+
231
+	/**
232
+	 * The executing step, the actual sending of the email
233
+	 * First checks to make sure the minimum fields are set (returns false if they are not)
234
+	 * Second it attempts to send the mail with php's mail() (returns false if it fails)
235
+	 *
236
+	 * return boolean whether or not the email was valid & sent
237
+	 */
238
+	public function send()
239
+	{
240
+		if (!$this->checkRequiredFields()) {
241
+			return false;
242
+		}
243
+
244
+		$recipients = $this->buildTo();
245
+		$subject = $this->subject;
246
+		$message = $this->buildMessage();
247
+		$headers = $this->buildHeaders();
248
+
249
+		return mail($recipients, $subject, $message, $headers);
250
+	}
251
+
252
+	/**
253
+	 * Call to check the minimum required fields
254
+	 *
255
+	 * @return boolean whether or not the email meets the minimum required fields
256
+	 */
257
+	protected function checkRequiredFields()
258
+	{
259
+		if (empty($this->toAddresses)) {
260
+			return false;
261
+		}
262
+		if (empty($this->subject)) {
263
+			return false;
264
+		}
265
+
266
+		if (empty($this->plainMessage) && empty($this->htmlMessage) && empty($this->attachments)) {
267
+			return false;
268
+		}
269
+
270
+		return true;
271
+	}
272
+
273
+	/**
274
+	 * Build the recipients from 'to'
275
+	 *
276
+	 * @return string comma-separated lit of recipients
277
+	 */
278
+	protected function buildTo()
279
+	{
280
+		return implode(', ', $this->toAddresses);
281
+	}
282
+
283
+	/**
284
+	 * Long, nasty creater of the actual message, with all the multipart logic you'd never want to see
285
+	 *
286
+	 * @return string email message
287
+	 */
288
+	protected function buildMessage()
289
+	{
290
+		$messageString = '';
292 291
         
293
-        if (!empty($this->attachments)) {
294
-            $messageString .= "--{$this->getBoundary()}" . self::LINE_BREAK;
295
-        }
296
-        if (!empty($this->plainMessage) && !empty($this->htmlMessage)) {
297
-            if (!empty($this->attachments)) {
298
-                $messageString .= "Content-Type: multipart/alternative; boundary={$this->getAlternativeBoundary()}" . self::LINE_BREAK;
299
-                $messageString .= self::LINE_BREAK;
300
-            }
301
-            $messageString .= "--{$this->getAlternativeBoundary()}" . self::LINE_BREAK;
302
-            $messageString .= 'Content-Type: text/plain; charset="iso-8859"' . self::LINE_BREAK;
303
-            $messageString .= 'Content-Transfer-Encoding: 7bit' . self::LINE_BREAK;
304
-            $messageString .= self::LINE_BREAK;
305
-            $messageString .= $this->plainMessage;
306
-            $messageString .= self::LINE_BREAK;
307
-            $messageString .= "--{$this->getAlternativeBoundary()}" . self::LINE_BREAK;
308
-            $messageString .= 'Content-Type: text/html; charset="iso-8859-1"' . self::LINE_BREAK;
309
-            $messageString .= 'Content-Transfer-Encoding: 7bit' . self::LINE_BREAK;
310
-            $messageString .= self::LINE_BREAK;
311
-            $messageString .= $this->htmlMessage;
312
-            $messageString .= self::LINE_BREAK;
313
-            $messageString .= "--{$this->getAlternativeBoundary()}--" . self::LINE_BREAK;
314
-            $messageString .= self::LINE_BREAK;
315
-        } elseif (!empty($this->plainMessage)) {
316
-            if (!empty($this->attachments)) {
317
-                $messageString .= 'Content-Type: text/plain; charset="iso-8859"' . self::LINE_BREAK;
318
-                $messageString .= 'Content-Transfer-Encoding: 7bit' . self::LINE_BREAK;
319
-                $messageString .= self::LINE_BREAK;
320
-            }
321
-            $messageString .= $this->plainMessage;
322
-            $messageString .= self::LINE_BREAK;
323
-        } elseif (!empty($this->htmlMessage)) {
324
-            if (!empty($this->attachments)) {
325
-                $messageString .= 'Content-Type: text/html; charset="iso-8859-1"' . self::LINE_BREAK;
326
-                $messageString .= 'Content-Transfer-Encoding: 7bit' . self::LINE_BREAK;
327
-                $messageString .= self::LINE_BREAK;
328
-            }
329
-            $messageString .= $this->htmlMessage;
330
-            $messageString .= self::LINE_BREAK;
331
-        }
332
-        if (!empty($this->attachments)) {
333
-            foreach ($this->attachments as $attachment) {
334
-                $messageString .= "--{$this->getBoundary()}" . self::LINE_BREAK;
335
-                $messageString .= "Content-Type: {$attachment['type']}; name=\"{$attachment['title']}\"" . self::LINE_BREAK;
336
-                $messageString .= 'Content-Transfer-Encoding: base64' . self::LINE_BREAK;
337
-                $messageString .= 'Content-Disposition: attachment' . self::LINE_BREAK;
338
-                $messageString .= self::LINE_BREAK;
339
-                $messageString .= $this->buildAttachmentContent($attachment);
340
-                $messageString .= self::LINE_BREAK;
341
-            }
342
-            $messageString .= "--{$this->getBoundary()}--" . self::LINE_BREAK;
343
-        }
344
-        return $messageString;
345
-    }
346
-
347
-
348
-    /**
349
-     * Builder for the additional headers needed for multipart emails
350
-     *
351
-     * @return string headers needed for multipart
352
-     */
353
-    protected function buildHeaders()
354
-    {
355
-        $headerString = '';
356
-        foreach ($this->headers as $key => $value) {
357
-            $headerString .= sprintf('%s: %s', $key, $value) . self::LINE_BREAK;
358
-        }
359
-
360
-        if (!empty($this->ccAddresses)) {
361
-            $headerString .= 'CC: ' . implode(', ', $this->ccAddresses) . self::LINE_BREAK;
362
-        }
363
-        if (!empty($this->bccAddresses)) {
364
-            $headerString .= 'BCC: ' . implode(', ', $this->bccAddresses) . self::LINE_BREAK;
365
-        }
292
+		if (!empty($this->attachments)) {
293
+			$messageString .= "--{$this->getBoundary()}" . self::LINE_BREAK;
294
+		}
295
+		if (!empty($this->plainMessage) && !empty($this->htmlMessage)) {
296
+			if (!empty($this->attachments)) {
297
+				$messageString .= "Content-Type: multipart/alternative; boundary={$this->getAlternativeBoundary()}" . self::LINE_BREAK;
298
+				$messageString .= self::LINE_BREAK;
299
+			}
300
+			$messageString .= "--{$this->getAlternativeBoundary()}" . self::LINE_BREAK;
301
+			$messageString .= 'Content-Type: text/plain; charset="iso-8859"' . self::LINE_BREAK;
302
+			$messageString .= 'Content-Transfer-Encoding: 7bit' . self::LINE_BREAK;
303
+			$messageString .= self::LINE_BREAK;
304
+			$messageString .= $this->plainMessage;
305
+			$messageString .= self::LINE_BREAK;
306
+			$messageString .= "--{$this->getAlternativeBoundary()}" . self::LINE_BREAK;
307
+			$messageString .= 'Content-Type: text/html; charset="iso-8859-1"' . self::LINE_BREAK;
308
+			$messageString .= 'Content-Transfer-Encoding: 7bit' . self::LINE_BREAK;
309
+			$messageString .= self::LINE_BREAK;
310
+			$messageString .= $this->htmlMessage;
311
+			$messageString .= self::LINE_BREAK;
312
+			$messageString .= "--{$this->getAlternativeBoundary()}--" . self::LINE_BREAK;
313
+			$messageString .= self::LINE_BREAK;
314
+		} elseif (!empty($this->plainMessage)) {
315
+			if (!empty($this->attachments)) {
316
+				$messageString .= 'Content-Type: text/plain; charset="iso-8859"' . self::LINE_BREAK;
317
+				$messageString .= 'Content-Transfer-Encoding: 7bit' . self::LINE_BREAK;
318
+				$messageString .= self::LINE_BREAK;
319
+			}
320
+			$messageString .= $this->plainMessage;
321
+			$messageString .= self::LINE_BREAK;
322
+		} elseif (!empty($this->htmlMessage)) {
323
+			if (!empty($this->attachments)) {
324
+				$messageString .= 'Content-Type: text/html; charset="iso-8859-1"' . self::LINE_BREAK;
325
+				$messageString .= 'Content-Transfer-Encoding: 7bit' . self::LINE_BREAK;
326
+				$messageString .= self::LINE_BREAK;
327
+			}
328
+			$messageString .= $this->htmlMessage;
329
+			$messageString .= self::LINE_BREAK;
330
+		}
331
+		if (!empty($this->attachments)) {
332
+			foreach ($this->attachments as $attachment) {
333
+				$messageString .= "--{$this->getBoundary()}" . self::LINE_BREAK;
334
+				$messageString .= "Content-Type: {$attachment['type']}; name=\"{$attachment['title']}\"" . self::LINE_BREAK;
335
+				$messageString .= 'Content-Transfer-Encoding: base64' . self::LINE_BREAK;
336
+				$messageString .= 'Content-Disposition: attachment' . self::LINE_BREAK;
337
+				$messageString .= self::LINE_BREAK;
338
+				$messageString .= $this->buildAttachmentContent($attachment);
339
+				$messageString .= self::LINE_BREAK;
340
+			}
341
+			$messageString .= "--{$this->getBoundary()}--" . self::LINE_BREAK;
342
+		}
343
+		return $messageString;
344
+	}
345
+
346
+
347
+	/**
348
+	 * Builder for the additional headers needed for multipart emails
349
+	 *
350
+	 * @return string headers needed for multipart
351
+	 */
352
+	protected function buildHeaders()
353
+	{
354
+		$headerString = '';
355
+		foreach ($this->headers as $key => $value) {
356
+			$headerString .= sprintf('%s: %s', $key, $value) . self::LINE_BREAK;
357
+		}
358
+
359
+		if (!empty($this->ccAddresses)) {
360
+			$headerString .= 'CC: ' . implode(', ', $this->ccAddresses) . self::LINE_BREAK;
361
+		}
362
+		if (!empty($this->bccAddresses)) {
363
+			$headerString .= 'BCC: ' . implode(', ', $this->bccAddresses) . self::LINE_BREAK;
364
+		}
366 365
         
367
-        if (!empty($this->attachments)) {
368
-            $headerString .= "Content-Type: multipart/mixed; boundary=\"{$this->getBoundary()}\"";
369
-        } elseif (!empty($this->plainMessage) && !empty($this->htmlMessage)) {
370
-            $headerString .= "Content-Type: multipart/alternative; boundary=\"{$this->getAlternativeBoundary()}\"";
371
-        } elseif (!empty($this->htmlMessage)) {
372
-            $headerString .= 'Content-type: text/html; charset="iso-8859-1"';
373
-        }
374
-
375
-        return $headerString;
376
-    }
377
-
378
-    /**
379
-     * File reader for attachments
380
-     *
381
-     * @return string binary representation of file, base64'd
382
-     */
383
-    protected function buildAttachmentContent($attachment)
384
-    {
385
-        if (!file_exists($attachment['path'])) {
386
-            return ''; // todo log error
387
-        }
388
-
389
-        $handle = fopen($attachment['path'], 'r');
390
-        $contents = fread($handle, filesize($attachment['path']));
391
-        fclose($handle);
392
-
393
-        $contents = base64_encode($contents);
394
-        $contents = chunk_split($contents);
395
-        return $contents;
396
-    }
397
-
398
-    /**
399
-     * Holder for the boundry logic
400
-     * Not called/created unless it's needed
401
-     *
402
-     * @return  string  boundary
403
-     */
404
-    protected function getBoundary()
405
-    {
406
-        if (!isset($this->boundary)) {
407
-            $this->boundary = sprintf('PHP-mixed-%s', uniqid());
408
-        }
409
-        return $this->boundary;
410
-    }
411
-
412
-    /**
413
-     * Holder to create the alternative boundry logic
414
-     * Not called/created unless it's needed
415
-     *
416
-     * @return string alternative boundary
417
-     */
418
-    protected function getAlternativeBoundary()
419
-    {
420
-        if (!isset($this->alternativeBoundary)) {
421
-            $this->alternativeBoundary = sprintf('PHP-alternative-%s', uniqid());
422
-        }
423
-        return $this->alternativeBoundary;
424
-    }
366
+		if (!empty($this->attachments)) {
367
+			$headerString .= "Content-Type: multipart/mixed; boundary=\"{$this->getBoundary()}\"";
368
+		} elseif (!empty($this->plainMessage) && !empty($this->htmlMessage)) {
369
+			$headerString .= "Content-Type: multipart/alternative; boundary=\"{$this->getAlternativeBoundary()}\"";
370
+		} elseif (!empty($this->htmlMessage)) {
371
+			$headerString .= 'Content-type: text/html; charset="iso-8859-1"';
372
+		}
373
+
374
+		return $headerString;
375
+	}
376
+
377
+	/**
378
+	 * File reader for attachments
379
+	 *
380
+	 * @return string binary representation of file, base64'd
381
+	 */
382
+	protected function buildAttachmentContent($attachment)
383
+	{
384
+		if (!file_exists($attachment['path'])) {
385
+			return ''; // todo log error
386
+		}
387
+
388
+		$handle = fopen($attachment['path'], 'r');
389
+		$contents = fread($handle, filesize($attachment['path']));
390
+		fclose($handle);
391
+
392
+		$contents = base64_encode($contents);
393
+		$contents = chunk_split($contents);
394
+		return $contents;
395
+	}
396
+
397
+	/**
398
+	 * Holder for the boundry logic
399
+	 * Not called/created unless it's needed
400
+	 *
401
+	 * @return  string  boundary
402
+	 */
403
+	protected function getBoundary()
404
+	{
405
+		if (!isset($this->boundary)) {
406
+			$this->boundary = sprintf('PHP-mixed-%s', uniqid());
407
+		}
408
+		return $this->boundary;
409
+	}
410
+
411
+	/**
412
+	 * Holder to create the alternative boundry logic
413
+	 * Not called/created unless it's needed
414
+	 *
415
+	 * @return string alternative boundary
416
+	 */
417
+	protected function getAlternativeBoundary()
418
+	{
419
+		if (!isset($this->alternativeBoundary)) {
420
+			$this->alternativeBoundary = sprintf('PHP-alternative-%s', uniqid());
421
+		}
422
+		return $this->alternativeBoundary;
423
+	}
425 424
 }
Please login to merge, or discard this patch.
tests/ArchangelTest.php 1 patch
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -7,76 +7,76 @@
 block discarded – undo
7 7
 class ArchangelTest extends PHPUnit_Framework_TestCase
8 8
 {
9 9
 
10
-    public function testIsInstanceOfArchangel()
11
-    {
12
-        $archangel = new Archangel();
13
-
14
-        $this->assertInstanceOf('Jacobemerick\Archangel\Archangel', $archangel);
15
-    }
16
-
17
-    public function testIsLoggerAwareInterface()
18
-    {
19
-        $archangel = new Archangel();
20
-
21
-        $this->assertInstanceOf('Psr\Log\LoggerAwareInterface', $archangel);
22
-    }
23
-
24
-    public function testConstructSetsDefaultMailer()
25
-    {
26
-        $archangel = new Archangel();
27
-        $mailer = sprintf('PHP/%s', phpversion());
28
-        $headers = array('X-Mailer' => $mailer);
29
-
30
-        $this->assertAttributeEquals($headers, 'headers', $archangel);
31
-    }
32
-
33
-    public function testConstructOverridesMailer()
34
-    {
35
-        $archangel = new Archangel('AwesomeMailer');
36
-        $headers = array('X-Mailer' => 'AwesomeMailer');
37
-
38
-        $this->assertAttributeEquals($headers, 'headers', $archangel);
39
-    }
40
-
41
-    public function testConstructSetsNullLogger()
42
-    {
43
-        $archangel = new Archangel();
44
-
45
-        $this->assertAttributeInstanceOf('Psr\Log\NullLogger', 'logger', $archangel);
46
-    }
47
-
48
-    public function testSetLogger()
49
-    {
50
-        $logger = $this->getMock('Psr\Log\LoggerInterface');
51
-        $archangel = new Archangel();
52
-        $archangel->setLogger($logger);
53
-
54
-        $this->assertAttributeSame($logger, 'logger', $archangel);
55
-    }
56
-
57
-    public function testAddTo()
58
-    {
59
-        $archangel = new Archangel();
60
-        $archangel->addTo('[email protected]');
61
-
62
-        $this->assertAttributeContains('[email protected]', 'toAddresses', $archangel);
63
-    }
64
-
65
-    public function testAddToMultiple()
66
-    {
67
-        $archangel = new Archangel();
68
-        $archangel->addTo('[email protected]');
69
-        $archangel->addTo('[email protected]');
70
-
71
-        $this->assertAttributeContains('[email protected]', 'toAddresses', $archangel);
72
-        $this->assertAttributeContains('[email protected]', 'toAddresses', $archangel);
73
-    }
74
-
75
-    public function testAddToWithTitle()
76
-    {
77
-        $archangel = new Archangel();
78
-        $archangel->addTo('[email protected]', 'Mr. Test Alot');
79
-
80
-        $this->assertAttributeContains('"Mr. Test Alot" <[email protected]>', 'toAddresses', $archangel);
81
-    }
10
+	public function testIsInstanceOfArchangel()
11
+	{
12
+		$archangel = new Archangel();
13
+
14
+		$this->assertInstanceOf('Jacobemerick\Archangel\Archangel', $archangel);
15
+	}
16
+
17
+	public function testIsLoggerAwareInterface()
18
+	{
19
+		$archangel = new Archangel();
20
+
21
+		$this->assertInstanceOf('Psr\Log\LoggerAwareInterface', $archangel);
22
+	}
23
+
24
+	public function testConstructSetsDefaultMailer()
25
+	{
26
+		$archangel = new Archangel();
27
+		$mailer = sprintf('PHP/%s', phpversion());
28
+		$headers = array('X-Mailer' => $mailer);
29
+
30
+		$this->assertAttributeEquals($headers, 'headers', $archangel);
31
+	}
32
+
33
+	public function testConstructOverridesMailer()
34
+	{
35
+		$archangel = new Archangel('AwesomeMailer');
36
+		$headers = array('X-Mailer' => 'AwesomeMailer');
37
+
38
+		$this->assertAttributeEquals($headers, 'headers', $archangel);
39
+	}
40
+
41
+	public function testConstructSetsNullLogger()
42
+	{
43
+		$archangel = new Archangel();
44
+
45
+		$this->assertAttributeInstanceOf('Psr\Log\NullLogger', 'logger', $archangel);
46
+	}
47
+
48
+	public function testSetLogger()
49
+	{
50
+		$logger = $this->getMock('Psr\Log\LoggerInterface');
51
+		$archangel = new Archangel();
52
+		$archangel->setLogger($logger);
53
+
54
+		$this->assertAttributeSame($logger, 'logger', $archangel);
55
+	}
56
+
57
+	public function testAddTo()
58
+	{
59
+		$archangel = new Archangel();
60
+		$archangel->addTo('[email protected]');
61
+
62
+		$this->assertAttributeContains('[email protected]', 'toAddresses', $archangel);
63
+	}
64
+
65
+	public function testAddToMultiple()
66
+	{
67
+		$archangel = new Archangel();
68
+		$archangel->addTo('[email protected]');
69
+		$archangel->addTo('[email protected]');
70
+
71
+		$this->assertAttributeContains('[email protected]', 'toAddresses', $archangel);
72
+		$this->assertAttributeContains('[email protected]', 'toAddresses', $archangel);
73
+	}
74
+
75
+	public function testAddToWithTitle()
76
+	{
77
+		$archangel = new Archangel();
78
+		$archangel->addTo('[email protected]', 'Mr. Test Alot');
79
+
80
+		$this->assertAttributeContains('"Mr. Test Alot" <[email protected]>', 'toAddresses', $archangel);
81
+	}
82 82
 }
Please login to merge, or discard this patch.