ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilRoleMailboxSearch Class Reference

Class ilRoleMailboxSearch. More...

+ Collaboration diagram for ilRoleMailboxSearch:

Public Member Functions

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

Protected Attributes

ilDBInterface $db
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

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

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

References $db, and $DIC.

34  {
35  global $DIC;
36 
37  if (null === $db) {
38  $db = $DIC->database();
39  }
40  $this->db = $db;
41  }
global $DIC
Definition: feed.php:28

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

Returns
int[] Array with role ids that were found

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

References $q, $res, ilMail\ILIAS_HOST, and ILIAS\Repository\int().

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

Field Documentation

◆ $db

ilDBInterface ilRoleMailboxSearch::$db
protected

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

Referenced by __construct().


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