summaryrefslogtreecommitdiff
path: root/it_mail.class
diff options
context:
space:
mode:
Diffstat (limited to 'it_mail.class')
-rw-r--r--it_mail.class51
1 files changed, 25 insertions, 26 deletions
diff --git a/it_mail.class b/it_mail.class
index 46095bf..5746056 100644
--- a/it_mail.class
+++ b/it_mail.class
@@ -82,7 +82,7 @@ function add_header($header, $value)
{
case 'To':
foreach ((array)$value as $val)
- $this->to[] = $this->header_escape($val, true);
+ $this->to[] = $this->addrlist_escape($val);
break;
case 'Subject':
@@ -91,12 +91,12 @@ function add_header($header, $value)
case 'Cc':
foreach ((array)$value as $val)
- $this->cc[] = $this->header_escape($val, true);
+ $this->cc[] = $this->addrlist_escape($val);
break;
case 'Bcc':
foreach ((array)$value as $val)
- $this->bcc[] = $this->header_escape($val, true);
+ $this->bcc[] = $this->addrlist_escape($val);
break;
case 'charset':
@@ -108,7 +108,7 @@ function add_header($header, $value)
/* FALLTHROUGH */
default:
$this->header_names[] = $header;
- $this->header_values[] = $this->header_escape($value, $header == 'From' || $header == 'Reply-To');
+ $this->header_values[] = $header == 'From' || $header =='Reply-To' ? $this->addrlist_escape($value) : $this->header_escape($value);
break;
}
}
@@ -302,32 +302,31 @@ function send($p = array())
* @param $string String to be escaped
* @return String escape suitable for sending in header line
*/
-function header_escape($string, $emailmode = false)
+function header_escape($string)
{
- $escape = function ($part)
- {
- return preg_match('/[\x00-\x1f\x7f-\xff]/', $part)
- ? ("=?{$this->charset}?Q?" . str_replace(" ", "_", preg_replace_callback('/[\x00-\x1f=\x7f-\xff]/', function($m) { return sprintf('=%02X', ord($m[0])); }, trim($part, '"'))) . "?=")
- : $part;
- };
+ return preg_match('/[\x00-\x1f\x7f-\xff]/', $string)
+ ? ("=?{$this->charset}?Q?" . str_replace(" ", "_", preg_replace_callback('/[\x00-\x1f=\x7f-\xff]/', function($m) { return sprintf('=%02X', ord($m[0])); }, trim($string, '"'))) . "?=")
+ : $string;
+}
- if ($emailmode)
+/**
+ * INTERNAL: Escape address lists in headers like From, To, Cc, Bcc
+ * @param $string String containing address list
+ * @return String suitable for sending in address list headers
+ */
+function addrlist_escape($string)
+{
+ # Exclude e-mail addresses from being encoded as
+ # e.g. GMail or Exchange have problems with that
+ foreach (explode(',', $string) as $mailbox)
{
- # If in emailmode (From, To, Cc, Bcc) then exclude e-mail addresses
- # from being encoded as e.g. GMail or Exchange have problems with that
- $emailpattern = '/^(.*)(\s+?<[^>]+@[^>]+>\s*)$/';
- foreach (explode(',', $string) as $mailbox)
- {
- if (preg_match($emailpattern, $mailbox, $matches))
- $result[] = $escape($matches[1]) . $matches[2];
- else
- $result[] = $mailbox;
- }
-
- return implode(',', $result);
+ if (preg_match('/^(.*)(\s+?<[^>]+@[^>]+>\s*)$/', $mailbox, $matches))
+ $result[] = $this->header_escape($matches[1]) . $matches[2];
+ else
+ $result[] = $mailbox;
}
- else
- return $escape($string);
+
+ return implode(',', $result);
}