ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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.

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) {
58  $parserFactory = new \ilMailRfc822AddressParserFactory();
59  }
60  $this->parserFactory = $parserFactory;
61  }
global $DIC
Definition: saml.php:7

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

References $domain, $parser, $query, $res, $roleId, and $row.

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 = $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 (strpos($role_title, 'il_') === 0 && $domain != null) {
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  } else {
236  if (!preg_match('/^[\\x00-\\x7E]+$/i', $local_part)) {
237  // 2013-12-05: According to #12283, we do not accept umlauts in the local part
238  $local_part = $unambiguous_role_title;
239  $use_phrase = false;
240  }
241  }
242 
243  // Add a "#" prefix to the local part
244  $local_part = '#' . $local_part;
245 
246  // Put quotes around the role title, if needed
247  if (preg_match('/[()<>@,;:.\[\]\x20]/', $local_part)) {
248  $local_part = '"' . $local_part . '"';
249  }
250 
251  $mailbox = ($domain == null) ?
252  $local_part :
253  $local_part . '@' . $domain;
254 
255  if ($this->localize) {
256  if (substr($role_title, 0, 3) == 'il_') {
257  $phrase = $this->lng->txt(substr($role_title, 0, strrpos($role_title, '_')));
258  } else {
259  $phrase = $role_title;
260  }
261 
262  if ($use_phrase) {
263  // make phrase RFC 822 conformant:
264  // - strip excessive whitespace
265  // - strip special characters
266  $phrase = preg_replace('/\s\s+/', ' ', $phrase);
267  $phrase = preg_replace('/[()<>@,;:\\".\[\]]/', '', $phrase);
268 
269  $mailbox = $phrase . ' <' . $mailbox . '>';
270  }
271  }
272 
273  try {
274  $parser = $this->parserFactory->getParser((string) $mailbox);
275  $parser->parse();
276 
277  return $mailbox;
278  } catch (\ilException $e) {
279  $res = $this->db->query("SELECT title FROM object_data WHERE obj_id = " . $this->db->quote($this->roleId, 'integer'));
280  if ($row = $this->db->fetchObject($res)) {
281  return '#' . $row->title;
282  } else {
283  return '';
284  }
285  }
286  }
foreach($_POST as $key=> $value) $res
$query
$row
$parser
Definition: BPMN2Parser.php:23
if(!array_key_exists('domain', $_REQUEST)) $domain
Definition: resume.php:8

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: