aboutsummaryrefslogtreecommitdiffstats
path: root/include/network.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/network.php')
-rw-r--r--include/network.php126
1 files changed, 60 insertions, 66 deletions
diff --git a/include/network.php b/include/network.php
index b3a3d715c..55eecac84 100644
--- a/include/network.php
+++ b/include/network.php
@@ -2,6 +2,7 @@
use Zotlabs\Lib\Activity;
use Zotlabs\Lib\Config;
+use Zotlabs\Lib\Mailer;
use Zotlabs\Lib\Zotfinger;
use Zotlabs\Lib\Libzot;
use Zotlabs\Lib\Queue;
@@ -612,7 +613,7 @@ function validate_email(string $addr): bool {
$matches = array();
$result = preg_match(
- '/^[A-Z0-9._%-]+@([A-Z0-9.-]+\.[A-Z0-9-]{2,})$/i',
+ '/^[A-Z0-9._%+-]+@([A-Z0-9.-]+\.[A-Z0-9-]{2,})$/i',
punify($addr),
$matches);
@@ -1488,11 +1489,11 @@ function do_delivery($deliveries, $force = false) {
$interval = Config::Get('queueworker', 'queue_interval', 500000);
- $deliveries_per_process = intval(Config::Get('system','delivery_batch_count'));
+ $deliveries_per_process = intval(Config::Get('system', 'delivery_batch_count'));
- if($deliveries_per_process <= 0)
+ if($deliveries_per_process <= 0) {
$deliveries_per_process = 1;
-
+ }
$deliver = [];
foreach($deliveries as $d) {
@@ -1813,54 +1814,9 @@ function network_to_name($s) {
*/
function z_mail($params) {
- if(! $params['fromEmail']) {
- $params['fromEmail'] = Config::Get('system','from_email');
- if(! $params['fromEmail'])
- $params['fromEmail'] = 'Administrator' . '@' . App::get_hostname();
- }
- if(! $params['fromName']) {
- $params['fromName'] = Config::Get('system','from_email_name');
- if(! $params['fromName'])
- $params['fromName'] = Zotlabs\Lib\System::get_site_name();
- }
- if(! $params['replyTo']) {
- $params['replyTo'] = Config::Get('system','reply_address');
- if(! $params['replyTo'])
- $params['replyTo'] = 'noreply' . '@' . App::get_hostname();
- }
-
- $params['sent'] = false;
- $params['result'] = false;
-
- /**
- * @hooks email_send
- * * \e params @see z_mail()
- */
- call_hooks('email_send', $params);
-
- if($params['sent']) {
- logger('notification: z_mail returns ' . (($params['result']) ? 'success' : 'failure'), LOGGER_DEBUG);
- return $params['result'];
- }
-
- $fromName = email_header_encode(html_entity_decode($params['fromName'],ENT_QUOTES,'UTF-8'),'UTF-8');
- $messageSubject = email_header_encode(html_entity_decode($params['messageSubject'],ENT_QUOTES,'UTF-8'),'UTF-8');
-
- $messageHeader =
- $params['additionalMailHeader'] .
- "From: $fromName <{$params['fromEmail']}>" . PHP_EOL .
- "Reply-To: $fromName <{$params['replyTo']}>" . PHP_EOL .
- "Content-Type: text/plain; charset=UTF-8";
-
- // send the message
- $res = mail(
- $params['toEmail'], // send to address
- $messageSubject, // subject
- $params['textVersion'],
- $messageHeader // message headers
- );
- logger('notification: z_mail returns ' . (($res) ? 'success' : 'failure'), LOGGER_DEBUG);
- return $res;
+ // Delegate the call to the Mailer class.
+ $mailer = new Mailer($params);
+ return $mailer->deliver();
}
@@ -2145,21 +2101,59 @@ function get_request_string($url) {
/**
- * Builds a url from the result of `parse_url`.
+ * Reconstructs a URL from its parsed components.
+ *
+ * This function takes a parsed URL as an associative array and reconstructs
+ * the URL based on the specified components (scheme, host, port, user, pass, path, query, fragment).
+ * You can specify which components should be included in the final URL by passing the optional
+ * `$parts` array. The function will return the complete URL string formed by combining
+ * only the parts that exist in both the parsed URL and the `$parts` array.
+ *
+ * @param array $parsed_url The parsed URL components as an associative array.
+ * The array can include keys like 'scheme', 'host', 'port', 'user', 'pass',
+ * 'path', 'query', 'fragment'.
*
- * @param array $parsed_url An associative array as produced by `parse_url`.
+ * @param array $parts An optional array that specifies which components of the URL
+ * should be included in the final string. Defaults to:
+ * ['scheme', 'host', 'port', 'user', 'pass', 'path', 'query', 'fragment'].
+ * If any of the components are not required, they can be omitted from the array.
*
- * @return string The reassembled URL as a string.
+ * @return string The reconstructed URL as a string.
*/
-function unparse_url(array $parsed_url): string {
- $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
- $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
- $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
- $user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
- $pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
- $pass = ($user || $pass) ? "$pass@" : '';
- $path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
- $query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
- $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
- return $scheme . $user . $pass . $host . $port . $path . $query . $fragment;
+function unparse_url(array $parsed_url, array $parts = ['scheme', 'host', 'port', 'user', 'pass', 'path', 'query', 'fragment']): string {
+ $url_parts = [];
+
+ if (in_array('scheme', $parts) && array_key_exists('scheme', $parsed_url)) {
+ $url_parts[] = $parsed_url['scheme'] . '://';
+ }
+
+ if (in_array('user', $parts) && array_key_exists('user', $parsed_url)) {
+ $url_parts[] = $parsed_url['user'];
+ if (in_array('pass', $parts) && array_key_exists('pass', $parsed_url)) {
+ $url_parts[] = ':' . $parsed_url['pass'];
+ }
+ $url_parts[] = '@';
+ }
+
+ if (in_array('host', $parts) && array_key_exists('host', $parsed_url)) {
+ $url_parts[] = $parsed_url['host'];
+ }
+
+ if (in_array('port', $parts) && array_key_exists('port', $parsed_url)) {
+ $url_parts[] = ':' . $parsed_url['port'];
+ }
+
+ if (in_array('path', $parts) && array_key_exists('path', $parsed_url)) {
+ $url_parts[] = $parsed_url['path'];
+ }
+
+ if (in_array('query', $parts) && array_key_exists('query', $parsed_url)) {
+ $url_parts[] = '?' . $parsed_url['query'];
+ }
+
+ if (in_array('fragment', $parts) && array_key_exists('fragment', $parsed_url)) {
+ $url_parts[] = '#' . $parsed_url['fragment'];
+ }
+
+ return implode('', $url_parts);
}