Merge pull request #4764 from MrPetovan/bug/4755-use-sender-header-invite

Use Sender: header for invite emails
This commit is contained in:
Michael Vogel 2018-04-07 08:31:14 +02:00 committed by GitHub
commit 5af9fa0be1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 22 deletions

View file

@ -45,10 +45,7 @@ function notification($params)
$hostname = substr($hostname, 0, strpos($hostname, ':')); $hostname = substr($hostname, 0, strpos($hostname, ':'));
} }
$sender_email = $a->config['sender_email']; $sender_email = $a->getSenderEmailAddress();
if (empty($sender_email)) {
$sender_email = L10n::t('noreply').'@'.$hostname;
}
if ($params['type'] != SYSTEM_EMAIL) { if ($params['type'] != SYSTEM_EMAIL) {
$user = dba::selectFirst('user', ['nickname', 'page-flags'], $user = dba::selectFirst('user', ['nickname', 'page-flags'],

View file

@ -35,28 +35,28 @@ function invite_post(App $a)
} }
$recips = ((x($_POST, 'recipients')) ? explode("\n", $_POST['recipients']) : []); $recipients = !empty($_POST['recipients']) ? explode("\n", $_POST['recipients']) : [];
$message = ((x($_POST, 'message')) ? notags(trim($_POST['message'])) : ''); $message = !empty($_POST['message']) ? notags(trim($_POST['message'])) : '';
$total = 0; $total = 0;
if (Config::get('system', 'invitation_only')) { if (Config::get('system', 'invitation_only')) {
$invonly = true; $invitation_only = true;
$x = PConfig::get(local_user(), 'system', 'invites_remaining'); $invites_remaining = PConfig::get(local_user(), 'system', 'invites_remaining');
if ((! $x) && (! is_site_admin())) { if ((! $invites_remaining) && (! is_site_admin())) {
return; return;
} }
} }
foreach ($recips as $recip) { foreach ($recipients as $recipient) {
$recip = trim($recip); $recipient = trim($recipient);
if (! valid_email($recip)) { if (! valid_email($recipient)) {
notice(L10n::t('%s : Not a valid email address.', $recip) . EOL); notice(L10n::t('%s : Not a valid email address.', $recipient) . EOL);
continue; continue;
} }
if ($invonly && ($x || is_site_admin())) { if ($invitation_only && ($invites_remaining || is_site_admin())) {
$code = autoname(8) . srand(1000, 9999); $code = autoname(8) . srand(1000, 9999);
$nmessage = str_replace('$invite_code', $code, $message); $nmessage = str_replace('$invite_code', $code, $message);
@ -66,9 +66,9 @@ function invite_post(App $a)
); );
if (! is_site_admin()) { if (! is_site_admin()) {
$x --; $invites_remaining --;
if ($x >= 0) { if ($invites_remaining >= 0) {
PConfig::set(local_user(), 'system', 'invites_remaining', $x); PConfig::set(local_user(), 'system', 'invites_remaining', $invites_remaining);
} else { } else {
return; return;
} }
@ -77,11 +77,16 @@ function invite_post(App $a)
$nmessage = $message; $nmessage = $message;
} }
$res = mail($recip, Email::encodeHeader(L10n::t('Please join us on Friendica'), 'UTF-8'), $additional_headers = 'From: ' . $a->user['email'] . "\n"
$nmessage, . 'Sender: ' . $a->getSenderEmailAddress() . "\n"
"From: " . $a->user['email'] . "\n"
. 'Content-type: text/plain; charset=UTF-8' . "\n" . 'Content-type: text/plain; charset=UTF-8' . "\n"
. 'Content-transfer-encoding: 8bit' ); . 'Content-transfer-encoding: 8bit';
$res = mail(
$recipient,
Email::encodeHeader(L10n::t('Please join us on Friendica'), 'UTF-8'),
$nmessage,
$additional_headers);
if ($res) { if ($res) {
$total ++; $total ++;
@ -92,7 +97,7 @@ function invite_post(App $a)
return; return;
} }
} else { } else {
notice(L10n::t('%s : Message delivery failed.', $recip) . EOL); notice(L10n::t('%s : Message delivery failed.', $recipient) . EOL);
} }
} }

View file

@ -1047,4 +1047,24 @@ class App
unset($this->config[$uid][$cat][$k]); unset($this->config[$uid][$cat][$k]);
} }
} }
/**
* Generates the site's default sender email address
*
* @return string
*/
public function getSenderEmailAddress()
{
$sender_email = Config::get('config', 'sender_email');
if (empty($sender_email)) {
$hostname = $this->get_hostname();
if (strpos($hostname, ':')) {
$hostname = substr($hostname, 0, strpos($hostname, ':'));
}
$sender_email = L10n::t('noreply') . '@' . $hostname;
}
return $sender_email;
}
} }