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

imap: lower some fields + content disposition keys #384

Merged
merged 1 commit into from Aug 27, 2020
Merged

imap: lower some fields + content disposition keys #384

merged 1 commit into from Aug 27, 2020

Conversation

sqwishy
Copy link

@sqwishy sqwishy commented Aug 22, 2020

Regarding #383

TestBodyStructure_Format does not pass right now because the BodyStructure contains lowercased values of the input string. So when it's formatted, its field list does not match the input.

I could:

  1. Move the case out of bodyStructureTests into its own test function that does the equivalent of TestBodyStructure_Parse on that one case.
  2. Add an optional member to the bodyStructureTests element struct type to allow overriding the expected value instead of formatFields(test.fields).

The first option seems less freaky. I thought I'd ask in case you have better ideas or preferences.

@sqwishy
Copy link
Author

sqwishy commented Aug 22, 2020

Oh, I also made a few more changes than strictly what was required with my particular issue.

  1. Whitespace is trimmed, mainly because mime.ParseMediaType does that and it seems like maybe that's a good thing? I'm not really sure. Let me know if this is a problem.

  2. Some other fields were altered, namely MIMEType MIMESubType Encoding. RFC 3501 makes a bunch of references to RFC 2045 that reads:

    All numeric and octet values are given in decimal notation in this
    set of documents. All media type values, subtype values, and
    parameter names as defined are case-insensitive. However, parameter
    values are case-sensitive unless otherwise specified for the specific
    parameter.

    But I'm bad at reading RFCs so I could totally be doing it wrong. This is just a best effort.

@foxcpp
Copy link
Collaborator

foxcpp commented Aug 22, 2020

Option 1 for changing test seems fine to me.

Whitespace is trimmed

No objection, not sure what would be the practical consideration though.

But I'm bad at reading RFCs so I could totally be doing it wrong. This is just a best effort.

RFC 3501 is indeed not explicit about this detail, but I assume it is following the same logic of
all strings being case-insensitive.

Case-folding these will prevent nasty surprises for naive users that write MIMEType == "text" and then get an obscure server implementation presenting values in upper case or message with such value that had case preserved by server when extracting structure data.

@sqwishy
Copy link
Author

sqwishy commented Aug 22, 2020

Option 1 for changing test seems fine to me.

I did this, let me know if there's anything else I missed.

message.go Outdated
@@ -119,6 +119,24 @@ func encodeHeader(s string) string {
return mime.QEncoding.Encode("utf-8", s)
}

func toLowerTrimmed(s string) string {
return strings.TrimSpace(strings.ToLower(s))
Copy link
Owner

Choose a reason for hiding this comment

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

Do we really need to trim spaces here? I haven't encountered fields with spaces in the wild yet.

Copy link
Author

Choose a reason for hiding this comment

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

Yah I don't know anything about email; wanted to get your guys' thoughts. I removed it.

message.go Outdated
}
if params, ok := disp[1].([]interface{}); ok {
bs.DispositionParams, _ = parseHeaderParamList(params)
keysLowered(bs.DispositionParams)
Copy link
Owner

Choose a reason for hiding this comment

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

I think we can inline the lower-casing in parseHeaderParamList.

Copy link
Author

Choose a reason for hiding this comment

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

Can we do that in ParseParamList? I think that's the most clean as the map is first populated there, but I didn't want to mess with a public/exported function.

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, we can't do that because that would be a breaking change.

At least with my mail, a bunch of things in messages, including
content-disposition headers, have uppercase keys.

This lowercases those strings.
Copy link
Owner

@emersion emersion left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@emersion emersion merged commit 54d331f into emersion:master Aug 27, 2020
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

3 participants