Overview
Comment:Ajout de l'entête Message-ID dans les mails partants, correction double-encodage des sujets pour l'envoi par SMTP. Via un patch de @daniel merci
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: a87e131fa4c68226a1dae2b6a979519875dbb396
User & Date: bohwaz on 2017-08-13 23:24:38
Other Links: branch diff | manifest | tags
Context
2017-08-14
01:27
Le mot de passe ne doit pas être obligatoire par défaut, parce que en fait dans 99% des cas on s'en fout qu'un membre ait un mot de passe check-in: 87feaa92c2 user: bohwaz tags: dev
2017-08-13
23:24
Ajout de l'entête Message-ID dans les mails partants, correction double-encodage des sujets pour l'envoi par SMTP. Via un patch de @daniel merci check-in: a87e131fa4 user: bohwaz tags: dev
2017-08-09
07:19
Utilisation du numéro plutôt que l'ID pour import/export de membre check-in: 6877253ad2 user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/Utils.php from [72549dd72f] to [07575ef06e].

404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
        $str = preg_replace('/<em>(\V*?)<\/em>/', '\'\'$1\'\'', $str);
        $str = preg_replace('/<li>(\V*?)<\/li>/', '* $1', $str);
        $str = preg_replace('/<ul>|<\/ul>/', '', $str);
        $str = preg_replace('/<a href="([^"]*?)">(\V*?)<\/a>/', '[[$2 | $1]]', $str);
        return $str;
    }

    static public function mail($to, $subject, $content, $additional_headers = [])
    {
        // Création du contenu du message
        $content = wordwrap($content);
        $content = trim($content);

        $content = preg_replace("#(?<!\r)\n#si", "\r\n", $content);

        // Construction des entêtes
        $headers = '';

        $config = Config::getInstance();

        if (empty($additional_headers['From']))
        {
            $additional_headers['From'] = '"NE PAS REPONDRE" <'.$config->get('email_envoi_automatique').'>';
        }

        $additional_headers['MIME-Version'] = '1.0';
        $additional_headers['Content-type'] = 'text/plain; charset=UTF-8';
        $additional_headers['Return-Path'] = $config->get('email_envoi_automatique');

        foreach ($additional_headers as $name=>$value)
        {
            $headers .= $name . ': '.$value."\r\n";
        }

        $headers = preg_replace("#(?<!\r)\n#si", "\r\n", $headers);

        $subject = '=?UTF-8?B?'.base64_encode($subject).'?=';

        if (is_array($to))
        {
            foreach ($to as $t)
            {
                if (!self::_sendMail($t, $subject, $content, $headers))
                {







|






<
<
<
<


|

|


|
|
|

<
<
<
<
|
<
|
<







404
405
406
407
408
409
410
411
412
413
414
415
416
417




418
419
420
421
422
423
424
425
426
427
428




429

430

431
432
433
434
435
436
437
        $str = preg_replace('/<em>(\V*?)<\/em>/', '\'\'$1\'\'', $str);
        $str = preg_replace('/<li>(\V*?)<\/li>/', '* $1', $str);
        $str = preg_replace('/<ul>|<\/ul>/', '', $str);
        $str = preg_replace('/<a href="([^"]*?)">(\V*?)<\/a>/', '[[$2 | $1]]', $str);
        return $str;
    }

    static public function mail($to, $subject, $content, $headers = [])
    {
        // Création du contenu du message
        $content = wordwrap($content);
        $content = trim($content);

        $content = preg_replace("#(?<!\r)\n#si", "\r\n", $content);




        $config = Config::getInstance();

        if (empty($headers['From']))
        {
            $headers['From'] = '"NE PAS REPONDRE" <'.$config->get('email_envoi_automatique').'>';
        }

        $headers['MIME-Version'] = '1.0';
        $headers['Content-type'] = 'text/plain; charset=UTF-8';
        $headers['Return-Path'] = $config->get('email_envoi_automatique');





        $hash = sha1(uniqid() . var_export([$additional_headers, $to, $subject, $content], true));

        $headers['Message-ID'] = sprintf('%s@%s', $hash, isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : gethostname());


        if (is_array($to))
        {
            foreach ($to as $t)
            {
                if (!self::_sendMail($t, $subject, $content, $headers))
                {
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480










481
482
483
484
485
486
487
488
                throw new \RuntimeException('Impossible d\'envoyer l\'email');
            }
        }

        return true;
    }

    static protected function _sendMail($to, $subject, $content, $headers)
    {
        if (SMTP_HOST)
        {
            $const = '\KD2\SMTP::' . strtoupper(SMTP_SECURITY);
            
            if (!defined($const))
            {
                throw new \LogicException('Configuration: SMTP_SECURITY n\'a pas une valeur reconnue. Valeurs acceptées: STARTTLS, SSL, NONE.');
            }

            $secure = constant($const);

            $smtp = new SMTP(SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD, $secure);
            return $smtp->send($to, $subject, $content, $headers);
        }
        else
        {










            return mail('bohwaz', $subject, $content, $headers);
        }
    }

    static public function clearCaches($path = false)
    {
        if (!$path)
        {







|

















>
>
>
>
>
>
>
>
>
>
|







446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
                throw new \RuntimeException('Impossible d\'envoyer l\'email');
            }
        }

        return true;
    }

    static protected function _sendMail($to, $subject, $content, array $headers)
    {
        if (SMTP_HOST)
        {
            $const = '\KD2\SMTP::' . strtoupper(SMTP_SECURITY);
            
            if (!defined($const))
            {
                throw new \LogicException('Configuration: SMTP_SECURITY n\'a pas une valeur reconnue. Valeurs acceptées: STARTTLS, SSL, NONE.');
            }

            $secure = constant($const);

            $smtp = new SMTP(SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD, $secure);
            return $smtp->send($to, $subject, $content, $headers);
        }
        else
        {
            // Encodage du sujet
            $subject = sprintf('=?UTF-8?B?%s?=', base64_encode($subject));
            $raw_headers = '';

            // Sérialisation des entêtes
            foreach ($additional_headers as $name=>$value)
            {
                $raw_headers .= sprintf("%s: %s\r\n", $name, $value);
            }

            return mail($to, $subject, $content, $raw_headers);
        }
    }

    static public function clearCaches($path = false)
    {
        if (!$path)
        {