summaryrefslogtreecommitdiff
path: root/it_mail.class
diff options
context:
space:
mode:
authorDavid Flatz2014-04-28 14:55:36 +0200
committerDavid Flatz2014-04-28 15:55:06 +0200
commitc6639d1537032199304c2d5c2b25df3517f7da9b (patch)
tree1cd61a1637a3b2897600280ba0c2af3948a9826c /it_mail.class
parentdb2d783be5c72d445f97aae5a0cb51fe2504b983 (diff)
downloaditools-c6639d1537032199304c2d5c2b25df3517f7da9b.tar.gz
itools-c6639d1537032199304c2d5c2b25df3517f7da9b.tar.bz2
itools-c6639d1537032199304c2d5c2b25df3517f7da9b.zip
fix escaping of addrlists, don't escape email address
Diffstat (limited to 'it_mail.class')
-rw-r--r--it_mail.class30
1 files changed, 20 insertions, 10 deletions
diff --git a/it_mail.class b/it_mail.class
index f24a603..46095bf 100644
--- a/it_mail.class
+++ b/it_mail.class
@@ -304,20 +304,30 @@ function send($p = array())
*/
function header_escape($string, $emailmode = false)
{
- # 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)
+ $escape = function ($part)
{
- # Encode if not email address and contains special chars
- $result .= !preg_match($emailpattern, $part) && preg_match('/[\x00-\x1f\x7f-\xff]/', $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 $result;
+ if ($emailmode)
+ {
+ # 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);
+ }
+ else
+ return $escape($string);
}