A basic StreamedMail implementation should be created which will use StreamingMailStoreMBean. In the event the size of the mail goes above MAX_IN_MEM then all output should be sent to the StreamingMailStoreMBean which should return an ID. The idea is that the StreamingMailStoreMBean (pluggable implementation) will write to the filesystem or to a DB Blob type that does not store the mail in the HEAP. This will involve changes to the mailbox implementation to allow us to store a pointer to the mailstore, mail ID rather than the actual mail. Large mails won't be cached and thus the MAX_IN_MEM is trading performance for heap safety.
Eventually there ought to be database and filesystem versions. The database version being more cluster-friendly. The behavior ought to be toggleable on the whole as this can be avoided with a MAX_MAIL size and the basic case. On exceptionally busy systems or systems with large attachment sizes though, this will be better.