<?php
$data = "from remote.intra.domain.net (sbs-2011.intra.local [0.0.0.0]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by mailhost.domain.net (Postfix) with ESMTPS id A2E067029D9 for <john.doe@domain.net>" ;
function extractComments( $data )
{
$comments = [ ] ;
$index = null ;
$parensCounter = 0 ;
{
if ( $char == '(' && ! isset ( $index ) ) {
$index = count ( $comments ) ; $comments [ $index ] = '' ;
}
else if ( $char == '(' )
{
$parensCounter ++;
$comments [ $index ] .= $char ;
}
else if ( $char == ')' && $parensCounter != 0 )
{
$parensCounter --;
$comments [ $index ] .= $char ;
}
else if ( $char == ')' )
{
$parensCounter = 0 ;
$index = null ;
}
{
$comments [ $index ] .= $char ;
}
}
return $comments ;
}
function extractDomain( $data )
{
$matches = [ ] ;
return $matches [ 1 ] ;
}
PD9waHAKCiRkYXRhID0gImZyb20gcmVtb3RlLmludHJhLmRvbWFpbi5uZXQgKHNicy0yMDExLmludHJhLmxvY2FsIFswLjAuMC4wXSkgKHVzaW5nIFRMU3YxIHdpdGggY2lwaGVyIEFFUzEyOC1TSEEgKDEyOC8xMjggYml0cykpIChObyBjbGllbnQgY2VydGlmaWNhdGUgcmVxdWVzdGVkKSBieSBtYWlsaG9zdC5kb21haW4ubmV0IChQb3N0Zml4KSB3aXRoIEVTTVRQUyBpZCBBMkUwNjcwMjlEOSBmb3IgPGpvaG4uZG9lQGRvbWFpbi5uZXQ+IjsKCmZ1bmN0aW9uIGV4dHJhY3RDb21tZW50cygkZGF0YSkKewogICAgJGNvbW1lbnRzICAgICAgPSBbXTsKICAgICRpbmRleCAgICAgICAgID0gbnVsbDsKICAgICRwYXJlbnNDb3VudGVyID0gMDsKCiAgICBmb3JlYWNoKHN0cl9zcGxpdCgkZGF0YSkgYXMgJGNoYXIpCiAgICB7CiAgICAgICAgaWYoJGNoYXIgPT0gJygnICYmICFpc3NldCgkaW5kZXgpKQogICAgICAgIHsKICAgICAgICAgICAgJGluZGV4ID0gY291bnQoJGNvbW1lbnRzKTsKICAgICAgICAgICAgJGNvbW1lbnRzWyRpbmRleF0gPSAnJzsKICAgICAgICB9CiAgICAgICAgZWxzZSBpZigkY2hhciA9PSAnKCcpCiAgICAgICAgewogICAgICAgICAgICAkcGFyZW5zQ291bnRlcisrOwogICAgICAgICAgICAkY29tbWVudHNbJGluZGV4XSAuPSAkY2hhcjsKICAgICAgICB9CiAgICAgICAgZWxzZSBpZigkY2hhciA9PSAnKScgJiYgJHBhcmVuc0NvdW50ZXIgIT0gMCkKICAgICAgICB7CiAgICAgICAgICAgICRwYXJlbnNDb3VudGVyLS07CiAgICAgICAgICAgICRjb21tZW50c1skaW5kZXhdIC49ICRjaGFyOwogICAgICAgIH0KICAgICAgICBlbHNlIGlmKCRjaGFyID09ICcpJykKICAgICAgICB7CiAgICAgICAgICAgICRwYXJlbnNDb3VudGVyID0gMDsKICAgICAgICAgICAgJGluZGV4ID0gbnVsbDsKICAgICAgICB9CiAgICAgICAgZWxzZSBpZihpc3NldCgkaW5kZXgpKQogICAgICAgIHsKICAgICAgICAgICAgJGNvbW1lbnRzWyRpbmRleF0gLj0gJGNoYXI7CiAgICAgICAgfQogICAgfQoKICAgIHJldHVybiAkY29tbWVudHM7Cn0KCmZ1bmN0aW9uIGV4dHJhY3REb21haW4oJGRhdGEpCnsKICAgICRtYXRjaGVzID0gW107CgogICAgcHJlZ19tYXRjaCgnI2Zyb21ccyguKylccysjVScsICRkYXRhLCAkbWF0Y2hlcyk7CgogICAgcmV0dXJuICRtYXRjaGVzWzFdOwp9Cgp2YXJfZHVtcChhcnJheV9tZXJnZShbZXh0cmFjdERvbWFpbigkZGF0YSldLCBleHRyYWN0Q29tbWVudHMoJGRhdGEpKSk7