From 4504fb79fb53f81d4c9659e17b357f47675b2492 Mon Sep 17 00:00:00 2001 From: joebordes Date: Tue, 4 Apr 2023 09:03:39 +0200 Subject: [PATCH] fix(MailMgr) show and relate with TO in Sent folder --- .../modules/MailManager/Folder.Open.tpl | 2 +- modules/MailManager/MailManager.js | 2 +- .../src/controllers/MailController.php | 1 + .../src/controllers/RelationController.php | 55 +++++++++++-------- modules/MailManager/src/models/Message.php | 12 +++- 5 files changed, 45 insertions(+), 27 deletions(-) diff --git a/Smarty/templates/modules/MailManager/Folder.Open.tpl b/Smarty/templates/modules/MailManager/Folder.Open.tpl index 6b443007f7..6d502c69d6 100644 --- a/Smarty/templates/modules/MailManager/Folder.Open.tpl +++ b/Smarty/templates/modules/MailManager/Folder.Open.tpl @@ -76,7 +76,7 @@ - {$MAIL->from(30)} + {if $FOLDER->name()=='Sent'}{$MAIL->to(30)}{else}{$MAIL->from(30)}{/if} {$MAIL->subject()} {$MAIL->date(true)} diff --git a/modules/MailManager/MailManager.js b/modules/MailManager/MailManager.js index 6dc5cf5951..acf49dcd8c 100644 --- a/modules/MailManager/MailManager.js +++ b/modules/MailManager/MailManager.js @@ -571,7 +571,7 @@ if (typeof(MailManager) == 'undefined') { method: 'POST', url: 'index.php?'+MailManager._baseurl() + '_operation=relation&_operationarg=find&_mfrom=' + encodeURIComponent(meta['from']) + '&_folder=' + encodeURIComponent(meta['folder']) + '&_msgno=' + encodeURIComponent(meta['msgno']) + '&_msguid=' + - encodeURIComponent(meta['msguid'].replace('<', '<').replace('>', '>')) + encodeURIComponent(meta['msguid'].replace('<', '<').replace('>', '>')) + '&_mto=' + encodeURIComponent(meta['to']) }).done(function (transport) { jQuery('#_mailrecord_findrel_btn_').html(MailManager.i18n('JSLBL_Find_Relation_Now')); jQuery('#_mailrecord_findrel_btn_').prop('disabled', false); diff --git a/modules/MailManager/src/controllers/MailController.php b/modules/MailManager/src/controllers/MailController.php index 01a3eea290..31a397fc86 100644 --- a/modules/MailManager/src/controllers/MailController.php +++ b/modules/MailManager/src/controllers/MailController.php @@ -48,6 +48,7 @@ public function process(MailManager_Request $request) { $metainfo = array( 'from' => $mail->from(), + 'to' => $mail->to(), 'subject' => $mail->subject(), 'msgno' => $mail->msgNo(), 'msguid' => $mail->uniqueid(), diff --git a/modules/MailManager/src/controllers/RelationController.php b/modules/MailManager/src/controllers/RelationController.php index 8940a14d7f..425c26ab41 100644 --- a/modules/MailManager/src/controllers/RelationController.php +++ b/modules/MailManager/src/controllers/RelationController.php @@ -57,19 +57,20 @@ public function process(MailManager_Request $request) { $results = array(); $modules = array(); $allowedModules = $this->getCurrentUserMailManagerAllowedModules(); - foreach (self::$MODULES as $MODULE) { - if (!in_array($MODULE, $allowedModules)) { - continue; - } - - $from = $request->get('_mfrom'); - if (empty($from)) { - continue; + $fname = $request->get('_folder'); + $relateWith = $request->get('_mfrom'); + if ($fname=='Sent') { + $relateWith = $request->get('_mto'); + } + if (!empty($relateWith)) { + foreach (self::$MODULES as $MODULE) { + if (!in_array($MODULE, $allowedModules)) { + continue; + } + $results[$MODULE] = $this->lookupModuleRecordsWithEmail($MODULE, $relateWith, $msguid); + $describe = $this->wsDescribe($MODULE); + $modules[$MODULE] = array('label' => $describe['label'], 'name' => textlength_check($describe['name']), 'id' => $describe['idPrefix'] ); } - - $results[$MODULE] = $this->lookupModuleRecordsWithEmail($MODULE, $from, $msguid); - $describe = $this->wsDescribe($MODULE); - $modules[$MODULE] = array('label' => $describe['label'], 'name' => textlength_check($describe['name']), 'id' => $describe['idPrefix'] ); } $viewer->assign('LOOKUPS', $results); $viewer->assign('MODULES', $modules); @@ -78,7 +79,7 @@ public function process(MailManager_Request $request) { $viewer->assign('LinkToAvailableActions', $this->linkToAvailableActions()); $viewer->assign('AllowedModules', $allowedModules); $viewer->assign('MSGNO', $request->get('_msgno')); - $viewer->assign('FOLDER', $request->get('_folder')); + $viewer->assign('FOLDER', $fname); $response->setResult(array('ui' => $viewer->fetch($this->getModuleTpl('Relationship.tpl')))); } elseif ('link' == $request->getOperationArg()) { $linkto = $request->get('_mlinkto'); @@ -111,7 +112,7 @@ public function process(MailManager_Request $request) { $validationData = $qcreate_array['data']; $data = split_validationdataArray($validationData); - $qcreate_array['form'] = $this->processFormData($qcreate_array['form'], $mail); + $qcreate_array['form'] = $this->processFormData($qcreate_array['form'], $mail, $foldername); $viewer->assign('QUICKCREATE', $qcreate_array['form']); if ($moduleName == 'HelpDesk') { $viewer->assign('QCMODULE', getTranslatedString('Ticket', 'HelpDesk')); @@ -163,8 +164,12 @@ public function process(MailManager_Request $request) { switch ($linkModule) { case 'HelpDesk': - $from = $mail->from(); - $focus->column_fields['parent_id'] = $this->setParentForHelpDesk($parent, $from); + if ($foldername=='Sent') { + $relwith = $mail->to(); + } else { + $relwith = $mail->from(); + } + $focus->column_fields['parent_id'] = $this->setParentForHelpDesk($parent, $relwith); break; case 'ModComments': @@ -229,11 +234,11 @@ public function process(MailManager_Request $request) { * @param array Email Address of the received mail * @return integer - Parent(crmid) */ - public function setParentForHelpDesk($parent, $from) { + public function setParentForHelpDesk($parent, $relwith) { global $current_user; if (empty($parent)) { - if (!empty($from)) { - $parentInfo = MailManager::lookupMailInVtiger($from[0], $current_user); + if (!empty($relwith)) { + $parentInfo = MailManager::lookupMailInVtiger($relwith[0], $current_user); if (!empty($parentInfo[0]['record'])) { $parentId = vtws_getIdComponents($parentInfo[0]['record']); return $parentId[1]; @@ -250,11 +255,15 @@ public function setParentForHelpDesk($parent, $from) { * @param MailManager_Model_Message $mail * @return array */ - public function processFormData($qcreate_array, $mail) { + public function processFormData($qcreate_array, $mail, $foldername = '') { $subject = $mail->subject(); - $from = $mail->from(); - if (!empty($from)) { - $mail_fromAddress = implode(',', $from); + if ($foldername=='Sent') { + $relwith = $mail->to(); + } else { + $relwith = $mail->from(); + } + if (!empty($relwith)) { + $mail_fromAddress = implode(',', (array)$relwith); } if (!empty($mail_fromAddress)) { $name = explode('@', $mail_fromAddress); diff --git a/modules/MailManager/src/models/Message.php b/modules/MailManager/src/models/Message.php index 6ffb304693..796aaa9757 100644 --- a/modules/MailManager/src/models/Message.php +++ b/modules/MailManager/src/models/Message.php @@ -450,8 +450,15 @@ public function from($maxlen = 0) { * @param string Email from */ public function setFrom($from) { - $mailFrom = str_replace('_', ' ', $from); - $this->_from = @self::__mime_decode($mailFrom); + $this->_from = @self::__mime_decode(str_replace('_', ' ', $from)); + } + + /** + * Sets the Mail To Email Address + * @param string Email to + */ + public function setTo($to) { + $this->_to = @self::__mime_decode(str_replace('_', ' ', $to)); } /** @@ -577,6 +584,7 @@ public static function parseOverview($result) { $instance = new self(); $instance->setSubject(isset($result->subject) ? $result->subject : ''); $instance->setFrom((isset($result->from) ? $result->from : '')); + $instance->setTo((isset($result->to) ? $result->to : '')); $instance->setDate($result->date); $instance->setRead($result->seen); $instance->setMsgNo($result->msgno);