genkgo / mail

Library to send e-mails over different transports and protocols (like SMTP and IMAP) using immutable messages and streams. Also includes SMTP server.
https://mail.readthedocs.io/
Other
402 stars 21 forks source link

ContentID enhancement #27

Closed mpyw closed 6 years ago

mpyw commented 7 years ago

Currently ContentID is just a simple data container object. I think it needs the following features at least:

  1. When it is constructed:
    • It should be validated as url-addr-spec
  2. When it is represented as a header:
    • It should be enclosed with < and >
    • Its domain-part should be idn-encoded
  3. When it is represended as a CID-URL:
    • It should be prefixed with cid:
    • Its local-part should be percent-encoded
    • Its domain-part should be idn-encoded

However, it may break backward compatibility. To avoid it, static helper method is preferred.

$contentId = ContentID::fromUrlAddress("画像01@example.みんな"); // equivalent to new ContentID("<画像01@example.xn--q9jyb4c>")

// external interfaces for building HTML
$contentId->getCidUrl(); // returns "cid:%E7%94%BB%E5%83%8F01@example.xn--q9jyb4c"
$embeddedImage->getContentId()->getCidUrl();  // returns "cid:%E7%94%BB%E5%83%8F01@example.xn--q9jyb4c"

Citations from RFC 2392:

   The URLs take the form

     content-id    = url-addr-spec

     message-id    = url-addr-spec

     url-addr-spec = addr-spec  ; URL encoding of RFC 822 addr-spec

     cid-url       = "cid" ":" content-id

     mid-url       = "mid" ":" message-id [ "/" content-id ]
 A "cid" URL is converted to the corresponding Content-ID message
   header [MIME] by removing the "cid:" prefix, converting the % encoded
   character to their equivalent US-ASCII characters, and enclosing the
   remaining parts with an angle bracket pair, "<" and ">".  For
   example, "cid:foo4%25foo1@bar.net" corresponds to

     Content-ID: <foo4%25foo1@bar.net>

   Reversing the process and converting URL special characters to their
   % encodings produces the original cid.

(I think the example is wrong; Content-ID: <foo4%foo1@bar.net> seems to be correct)

I'm afraid that I'm not so familiar with RFC details...

frederikbosch commented 7 years ago

Good catch! Reading RFCs is a hell of a job. I can tell that from the experience of this library. I will also have a look at the RFC and see what we can do to stay in line with it without breaking BC.