ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilRoleMailboxSearch Class Reference

Class ilRoleMailboxSearch. More...

+ Collaboration diagram for ilRoleMailboxSearch:

Public Member Functions

 __construct (\ilMailRfc822AddressParserFactory $parserFactory, \ilDBInterface $db=null)
 ilRoleMailboxSearch constructor. More...
 
 searchRoleIdsByAddressString (string $a_address_list)
 Finds all role ids that match the specified user friendly role mailbox address list. More...
 

Protected Attributes

 $parserFactory
 
 $db
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilRoleMailboxSearch::__construct ( \ilMailRfc822AddressParserFactory  $parserFactory,
\ilDBInterface  $db = null 
)

ilRoleMailboxSearch constructor.

Parameters
\ilMailRfc822AddressParserFactory$parserFactory
\ilDBInterface | null$db

Definition at line 23 of file class.ilRoleMailboxSearch.php.

References $db, $DIC, and $parserFactory.

26  {
27  global $DIC;
28 
29  $this->parserFactory = $parserFactory;
30 
31  if (null === $db) {
32  $db = $DIC->database();
33  }
34  $this->db = $db;
35  }
global $DIC
Definition: saml.php:7

Member Function Documentation

◆ searchRoleIdsByAddressString()

ilRoleMailboxSearch::searchRoleIdsByAddressString ( string  $a_address_list)

Finds all role ids that match the specified user friendly role mailbox address list.

The role mailbox name address list is an e-mail address list according to IETF RFC 822:

address list = role mailbox, {"," role mailbox } ; role mailbox = "#", local part, ["@" domain] ;

Examples: The following role mailbox names are all resolved to the role il_crs_member_123:

#Course.A #member.A #il_crs_member_123.A #il_crs_member_123 #il_crs_member_123

Examples: The following role mailbox names are all resolved to the role il_crs_member_345:

#member@[English Course] #il_crs_member_345@[English Course] #il_crs_member_345 #il_crs_member_345

If only the local part is specified, or if domain is equal to "ilias", ILIAS compares the title of role objects with local part. Only roles that are not in a trash folder are considered for the comparison.

If a domain is specified, and if the domain is not equal to "ilias", ILIAS compares the title of objects with the domain. Only objects that are not in a trash folder are considered for the comparison. Then ILIAS searches for local roles which contain the local part in their title. This allows for abbreviated role names, e.g. instead of having to specify #il_grp_member_345, it is sufficient to specify #member.

The address list may contain addresses thate are not role mailboxes. These addresses are ignored.

If a role mailbox address is ambiguous, this function returns the ID's of all role objects that are possible recipients for the role mailbox address.

If Pear Mail is not installed, then the mailbox address

Parameters
string$a_address_list
Returns
int[] Array with role ids that were found

Definition at line 80 of file class.ilRoleMailboxSearch.php.

References $domain, $parser, $query, $res, $row, and ilMail\ILIAS_HOST.

