/// <summary> /// Выполняет поиск входящих писем с подтверждением об обработке файлов за указанный период /// </summary> /// <param name="begin">Дата начиная с которой будет происходить поиск писем</param> /// <returns></returns> public static ItemType[] GetMessages(DateTime begin) { ExchangeServiceBinding bind = new ExchangeServiceBinding(); bind.Credentials = new NetworkCredential(AppHelper.Configuration.Exchange.Username.GetDecryptedString(), AppHelper.Configuration.Exchange.Password.GetDecryptedString(), AppHelper.Configuration.Exchange.Domain); bind.Url = "https://" + AppHelper.Configuration.Exchange.ServerName + "/EWS/Exchange.asmx"; FindItemType findType = new FindItemType(); findType.Traversal = ItemQueryTraversalType.Shallow; findType.ItemShape = new ItemResponseShapeType(); findType.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties; DistinguishedFolderIdType folder = new DistinguishedFolderIdType(); folder.Id = DistinguishedFolderIdNameType.inbox; findType.ParentFolderIds = new BaseFolderIdType[] { folder }; IsEqualToType isEq = new IsEqualToType(); PathToUnindexedFieldType uPath = new PathToUnindexedFieldType(); uPath.FieldURI = UnindexedFieldURIType.messageFrom; FieldURIOrConstantType constType = new FieldURIOrConstantType(); ConstantValueType constValue = new ConstantValueType(); constValue.Value = AppHelper.Configuration.Exchange.SenderName; constType.Item = constValue; isEq.Item = uPath; isEq.FieldURIOrConstant = constType; IsGreaterThanOrEqualToType isGrEq = new IsGreaterThanOrEqualToType(); PathToUnindexedFieldType uPath2 = new PathToUnindexedFieldType(); uPath2.FieldURI = UnindexedFieldURIType.itemDateTimeSent; FieldURIOrConstantType constType2 = new FieldURIOrConstantType(); ConstantValueType constValue2 = new ConstantValueType(); constValue2.Value = string.Format("{0}-{1}-{2}T00:00:00Z", begin.Year, begin.Month.ToString("D2"), begin.Day.ToString("D2")); constType2.Item = constValue2; isGrEq.Item = uPath2; isGrEq.FieldURIOrConstant = constType2; AndType and = new AndType(); and.Items = new SearchExpressionType[] { isEq, isGrEq }; findType.Restriction = new RestrictionType(); findType.Restriction.Item = and; FindItemResponseType findResp = bind.FindItem(findType); FindItemResponseMessageType resMes = findResp.ResponseMessages.Items[0] as FindItemResponseMessageType; if (resMes.ResponseClass != ResponseClassType.Success) { throw new Exception("Ошибка при получении ответа от сервера Exchange:\n" + resMes.MessageText); } ItemType[] messages = (resMes.RootFolder.Item as ArrayOfRealItemsType).Items; return(messages); }
/// <summary> /// A new, improved ContactsView method (Listing 6-16) /// </summary> /// <param name="folderId">Folder to perform FindItem in</param> /// <param name="responseShape">ResponseShape for returned contacts</param> /// <param name="pathForRestriction">The property path to compare against</param> /// <param name="lowerBounds">lower bounds string (inclusive)</param> /// <param name="upperBounds">upper bounds string (exclusive)</param> /// <param name="offset">For indexed paging, the offset into the result set to start at</param> /// <param name="maxEntries">Max entries to return for each page. Zero for unbounded</param> /// <returns>FindItemResponseMessageType</returns> /// public FindItemResponseMessageType SuperContactsView( BaseFolderIdType folderId, ItemResponseShapeType responseShape, BasePathToElementType pathForRestriction, string lowerBounds, string upperBounds, int offset, int maxEntries) { FindItemType request = new FindItemType(); request.ItemShape = responseShape; // If they set a maxEntries > 0, use indexed paging just to limit the results. // if (maxEntries > 0) { IndexedPageViewType paging = new IndexedPageViewType(); paging.BasePoint = IndexBasePointType.Beginning; paging.Offset = offset; paging.MaxEntriesReturned = maxEntries; paging.MaxEntriesReturnedSpecified = true; request.Item = paging; } request.ParentFolderIds = new BaseFolderIdType[] { folderId }; request.Traversal = ItemQueryTraversalType.Shallow; // Build up our restriction // AndType and = new AndType(); IsGreaterThanOrEqualToType lowerBoundsFilter = new IsGreaterThanOrEqualToType(); lowerBoundsFilter.Item = pathForRestriction; lowerBoundsFilter.FieldURIOrConstant = new FieldURIOrConstantType(); ConstantValueType lowerBoundsValue = new ConstantValueType(); lowerBoundsValue.Value = lowerBounds; lowerBoundsFilter.FieldURIOrConstant.Item = lowerBoundsValue; IsLessThanType upperBoundsFilter = new IsLessThanType(); upperBoundsFilter.Item = pathForRestriction; upperBoundsFilter.FieldURIOrConstant = new FieldURIOrConstantType(); ConstantValueType upperBoundsValue = new ConstantValueType(); upperBoundsValue.Value = upperBounds; upperBoundsFilter.FieldURIOrConstant.Item = upperBoundsValue; and.Items = new SearchExpressionType[] { lowerBoundsFilter, upperBoundsFilter }; request.Restriction = new RestrictionType(); request.Restriction.Item = and; // Make the request // FindItemResponseType response = this.FindItem(request); return response.ResponseMessages.Items[0] as FindItemResponseMessageType; }