Comments (7)
Can you please provide some example code showing what you tried to do? And the error message or stack trace that you got? CalendarItem.appointment_state
is a read-only field, so it's surprising that you reached AppointmentStateField.from_xml
.
from exchangelib.
I'm trying to transfer all messages from one mailbox to another.
Messages like MeetingRequest too.
Example
get_folder - GetFolder
get_item - GetItem
create_item - CreateItem
These are wrappers on functions for convenience.
...
message_source = ews_control_source.get_item(task.source_message_oid, task.source_message_changekey)
folder_parent_target = ews_control_target.get_folder(task.target_folder_oid)
...
message_target = ews_control_target.create_item(folder_parent_target, message_source)
task.target_message_oid = message_target.id
task.target_message_changekey = message_target.changekey
stack trace
Traceback (most recent call last):
File "/app/t2t_migrator/workers/queue_base.py", line 70, in __call__
await current_function(task)
File "/app/t2t_migrator/workers/queue_mail_message.py", line 71, in ews_mail_message_create
await self.mail_control.create_mail_message_by_ews(
File "/app/t2t_migrator/controls/mail.py", line 1398, in create_mail_message_by_ews
message_target = ews_control_target.create_item(folder_parent_target, message_source)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/t2t_migrator/controls/ews.py", line 101, in create_item
return list(CreateItem(account=self.account).call(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.cache/pypoetry/virtualenvs/migrationt2t-9TtSrW0h-py3.11/lib/python3.11/site-packages/exchangelib/services/common.py", line 225, in _elems_to_objs
for elem in elems:
File "/root/.cache/pypoetry/virtualenvs/migrationt2t-9TtSrW0h-py3.11/lib/python3.11/site-packages/exchangelib/services/common.py", line 287, in _chunked_get_elements
yield from self._get_elements(payload=payload_func(chunk, **kwargs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.cache/pypoetry/virtualenvs/migrationt2t-9TtSrW0h-py3.11/lib/python3.11/site-packages/exchangelib/services/create_item.py", line 95, in get_payload
set_xml_value(item_elems, item, version=self.account.version)
File "/root/.cache/pypoetry/virtualenvs/migrationt2t-9TtSrW0h-py3.11/lib/python3.11/site-packages/exchangelib/util.py", line 259, in set_xml_value
elem.append(value.to_xml(version=version))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.cache/pypoetry/virtualenvs/migrationt2t-9TtSrW0h-py3.11/lib/python3.11/site-packages/exchangelib/properties.py", line 319, in to_xml
self.clean(version=version)
File "/root/.cache/pypoetry/virtualenvs/migrationt2t-9TtSrW0h-py3.11/lib/python3.11/site-packages/exchangelib/properties.py", line 300, in clean
setattr(self, f.name, f.clean(val, version=version))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.cache/pypoetry/virtualenvs/migrationt2t-9TtSrW0h-py3.11/lib/python3.11/site-packages/exchangelib/fields.py", line 444, in clean
value = super().clean(value, version=version)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.cache/pypoetry/virtualenvs/migrationt2t-9TtSrW0h-py3.11/lib/python3.11/site-packages/exchangelib/fields.py", line 334, in clean
raise TypeError(f"Field {self.name!r} value {value!r} must be of type {self.value_cls}")
TypeError: Field 'appointment_state' value ('Meeting', 'Received') must be of type <class 'int'>
from exchangelib.
You didn't include enough code for me to be able to reproduce.
Anyway, this is not a bug. You're calling CreateItem
directly in "/app/t2t_migrator/controls/ews.py", line 101. You're free to use the low-level components of exchangelib, but then you need to handle the details yourself, for example which fields are read-only and which aren't.
If you want exchangelib to handle all that, then do something like CalendarItem(account=target_account, subject=..., ...).save()
.
from exchangelib.
I still think this is a type error.
This happens because AppointmentStateField inherits from IntegerField and AppointmentStateField.value_cls = int, and AppointmentStateField.from_xml returns tuple[str].
I understand that this is a read-only field. It does not go further into the request. Even if it goes away (by copying the library locally and conducting experiments), it does not create an error.
For myself in the fork, I will leave the code AppointmentStateField.from_xml, which does not throw an exception.
def from_xml(self, elem, account):
return super().from_xml(elem=elem, account=account)
Thank you.
I have one more question.
I use the same code to transfer all messages and there was a problem that all letters are marked Draft.
Using ExtendedProperty, I can remove this.
# add property
class IsDraft(ExtendedProperty):
property_tag = 0x0E07 # 3591
property_type = "Integer"
...
Item.register("extended_is_draft", IsDraft)
...
message_source = ews_control_source.get_item(task.source_message_oid, task.source_message_changekey)
message_source.extended_is_draft = message_source.is_draft
message_target = ews_control_target.create_item(folder_parent_target, message_source)
Can you tell me if there could be a similar property in ExtendedProperty for AppointmentState?
from exchangelib.
AppointmentStateField
is special because it's implemented as a bitmask in EWS. EWS sends an integer in XML. Therefore, the field is implemented as an integer field. But bitmasks are annoying to work with in Python, so we help the user by expanding the bitmask options to a tuple. Since the field is read-only, there's no point in implementing AppointmentStateField.to_xml()
because there's no path to it via the supported API in exchangelib.
It's also possible that AppointmentState
is indeed read-write but we just haven't found the correct incantations to write back the value. But https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/appointmentstate explicitly states that the field is read-only.
I don't know if AppointmentState
can be accessed via an extended property, unfortunately.
from exchangelib.
When transferring items from one account to another, you also have the possibility to export and upload.
from exchangelib.
I agree with you about working with bit masks and working with this field.
I have a specific task (data migration from one mailbox to another). We used imap, but we couldn’t find how to access archived mailboxes.
I'll try this option with Export and upload
Thank you
from exchangelib.
Related Issues (20)
- ErrorInvalidSchemaVersionForMailboxVersion with exchangelib v5.2.1 and Exchange server version 15.2.1544.4 HOT 45
- EOF occurred in violation of protocol HOT 4
- ValueError trying to delete a rule HOT 2
- Error getting folders for v5.2.1+ (server 2010sp3 upd.29) HOT 3
- Cannot fetch calendar folder HOT 4
- Problem getting auth type from Exchange server HOT 15
- The request failed schema validation HOT 9
- Get more than 100 records with a.protocol.resolve_names HOT 1
- EWS does not support returning more than 100 results. See https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/resolvenames-operation
- How to disable check_hostname HOT 5
- some new distinguished folders cause 500 error HOT 4
- Support Custom Authentication Domains for Global and Governmental Environments (gcc-high, dod, etc) HOT 1
- Implement passing an Account object to GetUserAvailability in order to fix the "Returning naive datetime"-warning for timezone-unaware server responses. HOT 3
- Not enough scope error HOT 4
- OOF, The scheduled duration for sending automatic replies isn't valid HOT 4
- 403 Error | App Delegate Access for Personal Outlook Account HOT 5
- Accessing shared calendars does no longer work on 5.4.2 but it does work on 5.2.0 HOT 12
- Calendar items sent to users have reminder as 15 minutes regardless of reminder_is_set set to False HOT 1
- attachment.name returns None for Attached Outlook Items Despite Valid Subject HOT 4
- "Unsafe legacy renegotiation disabled" error in Python 3.12 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from exchangelib.