ILIAS  release_8 Revision v8.23
ilRoleMailboxSearch Class Reference

Class ilRoleMailboxSearch. More...

+ Collaboration diagram for ilRoleMailboxSearch:

Public Member Functions

 __construct (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

ilMailRfc822AddressParserFactory $parserFactory
 
ilDBInterface $db
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

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

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

References $db, $DIC, and $parserFactory.

35  {
36  global $DIC;
37 
38  $this->parserFactory = $parserFactory;
39 
40  if (null === $db) {
41  $db = $DIC->database();
42  }
43  $this->db = $db;
44  }
ilMailRfc822AddressParserFactory $parserFactory
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 88 of file class.ilRoleMailboxSearch.php.

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

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

Field Documentation

◆ $db

ilDBInterface ilRoleMailboxSearch::$db
protected

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

Referenced by __construct().

◆ $parserFactory

ilMailRfc822AddressParserFactory ilRoleMailboxSearch::$parserFactory
protected

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

Referenced by __construct().


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