def _generate_event(self, type):
     return getattr(T, type)(
         T.TimeStamp(now().isoformat()),
         T.ItemId(
             Id=get_random_string(),
             ChangeKey=get_random_string(),
         ),
         T.ParentFolderId(
             Id=get_random_string(),
             ChangeKey=get_random_string(),
         ),
     )
    def __init__(self, subscription_ids, timeout_minutes=30):
        """
        Initialize the request.

        :param principal: Principal email to impersonate
        :param subscription_id: Subscription ID to get rid of
        """
        self.timeout_minutes = timeout_minutes
        root = M.GetStreamingEvents(
            M.SubscriptionIds(*[T.SubscriptionId(x)
                                for x in subscription_ids]),
            M.ConnectionTimeout(str(timeout_minutes)),
        )
        super(GetStreamingEventsRequest, self).__init__(root)
    def __init__(self, principal):
        """
        Initialize the request.

        :param principal: Principal email to impersonate
        """
        root = M.Subscribe(
            M.StreamingSubscriptionRequest(
                T.FolderIds(
                    get_distinguished_folder_id_element(principal,
                                                        'calendar')),
                T.EventTypes(
                    T.EventType('NewMailEvent'),
                    T.EventType('CreatedEvent'),
                    T.EventType('DeletedEvent'),
                    T.EventType('ModifiedEvent'),
                    T.EventType('MovedEvent'),
                    T.EventType('CopiedEvent'),
                    T.EventType('FreeBusyChangedEvent'),
                ),
            ))
        super(SubscribeRequest, self).__init__(root, impersonation=principal)
Beispiel #4
0
 def handle_resolve_names(self, request):
     if not request.xpath("//m:ResolveNames", namespaces=NAMESPACES):
         return  # pragma: no cover
     ldap_address = request.xpath("//m:UnresolvedEntry",
                                  namespaces=NAMESPACES)[0].text
     assert ldap_address == '/O=Dummy'
     return M.ResolveNamesResponse(
         M.ResponseMessages(
             M.ResolveNamesResponseMessage(
                 {'ResponseClass': 'Success'}, M.ResponseCode('NoError'),
                 M.ResolutionSet(
                     {
                         'TotalItemsInView': '1',
                         'IncludesLastItemInRange': 'true',
                     },
                     T.Resolution(
                         T.Mailbox(T.EmailAddress('*****@*****.**'),
                                   T.RoutingType('SMTP'),
                                   T.MailboxType('Mailbox')),
                         T.Contact(
                             T.DisplayName('Dummy Bob'),
                             T.GivenName('Bob'),
                             T.Surname('Dummy'),
                         ))))))
 def handle_get_events(self, request):
     if not request.xpath('//m:GetStreamingEvents',
                          namespaces=NAMESPACES):  # pragma: no cover
         return
     sub_id = request.xpath('//t:SubscriptionId',
                            namespaces=NAMESPACES)[0].text
     # This would be a long-polling operation,
     # but ain't nobody got time for that
     return M.GetStreamingEventsResponse(
         M.ResponseMessages(
             M.GetStreamingEventsResponseMessage(
                 M.ResponseCode('NoError'),
                 M.Notifications(
                     M.Notification(
                         T.SubscriptionId(sub_id),
                         self._generate_event('NewMailEvent'),
                     ), ),
                 ResponseClass='Success',
             ), ), )
Beispiel #6
0
    def handle_find_items(self, request):
        if not request.xpath("//m:FindItem", namespaces=NAMESPACES):
            return  # pragma: no cover
        email_address = request.xpath("//t:EmailAddress",
                                      namespaces=NAMESPACES)[0].text

        items = [
            self._generate_calendar_item(props)
            for props in self._email_to_props.get(email_address, {}).values()
        ]
        return M.FindItemResponse(
            M.ResponseMessages(
                M.FindItemResponseMessage(
                    {'ResponseClass': 'Success'}, M.ResponseCode('NoError'),
                    M.RootFolder(
                        {
                            'TotalItemsInView': str(len(items)),
                            'IncludesLastItemInRange': 'true',
                        }, T.Items(*items)))))
Beispiel #7
0
 def _generate_items_fragment(self, change_key):
     return M.Items(
         T.CalendarItem(T.ItemId(Id=self.item_id, ChangeKey=change_key)))
Beispiel #8
0
 def _generate_calendar_item(self, props):
     return T.CalendarItem(
         props['id'].to_xml(), T.Subject(props['subject']),
         T.HasAttachments('false'), T.IsAssociated('false'),
         T.Start(format_date_for_xml(props['start'])),
         T.End(format_date_for_xml(props['end'])),
         T.LegacyFreeBusyStatus('Busy'), T.Location(""),
         T.CalendarItemType('Single'),
         T.Organizer(
             T.Mailbox(T.Name(props['organizer_name']),
                       T.EmailAddress('/O=Dummy'), T.RoutingType('EX'),
                       T.MailboxType('OneOff'))))