From a86d1806ae266d09c9d62a48cc2e495e3221a7a4 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 6 Apr 2018 21:47:16 -0400 Subject: [PATCH 1/4] Add App->getSenderEmailAddress method --- src/App.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/App.php b/src/App.php index 55623e1e81..1acd35ac34 100644 --- a/src/App.php +++ b/src/App.php @@ -1047,4 +1047,24 @@ class App 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; + } } From 32ca95a1b08ee0086a2cadac32b382c9c1a541bc Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 6 Apr 2018 21:47:42 -0400 Subject: [PATCH 2/4] Use App->getSenderEmailAddress in include/enotify --- include/enotify.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/include/enotify.php b/include/enotify.php index d1c7dc1f41..68208ec5ac 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -45,10 +45,7 @@ function notification($params) $hostname = substr($hostname, 0, strpos($hostname, ':')); } - $sender_email = $a->config['sender_email']; - if (empty($sender_email)) { - $sender_email = L10n::t('noreply').'@'.$hostname; - } + $sender_email = $a->getSenderEmailAddress(); if ($params['type'] != SYSTEM_EMAIL) { $user = dba::selectFirst('user', ['nickname', 'page-flags'], From 0f02d1a449aa5dc172696325ce43949783862eba Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 6 Apr 2018 21:48:37 -0400 Subject: [PATCH 3/4] Use App->getSenderEmailAddress in mod/invite - Use "Sender: " header - Rename confusing variables --- mod/invite.php | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/mod/invite.php b/mod/invite.php index d638b860b4..03330f32cf 100644 --- a/mod/invite.php +++ b/mod/invite.php @@ -35,28 +35,28 @@ function invite_post(App $a) } - $recips = ((x($_POST, 'recipients')) ? explode("\n", $_POST['recipients']) : []); - $message = ((x($_POST, 'message')) ? notags(trim($_POST['message'])) : ''); + $recipients = !empty($_POST['recipients']) ? explode("\n", $_POST['recipients']) : []; + $message = !empty($_POST['message']) ? notags(trim($_POST['message'])) : ''; $total = 0; if (Config::get('system', 'invitation_only')) { - $invonly = true; - $x = PConfig::get(local_user(), 'system', 'invites_remaining'); - if ((! $x) && (! is_site_admin())) { + $invitation_only = true; + $invites_remaining = PConfig::get(local_user(), 'system', 'invites_remaining'); + if ((! $invites_remaining) && (! is_site_admin())) { return; } } - foreach ($recips as $recip) { - $recip = trim($recip); + foreach ($recipients as $recipient) { + $recipient = trim($recipient); - if (! valid_email($recip)) { - notice(L10n::t('%s : Not a valid email address.', $recip) . EOL); + if (! valid_email($recipient)) { + notice(L10n::t('%s : Not a valid email address.', $recipient) . EOL); continue; } - if ($invonly && ($x || is_site_admin())) { + if ($invitation_only && ($invites_remaining || is_site_admin())) { $code = autoname(8) . srand(1000, 9999); $nmessage = str_replace('$invite_code', $code, $message); @@ -66,9 +66,9 @@ function invite_post(App $a) ); if (! is_site_admin()) { - $x --; - if ($x >= 0) { - PConfig::set(local_user(), 'system', 'invites_remaining', $x); + $invites_remaining --; + if ($invites_remaining >= 0) { + PConfig::set(local_user(), 'system', 'invites_remaining', $invites_remaining); } else { return; } @@ -77,11 +77,16 @@ function invite_post(App $a) $nmessage = $message; } - $res = mail($recip, Email::encodeHeader(L10n::t('Please join us on Friendica'), 'UTF-8'), - $nmessage, - "From: " . $a->user['email'] . "\n" + $additional_headers = 'From: ' . $a->getSenderEmailAddress() . "\n" + . 'Sender: ' . $a->user['email'] . "\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) { $total ++; @@ -92,7 +97,7 @@ function invite_post(App $a) return; } } else { - notice(L10n::t('%s : Message delivery failed.', $recip) . EOL); + notice(L10n::t('%s : Message delivery failed.', $recipient) . EOL); } } From 9220025b123fa211c31ad4d48387d5b83092f473 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 7 Apr 2018 02:26:33 -0400 Subject: [PATCH 4/4] Exchange Sender: and From: headers in mod/invite --- mod/invite.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mod/invite.php b/mod/invite.php index 03330f32cf..6807ff2c12 100644 --- a/mod/invite.php +++ b/mod/invite.php @@ -77,8 +77,8 @@ function invite_post(App $a) $nmessage = $message; } - $additional_headers = 'From: ' . $a->getSenderEmailAddress() . "\n" - . 'Sender: ' . $a->user['email'] . "\n" + $additional_headers = 'From: ' . $a->user['email'] . "\n" + . 'Sender: ' . $a->getSenderEmailAddress() . "\n" . 'Content-type: text/plain; charset=UTF-8' . "\n" . 'Content-transfer-encoding: 8bit';