As said, code tags are needed to make code readable. But peering through the fog, it does look like the pattern matching to get email addresses is inappropriate. The data appears to enclose email addresses in angle brackets, so having split on colon-space, additional pattern matching needs to be performed on the fields array to extract the required data from the fields.