Example how to handle mail content from a variable:
<?php
$buffer = [...] // Mail Content from pipe or whatever
$mail = mailparse_msg_create();
mailparse_msg_parse($mail,$buffer);
$struct = mailparse_msg_get_structure($mail); 
foreach($struct as $st) { 
    $section = mailparse_msg_get_part($mail, $st); 
    $info = mailparse_msg_get_part_data($section); 
    
    print_r($info);
}
?>