mirror of
https://github.com/retailcrm/Fetch.git
synced 2025-04-05 14:23:35 +03:00
Compare commits
10 commits
Author | SHA1 | Date | |
---|---|---|---|
|
8dcbff5d4c | ||
|
cd6af40196 | ||
|
521f7bcff7 | ||
|
bcaa835898 | ||
|
2f87688e3d | ||
|
370b3ed6f8 | ||
|
40025f2dea | ||
|
1c0e393b13 | ||
|
68cb173bc5 | ||
|
204aa76657 |
2 changed files with 52 additions and 11 deletions
|
@ -100,12 +100,14 @@ class Attachment
|
||||||
try {
|
try {
|
||||||
$hObject = imap_rfc822_parse_headers($header);
|
$hObject = imap_rfc822_parse_headers($header);
|
||||||
|
|
||||||
$subject = MIME::decode($hObject->subject, Message::$charset);
|
if (property_exists($hObject, 'subject')) {
|
||||||
$subject = preg_replace('#\s+#', ' ', $subject);
|
$subject = MIME::decode($hObject->subject, Message::$charset);
|
||||||
$subject = preg_replace('#^(.{0,50})#u', '$1', $subject);
|
$subject = preg_replace('#\s+#', ' ', $subject);
|
||||||
|
$subject = preg_replace('#^(.{0,50})#u', '$1', $subject);
|
||||||
|
|
||||||
if ($subject) {
|
if ($subject) {
|
||||||
$this->filename = $subject . '.eml';
|
$this->filename = $subject . '.eml';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
|
|
||||||
|
@ -116,13 +118,25 @@ class Attachment
|
||||||
|
|
||||||
$parameters = Message::getParametersFromStructure($structure);
|
$parameters = Message::getParametersFromStructure($structure);
|
||||||
|
|
||||||
|
// quick fix for Content-Disposition extended notation
|
||||||
|
// name*0*=UTF-8''%D0%A...
|
||||||
|
// name*1*=%D0%B8...
|
||||||
|
// etc
|
||||||
|
if (!empty($parameters['filename*'])) {
|
||||||
|
$this->setFileName($parameters['filename*']);
|
||||||
|
} elseif (!empty($parameters['name*'])) {
|
||||||
|
$this->setFileName($parameters['name*']);
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($parameters['filename'])) {
|
if (!empty($parameters['filename'])) {
|
||||||
$this->setFileName($parameters['filename']);
|
$this->setFileName($parameters['filename']);
|
||||||
} elseif (!empty($parameters['name'])) {
|
} elseif (!empty($parameters['name'])) {
|
||||||
$this->setFileName($parameters['name']);
|
$this->setFileName($parameters['name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->size = $structure->bytes;
|
if (property_exists($structure, 'bytes')) {
|
||||||
|
$this->size = $structure->bytes;
|
||||||
|
}
|
||||||
|
|
||||||
$this->mimeType = Message::typeIdToString($structure->type);
|
$this->mimeType = Message::typeIdToString($structure->type);
|
||||||
|
|
||||||
|
|
|
@ -249,9 +249,15 @@ class Message
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
$this->subject = MIME::decode($messageOverview->subject, self::$charset);
|
if (property_exists($messageOverview, 'subject')) {
|
||||||
$this->date = strtotime($messageOverview->date);
|
$this->subject = MIME::decode($messageOverview->subject, self::$charset);
|
||||||
$this->size = $messageOverview->size;
|
}
|
||||||
|
|
||||||
|
if (property_exists($messageOverview, 'date') && null !== $messageOverview->date) {
|
||||||
|
$this->date = strtotime($messageOverview->date);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->size = $messageOverview->size;
|
||||||
|
|
||||||
foreach (self::$flagTypes as $flag)
|
foreach (self::$flagTypes as $flag)
|
||||||
$this->status[$flag] = ($messageOverview->$flag == 1);
|
$this->status[$flag] = ($messageOverview->$flag == 1);
|
||||||
|
@ -381,7 +387,7 @@ class Message
|
||||||
public function getStructure($forceReload = false)
|
public function getStructure($forceReload = false)
|
||||||
{
|
{
|
||||||
if ($forceReload || !isset($this->structure)) {
|
if ($forceReload || !isset($this->structure)) {
|
||||||
$this->structure = imap_fetchstructure($this->imapStream, $this->uid, FT_UID);
|
$this->structure = @imap_fetchstructure($this->imapStream, $this->uid, FT_UID);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->structure;
|
return $this->structure;
|
||||||
|
@ -532,8 +538,23 @@ class Message
|
||||||
*/
|
*/
|
||||||
protected function processStructure($structure, $partIdentifier = null)
|
protected function processStructure($structure, $partIdentifier = null)
|
||||||
{
|
{
|
||||||
|
if (!$structure) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$parameters = self::getParametersFromStructure($structure);
|
$parameters = self::getParametersFromStructure($structure);
|
||||||
|
|
||||||
|
// quick fix for Content-Disposition extended notation
|
||||||
|
// name*0*=UTF-8''%D0%A...
|
||||||
|
// name*1*=%D0%B8...
|
||||||
|
// etc
|
||||||
|
if (empty($parameters['name']) && !empty($parameters['name*'])) {
|
||||||
|
$parameters['name'] = $parameters['name*'];
|
||||||
|
}
|
||||||
|
if (empty($parameters['filename']) && !empty($parameters['filename*'])) {
|
||||||
|
$parameters['filename'] = $parameters['filename*'];
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($parameters['name']) || !empty($parameters['filename'])) {
|
if (!empty($parameters['name']) || !empty($parameters['filename'])) {
|
||||||
$attachment = new Attachment($this, $structure, $partIdentifier);
|
$attachment = new Attachment($this, $structure, $partIdentifier);
|
||||||
$this->attachments[] = $attachment;
|
$this->attachments[] = $attachment;
|
||||||
|
@ -743,7 +764,13 @@ class Message
|
||||||
foreach ($addresses as $address) {
|
foreach ($addresses as $address) {
|
||||||
if (property_exists($address, 'mailbox') && $address->mailbox != 'undisclosed-recipients') {
|
if (property_exists($address, 'mailbox') && $address->mailbox != 'undisclosed-recipients') {
|
||||||
$currentAddress = array();
|
$currentAddress = array();
|
||||||
$currentAddress['address'] = $address->mailbox . '@' . $address->host;
|
|
||||||
|
$host = '';
|
||||||
|
if (property_exists($address, 'host')) {
|
||||||
|
$host = $address->host;
|
||||||
|
}
|
||||||
|
|
||||||
|
$currentAddress['address'] = $address->mailbox . '@' . $host;
|
||||||
if (isset($address->personal)) {
|
if (isset($address->personal)) {
|
||||||
$currentAddress['name'] = MIME::decode($address->personal, self::$charset);
|
$currentAddress['name'] = MIME::decode($address->personal, self::$charset);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue