Update app.py
Browse files
app.py
CHANGED
|
@@ -325,8 +325,26 @@ def fetch_emails_by_date(service, target_date, max_results=50):
|
|
| 325 |
msg = service.users().messages().get(userId='me', id=m_info['id']).execute()
|
| 326 |
headers = {h['name']: h['value'] for h in msg['payload']['headers']}
|
| 327 |
|
| 328 |
-
|
| 329 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
|
| 331 |
structured_emails.append({
|
| 332 |
'id': msg['id'],
|
|
|
|
| 325 |
msg = service.users().messages().get(userId='me', id=m_info['id']).execute()
|
| 326 |
headers = {h['name']: h['value'] for h in msg['payload']['headers']}
|
| 327 |
|
| 328 |
+
body = ""
|
| 329 |
+
payload = msg.get('payload', {})
|
| 330 |
+
|
| 331 |
+
def get_body(parts):
|
| 332 |
+
for part in parts:
|
| 333 |
+
mimeType = part.get('mimeType')
|
| 334 |
+
data = part.get('body', {}).get('data')
|
| 335 |
+
if mimeType == 'text/plain' and data:
|
| 336 |
+
return base64.urlsafe_b64decode(data).decode('utf-8')
|
| 337 |
+
elif 'parts' in part:
|
| 338 |
+
result = get_body(part['parts'])
|
| 339 |
+
if result: return result
|
| 340 |
+
return ""
|
| 341 |
+
|
| 342 |
+
if 'parts' in payload:
|
| 343 |
+
body = get_body(payload['parts'])
|
| 344 |
+
else:
|
| 345 |
+
data = payload.get('body', {}).get('data')
|
| 346 |
+
if data:
|
| 347 |
+
body = base64.urlsafe_b64decode(data).decode('utf-8')
|
| 348 |
|
| 349 |
structured_emails.append({
|
| 350 |
'id': msg['id'],
|