19 declare(strict_types=1);
34 protected int $roleId,
35 protected bool $localize =
true,
43 $db = $DIC->database();
48 $lng = $DIC->language();
52 if (
null === $parserFactory) {
119 $query =
"SELECT rdat.title role_title,odat.title object_title, " .
120 " oref.ref_id object_ref " .
121 "FROM object_data rdat " .
122 "JOIN rbac_fa fa ON fa.rol_id = rdat.obj_id " .
123 "JOIN tree rtree ON rtree.child = fa.parent " .
124 "JOIN object_reference oref ON oref.ref_id = rtree.child " .
125 "JOIN object_data odat ON odat.obj_id = oref.obj_id " .
126 "WHERE rdat.obj_id = " . $this->db->quote($this->roleId,
'integer') .
" " .
127 "AND fa.assign = 'y' ";
128 $res = $this->db->query($query);
129 if (($row = $this->db->fetchObject(
$res)) ===
null) {
133 $object_title = $row->object_title;
134 $object_ref = (
int) $row->object_ref;
135 $role_title = $row->role_title;
140 $domain = $object_title;
141 $local_part = $role_title;
144 $q =
"SELECT COUNT(DISTINCT dat.obj_id) count " .
145 "FROM object_data dat " .
146 "JOIN object_reference ref ON ref.obj_id = dat.obj_id " .
147 "JOIN tree ON tree.child = ref.ref_id " .
148 "WHERE title = " . $this->db->quote($object_title,
'text') .
" " .
149 "AND tree.tree = 1 ";
150 $res = $this->db->query(
$q);
151 $row = $this->db->fetchObject(
$res);
154 if ($row->count > 1) {
162 if ($domain !==
null && preg_match(
'/[\[\]\\]|[\x00-\x1f]|[\x28-\x29]|[;]/', (
string) $domain)) {
168 if ($domain !==
null &&
169 (preg_match(
'/[()<>@,;:\\".\[\]]/', (
string) $domain) ||
170 preg_match(
'/[^\x21-\x8f]/', (
string) $domain))
172 $domain =
'[' . $domain .
']';
178 if ($domain !==
null && str_starts_with($role_title,
'il_')) {
179 $unambiguous_role_title = $role_title;
181 $pos = strpos($role_title,
'_', 3) + 1;
182 $local_part = substr(
185 strrpos($role_title,
'_') - $pos
188 $unambiguous_role_title =
'il_role_' . $this->roleId;
195 if ($domain ===
null) {
196 $q =
"SELECT COUNT(DISTINCT dat.obj_id) count " .
197 "FROM object_data dat " .
198 "JOIN object_reference ref ON ref.obj_id = dat.obj_id " .
199 "JOIN tree ON tree.child = ref.ref_id " .
200 "WHERE title = " . $this->db->quote($local_part,
'text') .
" " .
201 "AND tree.tree = 1 ";
203 $q =
"SELECT COUNT(rd.obj_id) count " .
204 "FROM object_data rd " .
205 "JOIN rbac_fa fa ON rd.obj_id = fa.rol_id " .
206 "JOIN tree t ON t.child = fa.parent " .
207 "WHERE fa.assign = 'y' " .
208 "AND t.child = " . $this->db->quote($object_ref,
'integer') .
" " .
209 "AND rd.title LIKE " . $this->db->quote(
210 '%' . preg_replace(
'/([_%])/',
'\\\\$1', $local_part) .
'%',
215 $res = $this->db->query(
$q);
216 $row = $this->db->fetchObject(
$res);
220 if ($row->count > 1) {
221 $local_part = $unambiguous_role_title;
228 if (preg_match(
'/[\\"\x00-\x1f]/', (
string) $local_part)) {
229 $local_part = $unambiguous_role_title;
230 } elseif (!preg_match(
'/^[\\x00-\\x7E]+$/i', (
string) $local_part)) {
232 $local_part = $unambiguous_role_title;
237 $local_part =
'#' . $local_part;
240 if (preg_match(
'/[()<>@,;:.\[\]\x20]/', $local_part)) {
241 $local_part =
'"' . $local_part .
'"';
244 $mailbox = ($domain ===
null) ?
246 $local_part .
'@' . $domain;
248 if ($this->localize) {
249 if (str_starts_with($role_title,
'il_')) {
250 $phrase = $this->
lng->txt(substr($role_title, 0, strrpos($role_title,
'_')));
252 $phrase = $role_title;
259 $phrase = preg_replace(
'/\s\s+/',
' ', $phrase);
260 $phrase = preg_replace(
'/[()<>@,;:\\".\[\]]/',
'', $phrase);
262 $mailbox = $phrase .
' <' . $mailbox .
'>';
267 $parser = $this->parserFactory->getParser($mailbox);
272 $res = $this->db->query(
"SELECT title FROM object_data WHERE obj_id = " . $this->db->quote(
276 if (($row = $this->db->fetchObject(
$res)) !==
null) {
277 return '#' . $row->title;
value()
Returns the mailbox address of a role.
Class ilRoleMailboxAddress.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Class ilMailRfc822AddressParserFactory.
__construct(protected int $roleId, protected bool $localize=true, ?ilMailRfc822AddressParserFactory $parserFactory=null, ?ilDBInterface $db=null, ?ilLanguage $lng=null)
ilMailRfc822AddressParserFactory $parserFactory