diff options
author | Christian Schneider | 2008-09-15 13:22:07 +0000 |
---|---|---|
committer | Christian Schneider | 2008-09-15 13:22:07 +0000 |
commit | c6ce30d4f80e155e2caf6d24f8ac873fd760bb09 (patch) | |
tree | 08661ae4d0daa9d60629eb215254544786b17959 | |
parent | 636bb99ad404c0744029200dbc046b65bcc8615b (diff) | |
download | itools-c6ce30d4f80e155e2caf6d24f8ac873fd760bb09.tar.gz itools-c6ce30d4f80e155e2caf6d24f8ac873fd760bb09.tar.bz2 itools-c6ce30d4f80e155e2caf6d24f8ac873fd760bb09.zip |
Fix bug with email addresses including full name and GMail
-rw-r--r-- | it_mail.class | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/it_mail.class b/it_mail.class index dedf950..d67effb 100644 --- a/it_mail.class +++ b/it_mail.class @@ -81,7 +81,7 @@ function add_header($header, $value) { case 'To': foreach ((array)$value as $val) - $this->to[] = $this->header_escape($val); + $this->to[] = $this->header_escape($val, true); break; case 'Subject': @@ -90,12 +90,12 @@ function add_header($header, $value) case 'Cc': foreach ((array)$value as $val) - $this->cc[] = $this->header_escape($val); + $this->cc[] = $this->header_escape($val, true); break; case 'Bcc': foreach ((array)$value as $val) - $this->bcc[] = $this->header_escape($val); + $this->bcc[] = $this->header_escape($val, true); break; case 'charset': @@ -107,7 +107,7 @@ function add_header($header, $value) /* FALLTHROUGH */ default: $this->header_names[] = $header; - $this->header_values[] = $this->header_escape($value); + $this->header_values[] = $this->header_escape($value, $header == 'From'); break; } } @@ -294,9 +294,22 @@ function send() * @param $string String to be escaped * @return String escape suitable for sending in header line */ -function header_escape($string) +function header_escape($string, $emailmode = false) { - return preg_match('/[\x00-\x1f\x7f-\xff]/', $string) ? ("=?iso-8859-1?Q?" . preg_replace('/[\x00-\x20=\x7f-\xff]/e', "sprintf('=%02X', ord('\\0'))", $string) . "?=") : $string; + # If in emailmode (From, To, Cc, Bcc) then exclude <email@domain.com> + # from being encoded as e.g. GMail has problems with that + # Otherwise encode whole string at once, i.e. do not split + $emailpattern = $emailmode ? '/(\s*<[^>]+@[^>]+>[,\s]*)/' : '/DO_NOT_SLPIT{64738}/'; + + foreach (preg_split($emailpattern, $string, -1, PREG_SPLIT_DELIM_CAPTURE) as $part) + { + # Encode if not email address and contains special chars + $result .= !preg_match($emailpattern, $part) && preg_match('/[\x00-\x1f\x7f-\xff]/', $part) + ? ("=?iso-8859-1?Q?" . str_replace(" ", "_", preg_replace('/[\x00-\x1f=\x7f-\xff]/e', "sprintf('=%02X', ord('\\0'))", $part)) . "?=") + : $part; + } + + return $result; } /** |