1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
   |  
private function edit($str)
    {
        //replace mail
        $str = Sanitizer::mailIntoData($str);
 
        // PGP Signed Message
        $str = preg_replace_callback('~^-----BEGIN PGP SIGNED MESSAGE-----\RHash:\s(.*)$~m', function($m) {
            self::$pgp['hash'][0] = $m[0];
            self::$pgp['hash'][1] = $m[1];
        }, $str);  
 
        // PGP Signature
        $str = preg_replace_callback('~^-----BEGIN PGP SIGNATURE-----\R\h*$(.*\S)?\s*\z~ms', function($m) {
            self::$pgp['sign'] = $m[0];
        }, $str);
 
        // correction pour le bloc de signature lors de PGP Message
        if(self::$pgp['hash']) $str = preg_replace('~^(.*(>+).*)>\s(-\s--)$~m', '$1'.$this->nl.$this->nl."$3", $str); 
        // place la signature finale dans un bloc de code
        if(self::$pgp['hash']) $pattern = '~^-\s--\h*$(.*\S)?\s*\z~ms';
        else $pattern = '~^--\h*$(.*\S)?\s*\z~ms';
        $str = preg_replace_callback($pattern, function ($m) {
            self::$sign = '```' . $m[1] . $this->nl . '```';
        }, $str);
 
        // line title (1rst)
        $str = preg_replace_callback('~^(\#+)(.+)$~m', function ($m) {
            self::$title = $m[2];
        }, $str);
 
        // line author (2d)
        $str = preg_replace_callback('~^(\*{2})(.+)(\*{2})$~m', function ($m) {
            self::$author = $m[2];
        }, $str); 
 
        // line date (3d)
        $str = preg_replace_callback('~^(\*+)(.+)(\*+)$~m', function ($m) {
            self::$date = $m[2];
        }, $str); 
 
        // efface les signatures dans les blockquotes
        $pattern = '~^(>+) --\h*(?:\R\1(?![^\r\n ]).*)*$~m';
        $str = preg_replace($pattern, '', $str); 
 
        // prend la ligne précédent le blockquote et ajoute une imbrication...
        //  for english
        $str = preg_replace('~^(?|(>+) |())(?=On\s[\d/]{6,8}\s[\d:]{4,5}\s[AP]M,.*\bwrote:\h*\R\1> )~m', '$1> ', $str);  
        //  for french    
        $str = preg_replace('~^(?|(>+) |())(?=\*\s.*\[[\d/-]{10}\s[\d:]{8}\s\+\d{4}]:\h*\R\1> )~m', '$1> ', $str);   
 
        // efface les astérisques en début de ligne ou de blockquote
        $str = preg_replace('~^>*\K ?\*+~m', '', $str);
 
        // descend d'un niveau de blockquote (si ce n'est déjà le cas)
        do {  
            $str = preg_replace('~^>(>++).*\R\K(?!\1(?:>|\h*$))~m', '$1' . $this->nl, $str, -1, $count);
        } while ($count);
 
        // ajoute une nouvelle ligne suivi d'autant de '>' si ligne 'auteur+date:'
        $str = preg_replace('~^(>+)(.*:)~m', '$1$2'.$this->nl.'$1', $str);
 
        return $str;
    } |