arcade-microsoft 0.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. arcade_microsoft-0.2.3/.gitignore +175 -0
  2. arcade_microsoft-0.2.3/.pre-commit-config.yaml +18 -0
  3. arcade_microsoft-0.2.3/.ruff.toml +44 -0
  4. arcade_microsoft-0.2.3/LICENSE +21 -0
  5. arcade_microsoft-0.2.3/Makefile +55 -0
  6. arcade_microsoft-0.2.3/PKG-INFO +21 -0
  7. arcade_microsoft-0.2.3/arcade_microsoft/__init__.py +0 -0
  8. arcade_microsoft-0.2.3/arcade_microsoft/client.py +26 -0
  9. arcade_microsoft-0.2.3/arcade_microsoft/outlook_calendar/__init__.py +7 -0
  10. arcade_microsoft-0.2.3/arcade_microsoft/outlook_calendar/_utils.py +225 -0
  11. arcade_microsoft-0.2.3/arcade_microsoft/outlook_calendar/constants.py +138 -0
  12. arcade_microsoft-0.2.3/arcade_microsoft/outlook_calendar/models.py +288 -0
  13. arcade_microsoft-0.2.3/arcade_microsoft/outlook_calendar/tools/__init__.py +7 -0
  14. arcade_microsoft-0.2.3/arcade_microsoft/outlook_calendar/tools/create_event.py +81 -0
  15. arcade_microsoft-0.2.3/arcade_microsoft/outlook_calendar/tools/get_event.py +29 -0
  16. arcade_microsoft-0.2.3/arcade_microsoft/outlook_calendar/tools/list_events_in_time_range.py +59 -0
  17. arcade_microsoft-0.2.3/arcade_microsoft/outlook_mail/__init__.py +24 -0
  18. arcade_microsoft-0.2.3/arcade_microsoft/outlook_mail/_utils.py +116 -0
  19. arcade_microsoft-0.2.3/arcade_microsoft/outlook_mail/constants.py +18 -0
  20. arcade_microsoft-0.2.3/arcade_microsoft/outlook_mail/enums.py +65 -0
  21. arcade_microsoft-0.2.3/arcade_microsoft/outlook_mail/message.py +218 -0
  22. arcade_microsoft-0.2.3/arcade_microsoft/outlook_mail/tools/__init__.py +28 -0
  23. arcade_microsoft-0.2.3/arcade_microsoft/outlook_mail/tools/read.py +122 -0
  24. arcade_microsoft-0.2.3/arcade_microsoft/outlook_mail/tools/send.py +94 -0
  25. arcade_microsoft-0.2.3/arcade_microsoft/outlook_mail/tools/write.py +115 -0
  26. arcade_microsoft-0.2.3/evals/outlook_calendar/additional_messages.py +28 -0
  27. arcade_microsoft-0.2.3/evals/outlook_calendar/eval_create_event.py +94 -0
  28. arcade_microsoft-0.2.3/evals/outlook_calendar/eval_get_event.py +53 -0
  29. arcade_microsoft-0.2.3/evals/outlook_calendar/eval_list_events_in_time_range.py +77 -0
  30. arcade_microsoft-0.2.3/evals/outlook_mail/additional_messages.py +83 -0
  31. arcade_microsoft-0.2.3/evals/outlook_mail/eval_read.py +210 -0
  32. arcade_microsoft-0.2.3/evals/outlook_mail/eval_send.py +127 -0
  33. arcade_microsoft-0.2.3/evals/outlook_mail/eval_write.py +104 -0
  34. arcade_microsoft-0.2.3/pyproject.toml +58 -0
  35. arcade_microsoft-0.2.3/tests/__init__.py +0 -0
  36. arcade_microsoft-0.2.3/tests/outlook_calendar/__init__.py +0 -0
  37. arcade_microsoft-0.2.3/tests/outlook_calendar/test_models.py +385 -0
  38. arcade_microsoft-0.2.3/tests/outlook_calendar/test_utils.py +118 -0
  39. arcade_microsoft-0.2.3/tests/outlook_mail/__init__.py +0 -0
  40. arcade_microsoft-0.2.3/tests/outlook_mail/test_message.py +249 -0
  41. arcade_microsoft-0.2.3/tests/outlook_mail/test_recipient.py +43 -0
  42. arcade_microsoft-0.2.3/tests/outlook_mail/test_utils.py +55 -0
