简介
在第1部分中,我讨论了Exchange Server 2007的简短的历史和一个与它的特殊功能的早期预警系统的简要说明。我会尽量保持短的文章,更集中。
在这一部分,我将解释如何阅读就可以寻找不同folderand的消息。
在这里,我们可以有两件事情。阅读所有邮件收件箱文件夹SentItems,草稿等预警系统,为我们提供了分页和排序的设施也可用于搜索这些文件夹中的一些准则
我将在本文中讨论两个。
关于不同的文件夹阅读邮件的几点
在这里,我们使用一个API FindItem预警系统提供的,只返回一个项目一512字节E.返回的对象的所有属性不能被填充,虽然我们可以指定一些我们想要的属性。
关键的早期预警系统的功能这里讨论的是:获取指定文件夹中的项目数获取指定文件夹中的未读项目数读数在指定的文件夹具有以下属性的项目排序(升序或降序)项目:像受某些属性的基础上,从等索引视图:指一个项目的指定号码(传呼)读的项目的具体属性搜索文件夹单属性搜索多属性搜索
对于这一切,我们需要像收件箱中的文件夹,SentItems,草稿等FolderID ... ...因此,我们需要调用下面这就像一个其他API:
获取一个指定的文件夹中的项目计数public FolderIdType FindFolderID()
{
DistinguishedFolderIdType objSearchRootFolder = new DistinguishedFolderIdType();
objSearchRootFolder.Id = DistinguishedFolderIdNameType.msgfolderroot;
FindFolderType requestFindFolder = new FindFolderType();
requestFindFolder.Traversal = FolderQueryTraversalType.Deep;
requestFindFolder.ParentFolderIds = new DistinguishedFolderIdType[] { objSearchRootFolder };
requestFindFolder.FolderShape = new FolderResponseShapeType();
requestFindFolder.FolderShape.BaseShape = DefaultShapeNamesType.IdOnly;
//Search filter definition
requestFindFolder.Restriction = new RestrictionType();
#region Contains expression
ContainsExpressionType objContainsExpression = new ContainsExpressionType();
objContainsExpression.ContainmentMode = ContainmentModeType.FullString;
objContainsExpression.ContainmentModeSpecified = true;
objContainsExpression.ContainmentComparison = ContainmentComparisonType.Exact;
objContainsExpression.ContainmentComparisonSpecified = true;
PathToUnindexedFieldType objFieldFolderName = new PathToUnindexedFieldType();
objFieldFolderName.FieldURI = UnindexedFieldURIType.folderDisplayName;
objContainsExpression.Item = objFieldFolderName;
objContainsExpression.Constant = new ConstantValueType();
objContainsExpression.Constant.Value = "Inbox";
#endregion Contains expression
requestFindFolder.Restriction.Item = objContainsExpression;
FindFolderResponseType objFindFolderResponse =
_esb.FindFolder(requestFindFolder);
if (objFindFolderResponse.ResponseMessages.Items.Length == 0)
return null;
foreach (ResponseMessageType responseMsg in
objFindFolderResponse.ResponseMessages.Items)
{
if (responseMsg.ResponseClass == ResponseClassType.Success)
{
FindFolderResponseMessageType objFindResponse =
responseMsg as FindFolderResponseMessageType;
foreach (
BaseFolderType objFolderType in objFindResponse.RootFolder.Folders)
{
return objFolderType.FolderId;
}
}
}
return null;
}
,如果该文件夹不包含任何项目,它会返回-1。{C}获取一个指定的文件夹中的未读项目的计数
读一个指定的文件夹中的项目public List<messagetype> GetFolderItems()
{
FindItemType findRequest = new FindItemType();
findRequest.ItemShape = new ItemResponseShapeType();
ItemResponseShapeType itemProperties = new ItemResponseShapeType();
// Use the Default shape for the response.
itemProperties.BaseShape = DefaultShapeNamesType.Default;
findRequest.ItemShape = itemProperties;
Set the inbox as the parent search folder in search attachementRequest.
BaseFolderIdType p_folder = FindFolderID();
findRequest.ParentFolderIds = new BaseFolderIdType[] { p_folder };
findRequest.Traversal = ItemQueryTraversalType.Shallow;
// Perform the inbox search
FindItemResponseType response = _esb.FindItem(findRequest);
FindItemResponseMessageType responseMessage =
response.ResponseMessages.Items[0]
as FindItemResponseMessageType;
if (responseMessage.ResponseCode != ResponseCodeType.NoError)
{
throw new Exception(responseMessage.MessageText);
}
else
{
// Set the next index to use
ArrayOfRealItemsType items = responseMessage.RootFolder.Item as
ArrayOfRealItemsType;
if (items.Items == null)
{
// no items in the view.
return null;
}
// Create our response list
List<messagetype> result = new List<messagetype>(items.Items.Length);
foreach (MessageType item in items.Items)
{
result.Add(item);
}
return result;
}
}
进行排序,首先我们需要选择在哪个领域,我要排序,在这里我选择的主题:FieldOrderType[] fieldsOrder = new FieldOrderType[1];
fieldsOrder[0] = new FieldOrderType();
PathToUnindexedFieldType pathSortField = new PathToUnindexedFieldType();
pathSortField.FieldURI = UnindexedFieldURIType.itemSubject;
fieldsOrder[0].Order = SortDirectionType.Descending;
findRequest.SortOrder = fieldsOrder;
对于索引视图(即如果我想提出在从服务器的时间只有10个项目),我们可以设置返回的最大项目,可以设置startitem我想。IndexedPageViewType indexedView = new IndexedPageViewType();
indexedView.BasePoint = IndexBasePointType.Beginning;
indexedView.MaxEntriesReturned = p_intMaxRec;
indexedView.MaxEntriesReturnedSpecified = true;
indexedView.Offset = p_intStartIdx;
findRequest.Item = indexedView;
在这里,如果我想要一些特殊的属性,然后我可以象下面这样做:
搜索文件夹
PathToUnindexedFieldType pathSentDateTime = new PathToUnindexedFieldType();
pathSentDateTime.FieldURI = UnindexedFieldURIType.itemDateTimeSent;
itemProperties.AdditionalProperties = new BasePathToElementType[] { pathSentDateTime;}
findRequest.ItemShape = itemProperties;
搜索任何文件夹,我们需要做所有这些属性相同的上述。我们在这里还需要类RestrictionType的一个对象:RestrictionType objRestrictionType = new RestrictionType();
在搜索中,我们有两个选择:搜索类似或sentdatetime等单一属性搜索类似sentdatetime多个属性等。
对于单一的搜索属性,我们需要创建对象的OrType OrType orType = new OrType();
其他多个 AndType andType = new AndType();
和其他类型的对象为ContainsExpressionType
这里ContainsRxpressionType是因为,比方说,如果这个问题是打招呼,我们给值只是"HEL??,那么它会搜索所有的项目,其中主体价值包含"HEL .???/ p > ContainsExpressionType expressionType = null;
List<searchexpressiontype> searchExps = null;
现在为主题的搜索PathToUnindexedFieldType path.FieldURI = UnindexedFieldURIType.itemSubject;
expressionType = new ContainsExpressionType();
expressionType.Item = path;
expressionType.ContainmentMode = ContainmentModeType.Substring; //seach for substrings
expressionType.ContainmentModeSpecified = true;
expressionType.ContainmentComparison =
ContainmentComparisonType.IgnoreCaseAndNonSpacingCharacters;
expressionType.ContainmentComparisonSpecified = true;
expressionType.Constant = new ConstantValueType();
expressionType.Constant.Value = Hi? //search for any string containing
searchExps.Add(expressionType);
同样,我们可以遍历许多properies,因为我们希望:
现在andType andType.Items = searchExps.ToArray();
objRestrictionType.Item = andType;
为OrType orType.Items = searchExps.ToArray();
objRestrictionType.Item = orType;
此限制类型的对象,我们需要在findrequest设置为: findRequest.Restriction = p_RestrictionType;
,然后将搜索文件夹的限制。
我将讨论在未来的一部分,从不同的文件夹中读取邮件的详细信息。此外,我将试图掩盖EWS的扩展属性,这是非常有用的,当我们需要为每一个项目的一些自定义属性的主要特点之一。