mail : cut the long attachment filenames in headers with the correct encoding
mail : manage correctely the double-quotes in filenames git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2936 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
48
mail.php
48
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 <toto@toto.com>, titi <titi@titi.com>
|
||||
* array (array ("name"=>"toto toto", "mail"=>"toto@toto.com"),
|
||||
|
||||
Reference in New Issue
Block a user