From 974c9e392c6571786a8d13f3948232b1305042d6 Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Wed, 10 Sep 2008 19:09:20 +0000 Subject: Handle arrays for header values passed to it_mail --- it_mail.class | 44 ++++++++++++-------------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) (limited to 'it_mail.class') diff --git a/it_mail.class b/it_mail.class index 7a09085..9057ef3 100644 --- a/it_mail.class +++ b/it_mail.class @@ -62,13 +62,10 @@ class it_mail * Note: Headers To, Cc, Bcc can be arrays * @param $headers Array of headers for this email, e.g. From, To and Subject */ -function it_mail($headers = "") +function it_mail($headers = array()) { - if (is_array($headers)) - { - foreach ($headers as $header => $value) - $this->add_header($header, $value); - } + foreach ((array)$headers as $header => $value) + $this->add_header($header, $value); } @@ -80,42 +77,25 @@ function it_mail($headers = "") */ function add_header($header, $value) { - $value = $this->header_escape($value); - switch ($header) { case 'To': - if (is_array($value)) - { - foreach ($value as $val) - $this->to[] = $val; - } - else - $this->to[] = $value; + foreach ((array)$value as $val) + $this->to[] = $this->header_escape($val); break; case 'Subject': - $this->subject .= $value; + $this->subject .= $value; # Escape on sending break; case 'Cc': - if (is_array($value)) - { - foreach ($value as $val) - $this->cc[] = $val; - } - else - $this->cc[] = $value; + foreach ((array)$value as $val) + $this->cc[] = $this->header_escape($val); break; case 'Bcc': - if (is_array($value)) - { - foreach ($value as $val) - $this->bcc[] = $val; - } - else - $this->bcc[] = $value; + foreach ((array)$value as $val) + $this->bcc[] = $this->header_escape($val); break; case 'charset': @@ -127,7 +107,7 @@ function add_header($header, $value) /* FALLTHROUGH */ default: $this->header_names[] = $header; - $this->header_values[] = $value; + $this->header_values[] = $this->header_escape($value); break; } } @@ -305,7 +285,7 @@ function send() $text .= "--$boundary1--\n"; } - return mail($to, $this->subject, $text, join("\n", $headers), $this->flags); + return mail($to, $this->header_escape($this->subject), $text, join("\n", $headers), $this->flags); } -- cgit v1.2.3