Home › Forums › kdb+ › How to download attachments from *.eml file › Re: How to download attachments from *.eml file
-
Hi KPC,
Looking at an example .eml file here. If you wanted to parse the attachments purely in KDB/Q without the use of Python libs (although I suggest using Python libs) I’d suggest something along the lines of:
- read0 the *.eml file. Depending on the contents and if you want to interpret new lines literally or not you may find “c”$read1 a more appropriate solution
- Use regex to locate the contents of the attachment, content type and encoding type (from the example looks to default to b64)
- Decode the body of the attachment – for b64 decoding in KDB/Q it looks like this is a solution
b64Decode:{c:sum x=”=”;neg[c]_”c”$raze 256 vs’64 sv’0N 4#.Q.b6?x}? - Post-process the data further into Q objects if it’s suitable. E.g. if the filetype is a json you may want to utilise the .j.k json deserialiser for Q
The solution provided should be the preferred solution with embedPy. Adding to this there is a PyPi lib that claims to handle attachments too:
https://pypi.org/project/eml-parser/