@@ -0,0 +1,175 @@
1
+ .DS_Store
2
+ credentials.yaml
3
+ docker/credentials.yaml
4
+
5
+ *.lock
6
+
7
+ # example data
8
+ examples/data
9
+ scratch
10
+
11
+
12
+ docs/source
13
+
14
+ # From https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore
15
+
16
+ # Byte-compiled / optimized / DLL files
17
+ __pycache__/
18
+ *.py[cod]
19
+ *$py.class
20
+
21
+ # C extensions
22
+ *.so
23
+
24
+ # Distribution / packaging
25
+ .Python
26
+ build/
27
+ develop-eggs/
28
+ dist/
29
+ downloads/
30
+ eggs/
31
+ .eggs/
32
+ lib/
33
+ lib64/
34
+ parts/
35
+ sdist/
36
+ var/
37
+ wheels/
38
+ share/python-wheels/
39
+ *.egg-info/
40
+ .installed.cfg
41
+ *.egg
42
+ MANIFEST
43
+
44
+ # PyInstaller
45
+ # Usually these files are written by a python script from a template
46
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
47
+ *.manifest
48
+ *.spec
49
+
50
+ # Installer logs
51
+ pip-log.txt
52
+ pip-delete-this-directory.txt
53
+
54
+ # Unit test / coverage reports
55
+ htmlcov/
56
+ .tox/
57
+ .nox/
58
+ .coverage
59
+ .coverage.*
60
+ .cache
61
+ nosetests.xml
62
+ coverage.xml
63
+ *.cover
64
+ *.py,cover
65
+ .hypothesis/
66
+ .pytest_cache/
67
+ cover/
68
+
69
+ # Translations
70
+ *.mo
71
+ *.pot
72
+
73
+ # Django stuff:
74
+ *.log
75
+ local_settings.py
76
+ db.sqlite3
77
+ db.sqlite3-journal
78
+
79
+ # Flask stuff:
80
+ instance/
81
+ .webassets-cache
82
+
83
+ # Scrapy stuff:
84
+ .scrapy
85
+
86
+ # Sphinx documentation
87
+ docs/_build/
88
+
89
+ # PyBuilder
90
+ .pybuilder/
91
+ target/
92
+
93
+ # Jupyter Notebook
94
+ .ipynb_checkpoints
95
+
96
+ # IPython
97
+ profile_default/
98
+ ipython_config.py
99
+
100
+ # pyenv
101
+ # For a library or package, you might want to ignore these files since the code is
102
+ # intended to run in multiple environments; otherwise, check them in:
103
+ # .python-version
104
+
105
+ # pipenv
106
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
107
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
108
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
109
+ # install all needed dependencies.
110
+ #Pipfile.lock
111
+
112
+ # poetry
113
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
114
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
115
+ # commonly ignored for libraries.
116
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
117
+ poetry.lock
118
+
119
+ # pdm
120
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
121
+ #pdm.lock
122
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
123
+ # in version control.
124
+ # https://pdm.fming.dev/#use-with-ide
125
+ .pdm.toml
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # SageMath parsed files
135
+ *.sage.py
136
+
137
+ # Environments
138
+ .env
139
+ .venv
140
+ env/
141
+ venv/
142
+ ENV/
143
+ env.bak/
144
+ venv.bak/
145
+
146
+ # Spyder project settings
147
+ .spyderproject
148
+ .spyproject
149
+
150
+ # Rope project settings
151
+ .ropeproject
152
+
153
+ # mkdocs documentation
154
+ /site
155
+
156
+ # mypy
157
+ .mypy_cache/
158
+ .dmypy.json
159
+ dmypy.json
160
+
161
+ # Pyre type checker
162
+ .pyre/
163
+
164
+ # pytype static type analyzer
165
+ .pytype/
166
+
167
+ # Cython debug symbols
168
+ cython_debug/
169
+
170
+ # PyCharm
171
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
172
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
173
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
174
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
175
+ #.idea/
@@ -0,0 +1,18 @@
1
+ files: ^.*/microsoft/.*
2
+ repos:
3
+ - repo: https://github.com/pre-commit/pre-commit-hooks
4
+ rev: "v4.4.0"
5
+ hooks:
6
+ - id: check-case-conflict
7
+ - id: check-merge-conflict
8
+ - id: check-toml
9
+ - id: check-yaml
10
+ - id: end-of-file-fixer
11
+ - id: trailing-whitespace
12
+
13
+ - repo: https://github.com/astral-sh/ruff-pre-commit
14
+ rev: v0.6.7
15
+ hooks:
16
+ - id: ruff
17
+ args: [--fix]
18
+ - id: ruff-format
@@ -0,0 +1,44 @@
1
+ target-version = "py310"
2
+ line-length = 100
3
+ fix = true
4
+
5
+ [lint]
6
+ select = [
7
+ # flake8-2020
8
+ "YTT",
9
+ # flake8-bandit
10
+ "S",
11
+ # flake8-bugbear
12
+ "B",
13
+ # flake8-builtins
14
+ "A",
15
+ # flake8-comprehensions
16
+ "C4",
17
+ # flake8-debugger
18
+ "T10",
19
+ # flake8-simplify
20
+ "SIM",
21
+ # isort
22
+ "I",
23
+ # mccabe
24
+ "C90",
25
+ # pycodestyle
26
+ "E", "W",
27
+ # pyflakes
28
+ "F",
29
+ # pygrep-hooks
30
+ "PGH",
31
+ # pyupgrade
32
+ "UP",
33
+ # ruff
34
+ "RUF",
35
+ # tryceratops
36
+ "TRY",
37
+ ]
38
+
39
+ [lint.per-file-ignores]
40
+ "**/tests/*" = ["S101"]
41
+
42
+ [format]
43
+ preview = true
44
+ skip-magic-trailing-comma = false
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025, Arcade
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,55 @@
1
+ .PHONY: help
2
+
3
+ help:
4
+ @echo "🛠️ github Commands:\n"
5
+ @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
6
+
7
+ .PHONY: install
8
+ install: ## Install the uv environment and install all packages with dependencies
9
+ @echo "🚀 Creating virtual environment and installing all packages using uv"
10
+ @uv sync --active --all-extras --no-sources
11
+ @if [ -f .pre-commit-config.yaml ]; then uv run --no-sources pre-commit install; fi
12
+ @echo "✅ All packages and dependencies installed via uv"
13
+
14
+ .PHONY: install-local
15
+ install-local: ## Install the uv environment and install all packages with dependencies with local Arcade sources
16
+ @echo "🚀 Creating virtual environment and installing all packages using uv"
17
+ @uv sync --active --all-extras
18
+ @if [ -f .pre-commit-config.yaml ]; then uv run pre-commit install; fi
19
+ @echo "✅ All packages and dependencies installed via uv"
20
+
21
+ .PHONY: build
22
+ build: clean-build ## Build wheel file using poetry
23
+ @echo "🚀 Creating wheel file"
24
+ uv build
25
+
26
+ .PHONY: clean-build
27
+ clean-build: ## clean build artifacts
28
+ @echo "🗑️ Cleaning dist directory"
29
+ rm -rf dist
30
+
31
+ .PHONY: test
32
+ test: ## Test the code with pytest
33
+ @echo "🚀 Testing code: Running pytest"
34
+ @uv run --no-sources pytest -W ignore -v --cov --cov-config=pyproject.toml --cov-report=xml
35
+
36
+ .PHONY: coverage
37
+ coverage: ## Generate coverage report
38
+ @echo "coverage report"
39
+ @uv run --no-sources coverage report
40
+ @echo "Generating coverage report"
41
+ @uv run --no-sources coverage html
42
+
43
+ .PHONY: bump-version
44
+ bump-version: ## Bump the version in the pyproject.toml file by a patch version
45
+ @echo "🚀 Bumping version in pyproject.toml"
46
+ uv version --no-sources --bump patch
47
+
48
+ .PHONY: check
49
+ check: ## Run code quality tools.
50
+ @if [ -f .pre-commit-config.yaml ]; then\
51
+ echo "🚀 Linting code: Running pre-commit";\
52
+ uv run --no-sources pre-commit run -a;\
53
+ fi
54
+ @echo "🚀 Static type checking: Running mypy"
55
+ @uv run --no-sources mypy --config-file=pyproject.toml
@@ -0,0 +1,21 @@
1
+ Metadata-Version: 2.4
2
+ Name: arcade_microsoft
3
+ Version: 0.2.3
4
+ Summary: Arcade.dev LLM tools for Outlook Mail
5
+ Author-email: Arcade <dev@arcade.dev>
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.10
8
+ Requires-Dist: arcade-tdk<3.0.0,>=2.0.0
9
+ Requires-Dist: beautifulsoup4<5.0.0,>=4.10.0
10
+ Requires-Dist: msgraph-sdk<2.0.0,>=1.28.0
11
+ Requires-Dist: pytz<2025.0.0,>=2024.2
12
+ Provides-Extra: dev
13
+ Requires-Dist: arcade-ai[evals]<3.0.0,>=2.0.0; extra == 'dev'
14
+ Requires-Dist: arcade-serve<3.0.0,>=2.0.0; extra == 'dev'
15
+ Requires-Dist: mypy<1.6.0,>=1.5.1; extra == 'dev'
16
+ Requires-Dist: pre-commit<3.5.0,>=3.4.0; extra == 'dev'
17
+ Requires-Dist: pytest-asyncio<0.25.0,>=0.24.0; extra == 'dev'
18
+ Requires-Dist: pytest-cov<4.1.0,>=4.0.0; extra == 'dev'
19
+ Requires-Dist: pytest<8.4.0,>=8.3.0; extra == 'dev'
20
+ Requires-Dist: ruff<0.8.0,>=0.7.4; extra == 'dev'
21
+ Requires-Dist: tox<4.12.0,>=4.11.1; extra == 'dev'
File without changes
@@ -0,0 +1,26 @@
1
+ import datetime
2
+ from typing import Any
3
+
4
+ from azure.core.credentials import AccessToken, TokenCredential
5
+ from msgraph import GraphServiceClient
6
+
7
+ DEFAULT_SCOPE = "https://graph.microsoft.com/.default"
8
+
9
+
10
+ class StaticTokenCredential(TokenCredential):
11
+ """Implementation of TokenCredential protocol to be provided to the MSGraph SDK client"""
12
+
13
+ def __init__(self, token: str):
14
+ self._token = token
15
+
16
+ def get_token(self, *scopes: str, **kwargs: Any) -> AccessToken:
17
+ # An expiration is required by MSGraph SDK. Set to 1 hour from now.
18
+ expires_on = int(datetime.datetime.now(datetime.timezone.utc).timestamp()) + 3600
19
+ return AccessToken(self._token, expires_on)
20
+
21
+
22
+ def get_client(token: str) -> GraphServiceClient:
23
+ """Create and return a MSGraph SDK client, given the provided token."""
24
+ token_credential = StaticTokenCredential(token)
25
+
26
+ return GraphServiceClient(token_credential, scopes=[DEFAULT_SCOPE])
@@ -0,0 +1,7 @@
1
+ from arcade_microsoft.outlook_calendar.tools import (
2
+ create_event,
3
+ get_event,
4
+ list_events_in_time_range,
5
+ )
6
+
7
+ __all__ = ["create_event", "get_event", "list_events_in_time_range"]
@@ -0,0 +1,225 @@
1
+ import re
2
+ from datetime import datetime
3
+ from typing import Any
4
+
5
+ import pytz
6
+ from arcade_tdk.errors import ToolExecutionError
7
+ from kiota_abstractions.base_request_configuration import RequestConfiguration
8
+ from kiota_abstractions.headers_collection import HeadersCollection
9
+ from msgraph import GraphServiceClient
10
+ from msgraph.generated.users.item.mailbox_settings.mailbox_settings_request_builder import (
11
+ MailboxSettingsRequestBuilder,
12
+ )
13
+
14
+ from arcade_microsoft.outlook_calendar.constants import WINDOWS_TO_IANA
15
+
16
+
17
+ def validate_date_times(start_date_time: str, end_date_time: str) -> None:
18
+ """
19
+ Validate date times are in ISO 8601 format and
20
+ that end time is after start time (ignoring timezone offsets).
21
+
22
+ Args:
23
+ start_date_time: The start date time string to validate.
24
+ end_date_time: The end date time string to validate.
25
+
26
+ Raises:
27
+ ValueError: If the date times are not in ISO 8601 format
28
+ ToolExecutionError: If end time is not after start time.
29
+
30
+ Note:
31
+ This function ignores timezone offsets.
32
+ """
33
+ # parse into offset-aware datetimes
34
+ start_aware = datetime.fromisoformat(start_date_time)
35
+ end_aware = datetime.fromisoformat(end_date_time)
36
+
37
+ # drop tzinfo to treat both as naïve local times
38
+ start_naive = start_aware.replace(tzinfo=None)
39
+ end_naive = end_aware.replace(tzinfo=None)
40
+
41
+ if start_naive >= end_naive:
42
+ raise ToolExecutionError(
43
+ message="Start time must be before end time",
44
+ developer_message=(
45
+ f"The start time '{start_naive}' is not before the end time '{end_naive}'"
46
+ ),
47
+ )
48
+
49
+
50
+ def prepare_meeting_body(
51
+ body: str, custom_meeting_url: str | None, is_online_meeting: bool
52
+ ) -> tuple[str, bool]:
53
+ """Prepare meeting body and determine final online meeting status.
54
+
55
+ Args:
56
+ body: The original meeting body text
57
+ custom_meeting_url: Custom URL for the meeting, if one exists
58
+ is_online_meeting: Whether this should be an online meeting
59
+
60
+ Returns:
61
+ tuple: (Updated meeting body, final online meeting status)
62
+
63
+ Note:
64
+ If a custom meeting URL is provided, is_online_meeting will be set to False
65
+ to prevent Microsoft from generating its own meeting URL. The custom meeting
66
+ URL will then be added to the body of the meeting.
67
+ """
68
+ is_online_meeting = not custom_meeting_url and is_online_meeting
69
+
70
+ if custom_meeting_url:
71
+ body = f"""{body}\n
72
+ .........................................................................
73
+ Join online meeting
74
+ {custom_meeting_url}"""
75
+
76
+ return body, is_online_meeting
77
+
78
+
79
+ def validate_emails(emails: list[str]) -> None:
80
+ """Validate a list of email addresses.
81
+
82
+ Args:
83
+ emails: The list of email addresses to validate.
84
+
85
+ Raises:
86
+ ToolExecutionError: If any email address is invalid.
87
+ """
88
+ invalid_emails = []
89
+ for email in emails:
90
+ if not is_valid_email(email):
91
+ invalid_emails.append(email)
92
+ if invalid_emails:
93
+ raise ToolExecutionError(message=f"Invalid email address(es): {', '.join(invalid_emails)}")
94
+
95
+
96
+ def is_valid_email(email: str) -> bool:
97
+ """Simple check to see if an email address is valid.
98
+
99
+ Args:
100
+ email: The email address to check.
101
+
102
+ Returns:
103
+ True if the email address is valid, False otherwise.
104
+ """
105
+ pattern = r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
106
+ return re.match(pattern, email) is not None
107
+
108
+
109
+ def remove_timezone_offset(date_time: str) -> str:
110
+ """Remove the timezone offset from the date_time string."""
111
+ return re.sub(r"[+-][0-9]{2}:[0-9]{2}$|Z$", "", date_time)
112
+
113
+
114
+ def replace_timezone_offset(date_time: str, time_zone_offset: str) -> str:
115
+ """Replace the timezone offset in the date_time string with the time_zone_offset.
116
+
117
+ If the date_time str already contains a timezone offset, it will be replaced.
118
+ If the date_time str does not contain a timezone offset, the time_zone_offset will be appended
119
+
120
+ Args:
121
+ date_time: The date_time string to replace the timezone offset in.
122
+ time_zone_offset: The timezone offset to replace the existing timezone offset with.
123
+
124
+ Returns:
125
+ The date_time string with the timezone offset replaced or appended.
126
+ """
127
+ date_time = remove_timezone_offset(date_time)
128
+ return f"{date_time}{time_zone_offset}"
129
+
130
+
131
+ def convert_timezone_to_offset(time_zone: str) -> str:
132
+ """
133
+ Convert a timezone (Windows or IANA) to ISO 8601 offset.
134
+ First tries Windows timezone format, then IANA, then falls back to UTC if both fail.
135
+
136
+ Args:
137
+ time_zone: The timezone (Windows or IANA) to convert to ISO 8601 offset.
138
+
139
+ Returns:
140
+ The timezone offset in ISO 8601 format (e.g. '+08:00', '-07:00', or 'Z' for UTC)
141
+ """
142
+ # Try Windows timezone format
143
+ iana_timezone = WINDOWS_TO_IANA.get(time_zone)
144
+ if iana_timezone:
145
+ try:
146
+ tz = pytz.timezone(iana_timezone)
147
+ now = datetime.now(tz)
148
+ tz_offset = now.strftime("%z")
149
+
150
+ if len(tz_offset) == 5: # +HHMM format
151
+ tz_offset = f"{tz_offset[:3]}:{tz_offset[3:]}" # +HH:MM format
152
+ return tz_offset # noqa: TRY300
153
+ except (pytz.exceptions.UnknownTimeZoneError, ValueError):
154
+ pass
155
+
156
+ # Try IANA timezone format
157
+ try:
158
+ tz = pytz.timezone(time_zone)
159
+ now = datetime.now(tz)
160
+ tz_offset = now.strftime("%z")
161
+
162
+ if len(tz_offset) == 5: # +HHMM format
163
+ tz_offset = f"{tz_offset[:3]}:{tz_offset[3:]}" # +HH:MM format
164
+ return tz_offset # noqa: TRY300
165
+ except (pytz.exceptions.UnknownTimeZoneError, ValueError):
166
+ # Fallback to UTC
167
+ return "Z"
168
+
169
+
170
+ async def get_default_calendar_timezone(client: GraphServiceClient) -> str:
171
+ """Get the authenticated user's default calendar's timezone.
172
+
173
+ Args:
174
+ client: The GraphServiceClient to use to get
175
+ the authenticated user's default calendar's timezone.
176
+
177
+ Returns:
178
+ The timezone in "Windows timezone format" or "IANA timezone format".
179
+ """
180
+ query_params = MailboxSettingsRequestBuilder.MailboxSettingsRequestBuilderGetQueryParameters(
181
+ select=["timeZone"]
182
+ )
183
+ request_config = RequestConfiguration(
184
+ query_parameters=query_params,
185
+ )
186
+ response = await client.me.mailbox_settings.get(request_config)
187
+
188
+ if response and response.time_zone:
189
+ return response.time_zone
190
+ return "UTC"
191
+
192
+
193
+ def create_timezone_headers(time_zone: str) -> HeadersCollection:
194
+ """
195
+ Create headers with timezone preference.
196
+
197
+ Args:
198
+ time_zone: The timezone to set in the headers.
199
+
200
+ Returns:
201
+ Headers collection with timezone preference set.
202
+ """
203
+ headers = HeadersCollection()
204
+ headers.try_add("Prefer", f'outlook.timezone="{time_zone}"')
205
+ return headers
206
+
207
+
208
+ def create_timezone_request_config(
209
+ time_zone: str, query_parameters: Any | None = None
210
+ ) -> RequestConfiguration:
211
+ """
212
+ Create a request configuration with timezone headers and optional query parameters.
213
+
214
+ Args:
215
+ time_zone: The timezone to set in the headers.
216
+ query_parameters: Optional query parameters to include in the configuration.
217
+
218
+ Returns:
219
+ Request configuration with timezone headers and optional query parameters.
220
+ """
221
+ headers = create_timezone_headers(time_zone)
222
+ return RequestConfiguration(
223
+ headers=headers,
224
+ query_parameters=query_parameters,
225
+ )