ageron / ageron/handson-ml2

Chapter 3, Problem 4 Solution

Open
#149 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
30k
Forks
13.1k
PR merge metrics
No merged PRs in 30d

Description

Hi,

In solution to the spam classifier problem, `email_to_text()` function there are some inconsistencies. The first `"text/plain"` content type it finds is returned. The same is not true about the `"text/html"`, it will overwrite the variable `html`. Besides, I think the content of all sub emails should be concatenated. I suggest the following form:

```
def email_to_text(email):
text = ""
for part in email.walk():
ctype = part.get_content_type()
if not ctype in ("text/plain", "text/html"):
continue
try:
content = part.get_content()
except: # in case of encoding issues
content = str(part.get_payload())
if ctype == "text/plain":
text += content + "\n"
else:
text += html_to_plain_text(content) + "\n"

return text;
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.