Adapter for libpepmime, offering ObjC API.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.5 KiB

  1. //
  2. // PEPMessage2MIMEUtil.m
  3. // pEpMimeObjCAdapter_macOS
  4. //
  5. // Created by Andreas Buff on 01.07.21.
  6. //
  7. #import "PEPMessage2MIMEUtil.h"
  8. #import <PEPObjCAdapterTypes_macOS/PEPObjCAdapterTypes_macOS.h>
  9. #include <pEpMIME.hh>
  10. #include <string>
  11. #include <iostream>
  12. #import "PEPMessage+Engine.h"
  13. @implementation PEPMessage2MIMEUtil
  14. //BUFF:
  15. // check: 11:46 <Roker> die generierte MIME-Message ist 7-bit-ASCII sogar.
  16. - (nullable NSData*)mimeDataFromPEPMessage:(PEPMessage *)pEpMessage error:(NSError **)error {
  17. message *engineMsg = [pEpMessage toStruct];
  18. if (engineMsg == nil) {
  19. // set error
  20. return nil;
  21. }
  22. /*
  23. 11:54 <Roker> also: wenn der bool 'true' ist, werden in der generierten Message ein paar interne header und flags gesetzt, mehr nicht.
  24. 11:56 <Roker> "if unsure say 'no'" :-D
  25. */
  26. BOOL has_pEp_msg_attachment = false;
  27. BOOL omit_fields = false;
  28. char* c = pEpMIME::generate_message(engineMsg, omit_fields, has_pEp_msg_attachment);
  29. if (c == NULL) {
  30. // set error
  31. return nil;
  32. }
  33. //BUFF: rm
  34. std::cout << c << std::endl;
  35. std::cout << "§§§§§§§§§§§§§§§§§§" << std::endl;
  36. NSString *mimeString = [NSString stringWithUTF8String:c];
  37. if (!mimeString) {
  38. // set error
  39. free(c);
  40. return nil;
  41. }
  42. free(c);
  43. NSData *mimeData = [mimeString dataUsingEncoding:NSUTF8StringEncoding];
  44. if (!mimeData) {
  45. // set error
  46. return nil;
  47. }
  48. return mimeData;
  49. }
  50. @end