@@ -138,7 +138,7 @@ final class Message implements MessageContract
138
138
'eps ' => 'application/postscript ' ,
139
139
'ps ' => 'application/postscript ' ,
140
140
141
- // ms office
141
+ // MS Office
142
142
'doc ' => 'application/msword ' ,
143
143
'rtf ' => 'application/rtf ' ,
144
144
'xls ' => 'application/vnd.ms-excel ' ,
@@ -187,7 +187,7 @@ public function __clone()
187
187
188
188
/**
189
189
* @param string|null $subject Subject of message.
190
- * @return self
190
+ * @return $this
191
191
*/
192
192
public function setSubject ($ subject )
193
193
{
@@ -198,7 +198,7 @@ public function setSubject($subject)
198
198
199
199
/**
200
200
* @param string|null $html HTML text of message.
201
- * @return self
201
+ * @return $this
202
202
*/
203
203
public function setHtml ($ html = null )
204
204
{
@@ -216,7 +216,7 @@ public function setHtml($html = null)
216
216
217
217
/**
218
218
* @param string|null $text Plain text of message.
219
- * @return self
219
+ * @return $this
220
220
*/
221
221
public function setText ($ text = null )
222
222
{
@@ -258,7 +258,7 @@ public function setSender($email, $name = null)
258
258
* @param string $email Recipient email.
259
259
* @param string|null $name Recipient name.
260
260
* @param string $type Recipient type. May be 'to', 'cc' or 'bcc'. Default 'to'.
261
- * @return self
261
+ * @return $this
262
262
* @throws InvalidEmailException
263
263
*/
264
264
public function addRecipient ($ email , $ name = null , $ type = self ::RECIPIENT_TO )
@@ -290,7 +290,7 @@ public function getRecipientName($email)
290
290
291
291
/**
292
292
* @param string $email Recipient email.
293
- * @return self
293
+ * @return $this
294
294
*/
295
295
public function removeRecipient ($ email )
296
296
{
@@ -303,7 +303,7 @@ public function removeRecipient($email)
303
303
304
304
/**
305
305
* @param string $type Recipient type. May be 'to', 'cc', 'bcc' or null. Default null.
306
- * @return self
306
+ * @return $this
307
307
*/
308
308
public function removeRecipients ($ type = null )
309
309
{
@@ -327,7 +327,7 @@ public function removeRecipients($type = null)
327
327
* @param string $name
328
328
* @param string $content
329
329
* @param string|null $mime
330
- * @return self
330
+ * @return $this
331
331
*/
332
332
public function attachFromString ($ name , $ content , $ mime = null )
333
333
{
@@ -348,7 +348,7 @@ public function attachFromString($name, $content, $mime = null)
348
348
* @param string $name
349
349
* @param string $path
350
350
* @param string|null $mime
351
- * @return self
351
+ * @return $this
352
352
*/
353
353
public function attachFromFile ($ name , $ path , $ mime = null )
354
354
{
@@ -368,7 +368,7 @@ public function attachFromFile($name, $path, $mime = null)
368
368
369
369
/**
370
370
* @param string $name
371
- * @return self
371
+ * @return $this
372
372
*/
373
373
public function detach ($ name )
374
374
{
@@ -384,7 +384,7 @@ public function detach($name)
384
384
* @param string $id
385
385
* @param string $content
386
386
* @param string $mime
387
- * @return self
387
+ * @return $this
388
388
*/
389
389
public function setHtmlContentFromString ($ id , $ content , $ mime = 'application/octet-stream ' )
390
390
{
@@ -405,7 +405,7 @@ public function setHtmlContentFromString($id, $content, $mime = 'application/oct
405
405
* @param string $id
406
406
* @param string $path
407
407
* @param string $mime
408
- * @return self
408
+ * @return $this
409
409
*/
410
410
public function setHtmlContentFromFile ($ id , $ path , $ mime = 'application/octet-stream ' )
411
411
{
@@ -425,7 +425,7 @@ public function setHtmlContentFromFile($id, $path, $mime = 'application/octet-st
425
425
426
426
/**
427
427
* @param string $id
428
- * @return self
428
+ * @return $this
429
429
*/
430
430
public function unsetBodyHtmlContent ($ id )
431
431
{
@@ -440,7 +440,7 @@ public function unsetBodyHtmlContent($id)
440
440
/**
441
441
* @param string $header Header name.
442
442
* @param string|null $value Header values.
443
- * @return self
443
+ * @return $this
444
444
*/
445
445
public function setHeader ($ header , $ value )
446
446
{
@@ -475,7 +475,7 @@ public function getHeader($header)
475
475
476
476
/**
477
477
* @param string $header Header name.
478
- * @return string|null Header values.
478
+ * @return $this
479
479
*/
480
480
public function removeHeader ($ header )
481
481
{
@@ -485,7 +485,7 @@ public function removeHeader($header)
485
485
}
486
486
487
487
/**
488
- * @return string[] Recipients emails.
488
+ * @inheritDoc
489
489
*/
490
490
public function getRecipients ()
491
491
{
@@ -501,7 +501,7 @@ public function getSubject()
501
501
}
502
502
503
503
/**
504
- * @return string Rew string as email headers
504
+ * @inheritDoc
505
505
*/
506
506
public function getHeadersRaw ()
507
507
{
@@ -540,6 +540,9 @@ public function getBodyRaw()
540
540
return $ info ['data ' ];
541
541
}
542
542
543
+ /**
544
+ * @inheritDoc
545
+ */
543
546
public function getPersonalMessages ()
544
547
{
545
548
$ messages = array ();
@@ -572,9 +575,9 @@ public function serialize()
572
575
/**
573
576
* @inheritDoc
574
577
*/
575
- public function unserialize ($ serialized )
578
+ public function unserialize ($ data )
576
579
{
577
- $ raw = unserialize ($ serialized );
580
+ $ raw = unserialize ($ data );
578
581
$ empty = array (
579
582
'id ' => array (),
580
583
'headers ' => array (),
@@ -650,7 +653,7 @@ private function getMainInfo($onlyType)
650
653
if (!is_null ($ this ->text ) && is_null ($ this ->html )) {
651
654
$ result ['type ' ] = 'text/plain; charset=UTF-8 ' ;
652
655
if (!$ onlyType ) {
653
- $ result ['data ' ] = quoted_printable_encode ($ this ->text );
656
+ $ result ['data ' ] = $ this -> encodeBody ($ this ->text );
654
657
}
655
658
return $ result ;
656
659
}
@@ -671,7 +674,7 @@ private function getMainInfo($onlyType)
671
674
$ text .= 'Content-Type: text/plain; charset=UTF-8 ' . $ eol ;
672
675
$ text .= 'Content-Transfer-Encoding: quoted-printable ' . $ eol ;
673
676
$ text .= $ eol ;
674
- $ text .= quoted_printable_encode ($ this ->text ) . $ eol ;
677
+ $ text .= $ this -> encodeBody ($ this ->text ) . $ eol ;
675
678
676
679
$ html = $ eol ;
677
680
$ html .= $ this ->encodeHeader ('Content-Type ' , $ htmlInfo ['type ' ]) . $ eol ;
@@ -698,7 +701,7 @@ private function getHtmlInfo($onlyType)
698
701
if (is_null ($ this ->html )) {
699
702
return $ result ;
700
703
}
701
- $ raw = quoted_printable_encode ($ this ->html );
704
+ $ raw = $ this -> encodeBody ($ this ->html );
702
705
if (empty ($ this ->contents )) {
703
706
$ result ['type ' ] = 'text/html; charset=UTF-8 ' ;
704
707
} else {
@@ -749,16 +752,13 @@ private function randomString()
749
752
{
750
753
$ start = 268435456 ;
751
754
$ finish = 4294967295 ;
752
- $ rand = null ;
753
- if (function_exists ('random_int ' )) {
754
- try {
755
- /** @noinspection PhpElementIsNotAvailableInCurrentPhpVersionInspection */
756
- $ rand = random_int ($ start , $ finish );
757
- } catch (Exception $ e ) {
758
- $ rand = null ;
759
- }
755
+ if (!function_exists ('random_int ' )) {
756
+ return dechex (rand ($ start , $ finish ));
760
757
}
761
- if (!$ rand ) {
758
+
759
+ try {
760
+ $ rand = random_int ($ start , $ finish );
761
+ } catch (Exception $ e ) {
762
762
$ rand = rand ($ start , $ finish );
763
763
}
764
764
return dechex ($ rand );
@@ -767,14 +767,14 @@ private function randomString()
767
767
/**
768
768
* @param string $header Header name.
769
769
* @param string $value Header values.
770
- * @return self
770
+ * @return void
771
771
*/
772
772
private function setAnyHeader ($ header , $ value )
773
773
{
774
774
$ header = $ this ->prepareHeaderName ($ header );
775
775
$ value = $ this ->prepareHeaderValue ($ value );
776
776
if (!$ header ) {
777
- return $ this ;
777
+ return ;
778
778
}
779
779
if ($ value ) {
780
780
$ this ->headers [$ header ] = $ value ;
@@ -783,26 +783,24 @@ private function setAnyHeader($header, $value)
783
783
unset($ this ->headers [$ header ]);
784
784
}
785
785
}
786
- return $ this ;
787
786
}
788
787
789
788
/**
790
789
* @param string $header Header name.
791
- * @return string|null Header values.
790
+ * @return void
792
791
*/
793
792
private function removeAnyHeader ($ header )
794
793
{
795
794
$ header = $ this ->prepareHeaderName ($ header );
796
795
if (array_key_exists ($ header , $ this ->headers )) {
797
796
unset($ this ->headers [$ header ]);
798
797
}
799
- return $ this ;
800
798
}
801
799
802
800
/**
803
801
* @param string $header
804
802
* @param bool $removing
805
- * @return bool
803
+ * @return void
806
804
* @throws HeaderNotModifiedException
807
805
*/
808
806
private function touchHeader ($ header , $ removing )
@@ -814,7 +812,6 @@ private function touchHeader($header, $removing)
814
812
$ method = is_array ($ this ->protectedHeaders [$ header ]) ? $ this ->protectedHeaders [$ header ][$ key ] : null ;
815
813
throw new HeaderNotModifiedException ($ header , $ method );
816
814
}
817
- return true ;
818
815
}
819
816
820
817
/**
@@ -829,14 +826,13 @@ private function normalizeHeaderName($name)
829
826
if ($ name === 'message-id ' ) {
830
827
return 'Message-ID ' ;
831
828
}
832
- $ name = preg_replace_callback (
829
+ return preg_replace_callback (
833
830
'/(^|-)[a-z]/ui ' ,
834
831
function ($ match ) {
835
832
return strtoupper ($ match [0 ]);
836
833
},
837
834
$ name
838
835
);
839
- return $ name ;
840
836
}
841
837
842
838
/**
@@ -931,8 +927,7 @@ private function prepareAttachmentName($name)
931
927
*/
932
928
private function prepareContentId ($ name )
933
929
{
934
- $ name = (string )$ name ;
935
- return $ name ;
930
+ return (string )$ name ;
936
931
}
937
932
938
933
/**
@@ -1004,6 +999,15 @@ private function encodeHeader($header, $value)
1004
999
return $ result ;
1005
1000
}
1006
1001
1002
+ /**
1003
+ * @param string $data
1004
+ * @return string
1005
+ */
1006
+ private function encodeBody ($ data )
1007
+ {
1008
+ return quoted_printable_encode ($ data );
1009
+ }
1010
+
1007
1011
/**
1008
1012
* @param string $pathOrContent Path to file or Contents
1009
1013
* @return string
0 commit comments