Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_garbage_input(self):
# Test that we can survive garbage input for common field types
tz = EWSTimeZone.timezone('Europe/Copenhagen')
account = namedtuple('Account', ['default_timezone'])(default_timezone=tz)
payload = b'''\
THIS_IS_GARBAGE
'''
elem = to_xml(payload).find('{%s}Item' % TNS)
for field_cls in (Base64Field, BooleanField, IntegerField, DateField, DateTimeField, DecimalField):
field = field_cls('foo', field_uri='item:Foo', is_required=True, default='DUMMY')
self.assertEqual(field.from_xml(elem=elem, account=account), None)
# Test MS timezones
payload = b'''\
'''
elem = to_xml(payload).find('{%s}Item' % TNS)
field = TimeZoneField('foo', field_uri='item:Foo', default='DUMMY')
self.assertEqual(field.from_xml(elem=elem, account=account), None)
Choice('Normal'), Choice('Personal'), Choice('Private'), Choice('Confidential')
}, is_required=True, default='Normal'),
TextField('text_body', field_uri='item:TextBody', is_read_only=True, supported_from=EXCHANGE_2013),
BodyField('body', field_uri='item:Body'), # Accepts and returns Body or HTMLBody instances
AttachmentField('attachments', field_uri='item:Attachments'), # ItemAttachment or FileAttachment
DateTimeField('datetime_received', field_uri='item:DateTimeReceived', is_read_only=True),
IntegerField('size', field_uri='item:Size', is_read_only=True), # Item size in bytes
CharListField('categories', field_uri='item:Categories'),
ChoiceField('importance', field_uri='item:Importance', choices={
Choice('Low'), Choice('Normal'), Choice('High')
}, is_required=True, default='Normal'),
TextField('in_reply_to', field_uri='item:InReplyTo'),
BooleanField('is_submitted', field_uri='item:IsSubmitted', is_read_only=True),
BooleanField('is_draft', field_uri='item:IsDraft', is_read_only=True),
BooleanField('is_from_me', field_uri='item:IsFromMe', is_read_only=True),
BooleanField('is_resend', field_uri='item:IsResend', is_read_only=True),
BooleanField('is_unmodified', field_uri='item:IsUnmodified', is_read_only=True),
MessageHeaderField('headers', field_uri='item:InternetMessageHeaders', is_read_only=True),
DateTimeField('datetime_sent', field_uri='item:DateTimeSent', is_read_only=True),
DateTimeField('datetime_created', field_uri='item:DateTimeCreated', is_read_only=True),
# Placeholder for ResponseObjects
DateTimeField('reminder_due_by', field_uri='item:ReminderDueBy', is_required_after_save=True,
is_searchable=False),
BooleanField('reminder_is_set', field_uri='item:ReminderIsSet', is_required=True, default=False),
IntegerField('reminder_minutes_before_start', field_uri='item:ReminderMinutesBeforeStart',
is_required_after_save=True, min=0, default=0),
CharField('display_cc', field_uri='item:DisplayCc', is_read_only=True),
CharField('display_to', field_uri='item:DisplayTo', is_read_only=True),
BooleanField('has_attachments', field_uri='item:HasAttachments', is_read_only=True),
# ExtendedProperty fields go here
CultureField('culture', field_uri='item:Culture', is_required_after_save=True, is_searchable=False),
EffectiveRightsField('effective_rights', field_uri='item:EffectiveRights', is_read_only=True),
ChoiceField('sensitivity', field_uri='item:Sensitivity', choices={
Choice('Normal'), Choice('Personal'), Choice('Private'), Choice('Confidential')
}, is_required=True, default='Normal'),
TextField('text_body', field_uri='item:TextBody', is_read_only=True, supported_from=EXCHANGE_2013),
BodyField('body', field_uri='item:Body'), # Accepts and returns Body or HTMLBody instances
AttachmentField('attachments', field_uri='item:Attachments'), # ItemAttachment or FileAttachment
DateTimeField('datetime_received', field_uri='item:DateTimeReceived', is_read_only=True),
IntegerField('size', field_uri='item:Size', is_read_only=True), # Item size in bytes
CharListField('categories', field_uri='item:Categories'),
ChoiceField('importance', field_uri='item:Importance', choices={
Choice('Low'), Choice('Normal'), Choice('High')
}, is_required=True, default='Normal'),
TextField('in_reply_to', field_uri='item:InReplyTo'),
BooleanField('is_submitted', field_uri='item:IsSubmitted', is_read_only=True),
BooleanField('is_draft', field_uri='item:IsDraft', is_read_only=True),
BooleanField('is_from_me', field_uri='item:IsFromMe', is_read_only=True),
BooleanField('is_resend', field_uri='item:IsResend', is_read_only=True),
BooleanField('is_unmodified', field_uri='item:IsUnmodified', is_read_only=True),
MessageHeaderField('headers', field_uri='item:InternetMessageHeaders', is_read_only=True),
DateTimeField('datetime_sent', field_uri='item:DateTimeSent', is_read_only=True),
DateTimeField('datetime_created', field_uri='item:DateTimeCreated', is_read_only=True),
# Placeholder for ResponseObjects
DateTimeField('reminder_due_by', field_uri='item:ReminderDueBy', is_required_after_save=True,
is_searchable=False),
BooleanField('reminder_is_set', field_uri='item:ReminderIsSet', is_required=True, default=False),
IntegerField('reminder_minutes_before_start', field_uri='item:ReminderMinutesBeforeStart',
is_required_after_save=True, min=0, default=0),
CharField('display_cc', field_uri='item:DisplayCc', is_read_only=True),
CharField('display_to', field_uri='item:DisplayTo', is_read_only=True),
BooleanField('has_attachments', field_uri='item:HasAttachments', is_read_only=True),
# ExtendedProperty fields go here
CultureField('culture', field_uri='item:Culture', is_required_after_save=True, is_searchable=False),
CharField('item_class', field_uri='item:ItemClass', is_read_only=True),
CharField('subject', field_uri='item:Subject'),
ChoiceField('sensitivity', field_uri='item:Sensitivity', choices={
Choice('Normal'), Choice('Personal'), Choice('Private'), Choice('Confidential')
}, is_required=True, default='Normal'),
TextField('text_body', field_uri='item:TextBody', is_read_only=True, supported_from=EXCHANGE_2013),
BodyField('body', field_uri='item:Body'), # Accepts and returns Body or HTMLBody instances
AttachmentField('attachments', field_uri='item:Attachments'), # ItemAttachment or FileAttachment
DateTimeField('datetime_received', field_uri='item:DateTimeReceived', is_read_only=True),
IntegerField('size', field_uri='item:Size', is_read_only=True), # Item size in bytes
CharListField('categories', field_uri='item:Categories'),
ChoiceField('importance', field_uri='item:Importance', choices={
Choice('Low'), Choice('Normal'), Choice('High')
}, is_required=True, default='Normal'),
TextField('in_reply_to', field_uri='item:InReplyTo'),
BooleanField('is_submitted', field_uri='item:IsSubmitted', is_read_only=True),
BooleanField('is_draft', field_uri='item:IsDraft', is_read_only=True),
BooleanField('is_from_me', field_uri='item:IsFromMe', is_read_only=True),
BooleanField('is_resend', field_uri='item:IsResend', is_read_only=True),
BooleanField('is_unmodified', field_uri='item:IsUnmodified', is_read_only=True),
MessageHeaderField('headers', field_uri='item:InternetMessageHeaders', is_read_only=True),
DateTimeField('datetime_sent', field_uri='item:DateTimeSent', is_read_only=True),
DateTimeField('datetime_created', field_uri='item:DateTimeCreated', is_read_only=True),
# Placeholder for ResponseObjects
DateTimeField('reminder_due_by', field_uri='item:ReminderDueBy', is_required_after_save=True,
is_searchable=False),
BooleanField('reminder_is_set', field_uri='item:ReminderIsSet', is_required=True, default=False),
IntegerField('reminder_minutes_before_start', field_uri='item:ReminderMinutesBeforeStart',
is_required_after_save=True, min=0, default=0),
CharField('display_cc', field_uri='item:DisplayCc', is_read_only=True),
CharField('display_to', field_uri='item:DisplayTo', is_read_only=True),
BooleanField('has_attachments', field_uri='item:HasAttachments', is_read_only=True),
ELEMENT_NAME = 'CalendarItem'
LOCAL_FIELDS = [
TextField('uid', field_uri='calendar:UID', is_required_after_save=True, is_searchable=False),
DateTimeField('start', field_uri='calendar:Start', is_required=True),
DateTimeField('end', field_uri='calendar:End', is_required=True),
DateTimeField('original_start', field_uri='calendar:OriginalStart', is_read_only=True),
BooleanField('is_all_day', field_uri='calendar:IsAllDayEvent', is_required=True, default=False),
FreeBusyStatusField('legacy_free_busy_status', field_uri='calendar:LegacyFreeBusyStatus', is_required=True,
default='Busy'),
TextField('location', field_uri='calendar:Location'),
TextField('when', field_uri='calendar:When'),
BooleanField('is_meeting', field_uri='calendar:IsMeeting', is_read_only=True),
BooleanField('is_cancelled', field_uri='calendar:IsCancelled', is_read_only=True),
BooleanField('is_recurring', field_uri='calendar:IsRecurring', is_read_only=True),
BooleanField('meeting_request_was_sent', field_uri='calendar:MeetingRequestWasSent', is_read_only=True),
BooleanField('is_response_requested', field_uri='calendar:IsResponseRequested', default=None,
is_required_after_save=True, is_searchable=False),
ChoiceField('type', field_uri='calendar:CalendarItemType', choices={Choice(c) for c in CALENDAR_ITEM_CHOICES},
is_read_only=True),
ChoiceField('my_response_type', field_uri='calendar:MyResponseType', choices={
Choice(c) for c in Attendee.RESPONSE_TYPES
}, is_read_only=True),
MailboxField('organizer', field_uri='calendar:Organizer', is_read_only=True),
AttendeesField('required_attendees', field_uri='calendar:RequiredAttendees', is_searchable=False),
AttendeesField('optional_attendees', field_uri='calendar:OptionalAttendees', is_searchable=False),
AttendeesField('resources', field_uri='calendar:Resources', is_searchable=False),
IntegerField('conflicting_meeting_count', field_uri='calendar:ConflictingMeetingCount', is_read_only=True),
IntegerField('adjacent_meeting_count', field_uri='calendar:AdjacentMeetingCount', is_read_only=True),
# Placeholder for ConflictingMeetings
# Placeholder for AdjacentMeetings
CharField('duration', field_uri='calendar:Duration', is_read_only=True),
DateTimeField('appointment_reply_time', field_uri='calendar:AppointmentReplyTime', is_read_only=True),
BooleanField('is_draft', field_uri='item:IsDraft', is_read_only=True),
BooleanField('is_from_me', field_uri='item:IsFromMe', is_read_only=True),
BooleanField('is_resend', field_uri='item:IsResend', is_read_only=True),
BooleanField('is_unmodified', field_uri='item:IsUnmodified', is_read_only=True),
MessageHeaderField('headers', field_uri='item:InternetMessageHeaders', is_read_only=True),
DateTimeField('datetime_sent', field_uri='item:DateTimeSent', is_read_only=True),
DateTimeField('datetime_created', field_uri='item:DateTimeCreated', is_read_only=True),
# Placeholder for ResponseObjects
DateTimeField('reminder_due_by', field_uri='item:ReminderDueBy', is_required_after_save=True,
is_searchable=False),
BooleanField('reminder_is_set', field_uri='item:ReminderIsSet', is_required=True, default=False),
IntegerField('reminder_minutes_before_start', field_uri='item:ReminderMinutesBeforeStart',
is_required_after_save=True, min=0, default=0),
CharField('display_cc', field_uri='item:DisplayCc', is_read_only=True),
CharField('display_to', field_uri='item:DisplayTo', is_read_only=True),
BooleanField('has_attachments', field_uri='item:HasAttachments', is_read_only=True),
# ExtendedProperty fields go here
CultureField('culture', field_uri='item:Culture', is_required_after_save=True, is_searchable=False),
EffectiveRightsField('effective_rights', field_uri='item:EffectiveRights', is_read_only=True),
CharField('last_modified_name', field_uri='item:LastModifiedName', is_read_only=True),
DateTimeField('last_modified_time', field_uri='item:LastModifiedTime', is_read_only=True),
BooleanField('is_associated', field_uri='item:IsAssociated', is_read_only=True, supported_from=EXCHANGE_2010),
URIField('web_client_read_form_query_string', field_uri='item:WebClientReadFormQueryString',
is_read_only=True, supported_from=EXCHANGE_2010),
URIField('web_client_edit_form_query_string', field_uri='item:WebClientEditFormQueryString',
is_read_only=True, supported_from=EXCHANGE_2010),
EWSElementField('conversation_id', field_uri='item:ConversationId', value_cls=ConversationId,
is_read_only=True, supported_from=EXCHANGE_2010),
BodyField('unique_body', field_uri='item:UniqueBody', is_read_only=True, supported_from=EXCHANGE_2010),
]
FIELDS = LOCAL_FIELDS[0:1] + BaseItem.FIELDS + LOCAL_FIELDS[1:]
__slots__ = tuple(f.name for f in FIELDS)
def clean(self, version=None):
super(CalendarView, self).clean(version=version)
if self.end < self.start:
raise ValueError("'start' must be before 'end'")
class CalendarEventDetails(EWSElement):
"""MSDN: https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/calendareventdetails"""
ELEMENT_NAME = 'CalendarEventDetails'
FIELDS = [
CharField('id', field_uri='ID'),
CharField('subject', field_uri='Subject'),
CharField('location', field_uri='Location'),
BooleanField('is_meeting', field_uri='IsMeeting'),
BooleanField('is_recurring', field_uri='IsRecurring'),
BooleanField('is_exception', field_uri='IsException'),
BooleanField('is_reminder_set', field_uri='IsReminderSet'),
BooleanField('is_private', field_uri='IsPrivate'),
]
__slots__ = tuple(f.name for f in FIELDS)
class CalendarEvent(EWSElement):
"""MSDN: https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/calendarevent"""
ELEMENT_NAME = 'CalendarEvent'
FIELDS = [
DateTimeField('start', field_uri='StartTime'),
DateTimeField('end', field_uri='EndTime'),
FreeBusyStatusField('busy_type', field_uri='BusyType', is_required=True, default='Busy'),
def clean(self, version=None):
super(CalendarView, self).clean(version=version)
if self.end < self.start:
raise ValueError("'start' must be before 'end'")
class CalendarEventDetails(EWSElement):
"""MSDN: https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/calendareventdetails"""
ELEMENT_NAME = 'CalendarEventDetails'
FIELDS = [
CharField('id', field_uri='ID'),
CharField('subject', field_uri='Subject'),
CharField('location', field_uri='Location'),
BooleanField('is_meeting', field_uri='IsMeeting'),
BooleanField('is_recurring', field_uri='IsRecurring'),
BooleanField('is_exception', field_uri='IsException'),
BooleanField('is_reminder_set', field_uri='IsReminderSet'),
BooleanField('is_private', field_uri='IsPrivate'),
]
__slots__ = tuple(f.name for f in FIELDS)
class CalendarEvent(EWSElement):
"""MSDN: https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/calendarevent"""
ELEMENT_NAME = 'CalendarEvent'
FIELDS = [
DateTimeField('start', field_uri='StartTime'),
DateTimeField('end', field_uri='EndTime'),
FreeBusyStatusField('busy_type', field_uri='BusyType', is_required=True, default='Busy'),
EWSElementField('details', field_uri='CalendarEventDetails', value_cls=CalendarEventDetails),
LOCAL_FIELDS = [
IntegerField('actual_work', field_uri='task:ActualWork', min=0),
DateTimeField('assigned_time', field_uri='task:AssignedTime', is_read_only=True),
TextField('billing_information', field_uri='task:BillingInformation'),
IntegerField('change_count', field_uri='task:ChangeCount', is_read_only=True, min=0),
TextListField('companies', field_uri='task:Companies'),
# 'complete_date' can be set, but is ignored by the server, which sets it to now()
DateTimeField('complete_date', field_uri='task:CompleteDate', is_read_only=True),
TextListField('contacts', field_uri='task:Contacts'),
ChoiceField('delegation_state', field_uri='task:DelegationState', choices={
Choice('NoMatch'), Choice('OwnNew'), Choice('Owned'), Choice('Accepted'), Choice('Declined'), Choice('Max')
}, is_read_only=True),
CharField('delegator', field_uri='task:Delegator', is_read_only=True),
DateTimeField('due_date', field_uri='task:DueDate'),
BooleanField('is_editable', field_uri='task:IsAssignmentEditable', is_read_only=True),
BooleanField('is_complete', field_uri='task:IsComplete', is_read_only=True),
BooleanField('is_recurring', field_uri='task:IsRecurring', is_read_only=True),
BooleanField('is_team_task', field_uri='task:IsTeamTask', is_read_only=True),
TextField('mileage', field_uri='task:Mileage'),
CharField('owner', field_uri='task:Owner', is_read_only=True),
DecimalField('percent_complete', field_uri='task:PercentComplete', is_required=True, default=Decimal(0.0),
min=Decimal(0), max=Decimal(100), is_searchable=False),
# Placeholder for Recurrence
DateTimeField('start_date', field_uri='task:StartDate'),
ChoiceField('status', field_uri='task:Status', choices={
Choice(NOT_STARTED), Choice('InProgress'), Choice(COMPLETED), Choice('WaitingOnOthers'), Choice('Deferred')
}, is_required=True, is_searchable=False, default=NOT_STARTED),
CharField('status_description', field_uri='task:StatusDescription', is_read_only=True),
IntegerField('total_work', field_uri='task:TotalWork', min=0),
]
FIELDS = Item.FIELDS + LOCAL_FIELDS
super(CalendarView, self).clean(version=version)
if self.end < self.start:
raise ValueError("'start' must be before 'end'")
class CalendarEventDetails(EWSElement):
"""MSDN: https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/calendareventdetails"""
ELEMENT_NAME = 'CalendarEventDetails'
FIELDS = [
CharField('id', field_uri='ID'),
CharField('subject', field_uri='Subject'),
CharField('location', field_uri='Location'),
BooleanField('is_meeting', field_uri='IsMeeting'),
BooleanField('is_recurring', field_uri='IsRecurring'),
BooleanField('is_exception', field_uri='IsException'),
BooleanField('is_reminder_set', field_uri='IsReminderSet'),
BooleanField('is_private', field_uri='IsPrivate'),
]
__slots__ = tuple(f.name for f in FIELDS)
class CalendarEvent(EWSElement):
"""MSDN: https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/calendarevent"""
ELEMENT_NAME = 'CalendarEvent'
FIELDS = [
DateTimeField('start', field_uri='StartTime'),
DateTimeField('end', field_uri='EndTime'),
FreeBusyStatusField('busy_type', field_uri='BusyType', is_required=True, default='Busy'),
EWSElementField('details', field_uri='CalendarEventDetails', value_cls=CalendarEventDetails),
]