Re: Email::Address::XS

[email protected] (Ricardo Signes) Thu, 30 Jun 2016 20:51:31 -0400
Newsgroups perl.pep
Message-ID <20160701005131.GA27257@debian>
--UlVJffcvxoiEqYs2
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable


My coworkers have returned to the other side of the world!  I attended YAPC=
!  i
had a vacation!  I am back.

* [email protected] [2016-06-01T12:44:01]
> On Tuesday 31 May 2016 02:42:48 Ricardo Signes wrote:
> > * [email protected] [2016-05-28T16:48:40]
> >=20
> > > Basically yes. From caller perspective I want to pass email address
> > > object and let Email::MIME to do MIME encoding correctly. Something
> > > like this:
> > >=20
> > > my $email =3D Email::MIME->create(
> > >=20
> > > 	header_addr =3D> [ ... ],
> > >=20
> > > );
> >=20
> > I think that requiring people to break headers up even further into
> > to add a "header_addr" argument is a bit much.  And why header_grps?

So, you had some responses to this which were quite helpful.

My suggestion was meant to be something like "why not make Email::MIME
understand some kind of object as the value in a header?"  I think this is
still right.

Your main responses were (please correct me if I am misunderstanding them):

1.  it should be possible and easy to supply a list of address objects
2.  it should be possible to have a named group, but not required
3.  we don't want ambiguity in how objects passed to (header_str =3D> [...])
    are interpreted

What if we defined a role (here, just a well-known name) called
Email::MIME::Header::Value, which is used to signal that a particular metho=
d,
say "as_mime_header", should be used to stringify?

When building the header, the code will do something like:

  $string =3D $name . ": "
          . ($value->DOES('Email::MIME::Header::Value')
              ? $value->as_mime_header
              : "$value");

No existing object will become confused by this change, only objects which =
do
the new role.

Then Email::Address::XS could provide some helper routines, so you could wr=
ite
and of:

    From =3D> '[email protected]'

    From =3D> Email::Address::XS->new(...)

    From =3D> address('[email protected]', 'Ricardo SIGNES')

    From =3D> addrlist( address('[email protected]', 'Ricardo SIGNES'), ... )

    From =3D> addrgroup( Humans =3D> address('[email protected]', 'Rik'), ... )

It might be best to make the first code sample actually do:

  $string =3D $name . ": "
          . ($value->DOES('Email::MIME::Header::Value')
              ? $value->as_mime_header($name, $mycrlf)  # <-- changed
              : "$value");

=2E..to let the object do folding.  I'm not sure about that one.  I'd want =
to
double-check whether there's a reason to not always do the folding of the
post-stringified form in Email::MIME.

Anyway, this avoids adding multiple more places to set headers and makes the
API extensible for other header types like Message-ID, etc, in the future.

What do you think of this all?

--=20
rjbs

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

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

iQEcBAEBAgAGBQJXdb6TAAoJEOYby6cMccU5V6AH/R+yd3JiH022rXptmWcSky23
hMEsTQCjKa5F+XM33Fl/TEvPhxk/D2Ip6uzd2ZIzraZsMXUgt6QQIPDWfhqM1Owv
/tJ0uq4bYU1MhEWX/jBVsxRkqq7xoAncpxiwE3EO7k78vxzrkRDI2lgewJVugL+X
C16xnLnOFWRDBdGOFnpis/V7nO8Rqn3/BadWAzpVUdoJ7msPrl4w7QvtLvzRi5dW
xsuvM5R1pqdd/DZxZz0tegt586BIKc3GAjPYQRh00p6lQPYgZiBKXNyn7NEKubAv
7/YGH0yELgSRRb4Q6s3DLrvFna3Y8b689ftHGXt8gTvaPeJm1pGSXncOY8j6d4o=
=OUZ1
-----END PGP SIGNATURE-----

--UlVJffcvxoiEqYs2--