ILIAS  release_8 Revision v8.24
ilRoleMailboxAddress Class Reference

Class ilRoleMailboxAddress. More...

+ Collaboration diagram for ilRoleMailboxAddress:

Public Member Functions

 __construct (int $roleId, bool $localize=true, ilMailRfc822AddressParserFactory $parserFactory=null, ilDBInterface $db=null, ilLanguage $lng=null)
 
 value ()
 Returns the mailbox address of a role. More...
 

Protected Attributes

int $roleId
 
bool $localize = true
 
ilMailRfc822AddressParserFactory $parserFactory
 
ilDBInterface $db
 
ilLanguage $lng
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilRoleMailboxAddress::__construct ( int  $roleId,
bool  $localize = true,
ilMailRfc822AddressParserFactory  $parserFactory = null,
ilDBInterface  $db = null,
ilLanguage  $lng = null 
)

Definition at line 35 of file class.ilRoleMailboxAddress.php.

41 {
42 global $DIC;
43
44 $this->roleId = $roleId;
45 $this->localize = $localize;
46
47 if (null === $db) {
48 $db = $DIC->database();
49 }
50 $this->db = $db;
51
52 if (null === $lng) {
53 $lng = $DIC->language();
54 }
55 $this->lng = $lng;
56
57 if (null === $parserFactory) {
59 }
60 $this->parserFactory = $parserFactory;
61 }
ilMailRfc822AddressParserFactory $parserFactory
global $DIC
Definition: feed.php:28

References $db, $DIC, $lng, $localize, $parserFactory, $roleId, and ILIAS\Repository\lng().

+ Here is the call graph for this function:

Member Function Documentation

◆ value()

ilRoleMailboxAddress::value ( )

Returns the mailbox address of a role.

Example 1: Mailbox address for an ILIAS reserved role name

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.

Example 2: Mailbox address for a manually defined role name

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

mailbox address

The "Author Courses" role of the category object "Courses" is returned as one of the following mailbox addresses:

a) "#Author Courses"@Courses b) Author Courses <#il_role_34234>

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.

Definition at line 121 of file class.ilRoleMailboxAddress.php.