80  : array
81  {
82  $parser = $this->parserFactory->getParser($a_address_list);
83  $parsedList = $parser->parse();
84 
85  $role_ids = array();
86  foreach ($parsedList as $address) {
87  $local_part = $address->getMailbox();
88  if (strpos($local_part, '#') !== 0 && !($local_part[0] == '"' && $local_part[1] == "#")) {
89  // A local-part which doesn't start with a '#' doesn't denote a role.
90  // Therefore we can skip it.
91  continue;
92  }
93 
94  $local_part = substr($local_part, 1);
95 
96  /* If role contains spaces, eg. 'foo role', double quotes are added which have to be removed here.*/
97  if ($local_part[0] == '#' && $local_part[strlen($local_part) - 1] == '"') {
98  $local_part = substr($local_part, 1);
99  $local_part = substr($local_part, 0, strlen($local_part) - 1);
100  }
101 
102  if (substr($local_part, 0, 8) == 'il_role_') {
103  $role_id = substr($local_part, 8);
104  $query = "SELECT t.tree " .
105  "FROM rbac_fa fa " .
106  "JOIN tree t ON t.child = fa.parent " .
107  "WHERE fa.rol_id = " . $this->db->quote($role_id, 'integer') . " " .
108  "AND fa.assign = 'y' " .
109  "AND t.tree = 1";
110  $res = $this->db->query($query);
111  if ($this->db->numRows($res) > 0) {
112  $role_ids[] = $role_id;
113  }
114  continue;
115  }
116 
117  $domain = $address->getHost();
118  if (strpos($domain, '[') == 0 && strrpos($domain, ']')) {
119  $domain = substr($domain, 1, strlen($domain) - 2);
120  }
121  if (strlen($local_part) == 0) {
122  $local_part = $domain;
123  $address->setHost(\ilMail::ILIAS_HOST);
125  }
126 
127  if (strtolower($address->getHost()) == \ilMail::ILIAS_HOST) {
128  // Search for roles = local-part in the whole repository
129  $query = "SELECT dat.obj_id " .
130  "FROM object_data dat " .
131  "JOIN rbac_fa fa ON fa.rol_id = dat.obj_id " .
132  "JOIN tree t ON t.child = fa.parent " .
133  "WHERE dat.title =" . $this->db->quote($local_part, 'text') . " " .
134  "AND dat.type = 'role' " .
135  "AND fa.assign = 'y' " .
136  "AND t.tree = 1";
137  } else {
138  // Search for roles like local-part in objects = host
139  $query = "SELECT rdat.obj_id " .
140  "FROM object_data odat " .
141  "JOIN object_reference oref ON oref.obj_id = odat.obj_id " .
142  "JOIN tree otree ON otree.child = oref.ref_id " .
143  "JOIN rbac_fa rfa ON rfa.parent = otree.child " .
144  "JOIN object_data rdat ON rdat.obj_id = rfa.rol_id " .
145  "WHERE odat.title = " . $this->db->quote($domain, 'text') . " " .
146  "AND otree.tree = 1 " .
147  "AND rfa.assign = 'y' " .
148  "AND rdat.title LIKE " .
149  $this->db->quote('%' . preg_replace('/([_%])/', '\\\\$1', $local_part) . '%', 'text');
150  }
151  $res = $this->db->query($query);
152 
153  $count = 0;
154  while ($row = $this->db->fetchAssoc($res)) {
155  $role_ids[] = $row['obj_id'];
156 
157  $count++;
158  }
159 
160  // Nothing found?
161  // In this case, we search for roles = host.
162  if ($count == 0 && strtolower($address->getHost()) == \ilMail::ILIAS_HOST) {
163  $q = "SELECT dat.obj_id " .
164  "FROM object_data dat " .
165  "JOIN object_reference ref ON ref.obj_id = dat.obj_id " .
166  "JOIN tree t ON t.child = ref.ref_id " .
167  "WHERE dat.title = " . $this->db->quote($domain, 'text') . " " .
168  "AND dat.type = 'role' " .
169  "AND t.tree = 1 ";
170  $res = $this->db->query($q);
171 
172  while ($row = $this->db->fetchAssoc($res)) {
173  $role_ids[] = $row['obj_id'];
174  }
175  }
176  }
177 
178  return $role_ids;
179  }
const ILIAS_HOST
foreach($_POST as $key=> $value) $res
$query
$row
$parser
Definition: BPMN2Parser.php:23
if(!array_key_exists('domain', $_REQUEST)) $domain
Definition: resume.php:8

Field Documentation

◆ $db

ilRoleMailboxSearch::$db
protected

Definition at line 16 of file class.ilRoleMailboxSearch.php.

Referenced by __construct().

◆ $parserFactory

ilRoleMailboxSearch::$parserFactory
protected

Definition at line 13 of file class.ilRoleMailboxSearch.php.

Referenced by __construct().


The documentation for this class was generated from the following file: