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    404           $str = preg_replace('/<em>(\V*?)<\/em>/', '\'\'$1\'\'', $str);
   405    405           $str = preg_replace('/<li>(\V*?)<\/li>/', '* $1', $str);
   406    406           $str = preg_replace('/<ul>|<\/ul>/', '', $str);
   407    407           $str = preg_replace('/<a href="([^"]*?)">(\V*?)<\/a>/', '[[$2 | $1]]', $str);
   408    408           return $str;
   409    409       }
   410    410   
   411         -    static public function mail($to, $subject, $content, $additional_headers = [])
          411  +    static public function mail($to, $subject, $content, $headers = [])
   412    412       {
   413    413           // Création du contenu du message
   414    414           $content = wordwrap($content);
   415    415           $content = trim($content);
   416    416   
   417    417           $content = preg_replace("#(?<!\r)\n#si", "\r\n", $content);
   418         -
   419         -        // Construction des entêtes
   420         -        $headers = '';
   421         -
   422    418           $config = Config::getInstance();
   423    419   
   424         -        if (empty($additional_headers['From']))
          420  +        if (empty($headers['From']))
   425    421           {
   426         -            $additional_headers['From'] = '"NE PAS REPONDRE" <'.$config->get('email_envoi_automatique').'>';
          422  +            $headers['From'] = '"NE PAS REPONDRE" <'.$config->get('email_envoi_automatique').'>';
   427    423           }
   428    424   
   429         -        $additional_headers['MIME-Version'] = '1.0';
   430         -        $additional_headers['Content-type'] = 'text/plain; charset=UTF-8';
   431         -        $additional_headers['Return-Path'] = $config->get('email_envoi_automatique');
          425  +        $headers['MIME-Version'] = '1.0';
          426  +        $headers['Content-type'] = 'text/plain; charset=UTF-8';
          427  +        $headers['Return-Path'] = $config->get('email_envoi_automatique');
   432    428   
   433         -        foreach ($additional_headers as $name=>$value)
   434         -        {
   435         -            $headers .= $name . ': '.$value."\r\n";
   436         -        }
   437         -
   438         -        $headers = preg_replace("#(?<!\r)\n#si", "\r\n", $headers);
   439         -
   440         -        $subject = '=?UTF-8?B?'.base64_encode($subject).'?=';
          429  +        $hash = sha1(uniqid() . var_export([$additional_headers, $to, $subject, $content], true));
          430  +        $headers['Message-ID'] = sprintf('%s@%s', $hash, isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : gethostname());
   441    431   
   442    432           if (is_array($to))
   443    433           {
   444    434               foreach ($to as $t)
   445    435               {
   446    436                   if (!self::_sendMail($t, $subject, $content, $headers))
   447    437                   {
................................................................................
   456    446                   throw new \RuntimeException('Impossible d\'envoyer l\'email');
   457    447               }
   458    448           }
   459    449   
   460    450           return true;
   461    451       }
   462    452   
   463         -    static protected function _sendMail($to, $subject, $content, $headers)
          453  +    static protected function _sendMail($to, $subject, $content, array $headers)
   464    454       {
   465    455           if (SMTP_HOST)
   466    456           {
   467    457               $const = '\KD2\SMTP::' . strtoupper(SMTP_SECURITY);
   468    458               
   469    459               if (!defined($const))
   470    460               {
................................................................................
   474    464               $secure = constant($const);
   475    465   
   476    466               $smtp = new SMTP(SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD, $secure);
   477    467               return $smtp->send($to, $subject, $content, $headers);
   478    468           }
   479    469           else
   480    470           {
   481         -            return mail('bohwaz', $subject, $content, $headers);
          471  +            // Encodage du sujet
          472  +            $subject = sprintf('=?UTF-8?B?%s?=', base64_encode($subject));
          473  +            $raw_headers = '';
          474  +
          475  +            // Sérialisation des entêtes
          476  +            foreach ($additional_headers as $name=>$value)
          477  +            {
          478  +                $raw_headers .= sprintf("%s: %s\r\n", $name, $value);
          479  +            }
          480  +
          481  +            return mail($to, $subject, $content, $raw_headers);
   482    482           }
   483    483       }
   484    484   
   485    485       static public function clearCaches($path = false)
   486    486       {
   487    487           if (!$path)
   488    488           {