Giter VIP home page Giter VIP logo

Comments (8)

captn3m0 avatar captn3m0 commented on August 19, 2024 2

I'm going to take a stab at this, thanks for the pointers.

Will report back if I face issues.

from mailmerge.

captn3m0 avatar captn3m0 commented on August 19, 2024 2

The spec says that cids must match the addr-spec, so they must match a valid email address. (Looks like all the SO answers don't match the spec).

Python 3.2+ comes with a cool email.utils.make_msgid method:

https://github.com/python/cpython/blob/68b352a6982f51e19bf9b9f4ae61b34f5864d131/Lib/email/utils.py#L174-L194

which adds a bit more randomness (and leaks the hostname). But that would still require html parsing to replace hrefs.

Going to pick https://pypi.org/project/html5/, which looks okay-enough for our usecase, and has zero-dependencies.

from mailmerge.

awdeorio avatar awdeorio commented on August 19, 2024 1

This is a great idea. Here's a Python example.

I think that the only modifications needed would be:

  1. When attaching an image, add a header Content-ID: <filename>
  2. Add an example to the README with an HTML email containing an image <img src="cid:<filename>"></img>

from mailmerge.

captn3m0 avatar captn3m0 commented on August 19, 2024 1

Got html5lib to working, but facing interesting test breakages because the markdown->html and markdown->html->html results in different orderings.

Edit: Got around this by changing tests to parse-and-assert instead of string-equivalence.

- <img alt="python logo not attached" src="http://pluspng.com/img-png/python-logo-png-open-2000.png" /></p></body></html>
+ <img src="http://pluspng.com/img-png/python-logo-png-open-2000.png" alt="python logo not attached" /></p></body></html>

from mailmerge.

seshrs avatar seshrs commented on August 19, 2024

When attaching an image, add a header Content-ID:

While this will work for most use cases, weโ€™d have to be careful about attachments from different paths with the same filename. (Then theyโ€™d all get the same content ID!)

To fix this case, we may have to transform all occurrences of a given attachment path to a randomly generated content ID. (With this approach, the message template would specify inline images as <img src=โ€œ./path/to/img.jpgโ€ />, and the path would be mapped to the correct content ID.)

from mailmerge.

captn3m0 avatar captn3m0 commented on August 19, 2024

Have a question regarding the implementation of the transformation.

I was thinking of writing the transformation as a markdown extension, which would work wonderfully, but won't work for the HTML email usecase.

To cover the HTML usecase, I would have to rewrite it with a html-parser (need suggestions here, do we want a heavy dependency like beautifulsoup?) and that kinda makes the markdown extension redundant.

3 options:

  • Keep the feature markdown-only (easy implementation, no extra dependencies)
  • Implement it twice, once as a markdown extension, and once for direct HTML emails.
  • Implement it once, just for HTML, and run the output of the markdown against the HTML transform.

Or is there an easy way to do HTML parsing natively in Python?

from mailmerge.

awdeorio avatar awdeorio commented on August 19, 2024

Hmm, it sounds like the reason for the markdown extension and the reason for possible HTML parsing is handling the "two attachments with same basename" case. The problem is the name clash in Content-Id, which is the basename of the two attachments.

How about making the Content-Id value the same as the user-specified attachment path? For example, a markdown formatted email with two attachments could look like this:

To: [email protected]
Attachment: dog.jpg
Attachment: ../dog.jpg
Content-Type: text/markdown

Dog 1 ![dog 1](cid:dog.jpg)

Dog 2 ![dog 2](cid:../dog.jpg)

The same message formatted with plaintext and HTML would be like this:

To: [email protected]
Content-Type: multipart/alternative; boundary="boundary"
MIME-Version: 1.0
Attachment: dog.jpg
Attachment: ../dog.jpg

--boundary
Content-Type: text/plain; charset="us-ascii"

Plaintext dog 1 and dog 2.

--boundary
Content-Type: text/html; charset="us-ascii"

<html><body>
<p><img alt="dog 1" src="cid:dog.jpg" /></p>
<p><img alt="dog 2" src="cid:../dog.jpg" /></p>
</body></html>

from mailmerge.

captn3m0 avatar captn3m0 commented on August 19, 2024
  • Didn't think of letting the user control CID, but it makes sense.
  • I am not 100% sure if all valid paths (*nix,windows) will also remain valid CIDs. Will check on this and get back ๐Ÿ‘

from mailmerge.

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.