I'm getting some data from a server and among other things I receive what looks like a MIME-encoded file (or files), as if it was an email body
This is an example of a two files response:
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=________________314159265358979323846
--________________314159265358979323846
Content-Type: application/xml; name="1140800950110001200045971048.xml"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="1140800950110001200045971048.xml"
PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZG [trimmed]
aW5pY2FsRG9jdW1lbnQ+Cg==
--________________314159265358979323846
Content-Type: application/pdf; name="1140800950110001200045971048.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="1140800950110001200045971048.pdf"
JVBERi0xLjQKJaqrrK0KNCAwIG9i [trimmed]
mCjIzMzA3CiUlRU9GCg==
--________________314159265358979323846--
I've got to extract the two files (in fact just the pdf would be fine) and then base64_decode them for displaying
There are a couple functions/libraries that would do this easily but it seems they all want an IMAP stream rather than a string, is a regex my only choice?