KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ How to download attachments from *.eml file Re: How to download attachments from *.eml file

  • Laura

    Administrator
    April 5, 2023 at 12:00 am

    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:

    1. 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
    2. Use regex to locate the contents of the attachment, content type and encoding type (from the example looks to default to b64)
    3. 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}?
    4. 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/