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

Consider check_trailing_bits=false for BASE64_MIME decoder #102

Closed
wathiede opened this issue Apr 8, 2024 · 1 comment · Fixed by #103
Closed

Consider check_trailing_bits=false for BASE64_MIME decoder #102

wathiede opened this issue Apr 8, 2024 · 1 comment · Fixed by #103

Comments

@wathiede
Copy link
Contributor

wathiede commented Apr 8, 2024

In staktrace/mailparse#96 it was considered to request this package allow trailing bits on the BASE64_MIME codec. The assumptions behind this reasoning are:

  • BASE64_MIME is tailored for email
  • in real world emails are sometimes imperfect, and returning something is better than nothing

Would this project be willing to accept a pull request that makes BASE64_MIME more liberal in its handling by setting check_trailing_bits=false? If not, that's okay, I can go back to the mailparse project and see if they're willing to handle it.

Note, I'm not associated with the project, I just personally stumbled across this problem recently, so I figured I'd start with their suggestion first.

@ia0
Copy link
Owner

ia0 commented Apr 8, 2024

There's at least 3 options:

  • The solution in base64 decoding should not be "strict" staktrace/mailparse#96 which is to define their own encoding with lazy-static.
  • Using data-encoding-macro which doesn't need lazy-initialization because it produces the encoding at compile-time (see below for a snippet).
  • Add a BASE64_MIME_PERMISSIVE constant in data-encoding. (I'm not willing to change the behavior of BASE64_MIME because this would be a breaking change. But adding a new constant for those who need to ignore trailing bits is fine.)
const BASE64_MIME_PERMISSIVE: data_encoding::Encoding = data_encoding_macro::new_encoding! {
    symbols: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
    padding: '=',
    check_trailing_bits: false, // NEW (defaults to true)
    wrap_width: 76,
    wrap_separator: "\r\n",
};

What do you think? Happy to add BASE64_MIME_PERMISSIVE if that's what you would prefer.

@ia0 ia0 closed this as completed in #103 Apr 9, 2024
ia0 added a commit that referenced this issue Apr 9, 2024
Fixes #102

---------

Co-authored-by: Julien Cretin <cretin@google.com>
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 a pull request may close this issue.

2 participants