Well, just something slapped down to keyboard. It needs some work (i.e. you might want to retrieve filenames, uudecode it etc). This should, however, give you the basic idea.
The function, as you can see, returns an array starting at index 1. So $returnVar[1] will be the data between the first begin .. end, and $returnVar[2] between the second etc.
Could probably be optimized as well ;]
function splitAttachments($mailBody) {
$attData = array();
$attCount = 1;
$storeData = 0;
foreach (explode("\n", $mailBody) AS $key => $val) {
if (substr($val, 0, 5) == 'begin') {
$storeData = 1; continue;
}
if (substr($val, 0, 3) == 'end') {
$storeData = 0; $attCount++; continue;
}
if ($storeData) $attData[$attCount] .= $val . "\n";
}
if ($storeData) {
print "Bewm";
exit();
}
return $attData;
}