IOSAD-91 using PEPAttachment
authorDirk Zimmermann <dirk@pep-project.org>
Mon, 16 Apr 2018 11:01:19 +0200
changeset 5776e6f13e2e4d3
parent 576 8f6da9a85634
child 578 a05f108cc223
IOSAD-91 using PEPAttachment
pEpObjCAdapter/PEPAttachment.h
pEpObjCAdapter/PEPMessage.h
pEpObjCAdapter/PEPMessageUtil.h
pEpObjCAdapter/PEPMessageUtil.m
pEpObjCTests/PEPSessionTest.m
     1.1 --- a/pEpObjCAdapter/PEPAttachment.h	Mon Apr 16 11:01:18 2018 +0200
     1.2 +++ b/pEpObjCAdapter/PEPAttachment.h	Mon Apr 16 11:01:19 2018 +0200
     1.3 @@ -8,6 +8,14 @@
     1.4  
     1.5  #import <Foundation/Foundation.h>
     1.6  
     1.7 +#import "bloblist.h"
     1.8 +
     1.9  @interface PEPAttachment : NSObject
    1.10  
    1.11 +@property (nonatomic) NSData *data;
    1.12 +@property (nonatomic) NSInteger size;
    1.13 +@property (nonatomic, nullable) NSString *mimeType;
    1.14 +@property (nonatomic, nullable) NSString *filename;
    1.15 +@property (nonatomic) content_disposition_type contentDisposition;
    1.16 +
    1.17  @end
     2.1 --- a/pEpObjCAdapter/PEPMessage.h	Mon Apr 16 11:01:18 2018 +0200
     2.2 +++ b/pEpObjCAdapter/PEPMessage.h	Mon Apr 16 11:01:19 2018 +0200
     2.3 @@ -12,6 +12,7 @@
     2.4  #import "PEPSessionProtocol.h"
     2.5  
     2.6  @class PEPIdentity;
     2.7 +@class PEPAttachment;
     2.8  
     2.9  @interface PEPMessage : NSObject
    2.10  
    2.11 @@ -33,7 +34,7 @@
    2.12  @property (nonatomic, nullable) NSDate *sentDate;
    2.13  @property (nonatomic, nullable) NSDate *receivedDate;
    2.14  
    2.15 -@property (nonatomic, nullable) NSArray<PEPDict *> *attachments;
    2.16 +@property (nonatomic, nullable) NSArray<PEPAttachment *> *attachments;
    2.17  
    2.18  @property (nonatomic, nullable) NSArray<NSArray<NSString *> *> *optionalFields;
    2.19  @property (nonatomic, nullable) NSArray<NSString *> *keywords;
     3.1 --- a/pEpObjCAdapter/PEPMessageUtil.h	Mon Apr 16 11:01:18 2018 +0200
     3.2 +++ b/pEpObjCAdapter/PEPMessageUtil.h	Mon Apr 16 11:01:19 2018 +0200
     3.3 @@ -107,9 +107,6 @@
     3.4  /** The mime type of an attachment */
     3.5  extern NSString *const _Nonnull kPepMimeType;
     3.6  
     3.7 -/** The content disposition of an attachment */
     3.8 -extern NSString *const _Nonnull kPepContentDisposition;
     3.9 -
    3.10  /** The pEp internal communication type */
    3.11  extern NSString *const _Nonnull kPepCommType;
    3.12  
     4.1 --- a/pEpObjCAdapter/PEPMessageUtil.m	Mon Apr 16 11:01:18 2018 +0200
     4.2 +++ b/pEpObjCAdapter/PEPMessageUtil.m	Mon Apr 16 11:01:19 2018 +0200
     4.3 @@ -10,6 +10,7 @@
     4.4  
     4.5  #import "PEPIdentity.h"
     4.6  #import "PEPMessage.h"
     4.7 +#import "PEPAttachment.h"
     4.8  
     4.9  #import "pEp_string.h"
    4.10  
    4.11 @@ -62,8 +63,6 @@
    4.12  
    4.13  NSString *const kPepMimeType = @"mimeType";
    4.14  
    4.15 -NSString *const kPepContentDisposition = @"contentDisposition";
    4.16 -
    4.17  NSString *const kPepCommType = @"comm_type";
    4.18  
    4.19  NSString *const kPepRawMessage = @"raw_message";
    4.20 @@ -138,22 +137,20 @@
    4.21      NSMutableArray *array = [NSMutableArray array];
    4.22      
    4.23      for (bloblist_t *_bl = bl; _bl && _bl->value; _bl = _bl->next) {
    4.24 -        NSMutableDictionary* blob = [NSMutableDictionary new];
    4.25 -        [blob setObject: [NSData dataWithBytes:_bl->value
    4.26 -                                 length:_bl->size]
    4.27 -              forKey:@"data"];
    4.28 +        PEPAttachment* theAttachment = [PEPAttachment new];
    4.29 +        theAttachment.data = [NSData dataWithBytes:_bl->value length:_bl->size];
    4.30 +
    4.31 +        if(_bl->filename && _bl->filename[0]) {
    4.32 +            theAttachment.filename = [NSString stringWithUTF8String:_bl->filename];
    4.33 +        }
    4.34 +
    4.35 +        if(_bl->mime_type && _bl->mime_type[0]) {
    4.36 +            theAttachment.mimeType = [NSString stringWithUTF8String:_bl->mime_type];
    4.37 +        }
    4.38 +
    4.39 +        theAttachment.contentDisposition = _bl->disposition;
    4.40          
    4.41 -        if(_bl->filename && _bl->filename[0])
    4.42 -            [blob setObject:[NSString stringWithUTF8String:_bl->filename]
    4.43 -                 forKey:@"filename"];
    4.44 -        
    4.45 -        if(_bl->mime_type && _bl->mime_type[0])
    4.46 -            [blob setObject: [NSString stringWithUTF8String:_bl->mime_type]
    4.47 -                 forKey:@"mimeType"];
    4.48 -
    4.49 -        [blob setObject:[NSNumber numberWithInt:_bl->disposition] forKey:kPepContentDisposition];
    4.50 -        
    4.51 -        [array addObject:blob];
    4.52 +        [array addObject:theAttachment];
    4.53      }
    4.54      return array;
    4.55  }
    4.56 @@ -170,8 +167,8 @@
    4.57      // free() might be the default, but let's be explicit
    4.58      bl->release_value = (void (*) (char *)) free;
    4.59  
    4.60 -    for (NSMutableDictionary *blob in array) {
    4.61 -        NSData *data = blob[@"data"];
    4.62 +    for (PEPAttachment *theAttachment in array) {
    4.63 +        NSData *data = theAttachment.data;
    4.64          size_t size = [data length];
    4.65  
    4.66          char *buf = malloc(size);
    4.67 @@ -179,13 +176,14 @@
    4.68          memcpy(buf, [data bytes], size);
    4.69          
    4.70          bl = bloblist_add(bl, buf, size,
    4.71 -                          [blob[@"mimeType"] UTF8String],
    4.72 -                          [[blob[@"filename"] precomposedStringWithCanonicalMapping] UTF8String]);
    4.73 +                          [[theAttachment.mimeType
    4.74 +                            precomposedStringWithCanonicalMapping]
    4.75 +                           UTF8String],
    4.76 +                          [[theAttachment.filename
    4.77 +                            precomposedStringWithCanonicalMapping]
    4.78 +                           UTF8String]);
    4.79  
    4.80 -        NSNumber *contentDispositionNum = [blob objectForKey:kPepContentDisposition];
    4.81 -        if (contentDispositionNum) {
    4.82 -            bl->disposition = contentDispositionNum.intValue;
    4.83 -        }
    4.84 +        bl->disposition = theAttachment.contentDisposition;
    4.85      }
    4.86      return _bl;
    4.87  }
     5.1 --- a/pEpObjCTests/PEPSessionTest.m	Mon Apr 16 11:01:18 2018 +0200
     5.2 +++ b/pEpObjCTests/PEPSessionTest.m	Mon Apr 16 11:01:19 2018 +0200
     5.3 @@ -12,6 +12,7 @@
     5.4  #import "NSDictionary+Extension.h"
     5.5  #import "PEPIdentity.h"
     5.6  #import "PEPMessage.h"
     5.7 +#import "PEPAttachment.h"
     5.8  #import "PEPTestUtils.h"
     5.9  #import "PEPTestSyncDelegate.h"
    5.10  
    5.11 @@ -761,7 +762,7 @@
    5.12      XCTAssertNotNil(encMsg);
    5.13      XCTAssertNil(error);
    5.14  
    5.15 -    XCTAssertNotEqualObjects(encMsg.attachments[0][@"mimeType"], @"application/pgp-encrypted");
    5.16 +    XCTAssertNotEqualObjects(encMsg.attachments[0].mimeType, @"application/pgp-encrypted");
    5.17  
    5.18      [self pEpCleanUp];
    5.19  }