I have a simple email in Gmail that looks like this:
Hi all
@alice - please prepare XXX for tomorrow
@bob - please prepare YYY for tomorrow
best,
Z
and I would like to fetch it, parse it and split by newline, so I would get a list of 5 elements:
['Hi all','@alice ...', '@bob ...', 'best,','Z']
but for some reason inside the sentence I get \r\n
which makes me break the line into 2 lines although in the original email there wasn't new line.
I parse it as following (after getting the proper credentials)
txt = service.users().messages().get(userId=user.email, id=email_msg['id']).execute()
payload = txt["payload"]
headers = payload["headers"]
parts = payload.get("parts")[0]
data = parts["body"]["data"]
data = data.replace("-", "+").replace("_", "/")
decoded_message = str(base64.b64decode(data), "utf-8")
split = decoded_message.splitlines()
final_split = list(filter(None, split))
but then the message I get looks like this:
Hi all\r\n\r\n@alice - please prepare XXX\r\nfor tomorrow\r\n@bob - please prepare YYY for tomorrow\\r\nr\nbest,\n\rZ
so if I split by \r\n
or \n
I get invalid result