Returns the mailbox address of a role.
The il_crs_member_345 role of the course object "English Course 1" is returned as one of the following mailbox addresses:
a) Course Member <#member@[English Course 1]> b) Course Member <#il_crs_member_345@[English Course 1]> c) Course Member <#il_crs_member_345>
Address a) is returned, if the title of the object is unique, and if there is only one local role with the substring "member" defined for the object.
Address b) is returned, if the title of the object is unique, but there is more than one local role with the substring "member" in its title.
Address c) is returned, if the title of the course object is not unique.
The "Admin" role of the category object "Courses" is returned as one of the following mailbox addresses:
a) Course Administrator <#Admin@Courses> b) Course Administrator <#Admin> c) Course Adminstrator <#il_role_34211>
Address a) is returned, if the title of the object is unique, and if there is only one local role with the substring "Admin" defined for the course object.
Address b) is returned, if the title of the object is not unique, but the role title is unique.
Address c) is returned, if neither the role title nor the title of the course object is unique.
Example 3: Mailbox address for a manually defined role title that can contains special characters in the local-part of a
The "Author Courses" role of the category object "Courses" is returned as one of the following mailbox addresses:
Address a) is returned, if the title of the role is unique.
Address b) is returned, if neither the role title nor the title of the course object is unique, or if the role title contains a quote or a backslash.
99 : string
100 {
101
102 $query = 'SELECT rdat.title role_title, odat.title object_title, ' .
103 ' oref.ref_id object_ref ' .
104 'FROM object_data rdat ' .
105 'INNER JOIN role_data roledat ON roledat.role_id = rdat.obj_id ' .
106 'INNER JOIN rbac_fa fa ON fa.rol_id = rdat.obj_id AND fa.assign = ' . $this->db->quote(
'y',
ilDBConstants::T_TEXT) .
' ' .
107 'INNER JOIN tree rtree ON rtree.child = fa.parent ' .
108 'INNER JOIN object_reference oref ON oref.ref_id = rtree.child ' .
109 'INNER JOIN object_data odat ON odat.obj_id = oref.obj_id ' .
111 $res = $this->db->query($query);
112 if (($row = $this->db->fetchObject(
$res)) ===
null) {
113 return '';
114 }
115
116 $object_title = $row->object_title;
117 $object_ref = (
int) $row->object_ref;
118 $role_title = $row->role_title;
119
120
121
122
123 $domain = $object_title;
124 $local_part = $role_title;
125
126
127 $q =
'SELECT COUNT(DISTINCT dat.obj_id) AS count ' .
128 'FROM object_data dat ' .
129 'INNER JOIN object_reference ref ON ref.obj_id = dat.obj_id AND ref.deleted IS NULL ' .
130 'INNER JOIN tree ON tree.child = ref.ref_id AND tree.tree = ' . $this->db->quote(1,
ilDBConstants::T_INTEGER) .
' ' .
132 $res = $this->db->query(
$q);
133 $row = $this->db->fetchObject(
$res);
134
135
136 if ($row->count !== 1) {
137 $domain = null;
138 }
139
140
141
142
143
144 if ($domain !== null && preg_match('/[\[\]\\]|[\x00-\x1f]|[\x28-\x29]|[;]/', (string) $domain)) {
145 $domain = null;
146 }
147
148
149
150 if ($domain !== null &&
151 (preg_match('/[()<>@,;:\\".\[\]]/', (string) $domain) ||
152 preg_match('/[^\x21-\x8f]/', (string) $domain))
153 ) {
154 $domain = '[' . $domain . ']';
155 }
156
157
158
159
160 if ($domain !== null && str_starts_with($role_title, 'il_')) {
161 $unambiguous_role_title = $role_title;
162
163 $pos = strpos($role_title, '_', 3) + 1;
164 $local_part = substr(
165 $role_title,
166 $pos,
167 strrpos($role_title, '_') - $pos
168 );
169 } else {
170 $unambiguous_role_title = 'il_role_' . $this->role_id;
171 }
172
173
174
175
176
177 if ($domain === null) {
178
179 $q =
'SELECT COUNT(DISTINCT rdat.role_id) AS count ' .
180 'FROM object_data dat ' .
181 'INNER JOIN role_data rdat ON rdat.role_id = dat.obj_id ' .
182 'INNER JOIN rbac_fa fa ON fa.rol_id = rdat.role_id ' .
183 'INNER JOIN tree t ON t.child = fa.parent ' .
184 'INNER JOIN object_reference oref ON oref.ref_id = t.child ' .
186 } else {
187 $q =
'SELECT COUNT(rd.obj_id) AS count ' .
188 'FROM object_data rd ' .
189 'INNER JOIN rbac_fa fa ON fa.rol_id = rd.obj_id AND fa.assign = ' . $this->db->quote(
'y',
ilDBConstants::T_TEXT) .
' ' .
190 'INNER JOIN tree t ON t.child = fa.parent AND t.child = ' . $this->db->quote($object_ref,
ilDBConstants::T_INTEGER) .
' ' .
191 'WHERE rd.title LIKE ' . $this->db->quote(
192 '%' . preg_replace('/([_%])/', '\\\\$1', $local_part) . '%',
194 ) . ' ';
195 }
196
197 $res = $this->db->query(
$q);
198 $row = $this->db->fetchObject(
$res);
199
200
201
202 if ($row->count !== 1) {
203 $local_part = $unambiguous_role_title;
204 }
205
206 $use_phrase = true;
207
208
209
210 if (preg_match('/[\\"\x00-\x1f]/', (string) $local_part)) {
211 $local_part = $unambiguous_role_title;
212 } elseif (!preg_match('/^[\\x00-\\x7E]+$/i', (string) $local_part)) {
213
214 $local_part = $unambiguous_role_title;
215 $use_phrase = false;
216 }
217
218
219 $local_part = '#' . $local_part;
220
221
222 if (preg_match('/[()<>@,;:.\[\]\x20]/', $local_part)) {
223 $local_part = '"' . $local_part . '"';
224 }
225
226 $mailbox = ($domain === null) ?
227 $local_part :
228 $local_part . '@' . $domain;
229
230 if ($this->localize) {
231 if (str_starts_with($role_title, 'il_')) {
232 $phrase = $this->
lng->txt(substr($role_title, 0, strrpos($role_title,
'_')));
233 } else {
234 $phrase = $role_title;
235 }
236
237 if ($use_phrase) {
238
239
240
241 $phrase = preg_replace('/\s\s+/', ' ', $phrase);
242 $phrase = preg_replace('/[()<>@,;:\\".\[\]]/', '', $phrase);
243
244 $mailbox = $phrase . ' <' . $mailbox . '>';
245 }
246 }
247
248 try {
249 $parser = $this->parser_factory->getParser($mailbox);
250 $parser->parse();
251
252 return $mailbox;
254 $res = $this->db->query(
255 'SELECT od.title
256 FROM object_data od
257 INNER JOIN role_data rd ON rd.role_id = od.obj_id
259 AND NOT EXISTS (
260 SELECT 1
261 FROM object_data maybe_same_role_od
262 INNER JOIN role_data maybe_same_role_rd ON maybe_same_role_rd.role_id = maybe_same_role_od.obj_id
263 WHERE maybe_same_role_od.title = od.title
264 AND maybe_same_role_od.obj_id != od.obj_id
265 )'
266 );
267 if (($row = $this->db->fetchObject(
$res)) !==
null) {
268 return '#' . $row->title;
269 }
270
271 return '#il_role_' . $this->role_id;
272 }
273 }