In mailparse version 2.1.1 (and perhaps earlier), when using mailparse_msg_extract_part() with a callback function, it breaks the data it passes to it into 4kB chunks and calls the callback function for each chunk. So, for example, if it's extracting a 41kB MIME part, the callback function you define will be called 11 times, each time with the next chunk of data. Here's some quick-and-dirty code that shows one way to handle this:

substr() uses the string length, not the position as third argument. The corrected version of the following code line:<?php$parts[$s] = substr($file_txt, $starting_pos_body, $ending_pos_body-$starting_pos_body);?>

get_structure returns array(1,1.1,1.1.2) etc but its not easy to get the contents of each part as mailparse_msg_extract_part() and mailparse_msg_extract_part_file() just return the lot. However get_part_data will return the string offsets so you know where to chop the message so you can get the contents of the parts.