Giter Site home page Giter Site logo

How to parse attachments about mailibex HOT 2 CLOSED

kbrw avatar kbrw commented on June 15, 2024
How to parse attachments

from mailibex.

Comments (2)

awetzel avatar awetzel commented on June 15, 2024

hello @heri16 :
First use MimeMail.from_string(mail_bin) to get the MimeMail tree struct, of your email, then . This gives you the exact "parsed" version of your email, then you can apply selectively some decode_headers functions to parse on demand some type of headers. And decode_body to decode the body.

m = mail |> MimeMail.decode_body |> MimeMail.Emails.decode_headers
               |> MimeMail.CTParams.decode_headers |> MimeMail.Words.decode_headers

then you can browser the MimeMail tree to get your attachments.

But since the low level API is necessary for DKIM signature for instance, it is cumbersome for basic email parsing. So the MimeMail.Flat module allows you to "flatten" the mimemail tree in order to easily retreive your attachments : instead of having a %Mimemail{headers: [kwlist],body: treeof-MimeMail} you handle a single kwlist (actually the headers kwlist) with the body tree as keyword key-values with special key :txt,:html,:attach,:attach_in,:include according to the shape of the body tree.

For instance, to get an included attachment :

(mail_bin |> MimeMail.from_string |> MimeMail.Flat.from_mail)[:include]

if there are several included attachments :

mail_bin |> MimeMail.from_string |> MimeMail.Flat.from_mail |> Enum.filter(&elem(&1,0) == :include)

from mailibex.

heri16 avatar heri16 commented on June 15, 2024

A little surprised that attachments don't have a Stream or GenStage based
interface. Nevertheless, thanks for this useful library. Please see my pull
requests.

On Monday, 18 July 2016, Arnaud Wetzel [email protected] wrote:

hello @heri16 https://github.com/heri16 :
First use MimeMail.from_string(mail_bin) to get the MimeMail tree
struct, of your email, then . This gives you the exact "parsed" version of
your email, then you can apply selectively some decode_headers functions
to parse on demand some type of headers. And decode_body to decode the
body.

m = mail |> MimeMail.decode_body |> MimeMail.Emails.decode_headers
|> MimeMail.CTParams.decode_headers |> MimeMail.Words.decode_headers

then you can browser the MimeMail tree to get your attachments.

But since the low level API is necessary for DKIM signature for
instance, it is cumbersome for basic email parsing. So the MimeMail.Flat
module allows you to "flatten" the mimemail tree in order to easily
retreive your attachments : instead of having a %Mimemail{headers:
[kwlist],body: treeof-MimeMail} you handle a single kwlist (actually the
headers kwlist) with the body tree as keyword key-values with special key
:txt,:html,:attach,:attach_in,:include according to the shape of the body
tree.

For instance, to get an included attachment :

(mail_bin |> MimeMail.from_string |> MimeMail.Flat.from_mail)[:include]

if there are several included attachments :

mail_bin |> MimeMail.from_string |> MimeMail.Flat.from_mail |> Enum.filter(&elem(&1,0) == :include)


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#4 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAgK_YpyhmTwidClMu3fMDdpivsh3QcQks5qWnTmgaJpZM4JMqwv
.

from mailibex.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.