Quoted-printable and email header encoding

603 views
Skip to first unread message

alexandr...@gmail.com

unread,
Jun 17, 2014, 12:49:53 PM6/17/14
to golan...@googlegroups.com
I needed quoted-printable functions for an email library I'm writing so I wrote a package containing functions to deal with quoted-printable encoding: qp.

In issue 4943 it had been proposed to move the quoted-printable functions of the standard library - which are not currently exported - to an other package. So I designed qp as a package that could be in the standard library. Although some of the code of my new package is borrowed from the existing code, most of the code has been rewritten.

This package could fixes every open issues about net/mail.
  • #4943 is the main issue fixed by this package
  • #4687 would be fixed thanks to the DecodeHeader function.
  • #6611, #7079 and #7140 would be fixed too by using DecodeHeader(), processing the results depending on the charset and then using ParseAddress() from net/mail.
This package is documented and tested. I also made a little package comparing the functions currently in the standard library with qp: qpbench.

As shown in the example qp fixes some minor bugs of the functions in the standard library. It is also faster and uses less memory. Here are the results of the benchmarks on my computer:

$ go test -bench . -benchmem
BenchmarkOldQpDecode      100000         19591 ns/op        4273 B/op           4 allocs/op
BenchmarkNewQpDecode      100000         15850 ns/op        4289 B/op           4 allocs/op
BenchmarkOldQEncode     1000000          2784 ns/op         256 B/op           5 allocs/op
BenchmarkNewQEncode     1000000          1007 ns/op         160 B/op           2 allocs/op
BenchmarkOldQDecode      500000          6785 ns/op        3030 B/op          32 allocs/op
BenchmarkNewQDecode     1000000          1266 ns/op         210 B/op           7 allocs/op

I can do a CL containing this package and a refactoring of the net/mail and mime/multipart package to use this package if needed. What do you think?

Brad Fitzpatrick

unread,
Jun 18, 2014, 12:27:35 PM6/18/14
to alexandr...@gmail.com, Russ Cox, David Symonds, Rob Pike, golang-dev
[+rsc, dsymonds, r]

I'm fine with a new encoding/qp package.

It seems to come up more often than encoding/ascii85, for instance, and is often asked for and needed in other packages.

Russ, David, Rob?



--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Russ Cox

unread,
Jun 18, 2014, 12:28:03 PM6/18/14
to Brad Fitzpatrick, alexandr...@gmail.com, David Symonds, Rob Pike, golang-dev
sure

Brad Fitzpatrick

unread,
Jun 18, 2014, 12:31:01 PM6/18/14
to Russ Cox, alexandr...@gmail.com, David Symonds, Rob Pike, golang-dev
Okay.

Alexander,

Start by submitting a CLA as described in the contributing docs. Once that's in, send a CL to add encoding/qp starting with what you've got and I'll leave comments.

Once we clean up the docs & API a bit you can get to work on fixing "every open issue about net/mail". (I assume you'd do at least most of those as part of this work.)




On Wed, Jun 18, 2014 at 9:28 AM, Russ Cox <r...@golang.org> wrote:
sure


Rob Pike

unread,
Jun 18, 2014, 12:38:10 PM6/18/14
to Brad Fitzpatrick, Russ Cox, alexandr...@gmail.com, David Symonds, golang-dev
Not happy with 'qp' as a name: when I see that out of context, it's
not at all obvious what it means. It needs a better name. Discuss that
here please before proceeding to code review.

-rob

Brad Fitzpatrick

unread,
Jun 18, 2014, 12:41:37 PM6/18/14
to Rob Pike, Russ Cox, alexandr...@gmail.com, David Symonds, golang-dev
It goes by one of two names commonly:

Quoted-Printable
QP

I figured encoding/quotedprintable was too long. No?

We could make something up like encoding/qprint or encoding/quoteprint but then we're just different.

Alexandre Cesaro

unread,
Jun 18, 2014, 12:48:30 PM6/18/14
to golan...@googlegroups.com, r...@golang.org, alexandr...@gmail.com, dsym...@golang.org
qprintable?

Also since QP encoding is hardly used outside emails, maybe it could be in mime/qp.

Russ Cox

unread,
Jun 18, 2014, 12:48:37 PM6/18/14
to Brad Fitzpatrick, Rob Pike, alexandr...@gmail.com, David Symonds, golang-dev
fwiw [encoding qp] or [qp encoding] on google resolve to exactly what we're talking about.

Rob Pike

unread,
Jun 18, 2014, 1:38:10 PM6/18/14
to Russ Cox, Brad Fitzpatrick, alexandr...@gmail.com, David Symonds, golang-dev
A search for encoding b64] gives you base64, but we're not shortening that one.

I think a two-letter package name is too short for something that
carries so little weight, and I had never heard of this abbreviation,
but if you all think it's the natural name, I could acquiesce. I admit
that "quotedprintable" is long but it's also the name everyone says
out loud when they talk about it. Look at this list:

% ls src/pkg/encoding
ascii85 base64 encoding.go json
asn1 binary gob pem
base32 csv hex xml
%

Every package name there is, when spoken, the name of the encoding on
common speech. I've never heard "qp" given as the name of
"quoted-printable". Maybe I move in the wrong circles.

-rob

Brad Fitzpatrick

unread,
Jun 18, 2014, 1:41:54 PM6/18/14
to Rob Pike, Russ Cox, alexandr...@gmail.com, David Symonds, golang-dev
We'll go with encoding/qp since it sounds like you're -1 on encoding/quotedprintable and -0.5 on encoding/qp.

At least you'll never see encoding/qp in isolation: in godoc it always has the summary next to it.

If you see it in an import path, it's only in MIME or email code anyway, in which case you know what it is.

Rob Pike

unread,
Jun 18, 2014, 1:44:02 PM6/18/14
to Brad Fitzpatrick, Russ Cox, alexandr...@gmail.com, David Symonds, golang-dev
I'm +1 with quotedprintable. Not sure why you thought otherwise. But I
can tell I'm being shouted down.

-rob

Brad Fitzpatrick

unread,
Jun 18, 2014, 1:48:02 PM6/18/14
to Rob Pike, Russ Cox, alexandr...@gmail.com, David Symonds, golang-dev
Fine with me. Sorry, I read that as "too long".

encoding/quotedprintable works for me.

Rob Pike

unread,
Jun 18, 2014, 1:56:18 PM6/18/14
to Brad Fitzpatrick, Russ Cox, alexandr...@gmail.com, David Symonds, golang-dev
My message said in too many words, "long but fits with the other names
on this list".

-rob
Reply all
Reply to author
Forward
0 new messages