Repository: oppia/oppia

Issue:
Conversion of html based emails to their equivalent text based emails
Currently in oppia, emails are encoded in html format but some users may be using text based clients or in several circumstances they may have to depend on text based email clients. In such scenario html emails need to be properly converted into their equivalent text based emails so that overall email body makes sense.

Generally emails may contain bullet points as:

```
<ul>some points:
<li>point 1</li>
<li>point 2</li>
</ul>
```

Above html is rendered as bullet points as following:

> <ul>some points:
> <li>point 1</li>
> <li>point 2</li>
> </ul>

But if emails are converted to text based from html format then current method for creating equivalent will render it as (observed behavior):

```
some points
point 1
point 2
```

Rather it should be rendered like following (expected behavior)

```
 some points
 -  point 1
 -  point 2
```

It contains a hyphen and a space before the beginning of actual text so that overall text email makes sense.

Some pointers: currently `_send_email()` function present in `core/domain/email_manager.py` does this job of conversion.



Discussion:
Can I take a crack at this? @seanlip 

Yep, go for it! I've assigned you.


Resolving patch:
diff --git a/core/domain/email_manager.py b/core/domain/email_manager.py
--- a/core/domain/email_manager.py
+++ b/core/domain/email_manager.py
@@ -171,7 +171,7 @@ def _send_email(
         return
 
     raw_plaintext_body = cleaned_html_body.replace('<br/>', '\n').replace(
-        '<br>', '\n').replace('</p><p>', '</p>\n<p>')
+        '<br>', '\n').replace('<li>', '<li>- ').replace('</p><p>', '</p>\n<p>')
     cleaned_plaintext_body = html_cleaner.strip_html_tags(raw_plaintext_body)
 
     if email_models.SentEmailModel.check_duplicate_message(


Test patch:
diff --git a/core/domain/email_manager_test.py b/core/domain/email_manager_test.py
--- a/core/domain/email_manager_test.py
+++ b/core/domain/email_manager_test.py
@@ -209,9 +209,9 @@ def test_correct_rights_are_written_in_manager_role_email_body(self):
             ', on Oppia.org.\n'
             '\n'
             'This allows you to:\n'
-            'Change the exploration permissions\n'
-            'Edit the exploration\n'
-            'View and playtest the exploration\n'
+            '- Change the exploration permissions\n'
+            '- Edit the exploration\n'
+            '- View and playtest the exploration\n'
             '\n'
             'You can find the exploration here.\n'
             '\n'
@@ -274,8 +274,8 @@ def test_correct_rights_are_written_in_editor_role_email_body(self):
             ', on Oppia.org.\n'
             '\n'
             'This allows you to:\n'
-            'Edit the exploration\n'
-            'View and playtest the exploration\n'
+            '- Edit the exploration\n'
+            '- View and playtest the exploration\n'
             '\n'
             'You can find the exploration here.\n'
             '\n'
@@ -337,7 +337,7 @@ def test_correct_rights_are_written_in_playtester_role_email_body(self):
             ', on Oppia.org.\n'
             '\n'
             'This allows you to:\n'
-            'View and playtest the exploration\n'
+            '- View and playtest the exploration\n'
             '\n'
             'You can find the exploration here.\n'
             '\n'