This logic is a little suspect.  There's no table of contents; if you know about N attachments, then you already have at least N-1 of them in their entirety, possibly all of them.  You would want to attribute the leftover size to the MIME part that was open when the EOF happened, be it attachment or body-part.