Skip to content

Commit

Permalink
Nits
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Jan 13, 2025
1 parent 0588724 commit 21d9d51
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 55 deletions.
4 changes: 2 additions & 2 deletions etc/mailkeywords.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{"name": "NULL", "function": "Mailer::kw_null", "global": true},
{"name": "OPT", "function": "*kw_opt", "global": true},
{"name": "URLENC", "function": "Mailer::kw_urlenc", "global": true},
{"name": "URLENC", "function": "*kw_urlenc", "global": true},
{"name": "PHP", "function": "Mailer::kw_php", "global": true},

{"name": "CONFNAME", "function": "*kw_confnames", "global": true},
Expand All @@ -26,7 +26,7 @@
{"name": "EMAIL", "function": "Mailer::kw_recipient", "userx": "EMAIL"},
{"name": "FIRST", "function": "Mailer::kw_recipient", "userx": "FIRST"},
{"name": "LAST", "function": "Mailer::kw_recipient", "userx": "LAST"},
{"name": "CAPABILITY", "function": "Mailer::kw_capability"},
{"name": "CAPABILITY", "function": "*kw_capability"},
{"name": "LOGINURL", "function": "*kw_login"},
{"name": "LOGINURLPARTS", "function": "*kw_login"},
{"name": "PASSWORD", "function": "*kw_login"},
Expand Down
4 changes: 2 additions & 2 deletions lib/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -715,14 +715,14 @@ function zlib_get_coding_type() {
* @param int $exitstatus
* @return bool */
function pcntl_wifexitedwith($status, $exitstatus = 0) {
return pcntl_wifexited($status) && pcntl_wexitstatus($status) == $exitstatus;
return pcntl_wifexited($status) && pcntl_wexitstatus($status) === $exitstatus;
}
} else {
/** @param int $status
* @param int $exitstatus
* @return bool */
function pcntl_wifexitedwith($status, $exitstatus = 0) {
return ($status & 0xff7f) == ($exitstatus << 8);
return ($status & 0xff7f) === ($exitstatus << 8);
}
}

Expand Down
58 changes: 28 additions & 30 deletions lib/mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function expand_user($contact, $out) {
}

