add( $this->get_recipient_from_string( $recipient ) ); } if ( isset( $recipient['email'] ) ) { $name = isset( $recipient['name'] ) ? $recipient['name'] : ''; $collection->add( new Recipient( $recipient['email'], $name ) ); } } ); return $collection; } public function get_email_counts( $extra ) { $values = array( 'to' => isset( $extra['to'] ) ? $extra['to'] : '', 'cc' => isset( $extra['headers']['cc'] ) ? $extra['headers']['cc'] : '', 'bcc' => isset( $extra['headers']['bcc'] ) ? $extra['headers']['bcc'] : '' ); $count = 0; foreach ( $values as $recipients ) { $recipients = $this->parse( $recipients ); $count += $recipients->count(); } return $count; } private function get_recipient_from_string( $string ) { if ( strpos( $string, '<' ) === false ) { return new Recipient( trim( $string ), '' ); } // Email seems to be in RFC5322 Mailbox format preg_match( '/([^<]*)<([^>]*)>/', $string, $email_data ); return new Recipient( $email_data[2], trim( $email_data[1], '" ' ) ); } }