Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

easy way to do content replacement #5

Open
thestick613 opened this issue Mar 3, 2015 · 1 comment
Open

easy way to do content replacement #5

thestick613 opened this issue Mar 3, 2015 · 1 comment

Comments

@thestick613
Copy link

Assuming i'd be using pyzmail as an email processor which replaces all url's with a shortener (for tracking), is the following approach correct?

for part in msg.mailparts:
    payload = part.get_payload() (this also decodes it and trasnforms it into unicode)
    if payload.type in ["text/plain", "text/html"]:
        # process payload in some way, replace links, etc..
        payload = payload.encode(part.charset)
        cte = part.part.get("Content-Transfer-Encoding") or "7bit"
        part.part.set_payload(encode payload according to cte, quopri, base64, etc..)

If this is correct, do you support a patch for a set_payload function?

@aspineux
Copy link
Owner

aspineux commented Mar 3, 2015

Hello
Generating and parsing emails was already a big challenge.
Modifying an existing email is a level harder.
Pyzmail was very well tested and reliable when I released it some years ago.
I don't have time to imagine and write tests for a set_payload() function to keep the high quality.
This is something I can't support.
My first concern is that I don't know if python email parser and generator are "invariant".
In other word if

email.message_from_string(any_raw_message).as_string()==any_raw_message

or at least consistent

It looks like you have a good understanding of the problem and are already close of the solution.
You can look at generate.py about how I use set_payload() to generate payload.

Hope this help
Alain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants