A C++ wrapper for the basic C datatypes defined by the pEpEngine.
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.

130 lines
6.2 KiB

  1. #include <gtest/gtest.h>
  2. #include "../src/types.hh"
  3. namespace
  4. {
  5. static const char* mail1_eml =
  6. "Return-Path: <alice@pep-project.org>\r\n"
  7. "X-Original-To: alice@pep-project.org\r\n"
  8. "Delivered-To: alice@pep-project.org\r\n"
  9. "Received: from localhost (localhost [127.0.0.1])\r\n"
  10. "\tby dragon.pibit.ch (Postfix) with ESMTP id B84AF171C06F\r\n"
  11. "\tfor <alice@pep-project.org>; Wed, 16 Jan 2019 16:29:39 +0100 (CET)\r\n"
  12. "Received: from dragon.pibit.ch ([127.0.0.1])\r\n"
  13. "\tby localhost (dragon.pibit.ch [127.0.0.1]) (amavisd-new, port 10024)\r\n"
  14. "\twith ESMTP id q0wZqHMoT1gS for <alice@pep-project.org>;\r\n"
  15. "\tWed, 16 Jan 2019 16:29:37 +0100 (CET)\r\n"
  16. "Received: from Alice-PC.local (unknown [192.168.128.20])\r\n"
  17. "\tby dragon.pibit.ch (Postfix) with ESMTPSA id 563DD171C06A\r\n"
  18. "\tfor <alice@pep-project.org>; Wed, 16 Jan 2019 16:29:37 +0100 (CET)\r\n"
  19. "To: Bob <bob@pep-project.org>\r\n"
  20. "From: Alice <alice@pep-project.org>\r\n"
  21. "Cc: Carol Couscous <carol.couscous+private@pep.lol>, Dave Doe (III) \r\n"
  22. " Dexter <dave-dexter@pep.ooo>, dodo@pep.lol, \"Eve @ Evil\" <eve@evil.lol>\r\n"
  23. " Mallory =?UTF-8?B?TcO2bGxlcg==?= (private) <\"mallory @ moeller\"@sinister.aq>\r\n"
  24. "Subject: =?UTF-8?B?UsO4ZGdyw7hkIG1lZCBmbMO4ZGU=?=\r\n"
  25. "Openpgp: preference=signencrypt\r\n"
  26. "Organization: =?UTF-8?B?8J+Ukg==?=\r\n"
  27. "Message-ID: <65a2df2c-ddc8-0875-a142-21acf62ed467@pep-project.org>\r\n"
  28. "References: <msg-alfa@pep.id> <msg-bravo@pep.aq> <lol-123456789@intern.sc.ful-lol.example>\r\n"
  29. " <msg-charlie@pep.aq>\r\n"
  30. "In-Reply-To: <msg-reply-0815@pep.aq>\r\n"
  31. "Date: Wed, 16 Jan 2019 16:29:30 +0100\r\n"
  32. "User-Agent: B\r\n"
  33. "MIME-Version: 1.0\r\n"
  34. "Content-Type: multipart/mixed;\r\n"
  35. " boundary=\"==pEp_01==\"\r\n"
  36. "\r\n"
  37. "This is a Multipart MIME message.\r\n"
  38. "--==pEp_01==\r\n"
  39. "Content-Type: multipart/alternative; boundary=\"==pEp_02==\";\r\n"
  40. " protected-headers=\"v1\"\r\n"
  41. "\r\n"
  42. "--==pEp_02==\r\n"
  43. "Content-Type: text/plain; charset=\"utf-8\"\r\n"
  44. "Content-Language: en-US\r\n"
  45. "Content-Transfer-Encoding: quoted-printable\r\n"
  46. "\r\n"
  47. "R=C3=B8dgr=C3=B8d med fl=C3=B8de?\r\n"
  48. "\r\n"
  49. "--==pEp_02==\r\n"
  50. "Content-Type: multipart/related; boundary=\"==pEp_LoL==\";\r\n"
  51. "\r\n"
  52. "--==pEp_LoL==\r\n"
  53. "Content-Type: text/html; charset=\"ISO-8859-1\";\r\n"
  54. "Content-Transfer-Encoding: quoted-printable\r\n"
  55. "\r\n"
  56. "<html lang=3D=22de=22><body>=DCbergr=F6=DFen=E4nderung: 1=\r\n"
  57. "0=80.</body></html>\r\n"
  58. "\r\n"
  59. "--==pEp_LoL==\r\n"
  60. "Content-Type: image/png; name=\"rebeccapurple-circle.png\"\r\n"
  61. "Content-Language: en-US\r\n"
  62. "Content-ID: <rebeccapurple-circle-fb25fbb3-fd0b-46af-b567-7d1aa5725c49@pep.lol>\r\n"
  63. "Content-Transfer-Encoding: base64\r\n"
  64. "Content-Disposition: inline;\r\n"
  65. " filename*0*=utf-8'en-US'rebeccapurple;\r\n"
  66. " filename*1*=%2Dcircle.png;\r\n"
  67. "\r\n"
  68. "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEVmM5n///9dvR/iAAAA\r\n"
  69. "H0lEQVQIHWP4Ic/wgJ3hADNDAyMIYQKIOFABUNkPeQC4LQeH3BOsvgAAAABJRU5ErkJggg==\r\n"
  70. "\r\n"
  71. "--==pEp_LoL==--\r\n" // end of multipart/related
  72. "\r\n"
  73. "--==pEp_02==--\r\n" // end of multipart/alternative
  74. "\r\n"
  75. "--==pEp_01==\r\n" // first "real" attachment, 2nd in bloblist
  76. "Content-Type: application/octet-stream; name=\"This is a long\r\n"
  77. " file name so it is split to multiple\r\n"
  78. " physical lines.bin\"\r\n"
  79. "Content-Language: en-US\r\n"
  80. "Content-Transfer-Encoding: base64\r\n"
  81. "Content-Disposition: attachment;\r\n"
  82. " filename*0=\"This is a long file name so it is split to\";\r\n"
  83. " filename*1=\" multiple physical lines.bin\";\r\n"
  84. "\r\n"
  85. "w5xiZXJncsO2w59lbsOkbmRlcnVuZyEK\r\n"
  86. "\r\n"
  87. "--==pEp_01==\r\n" // another text/plain part, 3rd in bloblist
  88. "Content-Type: text/plain; charset=\"ISO-8859-15\";\r\n"
  89. "Content-Transfer-Encoding: quoted-printable\r\n"
  90. "\r\n"
  91. "=DCbergr=F6=DFen=E4nderung: 10=A4.\r\n"
  92. "--==pEp_01==\r\n" // an attached PNG image with bizarre filename as 4th and last element in bloblist
  93. "Content-Type: image/png; name=\"=?UTF-8?B?8J+SqSDwn5iAIPCf?="
  94. " =?UTF-8?B?kqkg8J+YgCDwn5KpIPCfmIAg8J+SqSDwn5iAIPCfkqkg8J+YgCDwn5KpIPCfm?="
  95. " =?UTF-8?B?IAg8J+SqSDwn5iAIPCfkqkg8J+YgC5wbmc=?=\"\r\n"
  96. "Content-Language: en-US\r\n"
  97. "Content-Transfer-Encoding: base64\r\n"
  98. "Content-Disposition: attachment;\r\n"
  99. " filename*0*=utf-8''%F0%9F%92%A9%20%F0%9F%98%80%20%F0%9F%92%A9%20%F0;\r\n"
  100. " filename*1*=%9F%98%80%20%F0%9F%92%A9%20%F0%9F%98%80%20%F0%9F%92%A9;\r\n"
  101. " filename*2*=%20%F0%9F%98%80%20%F0%9F%92%A9%20%F0%9F%98%80%20%F0%9F;\r\n"
  102. " filename*3*=%92%A9%20%F0%9F%98%80%20%F0%9F%92%A9%20%F0%9F%98%80%20;\r\n"
  103. " filename*4*=%F0%9F%92%A9%20%F0%9F%98%80.png\r\n"
  104. "\r\n"
  105. "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEVmM5n///9dvR/iAAAA\r\n"
  106. " H0lEQVQIHWP4Ic/wgJ3hADN\r\n"
  107. "DAyMIYQKIOFABUNkPeQC4LQeH3BOsvgAAAABJRU5ErkJggg==\r\n"
  108. "--==pEp_01==--\r\n"
  109. "\r\n";
  110. } // end of anonymous namespace
  111. TEST( MessageTest, Simple )
  112. {
  113. pEp::Message msg{PEP_dir_outgoing, mail1_eml};
  114. EXPECT_EQ(msg->dir, PEP_dir_outgoing);
  115. EXPECT_STREQ( msg->shortmsg, "Rødgrød med fløde" );
  116. EXPECT_STREQ( msg->longmsg , "Rødgrød med fløde?\r\n" );
  117. EXPECT_EQ( identity_list_length(msg->to), 1 );
  118. EXPECT_EQ( identity_list_length(msg->cc), 4 );
  119. EXPECT_EQ( identity_list_length(msg->bcc), 0 );
  120. EXPECT_EQ( bloblist_length(msg->attachments), 4 );
  121. ASSERT_NE(msg->from, nullptr);
  122. EXPECT_STREQ( msg->from->username, "Alice");
  123. }