From 1244c6c7de2eb3fb7d5d49c6d78acf0255dd20ea Mon Sep 17 00:00:00 2001 From: Klaus Leithoff Date: Thu, 23 Apr 2015 14:31:33 +0000 Subject: [PATCH] try to cope with broken emailaddresses in our parseAddressList when using Horde_Mail_Rfc822->parseAddressList (returning empty object when fed with a broken address) --- emailadmin/inc/class.emailadmin_imapbase.inc.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/emailadmin/inc/class.emailadmin_imapbase.inc.php b/emailadmin/inc/class.emailadmin_imapbase.inc.php index 861f63ee55..a9fe9f2060 100644 --- a/emailadmin/inc/class.emailadmin_imapbase.inc.php +++ b/emailadmin/inc/class.emailadmin_imapbase.inc.php @@ -6306,11 +6306,22 @@ class emailadmin_imapbase { $rfc822 = new Horde_Mail_Rfc822(); $ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array()); + //error_log(__METHOD__.__LINE__.'#'.array2string($addresses).'#'.array2string($ret).'#'.$ret->count().'#'.$ret->count); + if ((empty($ret) || $ret->count()==0)&& is_string($addresses) && strlen($addresses)>0) + { + $matches = array(); + preg_match_all("/[\w\.,-.,_.,0-9.]+@[\w\.,-.,_.,0-9.]+/",$addresses,$matches); + //error_log(__METHOD__.__LINE__.array2string($matches)); + foreach ($matches[0] as &$match) $match = trim($match,', '); + $addresses = implode(',',$matches[0]); + //error_log(__METHOD__.__LINE__.array2string($addresses)); + $ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array()); + //error_log(__METHOD__.__LINE__.'#'.array2string($addresses).'#'.array2string($ret).'#'.$ret->count().'#'.$ret->count); + } //foreach($ret as $i => $adr) error_log(__METHOD__."('$addresses', $default_domain) parsed $i: mailbox=$adr->mailbox, host=$adr->host, personal=$adr->personal --> ".$adr); return $ret; } - /** * Send a read notification *