golang / go

The Go programming language

Home Page:https://go.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mime/quotedprintable: move quoted printable reader/writer to dedicated package

eaigner opened this issue · comments

Quoted-printable encoding and decoding is found in the mail and multipart packages. It
would be more useful if the quoted printable implementations would be moved to a
dedicated package like e.g. encoding/qp.

Comment 1:

They look different.  In net/mail, it's used for headers and references RFC 2047, which
says:
4.2. The "Q" encoding
   The "Q" encoding is similar to the "Quoted-Printable" content-
   transfer-encoding defined in RFC 2045.  It is designed to allow text
   containing mostly ASCII characters to be decipherable on an ASCII
   terminal without decoding.
The one in mime/multipart is only a decoder (of RFC 2045, not 2047) and doesn't have an
encoder.

Comment 2:

I see. A dedicated package for quoted-printable would be nice nevertheless (possibly
with an option for the "Q" format of RFC 2047)

Comment 3:

Also, when using the Get method on a mail.Header, it just uses textproto.MIMEHeader's
Get() internally. If that header field was also Q encoded (e.g. "Subject"), it is not
decoded, which it probably should, in mail.Header.Get().

Comment 4:

Labels changed: added priority-later, removed priority-triage, go1.1maybe.

Status changed to Accepted.

Comment 5:

Labels changed: added go1.2maybe.

Comment 6:

Labels changed: added feature.

Comment 7:

Not for Go 1.2.

Labels changed: removed go1.2maybe.

Comment 8:

Labels changed: added go1.3maybe.

Comment 9:

Labels changed: removed feature.

Comment 10:

Labels changed: added release-none, removed go1.3maybe.

Comment 11:

Labels changed: added repo-main.

Comment 12:

I would prefer that textproto did not transparently decode quoted-printable for me. I
would prefer to have an encoding package and do it myself.
Reason being that I'm reading an email template where the Content-Transfer-Encoding
header is used to specify what to encode the body to, and the body it unencoded because
it contains variables.

Comment 13:

I made a CL concerning this issue: https://golang.org/cl/101330049

Comment 14:

CL https://golang.org/cl/101330049 mentions this issue.

Comment 15 by joodngbo1976:

i also need the qp encoder to encoding, dose it exist in any golang packages?
such as encoding/qp?

Comment 16:

There is nothing in the standard library yet.
For the time being, you can use my package here:
http://godoc.org/github.com/alexcesaro/mail/quotedprintable

Comment 17 by joodngbo1976:

Thanks a lot, i plan to rewrite a quoted-printable encoder/decoder package based on the
C implementations

Comment 19:

CL https://golang.org/cl/132680044 mentions this issue.

Comment 20:

The implementation of quotedprintable.go at https://golang.org/cl/132680044
seems to violate RFC2045. It allows lines greater than 76 characters. Shouldn't these
get split with "=\n"?

That is right. However the 76-characters limit also applies to messages using base64 encoding.

That is why I don't think this limit should be enforced in the quoted-printable encoding functions. It should be in a new writer like mime.BodyWriter or be implemented by the user.

The 76 characters limit is an integral part of the quoted-printable standard, whereas it's only imposed on base64 within a MIME message. So basically, it's a violation for one, and a contextual adaptation for the other.

RFC2045:

The Quoted-Printable encoding REQUIRES that encoded lines be no more than 76 characters long.

@alexcesaro, et al, the tree is now open for changes. See https://groups.google.com/forum/#!topic/golang-dev/otCULnOjs7I for details. Let's work on MIME early in this dev cycle, instead of at the very end like last time, where we missed it (largely my fault due to holiday schedules).

Thanks, I just submitted the change: https://go-review.googlesource.com/#/c/1810/

@mohamedattahri You are right. Also I had a look at Gomail where I implemented the limit for both base64 and quoted-printable encoding: I used two different writers because the code was too different to be reusable.
So I will update my commit to enforce the limit.

CL https://golang.org/cl/7890 mentions this issue.