Overview
Comment:Switch away from SMTP::checkEmailIsValid now that we have something better
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | emails
Files: files | file ages | folders
SHA3-256: 1befd392aea11861f8240fd41f3dbf09fb616720ecb2956fc59d7fef286b4b93
User & Date: bohwaz on 2022-05-31 15:54:38
Other Links: branch diff | manifest | tags
Context
2022-05-31
16:02
Use constant check-in: 85a28a20cc user: bohwaz tags: emails
15:54
Switch away from SMTP::checkEmailIsValid now that we have something better check-in: 1befd392ae user: bohwaz tags: emails
14:40
Add MAIL_RETURN_PATH constant check-in: a73e7b83e2 user: bohwaz tags: emails
Changes

Modified src/include/lib/Garradin/Entities/Users/Email.php from [6c0166112c] to [084e4510f5].

109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
	static public function validateAddress(string $email): void
	{
		$user = strtok($email, '@');
		$host = strtok('');

		// Ce domaine n'existe pas (MX inexistant), erreur de saisie courante
		if ($host == 'gmail.fr') {
			throw new UserException('L\'adresse e-mail est invalide : est-ce que vous avez voulu écrire "gmail.com" ?');
		}

		if (!SMTP::checkEmailIsValid($email, false)) {
			foreach (self::COMMON_DOMAINS as $common_domain) {
				similar_text($common_domain, $host, $percent);

				if ($percent > 90) {







|







109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
	static public function validateAddress(string $email): void
	{
		$user = strtok($email, '@');
		$host = strtok('');

		// Ce domaine n'existe pas (MX inexistant), erreur de saisie courante
		if ($host == 'gmail.fr') {
			throw new UserException('Adresse invalide : "gmail.fr" n\'existe pas, il faut utiliser "gmail.com"');
		}

		if (!SMTP::checkEmailIsValid($email, false)) {
			foreach (self::COMMON_DOMAINS as $common_domain) {
				similar_text($common_domain, $host, $percent);

				if ($percent > 90) {

Modified src/include/lib/Garradin/Membres.php from [8be04b1af9] to [081983cad8].

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
<?php

namespace Garradin;

use KD2\Security;
use KD2\SMTP;
use Garradin\Membres\Session;

use Garradin\Files\Files;
use Garradin\Entities\Files\File;


use Garradin\Users\Emails;
use Garradin\UserTemplate\UserTemplate;

class Membres
{
    const ITEMS_PER_PAGE = 50;










>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php

namespace Garradin;

use KD2\Security;
use KD2\SMTP;
use Garradin\Membres\Session;

use Garradin\Files\Files;
use Garradin\Entities\Files\File;
use Garradin\Entities\Users\Email;

use Garradin\Users\Emails;
use Garradin\UserTemplate\UserTemplate;

class Membres
{
    const ITEMS_PER_PAGE = 50;
90
91
92
93
94
95
96
97
98




99

100
101
102
103
104
105
106
                        $data[$key] = 0;
                    }
                }
                elseif ($config->type == 'email')
                {
                    $data[$key] = strtolower(trim($data[$key]));

                    if (trim($data[$key]) !== '' && !SMTP::checkEmailIsValid($data[$key], false))
                    {




                        throw new UserException(sprintf('Adresse email invalide "%s" pour le champ "%s".', $data[$key], $config->title));

                    }
                }
                elseif ($config->type == 'select' && !in_array($data[$key], $config->options))
                {
                    throw new UserException('Le champ "' . $config->title . '" ne correspond pas à un des choix proposés.');
                }
                elseif ($config->type == 'multiple')







|

>
>
>
>
|
>







91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
                        $data[$key] = 0;
                    }
                }
                elseif ($config->type == 'email')
                {
                    $data[$key] = strtolower(trim($data[$key]));

                    if (trim($data[$key]) !== '')
                    {
                        try {
                            Email::validateAddress($data[$key]);
                        }
                        catch (UserException $e) {
                            throw new UserException(sprintf('Champ "%s" : %s', $config->title, $e->getMessage()));
                        }
                    }
                }
                elseif ($config->type == 'select' && !in_array($data[$key], $config->options))
                {
                    throw new UserException('Le champ "' . $config->title . '" ne correspond pas à un des choix proposés.');
                }
                elseif ($config->type == 'multiple')

Modified src/include/lib/Garradin/UserTemplate/Modifiers.php from [a8c52296fb] to [0fcc591164].

1
2
3
4
5
6


7
8
9
10
11
12
13
<?php

namespace Garradin\UserTemplate;

use Garradin\Utils;



use KD2\SMTP;

class Modifiers
{
	const PHP_MODIFIERS_LIST = [
		'strtolower',
		'strtoupper',






>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php

namespace Garradin\UserTemplate;

use Garradin\Utils;

use Garradin\Entities\Users\Email;

use KD2\SMTP;

class Modifiers
{
	const PHP_MODIFIERS_LIST = [
		'strtolower',
		'strtoupper',
56
57
58
59
60
61
62







63
64
65
66
67
68
69
70
	static public function regexp_replace($str, $pattern, $replace)
	{
		return preg_replace($pattern, $replace, $str);
	}

	static public function check_email($str)
	{







		return SMTP::checkEmailIsValid($str, true);
	}

	/**
	 * UTF-8 aware intelligent substr
	 * @param  string  $str         UTF-8 string
	 * @param  integer $length      Maximum string length
	 * @param  string  $placeholder Placeholder text to append at the string if it has been cut







>
>
>
>
>
>
>
|







58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
	static public function regexp_replace($str, $pattern, $replace)
	{
		return preg_replace($pattern, $replace, $str);
	}

	static public function check_email($str)
	{
		try {
			Email::validateAddress($str);
		}
		catch (UserException $e) {
			return false;
		}

		return true;
	}

	/**
	 * UTF-8 aware intelligent substr
	 * @param  string  $str         UTF-8 string
	 * @param  integer $length      Maximum string length
	 * @param  string  $placeholder Placeholder text to append at the string if it has been cut

Modified src/include/lib/Garradin/Users/Emails.php from [41c7d19360] to [b627b69df5].

397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
		if ($context != self::CONTEXT_SYSTEM) {
			$url = Email::getOptoutURL($recipient_hash);

			// RFC 8058
			$message->setHeader('List-Unsubscribe', sprintf('<%s>', $url));
			$message->setHeader('List-Unsubscribe-Post', 'Unsubscribe=Yes');

			$optout_text = "Vous recevez ce message car vous êtes inscrit comme membre de l'association.\n"
				. "Pour ne plus jamais recevoir de message de notre part cliquez sur le lien suivant :\n";

			$content .= "\n\n-- \n" . $optout_text . $url;

			if (null !== $content_html) {
				$optout_text = '<hr style="border-top: 2px solid #999; background: none;" /><p style="color: #000; background: #fff; padding: 10px; text-align: center; font-size: 9pt">' . nl2br(htmlspecialchars($optout_text));
				$optout_text.= sprintf('<br /><a href="%s" style="color: blue; text-decoration: underline; padding: 5px; border-radius: 5px; background: #ddd;">Me désinscrire</a></p>', $url);








|
|







397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
		if ($context != self::CONTEXT_SYSTEM) {
			$url = Email::getOptoutURL($recipient_hash);

			// RFC 8058
			$message->setHeader('List-Unsubscribe', sprintf('<%s>', $url));
			$message->setHeader('List-Unsubscribe-Post', 'Unsubscribe=Yes');

			$optout_text = "Vous recevez ce message car vous êtes dans nos contacts.\n"
				. "Pour ne plus jamais recevoir de message de notre part cliquez ici :\n";

			$content .= "\n\n-- \n" . $optout_text . $url;

			if (null !== $content_html) {
				$optout_text = '<hr style="border-top: 2px solid #999; background: none;" /><p style="color: #000; background: #fff; padding: 10px; text-align: center; font-size: 9pt">' . nl2br(htmlspecialchars($optout_text));
				$optout_text.= sprintf('<br /><a href="%s" style="color: blue; text-decoration: underline; padding: 5px; border-radius: 5px; background: #ddd;">Me désinscrire</a></p>', $url);