Skip to content

Commit

Permalink
fix mailbox service to handle bad chars
Browse files Browse the repository at this point in the history
  • Loading branch information
Pietro Martino Lugato committed Sep 25, 2024
1 parent eb0ea25 commit c9e1e6e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions A2rchi/utils/mailbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import email
import imaplib
import os
import re

### DEFINITIONS
# this constant defines an offset into the message description
Expand Down Expand Up @@ -184,11 +185,33 @@ def _get_fields(self, msg):

body, body_html = self._get_email_body(msg)
description = body if body else body_html
description = self._clear_text(description)
print("BODY:")
print(description)

return sender, cc, subject, description

def _clear_text(self,string):
emoj = re.compile("["
u"\U0001F600-\U0001F64F" # emoticons
u"\U0001F300-\U0001F5FF" # symbols & pictographs
u"\U0001F680-\U0001F6FF" # transport & map symbols
u"\U0001F1E0-\U0001F1FF" # flags (iOS)
u"\U00002500-\U00002BEF" # chinese char
u"\U00002702-\U000027B0"
u"\U000024C2-\U0001F251"
u"\U0001f926-\U0001f937"
u"\U00010000-\U0010ffff"
u"\u2640-\u2642"
u"\u2600-\u2B55"
u"\u200d"
u"\u23cf"
u"\u23e9"
u"\u231a"
u"\ufe0f" # dingbats
u"\u3030"
"]+", re.UNICODE)
return re.sub(emoj, '', string)

def _connect(self):
"""
Expand Down

0 comments on commit c9e1e6e

Please sign in to comment.