Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add emoji support in email subjects #25

Merged
merged 6 commits into from
Jul 19, 2021

Conversation

jmcampanini
Copy link
Contributor

When using git format-patch to produce email patches, the subject line will be encoded if any extended characters are present (i.e. emoji). This PR decodes those values for the subject, producing the original subject, including any emoji/other-characters.

Partially verified

This commit is signed with the committer’s verified signature.
spydon’s contribution has been verified via GPG key.
We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.

Partially verified

This commit is signed with the committer’s verified signature.
spydon’s contribution has been verified via GPG key.
We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.

Partially verified

This commit is signed with the committer’s verified signature.
spydon’s contribution has been verified via GPG key.
We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.

Verified

This commit was signed with the committer’s verified signature.
spydon Lukas Klingsbo

Verified

This commit was signed with the committer’s verified signature.
spydon Lukas Klingsbo
@bluekeyes
Copy link
Owner

Thanks for fixing this. Looking through decode_header in the Git source, it looks like there are several possible encodings. That said, I'm not sure if Git will produce any besides UTF-8.

I think if we want a complete solution here, it would be nice to implement additional decoding:

  1. Identify the encoding from the text between the first =? and the next ?
  2. Use the q? or b? to determine if the content until the next =? is encoded as quoted-printable or base64
  3. Decode the content
  4. Use ianaindex.MIME to look up the encoding
  5. Use the encoding from to convert the bytes to UTF-8

That said, if UTF-8 is the most common, it might be fine to skip decoding in non-UTF-8 cases and leave this as a future improvement.

// Decodes a subject line if encoded using quoted-printable UTF-8 Q encoding. This format is the
// result of a `git format-patch` when the commit title has an emoji (or other non-ASCII character).
// See for reference: https://stackoverflow.com/questions/27695749/gmail-api-not-respecting-utf-encoding-in-subject
func decodeUTF8Subject(encoded string) string {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's call this decodeSubject so it could be expanded for more encodings, either now or in the future.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@bluekeyes bluekeyes merged commit b575654 into bluekeyes:master Jul 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants