diff --git a/mail.php b/mail.php index 151fb36..52a0bad 100644 --- a/mail.php +++ b/mail.php @@ -1119,9 +1119,31 @@ class mail throw new \Exception ("Wanted section not found in addHeader", 404); $sectionMainID = $sectionID; } - $this->sections[$sectionMainID]["_headersArray"][][$header] = $value; - // TODO : Encode ? Strip ? - $this->sections[$sectionMainID]["_headersEML"] .= "$header: $value"; + if ($header === "Return-Path") + { + // Must be placed on the first line and must be unique + reset ($this->sections[$sectionMainID]["_headersArray"]); + if (key_exists (0, $this->sections[$sectionMainID]["_headersArray"]) && + key_exists ("Return-Path", $this->sections[$sectionMainID]["_headersArray"][0])) + { + // Remove the old one + array_shift ($this->sections[$sectionMainID]["_headersArray"]); + $this->sections[$sectionMainID]["_headersEML"] = + substr ($this->sections[$sectionMainID]["_headersEML"], + strpos ($this->sections[$sectionMainID]["_headersEML"], "\n") +1); + } + array_unshift ($this->sections[$sectionMainID]["_headersArray"], + array ($header => $value)); + $this->sections[$sectionMainID]["_headersEML"] = "$header: $value". + $this->sections[$sectionMainID]["_headersEML"]; + } + else + { + // The "normal" headers are places sequentially at the end of the headers + $this->sections[$sectionMainID]["_headersArray"][][$header] = $value; + // TODO : Encode ? Strip ? + $this->sections[$sectionMainID]["_headersEML"] .= "$header: $value"; + } $this->createMailEML (); }