Skip to content

easy way to do content replacement #5

@thestick613

Description

@thestick613

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions