/** * * @param string $receiver */ protected function _formatReceiver($receiver, $isFlow = false) { $arr = explode("\n", $receiver); $ret = array(); $section = array(); foreach ($arr as $line) { $line = trim($line); if (empty($line) || $line == '+') { continue; } if ($line == '>' && $isFlow) { $ret[] = $section; $section = array(); continue; } $pair = explode(' ', $line, 2); if (false !== strpos($pair[0], '@')) { $trueName = isset($pair[1]) ? $pair[1] : null; if (null === $trueName) { list(, $suffix) = explode('@', $pair[0]); $addressbook = Tudu_Addressbook::getInstance(); if (false === strpos($suffix, '.')) { $info = $addressbook->searchUser($this->_user->orgId, $pair[0]); if (!$info) { continue; } $trueName = $info['truename']; } else { $info = $addressbook->searchContact($this->_user->uniqueId, $pair[0], null); if (null === $info) { list($trueName, ) = explode('@', $pair[0]); } else { $trueName = $info['truename']; } } } if ($isFlow) { $section[$pair[0]] = array('username' => $pair[0], 'truename' => $trueName, 'email' => $pair[0]); } else { $ret[$pair[0]] = array('username' => $pair[0], 'truename' => $trueName, 'email' => $pair[0]); } } else { // 流程不允许群组 if ($isFlow) { continue; } $groupName = isset($pair[1]) ? $pair[1] : null; if (null === $groupName) { if (0 === strpos($pair[0], 'XG')) { $daoGroup = Tudu_Dao_Manager::getDao('Dao_Td_Contact_Group', Tudu_Dao_Manager::DB_MD); $group = $daoGroup->getGroup(array('uniqueid' => $this->_user->uniqueId, 'groupid' => $pair[0])); if (null === $group) { continue; } $groupName = $group->groupName; } else { $daoGroup = Tudu_Dao_Manager::getDao('Dao_Md_User_Group', Tudu_Dao_Manager::DB_MD); $group = $daoGroup->getGroup(array('orgid' => $this->_user->orgId, 'groupid' => $pair[0])); if (null === $group) { continue; } $groupName = $group->groupName; } } $ret[$pair[0]] = array('groupid' => $pair[0], 'truename' => $groupName); } } if (!empty($section) && $isFlow) { $ret[] = $section; } return $ret; }
/** * * @param string $receiver */ protected function _formatReceiver($receiver, $expandGroup = false) { $arr = explode("\n", $receiver); $ret = array(); foreach ($arr as $line) { $line = trim($line); if (empty($line)) { continue; } $pair = explode(' ', $line, 2); if (false !== strpos($pair[0], '@')) { $trueName = isset($pair[1]) ? $pair[1] : null; if (null === $trueName) { list(, $suffix) = explode('@', $pair[0]); $addressbook = Tudu_Addressbook::getInstance(); if (false === strpos($suffix, '.')) { $info = $addressbook->searchUser($this->_user->orgId, $pair[0]); if (!$info) { continue; } $trueName = $info['truename']; } else { $info = $addressbook->searchContact($this->_user->uniqueId, $pair[0], null); if (null === $info) { list($trueName, ) = explode('@', $pair[0]); } else { $trueName = $info['truename']; } } } $ret[$pair[0]] = array('email' => $pair[0], 'truename' => $trueName); } else { if ($expandGroup) { if (0 === strpos($pair[0], 'XG')) { $dao = Tudu_Dao_Manager::getDao('Dao_Td_Contact_Contact', Tudu_Dao_Manager::DB_TS); $users = $dao->getContacts(array('uniqueid' => $this->_user->uniqueId, 'groupid' => $pair[0]))->toArray(); foreach ($users as $user) { $ret[$user['contactid']] = array('email' => $user['email'], 'username' => $user['email'], 'truename' => $user['truename']); } } else { $dao = Tudu_Dao_Manager::getDao('Dao_Td_Md_User', Tudu_Dao_Manager::DB_MD); $users = $dao->getUsers(array('orgid' => $this->_user->orgId, 'groupid' => $pair[0]))->toArray(); foreach ($users as $user) { $ret[$user['userid'] . '@' . $user['orgid']] = array('email' => $user['userid'] . '@' . $user['orgid'], 'username' => $user['userid'] . '@' . $user['orgid'], 'truename' => $user['truename']); } } } else { $groupName = isset($pair[1]) ? $pair[1] : null; if (null === $groupName) { if (0 === strpos($pair[0], 'XG')) { $daoGroup = Tudu_Dao_Manager::getDao('Dao_Td_Contact_Group', Tudu_Dao_Manager::DB_TS); $group = $daoGroup->getGroup(array('uniqueid' => $this->_user->uniqueId, 'groupid' => $pair[0])); if (null === $group) { continue; } $groupName = $group->groupName; } else { $daoGroup = Tudu_Dao_Manager::getDao('Dao_Md_User_Group', Tudu_Dao_Manager::DB_MD); $group = $daoGroup->getGroup(array('orgid' => $this->_user->orgId, 'groupid' => $pair[0])); if (null === $group) { continue; } $groupName = $group->groupName; } } $ret[$pair[0]] = array('groupid' => $pair[0], 'truename' => $groupName); } } } return $ret; }