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