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

  • How to download attachments from *.eml file

    Posted by kpc on April 5, 2023 at 12:00 am

    How to download attachments from *.eml file using kdb code?

    kpc replied 9 months, 2 weeks ago 5 Members · 4 Replies
  • 4 Replies
  • rocuinneagain

    Member
    April 5, 2023 at 12:00 am

    Kdb+ can parse binary files as nicely shown at the recent KX meetup by

    https://community.kx.com/t5/Events/KX-Community-Meetup-New-York/ba-p/13880

    File formats can get complicated though so this can be a lot of work.

     

    If I wanted to do this task quickly I would either:

    a) Use a system call to a command line tool to extract the files on disk and then read them in from there.

    Writing them to current directory or using mktemp command to write in /var/tmp

    b) Wrap some exiting python code using EmbedPy to extract the email and attachments  to JSON and read in to kdb+ this way.

    Similar to how I did for XML with https://github.com/rianoc/qXML

     

    Some discussions on the topic in Python world:

    (Note: I have not tested these for functionality or safety)

  • 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/

  • lucuslium

    Member
    February 10, 2024 at 12:00 am

    Here I’m going to suggest you download attachments from the .eml file with the help of the EML Attachment Extractor Tool For users who want to download many attachments from EML and EMLX files, this is the most effective and user-friendly solution available. The program works well because users expect quick operation and error-free management of large files or data. This tool can be used to extract attachments from saved email EML files. Users only need to follow a few easy steps to open and remove the attachments. With this tool, you can extract CC, BCC, topic lines, and other types of data. Thunderbird, Windows Live Mail, and other eM clients are among the EML email clients with which it is compatible. Extracting attachments is easy on any Windows computer. Download the free to access additional features.

    Read More: http://www.softakensoftware.com/eml-attachment-remover.html

  • smithjens316

    Member
    February 22, 2024 at 12:00 am

    To download attachments from an *.eml file manually, you can open the file in an email client like Outlook or Thunderbird, then open the email and save the attachments individually. However, this process can be time-consuming, especially for multiple emails.

    Alternatively, you can use Advik EML Converter to extract attachments from *.eml files in bulk. This tool simplifies the process and saves you time by automatically extracting attachments from multiple *.eml files at once.

Log in to reply.