ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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)
 ilRoleMailboxAddress constructor. More...
 
 value ()
 Returns the mailbox address of a role. More...
 

Protected Attributes

 $roleId
 
 $localize = true
 
 $parserFactory
 
 $db
 
 $lng
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

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

ilRoleMailboxAddress constructor.

Parameters
int$roleId
bool$localizeA boolean flag whether mailbox addresses should be localized
ilMailRfc822AddressParserFactory | null$parserFactory
ilDBInterface | null$db
ilLanguage | null$lng

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

References $db, $DIC, $lng, $localize, $parserFactory, and $roleId.

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

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> 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" 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 122 of file class.ilRoleMailboxAddress.php.

References Vendor\Package\$e, $parser, $query, $res, and $roleId.

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

Field Documentation

◆ $db

ilRoleMailboxAddress::$db
protected

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

Referenced by __construct().

◆ $lng

ilRoleMailboxAddress::$lng
protected

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

Referenced by __construct().

◆ $localize

ilRoleMailboxAddress::$localize = true
protected

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

Referenced by __construct().

◆ $parserFactory

ilRoleMailboxAddress::$parserFactory
protected

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

Referenced by __construct().

◆ $roleId

ilRoleMailboxAddress::$roleId
protected

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

Referenced by __construct(), and value().


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