good encoding for mail subject
authorx2000habouzit <x2000habouzit>
Thu, 21 Oct 2004 13:12:06 +0000 (13:12 +0000)
committerx2000habouzit <x2000habouzit>
Thu, 21 Oct 2004 13:12:06 +0000 (13:12 +0000)
htdocs/vcard.php
include/newsletter.inc.php
include/xorg.misc.inc.php

index 0f4e940..9aebe3b 100644 (file)
  *  Foundation, Inc.,                                                      *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************
-        $Id: vcard.php,v 1.13 2004-10-21 12:26:12 x2000habouzit Exp $
+        $Id: vcard.php,v 1.14 2004-10-21 13:12:06 x2000habouzit Exp $
  ***************************************************************************/
 
 require("auto.prepend.inc.php");
 new_nonhtml_page('vcard.tpl', AUTH_COOKIE);
-
-function quoted_printable_encode($input, $line_max = 76) {
-    $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
-    $lines = preg_split("/(?:\r\n|\r|\n)/", $input);
-    $eol = "\r\n";
-    $linebreak = "=0A";
-    $escape = "=";
-    $output = "";
-
-    for ($j=0;$j<count($lines);$j++) {
-        $line = $lines[$j];
-        $linlen = strlen($line);
-        $newline = "";
-        for($i = 0; $i < $linlen; $i++) {
-            $c = substr($line, $i, 1);
-            $dec = ord($c);
-            if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only
-                $c = "=20";
-            } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
-                $h2 = floor($dec/16); $h1 = floor($dec%16);
-                $c = $escape.$hex["$h2"].$hex["$h1"];
-            }
-            if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
-                $output .= $newline.$escape."\n"; // soft line break; " =\r\n" is okay
-                $newline = "    ";
-            }
-            $newline .= $c;
-        } // end of for
-        $output .= $newline;
-        if ($j<count($lines)-1) $output .= $linebreak;
-    }
-    return trim($output);
-}
+require("xorg.misc.inc.php");
 
 function format_adr($params, &$smarty) {
     // $adr1, $adr2, $adr3, $cp, $ville, $region, $pays
index d3b7a52..8ad872a 100644 (file)
  *  Foundation, Inc.,                                                      *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************
-        $Id: newsletter.inc.php,v 1.21 2004-10-20 20:04:28 x2000habouzit Exp $
+        $Id: newsletter.inc.php,v 1.22 2004-10-21 13:12:06 x2000habouzit Exp $
  ***************************************************************************/
 
-
 define('FEMME', 1);
 define('HOMME', 0);
 
+require_once("xorg.misc.inc.php");
 
 class NewsLetter {
     var $_id;
@@ -83,7 +83,10 @@ class NewsLetter {
                              WHERE  id='{$this->_id}'");
     }
 
-    function title() { return stripslashes($this->_title); }
+    function title($mail_enc=false) {
+       $title = stripslashes($this->_title);
+       return $mail_enc ? "=?ISO-8859-1?Q?".quoted_printable_encode($title,200)."?=" : $title;;
+    }
     function head() { return stripslashes($this->_head); }
 
     function getArt($aid) {
@@ -251,7 +254,7 @@ EOF;
        require_once('diogenes.mailer.inc.php');
        $mailer = new DiogenesMailer("Lettre Mensuelle Polytechnique.org <info+nlp@polytechnique.org>",
                                     "$prenom $nom <$forlife@polytechnique.org>",
-                                    replace_accent($this->title()),
+                                    $this->title(true),
                                     $html);
        if($html) {
            $mailer->addPart('text/plain; charset=iso-8859-1', 'iso-8859-1', $this->toText($prenom,$nom,$sex));
@@ -433,5 +436,4 @@ function enriched_to_text($input,$html=false,$just=false,$indent=0,$width=68) {
        return $text;
     }
 }
-
 ?>
index 464e9f6..d7f1235 100644 (file)
  *  Foundation, Inc.,                                                      *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************
-        $Id: xorg.misc.inc.php,v 1.6 2004-09-03 00:15:51 x2000bedo Exp $
+        $Id: xorg.misc.inc.php,v 1.7 2004-10-21 13:12:06 x2000habouzit Exp $
  ***************************************************************************/
 
+function quoted_printable_encode($input, $line_max = 76) {
+    $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
+    $lines = preg_split("/(?:\r\n|\r|\n)/", $input);
+    $eol = "\r\n";
+    $linebreak = "=0A";
+    $escape = "=";
+    $output = "";
+
+    for ($j=0;$j<count($lines);$j++) {
+        $line = $lines[$j];
+        $linlen = strlen($line);
+        $newline = "";
+        for($i = 0; $i < $linlen; $i++) {
+            $c = substr($line, $i, 1);
+            $dec = ord($c);
+            if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only
+                $c = "=20";
+            } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
+                $h2 = floor($dec/16); $h1 = floor($dec%16);
+                $c = $escape.$hex["$h2"].$hex["$h1"];
+            }
+            if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
+                $output .= $newline.$escape."\n"; // soft line break; " =\r\n" is okay
+                $newline = "    ";
+            }
+            $newline .= $c;
+        } // end of for
+        $output .= $newline;
+        if ($j<count($lines)-1) $output .= $linebreak;
+    }
+    return trim($output);
+}
+
 /** vérifie si une adresse email (sans @) correspond à un alias (FIXME ou une liste)...
  * @param $email l'adresse email a verifier
  * @return BOOL