Skip to content

Commit 307b0dc

Browse files
committed
Date parsing updated
1 parent 6f573b1 commit 307b0dc

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

src/Message.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class Message {
119119
public $in_reply_to = '';
120120
public $sender = [];
121121
public $priority = 0;
122+
public $encoding = 'utf-8';
122123

123124
/**
124125
* Message body components
@@ -343,8 +344,10 @@ private function parseHeader() {
343344
} catch (\Exception $e) {
344345
switch (true) {
345346
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:
346348
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);
348351
$array = array_reverse($array);
349352
$date = trim(array_pop($array));
350353
break;
@@ -518,7 +521,8 @@ private function fetchStructure($structure, $partNumber = null) {
518521
$partNumber = 1;
519522
}
520523

521-
$encoding = $this->getEncoding($structure);
524+
$encoding = $this->checkEncoding($structure);
525+
$this->setEncoding($encoding);
522526

523527
$content = imap_fetchbody($this->client->getConnection(), $this->uid, $partNumber, $this->fetch_options | FT_UID);
524528
$content = $this->decodeString($content, $structure->encoding);
@@ -537,7 +541,8 @@ private function fetchStructure($structure, $partNumber = null) {
537541
$partNumber = 1;
538542
}
539543

540-
$encoding = $this->getEncoding($structure);
544+
$encoding = $this->checkEncoding($structure);
545+
$this->setEncoding($encoding);
541546

542547
$content = imap_fetchbody($this->client->getConnection(), $this->uid, $partNumber, $this->fetch_options | FT_UID);
543548
$content = $this->decodeString($content, $structure->encoding);
@@ -709,13 +714,13 @@ public function convertEncoding($str, $from = "ISO-8859-2", $to = "UTF-8") {
709714
}
710715

711716
/**
712-
* Get the encoding of a given abject
717+
* Get the encoding of a given object
713718
*
714719
* @param object|string $structure
715720
*
716721
* @return string
717722
*/
718-
public function getEncoding($structure) {
723+
public function checkEncoding($structure) {
719724
if (property_exists($structure, 'parameters')) {
720725
foreach ($structure->parameters as $parameter) {
721726
if (strtolower($parameter->attribute) == "charset") {
@@ -729,6 +734,26 @@ public function getEncoding($structure) {
729734
return 'UTF-8';
730735
}
731736

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+
732757
/**
733758
* Find the folder containing this message.
734759
*

0 commit comments

Comments
 (0)