diff --git a/mail.php b/mail.php index 502a861..d69af20 100644 --- a/mail.php +++ b/mail.php @@ -777,13 +777,29 @@ class mail $this->sectionAddChild ($sectionIDMixed, $sectionID); $finfo = new \finfo(FILEINFO_MIME); $mimetype = $finfo->buffer($fileContent); - $this->addHeader ("Content-Type", "$mimetype; name=$name\n", $sectionID); + $this->addHeader ("Content-Type", "$mimetype; name=\"". + str_replace ("\"", "=22", + $this->encodeHeaderStringWithPosition ($name, + "quoted-printable", + strlen ("Content-Type: $mimetype; name=")))."\"\r\n", + $sectionID); if ($inline === false) - $this->addHeader ("Content-Disposition", "attachment; filename=$name\r\n", + $this->addHeader ("Content-Disposition", "attachment; filename=\"". + str_replace ("\"", "=22", + $this->encodeHeaderStringWithPosition ($name, + "quoted-printable", + strlen ("Content-Disposition: attachment; ". + "filename="))). + "\"\r\n", $sectionID); else { - $this->addHeader ("Content-Disposition", "inline; filename=$name\r\n", + $this->addHeader ("Content-Disposition", "inline; filename=". + str_replace ("\"", "=22", + $this->encodeHeaderStringWithPosition ($name, + "quoted-printable", + strlen ("Content-Disposition: inline; filename=") + ))."\r\n", $sectionID); $contentID = $this->getMessageID (); $this->addHeader ("Content-ID", "$contentID\r\n", $sectionID); @@ -1393,6 +1409,32 @@ class mail strlen ($header)+2); } + /** Encode a header string not starting on first column. The number of chars + * need to be skipped is passed as argument. The function will correctely + * managethe associated carriage returns + * @param string $content The content to encode + * @param string $encoding The The encoding to use. + * The allowed encodings are "quoted-printable" or "base64" + * @param integer $blanks Initial blanks to be added on string + * @return string the content encoded by $encoding + */ + private function encodeHeaderStringWithPosition ($content, $encoding, $blanks) + { + $prefs = array ("input-charset" => "utf-8", + "output-charset" => "utf-8"); + if ($encoding === "quoted-printable") + $prefs["scheme"] = "Q"; + elseif ($encoding === "base64") + $prefs["scheme"] = "B"; + else + throw new \Exception (_("Invalid encoding provided to ". + "encodeHeaderStringWithPosition"), + 500); + return substr (iconv_mime_encode (str_repeat (" ", $blanks), $content, + $prefs), + $blanks+2); + } + /** Convert a From/To string to array. Manage multiple recipients * Ex. : toto toto , titi * array (array ("name"=>"toto toto", "mail"=>"toto@toto.com"),