Skip to content

Commit

Permalink
full gmail fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pablonyx committed Feb 18, 2025
1 parent 4866268 commit 79c1164
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from collections.abc import Callable
from collections.abc import Iterator
from datetime import datetime
Expand All @@ -24,16 +25,20 @@ def datetime_to_utc(dt: datetime) -> datetime:


def time_str_to_utc(datetime_str: str) -> datetime:
# Attempt to fix '(GMT+08:00)', '(GMT+03:30)', etc.
# Example: "Mon, 23 Dec 2024 17:10:32 +0800 (GMT+08:00)" => "Mon, 23 Dec 2024 17:10:32 +0800"
datetime_str = re.sub(r"\(GMT[+\-]\d{2}:\d{2}\)", "", datetime_str).strip()

try:
dt = parse(datetime_str)
except ValueError:
# Handle malformed timezone by attempting to fix common format issues
# Fix common format issues (e.g. "0000" => "+0000")
if "0000" in datetime_str:
# Convert "0000" to "+0000" for proper timezone parsing
fixed_dt_str = datetime_str.replace(" 0000", " +0000")
dt = parse(fixed_dt_str)
datetime_str = datetime_str.replace(" 0000", " +0000")
dt = parse(datetime_str)
else:
raise

return datetime_to_utc(dt)


Expand Down
1 change: 1 addition & 0 deletions backend/onyx/connectors/gmail/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ def _fetch_threads(
userId=user_email,
fields=THREAD_LIST_FIELDS,
q=query,
continue_on_404_or_403=True,
):
full_threads = execute_paginated_retrieval(
retrieval_function=gmail_service.users().threads().get,
Expand Down

0 comments on commit 79c1164

Please sign in to comment.