Giter Site home page Giter Site logo

Comments (6)

fedelemantuano avatar fedelemantuano commented on June 18, 2024 1

Hi @ad-m,

in mail-parser results there is a binary flag. If it's true the sample is a binary, else it's false is not binary.
If you read this part of code you can see:

...
charset = p.get_content_charset('utf-8') # get the charset
...

            if filename:
                    binary = False
                    mail_content_type = ported_string(p.get_content_type())
                    transfer_encoding = ported_string(
                        p.get('content-transfer-encoding', '')).lower()

                    if transfer_encoding == "base64" or \
                            (transfer_encoding == "quoted-printable" and
                             "application" in mail_content_type):
                        payload = p.get_payload(decode=False)
                        binary = True
                    else:
                        payload = ported_string(
                            p.get_payload(decode=True), encoding=charset)

mail-parser gives you the correct payload, so you should do:

            if binary:
                with open(sample, "wb") as f:
                    f.write(payload.decode("base64"))
            else:
                with open(sample, "w") as f:
                    f.write(payload.encode("utf-8"))

That's it

from mail-parser.

fedelemantuano avatar fedelemantuano commented on June 18, 2024 1

I added the store attachments function in mail-parser command line:

$ mailparser -f my_mail -sa -ap /tmp/attachments

from mail-parser.

fedelemantuano avatar fedelemantuano commented on June 18, 2024

I understood but mail-parser is a parser. If you want store sample on filesystem you should manage possible issues.
I can't introduce extra logic.

from mail-parser.

ad-m avatar ad-m commented on June 18, 2024

In my opinion, proper decoding of binarny attachments to a binary form native to Python is a part of parsing. In my opinion, the logic around decoder_map is an element of the project. This is in the scope of the project as much as the date parsing that is present today. Of course, saving attachments is out of the project. Parsing attachments of mail to the native binary form does not require writing them to the disk.

from mail-parser.

louis-red avatar louis-red commented on June 18, 2024

First of all @fedelemantuano, thank you for your awesome module.

On this issue though, from my POV as an user, I stand on @ad-m's side.
Maybe you think the attachments decoding is a trivial task, but it is one that will be done by each user that is interested in the attachments, and they will have to implement that little bit of logic in their code after having looked at that issue.

Maybe what is best on the user side is a common binary format for the payload, and additional logic should be kept (and possibly simplified) on the module side ?

from mail-parser.

fedelemantuano avatar fedelemantuano commented on June 18, 2024

I use mail-parser in SpamScope tool. I developed a function that writes the attachments (see here).
I use it every days and works well.

from mail-parser.

Related Issues (20)

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.