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 crash when semicolon present in attachment name #219

Merged
merged 1 commit into from
Apr 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion imbox/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,33 @@ def decode_param(param):
return name, v


def parse_content_disposition(content_disposition):
# Split content disposition on semicolon except when inside a string
in_quote = False
str_start = 0
ret = []

for i in range(len(content_disposition)):
if content_disposition[i] == ';' and not in_quote:
ret.append(content_disposition[str_start:i])
str_start = i+1
elif content_disposition[i] == '"' or content_disposition[i] == "'":
in_quote = not in_quote

if str_start < len(content_disposition):
ret.append(content_disposition[str_start:])

return ret



def parse_attachment(message_part):
# Check again if this is a valid attachment
content_disposition = message_part.get("Content-Disposition", None)
if content_disposition is not None and not message_part.is_multipart():
dispositions = [
disposition.strip()
for disposition in content_disposition.split(";")
for disposition in parse_content_disposition(content_disposition)
if disposition.strip()
]

Expand Down