Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to unset mailprefix, as well as override prefix per Mailer instance #4228

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 26 additions & 10 deletions inc/Mailer.class.php
Expand Up @@ -32,6 +32,8 @@ class Mailer

protected $replacements = ['text' => [], 'html' => []];

protected $subjectPrefix = "";

/**
* Constructor
*
Expand Down Expand Up @@ -282,6 +284,16 @@ public function setText($text)
$this->text = $text;
}

/**
* Set the subject prefix. This overrides the site's mailprefix config.
*
* @param string $param
*/
public function setSubjectPrefix($prefix)
{
$this->subjectPrefix = $prefix;
}

/**
* Add the To: recipients
*
Expand Down Expand Up @@ -573,18 +585,22 @@ protected function cleanHeaders()
}

if (isset($this->headers['Subject'])) {
// add prefix to subject
if (empty($conf['mailprefix'])) {
if (PhpString::strlen($conf['title']) < 20) {
$prefix = '[' . $conf['title'] . ']';
if ($conf['mailprefix'] != '!!not set!!' || !empty($this->subjectPrefix)) {
// add prefix to subject
if (!empty($this->subjectPrefix)) {
$prefix = '[' . $this->subjectPrefix . ']';
} elseif (empty($conf['mailprefix'])) {
if (PhpString::strlen($conf['title']) < 20) {
$prefix = '[' . $conf['title'] . ']';
} else {
$prefix = '[' . PhpString::substr($conf['title'], 0, 20) . '...]';
}
} else {
$prefix = '[' . PhpString::substr($conf['title'], 0, 20) . '...]';
$prefix = '[' . $conf['mailprefix'] . ']';
}
if (!str_starts_with($this->headers['Subject'], $prefix)) {
$this->headers['Subject'] = $prefix . ' ' . $this->headers['Subject'];
}
} else {
$prefix = '[' . $conf['mailprefix'] . ']';
}
if (!str_starts_with($this->headers['Subject'], $prefix)) {
$this->headers['Subject'] = $prefix . ' ' . $this->headers['Subject'];
}

// encode subject
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/config/lang/en/lang.php
Expand Up @@ -145,7 +145,7 @@
$lang['registernotify'] = 'Always send info on newly registered users to this email address';
$lang['mailfrom'] = 'Sender email address to use for automatic mails';
$lang['mailreturnpath'] = 'Recipient email address for non delivery notifications';
$lang['mailprefix'] = 'Email subject prefix to use for automatic mails. Leave blank to use the wiki title';
$lang['mailprefix'] = 'Email subject prefix to use for automatic mails. Leave blank to use the wiki title. Use <code>!!not set!!</code> to not use a prefix at all.';
$lang['htmlmail'] = 'Send better looking, but larger in size HTML multipart emails. Disable for plain text only mails.';
$lang['dontlog'] = 'Disable logging for these types of logs.';
$lang['logretain'] = 'How many days of logs to keep.';
Expand Down