我正在编写作为邮件客户端的 iOS 应用程序。由于某些限制,我必须使用 EWS(Exchange Web 服务)来处理邮箱。我所能做的就是向服务器发送 SOAP 请求以获取必要的信息。到目前为止,我已经设法使用SyncFolderItems Operation获取每个文件夹中的消息列表。之后,我使用GetItem (E-mail Message) Operation获取每个项目的详细信息。最后一个请求仅返回电子邮件附件 ID 和名称,但不返回它们的大小。但我需要了解它们才能让用户决定是否下载它们。我怎样才能得到这些信息?
这是代码,我在其中创建对服务器的 SOAP 请求。
+(NSString*) syncFolderItems:(NSString*)folderID :(NSString*) syncState
{
NSString * syncStateStr=@"<SyncState>%@</SyncState>";
if(syncState!=nil && ![syncState isEqualToString:@""])
{
syncStateStr=[NSString stringWithFormat:syncStateStr,syncState];
}
else
syncStateStr=@"";
NSString * request= @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">"
"<soap:Body>"
"<SyncFolderItems xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\">"
"<ItemShape>"
"<t:BaseShape>IdOnly</t:BaseShape>"
"</ItemShape>"
"<SyncFolderId>"
"<t:FolderId Id=\"%@\"/>"
"</SyncFolderId>"
"%@"
"<MaxChangesReturned>10</MaxChangesReturned>"
"</SyncFolderItems>"
"</soap:Body>"
"</soap:Envelope>";
return [NSString stringWithFormat:request, folderID,syncStateStr];
}
+(NSString*)getMailItemsDetails:(NSMutableArray*)items
{
NSString *request =
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">"
"<soap:Body>"
"<GetItem xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\">"
"<ItemShape>"
"<t:BaseShape>Default</t:BaseShape>"
"<t:IncludeMimeContent>false</t:IncludeMimeContent>"
"<t:AdditionalProperties>"
"<t:FieldURI FieldURI=\"item:Attachments\"/>"
"</t:AdditionalProperties>"
"</ItemShape>"
"<ItemIds>"
"%@"
"</ItemIds>"
"</GetItem>"
"</soap:Body>"
"</soap:Envelope>";
NSString *itemIdTemplate = @"<t:ItemId Id=\"%@\" />";
NSString *itemsIds = @"";
for(NSString *msgID in items)
{
NSString *itemId = [NSString stringWithFormat:itemIdTemplate, msgID];
itemsIds = [itemsIds stringByAppendingString:itemId];
}
return [NSString stringWithFormat:request, itemsIds];
}
我错过了什么吗?(可能是一些额外的属性?)我必须使用不同的请求吗?EWS 请求有可能吗?如果没有,是否有一些解决方法可以解决问题?任何帮助将不胜感激。