-
How to download attachments from *.eml file
Posted by kpc on April 5, 2023 at 12:00 amHow to download attachments from *.eml file using kdb code?
kpc replied 9 months, 2 weeks ago 5 Members · 4 Replies -
4 Replies
-
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)
-
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/ -
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
-
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.