@@ -119,6 +119,7 @@ class Message {
119
119
public $ in_reply_to = '' ;
120
120
public $ sender = [];
121
121
public $ priority = 0 ;
122
+ public $ encoding = 'utf-8 ' ;
122
123
123
124
/**
124
125
* Message body components
@@ -343,8 +344,10 @@ private function parseHeader() {
343
344
} catch (\Exception $ e ) {
344
345
switch (true ) {
345
346
case preg_match ('/([A-Z]{2,3}\,\ [0-9]{1,2}\ [A-Z]{2,3}\ [0-9]{4}\ [0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}\ [\-|\+][0-9]{4}\ \(.*)\)+$/i ' , $ date ) > 0 :
347
+ case preg_match ('/([A-Z]{2,3}\, \ [0-9]{1,2}\ [A-Z]{2,3}\ [0-9]{4}\ [0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}\ [\-|\+][0-9]{4}\ \(.*)\)+$/i ' , $ date ) > 0 :
346
348
case preg_match ('/([0-9]{1,2}\ [A-Z]{2,3}\ [0-9]{2,4}\ [0-9]{2}\:[0-9]{2}\:[0-9]{2}\ [A-Z]{2}\ \-[0-9]{2}\:[0-9]{2}\ \([A-Z]{2,3}\ \-[0-9]{2}:[0-9]{2}\))+$/i ' , $ date ) > 0 :
347
- $ array = explode ('( ' , $ date );
349
+ $ date = str_replace (' ' , ' ' , $ date );
350
+ $ array = explode ('( ' , $ date );
348
351
$ array = array_reverse ($ array );
349
352
$ date = trim (array_pop ($ array ));
350
353
break ;
@@ -518,7 +521,8 @@ private function fetchStructure($structure, $partNumber = null) {
518
521
$ partNumber = 1 ;
519
522
}
520
523
521
- $ encoding = $ this ->getEncoding ($ structure );
524
+ $ encoding = $ this ->checkEncoding ($ structure );
525
+ $ this ->setEncoding ($ encoding );
522
526
523
527
$ content = imap_fetchbody ($ this ->client ->getConnection (), $ this ->uid , $ partNumber , $ this ->fetch_options | FT_UID );
524
528
$ content = $ this ->decodeString ($ content , $ structure ->encoding );
@@ -537,7 +541,8 @@ private function fetchStructure($structure, $partNumber = null) {
537
541
$ partNumber = 1 ;
538
542
}
539
543
540
- $ encoding = $ this ->getEncoding ($ structure );
544
+ $ encoding = $ this ->checkEncoding ($ structure );
545
+ $ this ->setEncoding ($ encoding );
541
546
542
547
$ content = imap_fetchbody ($ this ->client ->getConnection (), $ this ->uid , $ partNumber , $ this ->fetch_options | FT_UID );
543
548
$ content = $ this ->decodeString ($ content , $ structure ->encoding );
@@ -709,13 +714,13 @@ public function convertEncoding($str, $from = "ISO-8859-2", $to = "UTF-8") {
709
714
}
710
715
711
716
/**
712
- * Get the encoding of a given abject
717
+ * Get the encoding of a given object
713
718
*
714
719
* @param object|string $structure
715
720
*
716
721
* @return string
717
722
*/
718
- public function getEncoding ($ structure ) {
723
+ public function checkEncoding ($ structure ) {
719
724
if (property_exists ($ structure , 'parameters ' )) {
720
725
foreach ($ structure ->parameters as $ parameter ) {
721
726
if (strtolower ($ parameter ->attribute ) == "charset " ) {
@@ -729,6 +734,26 @@ public function getEncoding($structure) {
729
734
return 'UTF-8 ' ;
730
735
}
731
736
737
+ /**
738
+ * Get the encoding
739
+ *
740
+ * @return string
741
+ */
742
+ public function getEncoding () {
743
+ return $ this ->encoding ;
744
+ }
745
+
746
+ /**
747
+ * Set the encoding
748
+ * @param $encoding
749
+ *
750
+ * @return $this
751
+ */
752
+ public function setEncoding ($ encoding ) {
753
+ $ this ->encoding = $ encoding ;
754
+ return $ this ;
755
+ }
756
+
732
757
/**
733
758
* Find the folder containing this message.
734
759
*
0 commit comments