Re: Email::Address::XS

[email protected] (Ricardo Signes) Sun, 11 Sep 2016 18:58:42 -0400
Newsgroups perl.pep
Message-ID <20160911225842.GA15041@debian>
--pf9I7BMVVzbSWLtt
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

* [email protected] [2016-09-05T04:25:11]
> I do not want to add ->as_mime_header (or other function) which will do
> MIME encoding/decoding into Email::Address::XS. That module is for
> formating and parsing email addresses headers, not for MIME
> encoding/decoding. Same as it is for Email::Address module.

The best way to know how to properly encode a structured header field is to
know both its structure and the way that the structure ie meant to be encod=
ed.
For example, to know that a `mailboxes` structure may have a display-name,
which would be words, which can be encoded, and may have an addr-spec, whic=
h is
not words, and so cannot be encoded.

Parsing and encoding are not separable concerns, here, because to know whet=
her
to decode a part, one most know what part it is, which means it has been
parsed.  You can only properly decode the structured data by knowing the
relationship between structure and encoding.  Then, you can only encode the
data by knowing the same.  This means that any interface between Email::MIME
and some structured field representation has a much more complex API, if
Email::MIME is responsible for the encoding and decoding.  It doesn't just =
need
a map of field name to class name, but also instructions on how structured =
data
are encoded and decoded.

This seems like it becomes a nasty mess of deep coupling.  Am I making some
fundamental mistake, here?

Anyway, isn't it certain that people who parse addresses from headers will =
want
to get a decoded form?  Surely this will be common:

  my @recipients =3D map {; $_->phrase_str // $_->address }
                   Address->parse( $email->header('To') );

The Dovecot parser (as I recall) does not decode encoded-words, so phrase_s=
tr
is easy to write.  Does every consumer of Address need to know how to decod=
e?
Further, won't people want to write:

  my $to =3D Address->new("=EA=B9=80=EC=A0=95=EC=9D=80", "[email protected]");

=2E..and then pass that object on to something that knows what to do with i=
t?
Does every possible consumer of Address need to know how to encode an Addre=
ss
object?

--=20
rjbs

--pf9I7BMVVzbSWLtt
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQEcBAEBAgAGBQJX1eGiAAoJEOYby6cMccU5UNUH/2Xpw3pqoA24g/ZiLy1CLV3h
rb4yNbbJ3xyhaUdob26YNN+DLv1aJl0x29TlnTxYxF9d6nNhmIStvC9MPChEOZHD
ECsv+OTePB/ng7lz1YLSNXIAx1Pnm95hNaU4Kc/SXbnZ0YvBuYI0hWCmtfHhVBay
cBJtkGRfEgK5rhPLRO5vLRyr4kisfNgrZaoYMoDOSxfcqSz9DZB+nbgslHGU2apI
lKz01KVTpWftKW2gxZS34kFFLxhiCmWHiymG0/C5GBlnfk5ZV4gYQoEncVe42sZu
A+KRpzPW8SJYEclwSoV5bKFQIIgUGgmyq7V4raNCrFHsbeEmCibA2Lfwg6rx3Qk=
=ScnL
-----END PGP SIGNATURE-----

--pf9I7BMVVzbSWLtt--