Improved gmail toolkit. Added support for threading in draft replies, multipart email parsing, and label management. Fixed the DateRange parameter issue in list_emails_by_headers. Added logging and removed print statements. Created custom exceptions for each specific google toolkit. ----- Summary of changes by @byrro: - Fixed minor bug related to the `date_range` argument of `list_emails_by_header` - A few utility functions (`build_email_message`, `build_reply_recipients`, `build_reply_body`) to centralize logic and remove repeated code from email-sending tools - New `reply_to_email` tool (apart from `write_draft_reply_email`, implemented by Alex) to keep the toolkit consistent - Evals and unit tests - Handling of reply-to (only sender) and reply-to-all recipients - Removed some unnecessary debug messages, which Alex had added to replace print statements - Removed HTML handling implemented by Alex in `write_draft_reply_email` > I think we should either support HTML across all applicable tools or not at all; I decided to remove it and leave this feature for a future PR. --------- Co-authored-by: Renato Byrro <rmbyrro@gmail.com>
18 lines
841 B
Python
18 lines
841 B
Python
import os
|
|
|
|
from arcade_google.tools.models import GmailReplyToWhom
|
|
|
|
# The default reply in Gmail is to only the sender. Since Gmail also offers the possibility of
|
|
# changing the default to 'reply to all', we support both options through an env variable.
|
|
# https://support.google.com/mail/answer/6585?hl=en&sjid=15399867888091633568-SA#null
|
|
try:
|
|
GMAIL_DEFAULT_REPLY_TO = GmailReplyToWhom(
|
|
# Values accepted are defined in the arcade_google.tools.models.GmailReplyToWhom Enum
|
|
os.getenv("ARCADE_GMAIL_DEFAULT_REPLY_TO", GmailReplyToWhom.ONLY_THE_SENDER.value).lower()
|
|
)
|
|
except ValueError as e:
|
|
raise ValueError(
|
|
"Invalid value for ARCADE_GMAIL_DEFAULT_REPLY_TO: "
|
|
f"'{os.getenv('ARCADE_GMAIL_DEFAULT_REPLY_TO')}'. Expected one of "
|
|
f"{list(GmailReplyToWhom.__members__.keys())}"
|
|
) from e
|