From fd7d73756a908889d6f6f7b9307a8a961a7cfdfd Mon Sep 17 00:00:00 2001 From: yuri Date: Wed, 15 Apr 2015 15:47:10 +0300 Subject: [PATCH] email improvement --- .../Espo/Resources/i18n/en_US/Email.json | 1 + .../Resources/metadata/clientDefs/Email.json | 11 ++---- application/Espo/SelectManagers/Email.php | 27 ++++++++++++-- application/Espo/Services/Email.php | 37 +++++++++++-------- 4 files changed, 49 insertions(+), 27 deletions(-) diff --git a/application/Espo/Resources/i18n/en_US/Email.json b/application/Espo/Resources/i18n/en_US/Email.json index d4d2571a88..97f2826366 100644 --- a/application/Espo/Resources/i18n/en_US/Email.json +++ b/application/Espo/Resources/i18n/en_US/Email.json @@ -55,6 +55,7 @@ "presetFilters": { "sent": "Sent", "archived": "Archived", + "inbox": "Inbox", "draft": "Draft" }, "massActions": { diff --git a/application/Espo/Resources/metadata/clientDefs/Email.json b/application/Espo/Resources/metadata/clientDefs/Email.json index b4092aec30..823cfe942f 100644 --- a/application/Espo/Resources/metadata/clientDefs/Email.json +++ b/application/Espo/Resources/metadata/clientDefs/Email.json @@ -55,7 +55,7 @@ }, "filterList": [ { - "name":"archived", + "name":"inbox", "style": "primary" }, { @@ -68,11 +68,8 @@ } ], "defaultFilterData": { - "bool": { - "onlyMy": true - }, - "presetName": "archived", - "primary": "archived" + "presetName": "inbox", + "primary": "inbox" }, - "boolFilterList": ["onlyMy"] + "boolFilterList": [] } diff --git a/application/Espo/SelectManagers/Email.php b/application/Espo/SelectManagers/Email.php index 5eec345142..887ed1cdec 100644 --- a/application/Espo/SelectManagers/Email.php +++ b/application/Espo/SelectManagers/Email.php @@ -34,24 +34,43 @@ class Email extends \Espo\Core\SelectManagers\Base ); } - protected function filterArchived(&$result) + protected function filterInbox(&$result) { + $eaList = $this->getUser()->get('emailAddresses'); + $idList = []; + foreach ($eaList as $ea) { + $idList[] = $ea->id; + } $result['whereClause'][] = array( - 'status' => 'Archived' + 'fromEmailAddressId!=' => $idList ); + $this->boolFilterOnlyMy(); } protected function filterSent(&$result) { + $eaList = $this->getUser()->get('emailAddresses'); + $idList = []; + foreach ($eaList as $ea) { + $idList[] = $ea->id; + } $result['whereClause'][] = array( - 'status' => 'Sent' + 'fromEmailAddressId=' => $idList ); } protected function filterDraft(&$result) { $result['whereClause'][] = array( - 'status' => 'Draft' + 'status' => 'Draft', + 'createdById' => $this->getUser()->id + ); + } + + protected function filterArchived(&$result) + { + $result['whereClause'][] = array( + 'status' => 'Archived' ); } diff --git a/application/Espo/Services/Email.php b/application/Espo/Services/Email.php index a78c776a45..a256f3b874 100644 --- a/application/Espo/Services/Email.php +++ b/application/Espo/Services/Email.php @@ -275,23 +275,13 @@ class Email extends Record { parent::loadAdditionalFieldsForList($entity); + $userEmailAdddressIdList = []; + foreach ($this->getUser()->get('emailAddresses') as $ea) { + $userEmailAdddressIdList[] = $ea->id; + } + $status = $entity->get('status'); - if (in_array($status, ['Archived', 'Received'])) { - $fromEmailAddressId = $entity->get('fromEmailAddressId'); - if (!empty($fromEmailAddressId)) { - $person = $this->getEntityManager()->getRepository('EmailAddress')->getEntityByAddressId($fromEmailAddressId); - if ($person) { - $entity->set('personStringData', $person->get('name')); - } else { - $fromName = self::parseFromName($entity->get('fromString')); - if (!empty($fromName)) { - $entity->set('personStringData', $fromName); - } else { - $entity->set('personStringData', $entity->get('fromEmailAddressName')); - } - } - } - } else if (in_array($status, ['Sent', 'Draft', 'Sending'])) { + if (in_array($entity->get('fromEmailAddressId'), $userEmailAdddressIdList)) { $entity->loadLinkMultipleField('toEmailAddresses'); $idList = $entity->get('toEmailAddressesIds'); $names = $entity->get('toEmailAddressesNames'); @@ -308,6 +298,21 @@ class Email extends Record } $entity->set('personStringData', 'To: ' . implode(', ', $arr)); } + } else { + $fromEmailAddressId = $entity->get('fromEmailAddressId'); + if (!empty($fromEmailAddressId)) { + $person = $this->getEntityManager()->getRepository('EmailAddress')->getEntityByAddressId($fromEmailAddressId); + if ($person) { + $entity->set('personStringData', $person->get('name')); + } else { + $fromName = self::parseFromName($entity->get('fromString')); + if (!empty($fromName)) { + $entity->set('personStringData', $fromName); + } else { + $entity->set('personStringData', $entity->get('fromEmailAddressName')); + } + } + } } $pdo = $this->getEntityManager()->getPDO();