Manage multi-part mails

Hello,
first, I’m sorry if the question has already been asked, but I couldn’t find an answer after a quick search:

some clients send us files via mails, so we have created a poller that polls the mailbox, retreives mails, and is supposed to give as an output a document list that would simply contain the attached files (as stream, bytes, anything) and their names.

So the poller sends a stream to a service that does that.

Our problem is that we havn’t found a clean solution for this.

Right now, the algorythm we use is this one:

  • convert the stream to a mimeData using “pub.mime.createMimeData”
  • convert the stream to a string we will call inputStream
  • get the number of parts using “pub.mime.getNumPart”
  • Iterate over the parts, getting the content
  • search for the next occurency of “filename” in the inputString
  • make a dirty parsing to get the actual attachment name
  • if the name is ok (we filter some extensions), add it to the list

Here is the problem:

  • each mail server uses a different header format (gmail, yahoo, exchange, etc.) which forces us to adapt our parser each time a client modifies something on his side, sometimes the file name is called “filename”, sometimes it’s just “name”, sometimes there are quotes, sometimes it’s in the content-type, sometimes in the content-disposition etc.

Isn’t there any clean way to get what we want (file and filename of all the attachments)? the “pub.mime.getTransportInfo” service looked promising, but it only gives one filename! (usually the first attachment)

Thanks for reading so far!