我正在编写一个邮件客户端的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请求是否可以这样做?如果没有,是否有解决问题的解决方法?任何帮助将不胜感激。
答案 0 :(得分:0)
Yarlik,据我说,服务器应该发送大小。
无论如何,让我看看是否找到了什么,必须转发给你。
但是,你可以在代表中做一件事,即;
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
}
-(NSURLRequest *)connection:(NSURLConnection *)connection
willSendRequest:(NSURLRequest *)request
redirectResponse:(NSURLResponse *)response {
}
long long fileSize = [response expectedContentLength];
它会给你文件大小。