if ($out === "EMAIL") {
return $flags & NAME_B ? "<$email>" : $email;
return $flags & NAME_B ? "<{$email}>" : $email;
} else if ($out === "CONTACT") {
return Text::name($r->firstName, $r->lastName, $email, $flags | NAME_E);
} else if ($out === "NAME") {
Expand Down Expand Up @@ -138,18 +138,16 @@ function kw_opt($args, $isbool) {
$yes = $this->expandvar($args, true);
if ($yes && !$isbool) {
return $this->expandvar($args, false);
} else {
return $yes;
}
return $yes;
}

static function kw_urlenc($args, $isbool, $m) {
$hasinner = $m->expandvar($args, true);
function kw_urlenc($args, $isbool) {
$hasinner = $this->expandvar($args, true);
if ($hasinner && !$isbool) {
return urlencode($m->expandvar($args, false));
} else {
return $hasinner;
return urlencode($this->expandvar($args, false));
}
return $hasinner;
}

function kw_confnames($args, $isbool, $uf) {
Expand Down Expand Up @@ -237,11 +235,11 @@ static function kw_recipient($args, $isbool, $m, $uf) {
return $m->expand_user($m->recipient, $uf->userx);
}

static function kw_capability($args, $isbool, $m, $uf) {
if ($m->capability_token) {
$m->sensitive = true;
function kw_capability($args, $isbool) {
if ($this->capability_token) {
$this->sensitive = true;
}
return $isbool || $m->capability_token ? $m->capability_token : "";
return $isbool || $this->capability_token ? $this->capability_token : "";
}

function kw_login($args, $isbool, $uf) {
Expand Down Expand Up @@ -339,13 +337,12 @@ function expandvar($what, $isbool) {

if ($isbool) {
return $mks ? null : false;
} else {
if (!isset($this->_unexpanded[$what])) {
$this->_unexpanded[$what] = true;
$this->unexpanded_warning_at($what);
}
return null;
}
if (!isset($this->_unexpanded[$what])) {
$this->_unexpanded[$what] = true;
$this->unexpanded_warning_at($what);
}
return null;
}


Expand Down Expand Up @@ -704,18 +701,19 @@ function populate_preparation(MailPreparation $prep, $template, $rest = []) {
$prep->headers["subject"] = $subject . $this->eol;
$prep->headers["to"] = "";
foreach (self::$email_fields as $lcfield => $field) {
if (($text = $mail[$lcfield] ?? "") !== "" && $text !== "<none>") {
if (($hdr = $mimetext->encode_email_header($field . ": ", $text))) {
$prep->headers[$lcfield] = $hdr . $this->eol;
} else {
$mimetext->mi->field = $lcfield;
$mimetext->mi->landmark = "{$field} field";
$prep->append_item($mimetext->mi);
$logmsg = "{$lcfield}: {$text}";
if (!in_array($logmsg, $this->_errors_reported)) {
error_log("mailer error on {$logmsg}");
$this->_errors_reported[] = $logmsg;
}
if (($text = $mail[$lcfield] ?? "") === "" || $text === "<none>") {
continue;
}
if (($hdr = $mimetext->encode_email_header($field . ": ", $text))) {
$prep->headers[$lcfield] = $hdr . $this->eol;
} else {
$mimetext->mi->field = $lcfield;
$mimetext->mi->landmark = "{$field} field";
$prep->append_item($mimetext->mi);
$logmsg = "{$lcfield}: {$text}";
if (!in_array($logmsg, $this->_errors_reported)) {
error_log("mailer error on {$logmsg}");
$this->_errors_reported[] = $logmsg;
}
}
}
Expand Down
40 changes: 19 additions & 21 deletions lib/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,16 +307,15 @@ static function initial($s) {
* @param bool $literal
* @return string */
static function word_regex($word, $literal = false) {
if ($word !== "") {
$aw = ctype_alnum($word[0]);
$zw = ctype_alnum($word[strlen($word) - 1]);
$sp = $literal ? '\s+' : '(?=\s).*\s';
return ($aw ? '\b' : '')
. str_replace(" ", $sp, preg_quote($word))
. ($zw ? '\b' : '');
} else {
if ($word === "") {
return "";
}
$aw = ctype_alnum($word[0]);
$zw = ctype_alnum($word[strlen($word) - 1]);
$sp = $literal ? '\s+' : '(?=\s).*\s';
return ($aw ? '\b' : '')
. str_replace(" ", $sp, preg_quote($word))
. ($zw ? '\b' : '');
}

const UTF8_INITIAL_NONLETTERDIGIT = '(?:\A|(?!\pL|\pN)\X)';
Expand All @@ -328,21 +327,20 @@ static function word_regex($word, $literal = false) {
* @param bool $literal
* @return string */
static function utf8_word_regex($word, $literal = false) {
if ($word !== "") {
$aw = preg_match('/\A(?:\pL|\pN)/u', $word);
$zw = preg_match('/(?:\pL|\pN)\z/u', $word);
// Maybe `$word` is not valid UTF-8. Avoid warnings later.
if ($aw || $zw || is_valid_utf8($word)) {
$sp = $literal ? '(?:\s|\p{Zs})+' : '(?=\s|\p{Zs}).*(?:\s|\p{Zs})';
return ($aw ? self::UTF8_INITIAL_NONLETTERDIGIT : '')
. str_replace(" ", $sp, preg_quote($word))
. ($zw ? self::UTF8_FINAL_NONLETTERDIGIT : '');
} else {
return self::utf8_word_regex(convert_to_utf8($word));
}
} else {
if ($word === "") {
return "";
}
$aw = preg_match('/\A(?:\pL|\pN)/u', $word);
$zw = preg_match('/(?:\pL|\pN)\z/u', $word);
// Maybe `$word` is not valid UTF-8. Avoid warnings later.
if ($aw || $zw || is_valid_utf8($word)) {
$sp = $literal ? '(?:\s|\p{Zs})+' : '(?=\s|\p{Zs}).*(?:\s|\p{Zs})';
return ($aw ? self::UTF8_INITIAL_NONLETTERDIGIT : '')
. str_replace(" ", $sp, preg_quote($word))
. ($zw ? self::UTF8_FINAL_NONLETTERDIGIT : '');
} else {
return self::utf8_word_regex(convert_to_utf8($word));
}
}

/** @param string $word
Expand Down

0 comments on commit 21d9d51

Please sign in to comment.