121 : string
122 {
123 // Retrieve the role title and the object title.
124 $query = "SELECT rdat.title role_title,odat.title object_title, " .
125 " oref.ref_id object_ref " .
126 "FROM object_data rdat " .
127 "JOIN rbac_fa fa ON fa.rol_id = rdat.obj_id " .
128 "JOIN tree rtree ON rtree.child = fa.parent " .
129 "JOIN object_reference oref ON oref.ref_id = rtree.child " .
130 "JOIN object_data odat ON odat.obj_id = oref.obj_id " .
131 "WHERE rdat.obj_id = " . $this->db->quote($this->roleId, 'integer') . " " .
132 "AND fa.assign = 'y' ";
133 $res = $this->db->query($query);
134 if (!$row = $this->db->fetchObject($res)) {
135 return '';
136 }
137
138 $object_title = $row->object_title;
139 $object_ref = (int) $row->object_ref;
140 $role_title = $row->role_title;
141
142 // In a perfect world, we could use the object_title in the
143 // domain part of the mailbox address, and the role title
144 // with prefix '#' in the local part of the mailbox address.
145 $domain = $object_title;
146 $local_part = $role_title;
147
148 // Determine if the object title is unique
149 $q = "SELECT COUNT(DISTINCT dat.obj_id) count " .
150 "FROM object_data dat " .
151 "JOIN object_reference ref ON ref.obj_id = dat.obj_id " .
152 "JOIN tree ON tree.child = ref.ref_id " .
153 "WHERE title = " . $this->db->quote($object_title, 'text') . " " .
154 "AND tree.tree = 1 ";
155 $res = $this->db->query($q);
156 $row = $this->db->fetchObject($res);
157
158 // If the object title is not unique, we get rid of the domain.
159 if ($row->count > 1) {
160 $domain = null;
161 }
162
163 // If the domain contains illegal characters, we get rid of it.
164 //if (domain != null && preg_match('/[\[\]\\]|[\x00-\x1f]/',$domain))
165 // Fix for Mantis Bug: 7429 sending mail fails because of brakets
166 // Fix for Mantis Bug: 9978 sending mail fails because of semicolon
167 if ($domain !== null && preg_match('/[\[\]\\]|[\x00-\x1f]|[\x28-\x29]|[;]/', $domain)) {
168 $domain = null;
169 }
170
171 // If the domain contains special characters, we put square
172 // brackets around it.
173 if ($domain !== null &&
174 (preg_match('/[()<>@,;:\\".\[\]]/', $domain) ||
175 preg_match('/[^\x21-\x8f]/', $domain))
176 ) {
177 $domain = '[' . $domain . ']';
178 }
179
180 // If the role title is one of the ILIAS reserved role titles,
181 // we can use a shorthand version of it for the local part
182 // of the mailbox address.
183 if ($domain !== null && strpos($role_title, 'il_') === 0) {
184 $unambiguous_role_title = $role_title;
185
186 $pos = strpos($role_title, '_', 3) + 1;
187 $local_part = substr(
188 $role_title,
189 $pos,
190 strrpos($role_title, '_') - $pos
191 );
192 } else {
193 $unambiguous_role_title = 'il_role_' . $this->roleId;
194 }
195
196 // Determine if the local part is unique. If we don't have a
197 // domain, the local part must be unique within the whole repositry.
198 // If we do have a domain, the local part must be unique for that
199 // domain.
200 if ($domain === null) {
201 $q = "SELECT COUNT(DISTINCT dat.obj_id) count " .
202 "FROM object_data dat " .
203 "JOIN object_reference ref ON ref.obj_id = dat.obj_id " .
204 "JOIN tree ON tree.child = ref.ref_id " .
205 "WHERE title = " . $this->db->quote($local_part, 'text') . " " .
206 "AND tree.tree = 1 ";
207 } else {
208 $q = "SELECT COUNT(rd.obj_id) count " .
209 "FROM object_data rd " .
210 "JOIN rbac_fa fa ON rd.obj_id = fa.rol_id " .
211 "JOIN tree t ON t.child = fa.parent " .
212 "WHERE fa.assign = 'y' " .
213 "AND t.child = " . $this->db->quote($object_ref, 'integer') . " " .
214 "AND rd.title LIKE " . $this->db->quote(
215 '%' . preg_replace('/([_%])/', '\\\\$1', $local_part) . '%',
216 'text'
217 ) . " ";
218 }
219
220 $res = $this->db->query($q);
221 $row = $this->db->fetchObject($res);
222
223 // if the local_part is not unique, we use the unambiguous role title
224 // instead for the local part of the mailbox address
225 if ($row->count > 1) {
226 $local_part = $unambiguous_role_title;
227 }
228
229 $use_phrase = true;
230
231 // If the local part contains illegal characters, we use
232 // the unambiguous role title instead.
233 if (preg_match('/[\\"\x00-\x1f]/', $local_part)) {
234 $local_part = $unambiguous_role_title;
235 } elseif (!preg_match('/^[\\x00-\\x7E]+$/i', $local_part)) {
236 // 2013-12-05: According to #12283, we do not accept umlauts in the local part
237 $local_part = $unambiguous_role_title;
238 $use_phrase = false;
239 }
240
241 // Add a "#" prefix to the local part
242 $local_part = '#' . $local_part;
243
244 // Put quotes around the role title, if needed
245 if (preg_match('/[()<>@,;:.\[\]\x20]/', $local_part)) {
246 $local_part = '"' . $local_part . '"';
247 }
248
249 $mailbox = ($domain === null) ?
250 $local_part :
251 $local_part . '@' . $domain;
252
253 if ($this->localize) {
254 if (strpos($role_title, 'il_') === 0) {
255 $phrase = $this->lng->txt(substr($role_title, 0, strrpos($role_title, '_')));
256 } else {
257 $phrase = $role_title;
258 }
259
260 if ($use_phrase) {
261 // make phrase RFC 822 conformant:
262 // - strip excessive whitespace
263 // - strip special characters
264 $phrase = preg_replace('/\s\s+/', ' ', $phrase);
265 $phrase = preg_replace('/[()<>@,;:\\".\[\]]/', '', $phrase);
266
267 $mailbox = $phrase . ' <' . $mailbox . '>';
268 }
269 }
270
271 try {
272 $parser = $this->parserFactory->getParser($mailbox);
273 $parser->parse();
274
275 return $mailbox;
276 } catch (ilException $e) {
277 $res = $this->db->query("SELECT title FROM object_data WHERE obj_id = " . $this->db->quote(
278 $this->roleId,
279 'integer'
280 ));
281 if ($row = $this->db->fetchObject($res)) {
282 return '#' . $row->title;
283 }
284
285 return '';
286 }
287 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$res
Definition: ltiservices.php:69
$query

References Vendor\Package\$e, $query, $res, $roleId, ILIAS\Repository\int(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilRoleMailboxAddress::$db
protected

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

Referenced by __construct().

◆ $lng

ilLanguage ilRoleMailboxAddress::$lng
protected

Definition at line 33 of file class.ilRoleMailboxAddress.php.

Referenced by __construct().

◆ $localize

bool ilRoleMailboxAddress::$localize = true
protected

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

Referenced by __construct().

◆ $parserFactory

ilMailRfc822AddressParserFactory ilRoleMailboxAddress::$parserFactory
protected

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

Referenced by __construct().

◆ $roleId

int ilRoleMailboxAddress::$roleId
protected

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

Referenced by __construct(), and value().


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