I have a message with over a 1000 embedded attachments(!), and it breaks Dovecot. The issue appears to be buffer management. There is some logic in the function message_part_deserialize_part that seems to assume that the message part structure is in a contiguous array, but that doesn't seem to be the case. I haven't been able to figure out enough about the memory management in Dovecot to fix the problem.
Below is a horrible workaround that just allocates a lot more memory for the message part array, so that it remains contiguous.
*** mail-index-update.c.orig Wed Mar 26 10:41:55 2003 --- mail-index-update.c Sun Apr 20 16:53:45 2003
*** 498,504 ****
if (cache_fields & DATA_FIELD_MESSAGEPART) {
t_push();
! buf = buffer_create_dynamic(data_stack_pool, 2048, (size_t)-1); message_part_serialize(part, buf);
--- 498,504 ----
if (cache_fields & DATA_FIELD_MESSAGEPART) {
t_push();
! buf = buffer_create_dynamic(data_stack_pool, 51200, (size_t)-1); message_part_serialize(part, buf);