Skip to content

Commit

Permalink
Merge branch 'wip-86264-m40' into MOODLE_40_STABLE
Browse files Browse the repository at this point in the history
# Conflicts:
#	local/o365/classes/feature/coursesync/main.php
#	local/o365/classes/feature/coursesync/utils.php
  • Loading branch information
weilai-irl committed Sep 29, 2022
2 parents 4f5eca7 + b7275bf commit c575cae
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions local/o365/classes/feature/coursesync/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,8 @@ public function process_course_reset(stdClass $course, stdClass $o365object, boo
$resetgroupnameprefix = 'disconnected-';
}
$updatedmailnickname = $resetgroupnameprefix . utils::get_group_mail_alias($course);
if (strlen($updatedmailnickname) > 63) {
$updatedmailnickname = substr($updatedmailnickname, 0, 63);
if (strlen($updatedmailnickname) > 60) {
$updatedmailnickname = substr($updatedmailnickname, 0, 60);
}
$updatedexistinggroup = [
'id' => $existinggroup['id'],
Expand Down
15 changes: 12 additions & 3 deletions local/o365/classes/feature/coursesync/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public static function get_group_mail_alias(stdClass $course) : string {

$coursepart = static::clean_up_group_mail_alias($coursepart);

$coursepartmaxlength = 64 - strlen($groupmailaliasprefix) - strlen($groupmailaliassuffix) - 1;
$coursepartmaxlength = 60 - strlen($groupmailaliasprefix) - strlen($groupmailaliassuffix);
if (strlen($coursepart) > $coursepartmaxlength) {
$coursepart = substr($coursepart, 0, $coursepartmaxlength);
}
Expand All @@ -380,10 +380,19 @@ public static function get_group_mail_alias(stdClass $course) : string {
* Remove unsupported characters from the mail alias parts, and return the result.
*
* @param string $mailalias
* @return string|string[]|null
* @return string
*/
public static function clean_up_group_mail_alias(string $mailalias) {
return preg_replace('/[^a-z0-9-_]+/iu', '', $mailalias);
$notallowedbasicchars = ['@', '(', ')', "\\", '[', ']', '"', ';', ':', '.', '<', '>', ' '];
$chars = preg_split( '//u', $mailalias, null, PREG_SPLIT_NO_EMPTY);
foreach($chars as $key => $char){
$charorder = ord($char);
if ($charorder < 0 || $charorder > 127 || in_array($char, $notallowedbasicchars)) {
unset($chars[$key]);
}
}

return implode($chars);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion local/o365/lang/en/local_o365.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
<li>All spaces will be removed from the group mail alias.</li>
<li>Only upper and lower case letters, numbers, - and _ are allowed in the group mail alias.</li>
<li>Group mail alias, including prefix and suffix cannot exceed 64 characters.</li>
<li>Mail alias of the group needs to be unique, otherwise a random 4 digit number will be appended to ensure uniqueness.</li>
<li>Mail alias of the group needs to be unique, otherwise a random 4-digit number will be appended to ensure uniqueness.</li>
</ul>';
$string['settings_team_name_prefix'] = 'Teams name prefix';
$string['settings_team_name_prefix_desc'] = '';
Expand Down

0 comments on commit c575cae

Please sign in to comment.