Browse Source

adjusts test expectations according to new info from MIME-17 & MIME-18. Updates readme, adds docs.

master
Andreas Buff 3 months ago
parent
commit
07f7f09fd0
8 changed files with 74 additions and 76 deletions
  1. +17
    -2
      Interface/PEPMessage+PEPMessage_MIME/PEPMessage+PEPMessage_MIME.h
  2. +0
    -31
      Interface/PEPMessage+PEPMessage_MIME/PEPMessage+PEPMessage_MIME.mm
  3. +1
    -0
      Interface/pEpMimeObjCAdapter.h
  4. +11
    -7
      README.md
  5. +4
    -4
      pEpMimeObjCAdapter.xcodeproj/project.pbxproj
  6. +0
    -27
      pEpMimeObjCAdapterTests_macOS/Interface/PEPMessage+PEPMessage_MIMETest.m
  7. +6
    -3
      pEpMimeObjCAdapterTests_macOS/TestUtils/PEPIdentity+PEPTestTypes.m
  8. +35
    -2
      pEpMimeObjCAdapterTests_macOS/TestUtils/PEPMessage+PEPTestTypes.m

+ 17
- 2
Interface/PEPMessage+PEPMessage_MIME/PEPMessage+PEPMessage_MIME.h View File

@ -11,16 +11,31 @@ NS_ASSUME_NONNULL_BEGIN
@interface PEPMessage (PEPMessage_MIME)
/// @param error Is guaranteed to be set in error case
/// @return MIME representation of this message, nil in error case
- (nullable NSData*)mimeDataWithError:(NSError **)error;
/// @param error Is guaranteed to be set in error case
/// @return MIME representation of this message, nil in error case
- (nullable NSString*)mimeStringWithError:(NSError **)error;
/// Factory method, creating a PEPMessage form the given MIME.
/// @note Re-set or update all Identities afterwards (from, to, cc, bcc, ...) with what you
/// know (userID, username, ...).
/// @param mimeData MIME data to create message with
/// @param error Is guaranteed to be set in error case
/// @return PEPMessage with given data, `nil`in error case
+ (nullable instancetype)pEpMessageWithMimeData:(NSData *)mimeData error:(NSError **)error;
/// Factory method, creating a PEPMessage form the given MIME.
/// @note Re-set or update all Identities afterwards (from, to, cc, bcc, ...) with what you
/// know (userID, username, ...).
/// @param mimeString MIME String to create message with
/// @param error Is guaranteed to be set in error case
/// @return PEPMessage with given data, `nil`in error case
+ (nullable instancetype)pEpMessageWithMimeString:(NSString *)mimeString error:(NSError **)error;
+ (nullable instancetype)DELETE_DEBUG_ROUNDTERIP_WITHOUT_OBJC_TYPES_INVOLVEDWithMimeString:(NSString *)mimeString;
@end
NS_ASSUME_NONNULL_END

+ 0
- 31
Interface/PEPMessage+PEPMessage_MIME/PEPMessage+PEPMessage_MIME.mm View File

