0
votes

I'm writing iOS app that is a mail client. Due to some restrictions I have to use EWS (Exchange Web Services) to work with mailbox. All I can do is sending SOAP request to the server to get the necessary information. So far I've managed to get the list of messages in each folder using SyncFolderItems Operation. After that I'm getting the details of each item using GetItem (E-mail Message) Operation. Last request returns only email attachments ids and names, but not their sizes. But I need to know them to let the user decide whether to download them or not. How I can get this information?

Here is the code, where I create SOAP request to the server.

+(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];
}

Am I missing something? (May be some additional properties?) Do I have to use different requests? Is such thing possible with EWS request? If not, is there some workaround to solve the problem? Any help will be greatly appreciated.

1
Curious if you ever came across a solution for this. I'm running into this problem right nowlidsinker

1 Answers

0
votes

Yarlik, according to me the size should be send by the server.

Anyways, let me see if found something, must forward to you.

But, you can do one thing in the delegates, ie;

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {

}
-(NSURLRequest *)connection:(NSURLConnection *)connection
        willSendRequest:(NSURLRequest *)request
       redirectResponse:(NSURLResponse *)response {
}

long long fileSize = [response expectedContentLength];

it'll give you the file size.