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

Fix binascii.Error: Incorrect padding #204

Merged
merged 1 commit into from
Aug 4, 2021

Commits on Aug 4, 2021

  1. Fix binascii.Error: Incorrect padding

    When decode_param receives a value like this:
    "=?ISO-8859-1?B?TEdGIC0gUGFzc28gYSBQYXNzbyAtIEZh?= =?ISO-8859-1?B?dHVyYW1lbnRvIEVsZXRy9G5pY28ucGRm?="
    
    It fails to decode the base64 correctly, and it gives the error:
    
    File "/usr/local/lib/python3.6/site-packages/imbox-0.9.8-py3.6.egg/imbox/messages.py", line 55, in _fetch_email_list
        yield uid, self._fetch_email(uid)
      File "/usr/local/lib/python3.6/site-packages/imbox-0.9.8-py3.6.egg/imbox/messages.py", line 44, in _fetch_email
        parser_policy=self.parser_policy)
      File "/usr/local/lib/python3.6/site-packages/imbox-0.9.8-py3.6.egg/imbox/parser.py", line 155, in fetch_email_by_uid
        email_object = parse_email(raw_email, policy=parser_policy)
      File "/usr/local/lib/python3.6/site-packages/imbox-0.9.8-py3.6.egg/imbox/parser.py", line 212, in parse_email
        attachment = parse_attachment(part)
      File "/usr/local/lib/python3.6/site-packages/imbox-0.9.8-py3.6.egg/imbox/parser.py", line 115, in parse_attachment
        name, value = decode_param(param)
      File "/usr/local/lib/python3.6/site-packages/imbox-0.9.8-py3.6.egg/imbox/parser.py", line 80, in decode_param
        value = base64.decodebytes(code.encode())
      File "/usr/lib64/python3.6/base64.py", line 546, in decodebytes
        return binascii.a2b_base64(s)
    binascii.Error: Incorrect padding
    
    So i changed the regular expression and started using findall instead, i also added a "fixer" for invalid base64 blocks, it adds "=" to the end of it if needed.
    Anderseta committed Aug 4, 2021
    Configuration menu
    Copy the full SHA
    e876451 View commit details
    Browse the repository at this point in the history