@ -52,37 +52,6 @@
return pEpMessage;
}
//BUFF:
+ (void)DELETE_DEBUG_ROUNDTERIP_WITHOUT_OBJC_TYPES_INVOLVEDWithMimeString:(NSString *)mimeString {
//TO ENGINE SG
std::string cppMimeString = std::string([mimeString UTF8String]);
message* engineMsg = pEpMIME::parse_message(cppMimeString.data(),
cppMimeString.size());
PEPMessage *pepBefore = [PEPMessage fromStruct:engineMsg];
NSLog(@"BEFORE\n##########################################");
[self DELETE_DEBUG_pringOptFieldsWithMessage:pepBefore];
char* c = pEpMIME::generate_message(engineMsg, false, false);
NSString *mimeStringBackConverted = [NSString stringWithUTF8String:c];
std::string cppMimeStringBackConverted = std::string([mimeStringBackConverted UTF8String]);
message* engineMsgBackConverted = pEpMIME::parse_message(cppMimeStringBackConverted.data(),
cppMimeStringBackConverted.size());
PEPMessage *pepAfter = [PEPMessage fromStruct:engineMsgBackConverted];
NSLog(@"AFTER\n##########################################");
[self DELETE_DEBUG_pringOptFieldsWithMessage:pepAfter];
}
+ (void)DELETE_DEBUG_pringOptFieldsWithMessage:(PEPMessage *)pEpMessage {
NSArray<NSArray<NSString*>*> *optFields = pEpMessage.optionalFields;
for (NSArray<NSString*> *field in optFields) {
NSString *key = field[0];
NSString *value = field[1];
NSLog(@"key: %@", key);
NSLog(@"value: %@", value);
NSLog(@"#########################################");
}
}
- (nullable NSData*)mimeDataWithError:(NSError **)error; {
NSString *mimeString = [self mimeStringWithError:error];
if (!mimeString) {


+ 1
- 0
Interface/pEpMimeObjCAdapter.h View File

@ -8,6 +8,7 @@
#import <Foundation/Foundation.h>
#import "PEPMessage+PEPMessage_MIME.h"
#import "NSError+PEPMimeObjCAdapter.h"
// Umbrella Header
@interface pEpMimeObjCAdapter : NSObject


+ 11
- 7
README.md View File

@ -1,4 +1,8 @@
# WIP
# pEpMimeObjCAdapter
Converts MIME (string or data) to and from PEPMessage.
Note: You have to update all PEPIdentities (from, to, cc, ...) with available data (userID, isOwn, ...) in a PEPMessage created from MIME.
## Dependencies
```
@ -16,7 +20,7 @@ cd src_pEpMime4macOS
mkdir -p local/include
mkdir -p local/lib
# Dont bother with crossbuild. We need the headers only.
# Dont bother with crossbuilding. We need the headers only.
git clone -b boost-1.73.0 --recursive https://github.com/boostorg/boost.git
pushd boost
./bootstrap.sh -mmacosx-version-min=10.10
@ -51,15 +55,15 @@ git clone https://gitea.pep.foundation/pep.foundation/pEpObjCAdapter.git
### Using Xcode
`open pEpMimeObjCAdapter/pEpMimeObjCAdapter.xcworkspace/`
open pEpMimeObjCAdapter/pEpMimeObjCAdapter.xcworkspace/
Build scheme "libpEpMimeObjCAdapter_macOS".
Build scheme "pEpMimeObjCAdapter_macOS".
### Using terminal
`xcodebuild -workspace "pEpMimeObjCAdapter.xcworkspace" -scheme "libpEpMimeObjCAdapter_macOS" -configuration RELEASE`
(or DEBUG)
```
xcodebuild -workspace "pEpMimeObjCAdapter.xcworkspace" -scheme "pEpMimeObjCAdapter_macOS" -configuration RELEASE
```
## Build Dir & Build Artefacts


+ 4
- 4
pEpMimeObjCAdapter.xcodeproj/project.pbxproj View File

@ -28,7 +28,7 @@
1585EA082696E60D00B822E1 /* PEPIdentity+PEPTestTypes.m in Sources */ = {isa = PBXBuildFile; fileRef = 1585EA072696E60D00B822E1 /* PEPIdentity+PEPTestTypes.m */; };
1585EA0B2696E62600B822E1 /* PEPAttachment+PEPTestTypes.m in Sources */ = {isa = PBXBuildFile; fileRef = 1585EA0A2696E62600B822E1 /* PEPAttachment+PEPTestTypes.m */; };
1585EA0D2696F69200B822E1 /* libc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 1585EA0C2696F69200B822E1 /* libc++.tbd */; };
1585EA442696FB1D00B822E1 /* Ihre Sendung 254539842170 wird verpackt - "bienenweber@t-online.de" <bienenweber@t-online.de> - 2020-04-22 1101.eml in Resources */ = {isa = PBXBuildFile; fileRef = 1585EA182696FB1C00B822E1 /* Ihre Sendung 254539842170 wird verpackt - "bienenweber@t-online.de" <bienenweber@t-online.de> - 2020-04-22 1101.eml */; };
1585EA722698329700B822E1 /* problemMail.eml in Resources */ = {isa = PBXBuildFile; fileRef = 1585EA712698329700B822E1 /* problemMail.eml */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -110,7 +110,7 @@
1585EA092696E62600B822E1 /* PEPAttachment+PEPTestTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PEPAttachment+PEPTestTypes.h"; sourceTree = "<group>"; };
1585EA0A2696E62600B822E1 /* PEPAttachment+PEPTestTypes.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "PEPAttachment+PEPTestTypes.m"; sourceTree = "<group>"; };
1585EA0C2696F69200B822E1 /* libc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libc++.tbd"; path = "usr/lib/libc++.tbd"; sourceTree = SDKROOT; };
1585EA182696FB1C00B822E1 /* Ihre Sendung 254539842170 wird verpackt - "bienenweber@t-online.de" <bienenweber@t-online.de> - 2020-04-22 1101.eml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "Ihre Sendung 254539842170 wird verpackt - \"bienenweber@t-online.de\" <bienenweber@t-online.de> - 2020-04-22 1101.eml"; sourceTree = "<group>"; };
1585EA712698329700B822E1 /* problemMail.eml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = problemMail.eml; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -240,7 +240,7 @@
1585E9F32695BE0300B822E1 /* test_mails */ = {
isa = PBXGroup;
children = (
1585EA182696FB1C00B822E1 /* Ihre Sendung 254539842170 wird verpackt - "bienenweber@t-online.de" <bienenweber@t-online.de> - 2020-04-22 1101.eml */,
1585EA712698329700B822E1 /* problemMail.eml */,
);
path = test_mails;
sourceTree = "<group>";
@ -413,7 +413,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1585EA442696FB1D00B822E1 /* Ihre Sendung 254539842170 wird verpackt - "bienenweber@t-online.de" <bienenweber@t-online.de> - 2020-04-22 1101.eml in Resources */,
1585EA722698329700B822E1 /* problemMail.eml in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};


+ 0
- 27
pEpMimeObjCAdapterTests_macOS/Interface/PEPMessage+PEPMessage_MIMETest.m View File

@ -12,37 +12,10 @@
#import "PEPMessage+PEPTestTypes.h"
@interface PEPMessage_MIMETest : XCTestCase
@end
@implementation PEPMessage_MIMETest
- (void)setUp {
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)testDELETE_DEBUG {
NSBundle *bundle = [NSBundle bundleForClass:self.class];
NSArray<NSURL*> *urls = [bundle URLsForResourcesWithExtension:@"eml" subdirectory:nil];
XCTAssertTrue(urls.count > 0, @"This test does nothing if there are zero mails in test_mails directory");
for (NSURL *url in urls) {
NSError *error = nil;
NSString *mailString = [NSString stringWithContentsOfURL:url
encoding:NSUTF8StringEncoding
error:&error];
if (!mailString) {
mailString = [NSString stringWithContentsOfURL:url
encoding:NSASCIIStringEncoding
error:&error];
}
if (!mailString) {
XCTFail(@"Error lodaing url: %@", url);
continue;
}
[PEPMessage DELETE_DEBUG_ROUNDTERIP_WITHOUT_OBJC_TYPES_INVOLVEDWithMimeString:mailString];
}
}
- (void)testPEPMessage2MIMEString_onlyRequiredFieldsSet {
PEPMessage *testee = [PEPMessage testMessageWithOnlyRequiredFieldsSet:YES];
[self assertPEPMessageToMimeString:testee];


+ 6
- 3
pEpMimeObjCAdapterTests_macOS/TestUtils/PEPIdentity+PEPTestTypes.m View File

@ -26,13 +26,16 @@
{
if (other == self) {
return YES;
} else if (![self.userID isEqual:other.userID]) {
} else if (![self.userID isEqual:other.userID]
&& !(self.userID == nil && other.userID == nil)) {
return NO;
} else if (![self.address isEqual:other.address]) {
return NO;
} else if (![self.userName isEqual:other.userName]) {
} else if (![self.userName isEqual:other.userName]
&& !(self.userName == nil && other.userName == nil)) {
return NO;
} else if (![self.fingerPrint isEqual:other.fingerPrint]) {
} else if (![self.fingerPrint isEqual:other.fingerPrint]
&& !(self.fingerPrint == nil && other.fingerPrint == nil)) {
return NO;
} else if (self.isOwn != other.isOwn) {
return NO;


+ 35
- 2
pEpMimeObjCAdapterTests_macOS/TestUtils/PEPMessage+PEPTestTypes.m View File

@ -58,7 +58,7 @@
result.cc = onlyRequiredFileds ? nil : @[cc1, cc2];
result.bcc = onlyRequiredFileds ? nil : @[bcc];
result.replyTo = onlyRequiredFileds ? nil : @[from];
result.attachments = onlyRequiredFileds ? nil : @[attachment1, attachment2];
return result;
}
@ -78,7 +78,7 @@
return NO;
} else if (![self.messageID isEqual:other.messageID] && !(self.messageID == nil && other.messageID == nil)) {
return NO;
} else if (![self.optionalFields isEqual:other.optionalFields] && !(self.optionalFields == nil && other.optionalFields == nil)) {
} else if (![self optFieldsOfMessage:self areContainedInMessage:other] && !(self.optionalFields == nil && other.optionalFields == nil)) {
return NO;
} else if (![self.from isEqual:other.from]) {
return NO;
@ -121,5 +121,38 @@
return YES;
}
/// pEPMIME tries to guarantee that the generated MIME is always valis / RFC conform. To to that
/// it might add headers like "content-type". Thus we can not check optionalFields for equality
/// (as additional headers might have been added. We check the all headers of msg1 are also
/// contained in msg2 instead.
- (BOOL)optFieldsOfMessage:(PEPMessage *)msg1 areContainedInMessage:(PEPMessage *)msg2 {
if (msg1.optionalFields.count > msg2.optionalFields.count) {
return NO;
}
for (NSArray<NSString*> *optField1 in msg1.optionalFields) {
NSString *key1 = optField1[0];
NSString *value1 = optField1[1];
BOOL keyFound = NO;
BOOL valueConfirmed = NO;
for (NSArray<NSString*> *optField2 in msg2.optionalFields) {
NSString *key2 = optField2[0];
if ([key2 isEqual:key1]) {
keyFound = YES;
NSString *value2 = optField2[1];
// pEpMIME may return less spaces, which is MIME conform but breaks the test for equality here. Thus we ignore whitespaces.
NSString *value1Trimmed = [value1 stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
NSString *value2Trimmed = [value2 stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];
if ([value2Trimmed isEqual:value1Trimmed]) {
valueConfirmed = YES;
}
}
}
if (!keyFound || !valueConfirmed) {
return NO;
}
}
return YES;
}
@end

Loading…
Cancel
Save