Comments (2)
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.
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_headersthen 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)
- Server implementation HOT 1
- Cannot decode blank body of a multipart mail HOT 2
- Add support for Windows HOT 1
- Support Pure Elixir implementation of iconv (e.g. Codepagex) HOT 2
- Unsafe operation: Creating atom with user input HOT 1
- Doesn't compile under 1.5.2 HOT 2
- crypto:rand_bytes/1 is deprecated HOT 1
- Error during compulation HOT 2
- warning: module attribute @shortdoc was set but never used HOT 2
- Body parsing with charset="utf-8" and Content-Transfer-Encoding: 8bit not working HOT 1
- New version on Hex. HOT 2
- Parser issues on "From" HOT 4
- (2021-08-25) Dependency codepagex does not compile with commit 58c9aaf HOT 2
- Content-Type: multipart/mixed seems to force base64 encoding somehow in Dkim.sign(mail)
- Compiler Warnings on Elixir 1.2.5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mailibex.