test/pEp_subject_received_test.cc
author Krista Bennett <krista@pep-project.org>
Fri, 19 Jan 2018 14:12:02 +0100
changeset 2418 05678e77bc6a
parent 2288 8aee10631677
child 2615 5cd3625e0d91
permissions -rw-r--r--
fixed update_identity call that could be called on a myself value in outgoing_message_rating
krista@1852
     1
#include <iostream>
krista@1852
     2
#include <iostream>
krista@1852
     3
#include <fstream>
krista@1852
     4
#include <string>
krista@1852
     5
#include <cstring> // for strcmp()
krista@1852
     6
#include <assert.h>
krista@1852
     7
#include "blacklist.h"
krista@1852
     8
#include "keymanagement.h"
krista@1852
     9
#include "message_api.h"
krista@1852
    10
#include "mime.h"
krista@1852
    11
#include "test_util.h" // for slurp()
krista@1852
    12
krista@1852
    13
using namespace std;
krista@1852
    14
krista@1852
    15
int main(int argc, char** argv) {
krista@1852
    16
krista@2045
    17
    cout << "\n*** check that p≡p subject is handled properly in received mails ***\n\n";
krista@1852
    18
krista@1852
    19
    PEP_SESSION session;
krista@1852
    20
    
krista@1852
    21
    cout << "calling init()\n";
krista@1852
    22
    PEP_STATUS status1 = init(&session);   
krista@1852
    23
    assert(status1 == PEP_STATUS_OK);
krista@1852
    24
    assert(session);
krista@1852
    25
    cout << "init() completed.\n";
krista@1852
    26
krista@1852
    27
    const char* keytexts[3];
krista@1852
    28
krista@1852
    29
    const string keytextkey1 = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
krista@1852
    30
    const string keytextkey2 = slurp("test_keys/priv/pep-test-recip-0x08DB0AEE_priv.asc");
krista@1852
    31
    const string keytextkey3 = slurp("test_keys/pub/pep-test-recip-0x08DB0AEE_pub.asc");
krista@1852
    32
    PEP_STATUS statuskey1 = import_key(session, keytextkey1.c_str(), keytextkey1.length(), NULL);
krista@1852
    33
    PEP_STATUS statuskey2 = import_key(session, keytextkey2.c_str(), keytextkey2.length(), NULL);
krista@1852
    34
    PEP_STATUS statuskey3 = import_key(session, keytextkey3.c_str(), keytextkey3.length(), NULL);
krista@1852
    35
krista@1852
    36
    pEp_identity * me = new_identity("pep.test.recip@kgrothoff.org", "93D19F24AD6F4C4BA9134AAF84D9217908DB0AEE", PEP_OWN_USERID, "pEp Test Recipient");    
krista@2288
    37
    me->me = true;
krista@1852
    38
    PEP_STATUS status = myself(session, me);
krista@1852
    39
    
krista@2067
    40
    pEp_identity * you = new_identity("pep.test.alice@pep-project.org", NULL, "TOFU_pep.test.alice@pep-project.org", "Alice Test");    
krista@2288
    41
    you->me = false;
krista@2288
    42
krista@1852
    43
    status = update_identity(session, you);
krista@1852
    44
    trust_personal_key(session, you);
krista@1852
    45
    status = update_identity(session, you);
krista@1852
    46
krista@1852
    47
    cout << "------------------------------------------------------------------------------------------" << endl;
krista@2046
    48
    cout << "Test 1a: Normal encrypted mail, pEp as substitute subject, regular subject in crypto text." << endl;
krista@1852
    49
    cout << "------------------------------------------------------------------------------------------" << endl;
krista@1852
    50
        
krista@2050
    51
    string mailtext = slurp("test_mails/pEp_subject_normal_1a.eml");
krista@1852
    52
    
krista@1852
    53
    message* msg_ptr = nullptr;
krista@1852
    54
    message* dest_msg = nullptr;
krista@1852
    55
    message* final_ptr = nullptr;
krista@1852
    56
    stringlist_t* keylist = nullptr;
krista@1852
    57
    PEP_rating rating;
krista@1852
    58
    PEP_decrypt_flags_t flags;
krista@1852
    59
    
krista@1852
    60
    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
krista@1852
    61
    assert(status == PEP_STATUS_OK);
krista@1852
    62
    assert(msg_ptr);
krista@1852
    63
    final_ptr = msg_ptr;
krista@1852
    64
    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
krista@1852
    65
    final_ptr = dest_msg ? dest_msg : msg_ptr;
krista@1852
    66
  
krista@1852
    67
    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
krista@1852
    68
    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
krista@1852
    69
    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
krista@1852
    70
krista@1852
    71
    assert(strcmp("This is the usual pEp subject that should replace the above.", final_ptr->shortmsg) == 0);
krista@1852
    72
krista@2046
    73
    cout << "Test 1a: Subject replaced as expected." << endl << endl;
krista@2046
    74
krista@2046
    75
    if (final_ptr == dest_msg)
krista@2046
    76
    	free_message(dest_msg);
krista@2046
    77
    free_message(msg_ptr);
krista@2046
    78
    free_stringlist(keylist);
krista@2046
    79
krista@2046
    80
    cout << "------------------------------------------------------------------------------------------" << endl;
krista@2046
    81
    cout << "Test 1b: Normal encrypted mail, p≡p as substitute subject, regular subject in crypto text." << endl;
krista@2046
    82
    cout << "------------------------------------------------------------------------------------------" << endl;
krista@2046
    83
        
krista@2050
    84
    mailtext = slurp("test_mails/p3p_subject_normal_1b.eml");
krista@2046
    85
    
krista@2046
    86
    msg_ptr = nullptr;
krista@2046
    87
    dest_msg = nullptr;
krista@2046
    88
    final_ptr = nullptr;
krista@2046
    89
    keylist = nullptr;
krista@2046
    90
    rating = PEP_rating_unreliable;
krista@2046
    91
    
krista@2046
    92
    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
krista@2046
    93
    assert(status == PEP_STATUS_OK);
krista@2046
    94
    assert(msg_ptr);
krista@2046
    95
    final_ptr = msg_ptr;
krista@2046
    96
    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
krista@2046
    97
    final_ptr = dest_msg ? dest_msg : msg_ptr;
krista@2046
    98
  
krista@2046
    99
    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
krista@2046
   100
    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
krista@2046
   101
    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
krista@2046
   102
krista@2046
   103
    assert(strcmp("This is the usual pEp subject that should replace the above.", final_ptr->shortmsg) == 0);
krista@2046
   104
krista@2046
   105
    cout << "Test 1b: Subject replaced as expected." << endl << endl;
krista@1852
   106
krista@1852
   107
    if (final_ptr == dest_msg)
krista@1852
   108
    	free_message(dest_msg);
krista@1852
   109
    free_message(msg_ptr);
krista@1852
   110
    free_stringlist(keylist);
krista@1852
   111
krista@1852
   112
    cout << "-------------------------------------------------------------------------------------------------" << endl;
krista@2046
   113
    cout << "Test 2a: Normal encrypted/signed mail, pEp as substitute subject, regular subject in crypto text." << endl;
krista@1852
   114
    cout << "-------------------------------------------------------------------------------------------------" << endl;
krista@1852
   115
krista@1852
   116
    msg_ptr = nullptr;
krista@1852
   117
    dest_msg = nullptr;
krista@1852
   118
    final_ptr = nullptr;
krista@1852
   119
    keylist = nullptr;
krista@1852
   120
    rating = PEP_rating_unreliable;
krista@1852
   121
    
krista@2050
   122
    mailtext = slurp("test_mails/pEp_subject_normal_signed_2a.eml");
krista@1852
   123
    
krista@1852
   124
    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
krista@1852
   125
    assert(status == PEP_STATUS_OK);
krista@1852
   126
    assert(msg_ptr);
krista@1852
   127
    final_ptr = msg_ptr;
krista@1852
   128
    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
krista@1852
   129
    final_ptr = dest_msg ? dest_msg : msg_ptr;
krista@1852
   130
  
krista@1852
   131
    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
krista@1852
   132
    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
krista@1852
   133
    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
krista@1852
   134
krista@1852
   135
    assert(strcmp("Now signed!", final_ptr->shortmsg) == 0);
krista@1852
   136
krista@2046
   137
    cout << "Test 2a: Subject replaced as expected." << endl << endl;
krista@1852
   138
krista@1852
   139
    if (final_ptr == dest_msg)
krista@1852
   140
        free_message(dest_msg);
krista@1852
   141
    free_message(msg_ptr);
krista@1852
   142
    free_stringlist(keylist);
krista@2046
   143
krista@2046
   144
    cout << "-------------------------------------------------------------------------------------------------" << endl;
krista@2046
   145
    cout << "Test 2b: Normal encrypted/signed mail, p≡p as substitute subject, regular subject in crypto text." << endl;
krista@2046
   146
    cout << "-------------------------------------------------------------------------------------------------" << endl;
krista@1852
   147
krista@1852
   148
    msg_ptr = nullptr;
krista@1852
   149
    dest_msg = nullptr;
krista@1852
   150
    final_ptr = nullptr;
krista@1852
   151
    keylist = nullptr;
krista@1852
   152
    rating = PEP_rating_unreliable;
krista@1852
   153
    
krista@2050
   154
    mailtext = slurp("test_mails/p3p_subject_normal_signed_2b.eml");
krista@1852
   155
    
krista@1852
   156
    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
krista@1852
   157
    assert(status == PEP_STATUS_OK);
krista@1852
   158
    assert(msg_ptr);
krista@1852
   159
    final_ptr = msg_ptr;
krista@1852
   160
    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
krista@1852
   161
    final_ptr = dest_msg ? dest_msg : msg_ptr;
krista@1852
   162
  
krista@1852
   163
    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
krista@1852
   164
    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
krista@1852
   165
    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
krista@1852
   166
krista@2046
   167
    assert(strcmp("Now signed!", final_ptr->shortmsg) == 0);
krista@1852
   168
krista@2046
   169
    cout << "Test 2b: Subject replaced as expected." << endl << endl;
krista@1852
   170
krista@1852
   171
    if (final_ptr == dest_msg)
krista@1852
   172
        free_message(dest_msg);
krista@1852
   173
    free_message(msg_ptr);
krista@1852
   174
    free_stringlist(keylist);
krista@1852
   175
krista@2046
   176
    
krista@2046
   177
    cout << "---------------------------------------------------------------------------" << endl;
krista@2046
   178
    cout << "Test 3a: Encrypted mail, pEp as displayed subject, no subject in body text." << endl;
krista@2046
   179
    cout << "---------------------------------------------------------------------------" << endl;
krista@1852
   180
krista@1852
   181
    msg_ptr = nullptr;
krista@1852
   182
    dest_msg = nullptr;
krista@1852
   183
    final_ptr = nullptr;
krista@1852
   184
    keylist = nullptr;
krista@1852
   185
    rating = PEP_rating_unreliable;
krista@1852
   186
    
krista@2050
   187
    mailtext = slurp("test_mails/pEp_encrypted_subject_IS_pEp_3a.eml");
krista@1852
   188
    
krista@1852
   189
    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
krista@1852
   190
    assert(status == PEP_STATUS_OK);
krista@1852
   191
    assert(msg_ptr);
krista@1852
   192
    final_ptr = msg_ptr;
krista@1852
   193
    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
krista@1852
   194
    final_ptr = dest_msg ? dest_msg : msg_ptr;
krista@1852
   195
  
krista@1852
   196
    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
krista@1852
   197
    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
krista@1852
   198
    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
krista@1852
   199
krista@1852
   200
    assert(strcmp("pEp", final_ptr->shortmsg) == 0);
krista@1852
   201
krista@2046
   202
    cout << "Test 3a: Subject remains intact as desired." << endl << endl;
krista@1852
   203
krista@1852
   204
    if (final_ptr == dest_msg)
krista@1852
   205
        free_message(dest_msg);
krista@1852
   206
    free_message(msg_ptr);
krista@1852
   207
    free_stringlist(keylist);
krista@1852
   208
krista@2046
   209
    cout << "---------------------------------------------------------------------------" << endl;
krista@2046
   210
    cout << "Test 3b: Encrypted mail, p≡p as displayed subject, no subject in body text." << endl;
krista@2046
   211
    cout << "---------------------------------------------------------------------------" << endl;
krista@1852
   212
krista@1852
   213
    msg_ptr = nullptr;
krista@1852
   214
    dest_msg = nullptr;
krista@1852
   215
    final_ptr = nullptr;
krista@1852
   216
    keylist = nullptr;
krista@1852
   217
    rating = PEP_rating_unreliable;
krista@1852
   218
    
krista@2050
   219
    mailtext = slurp("test_mails/p3p_encrypted_subject_IS_pEp_3b.eml");
krista@1852
   220
    
krista@1852
   221
    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
krista@1852
   222
    assert(status == PEP_STATUS_OK);
krista@1852
   223
    assert(msg_ptr);
krista@1852
   224
    final_ptr = msg_ptr;
krista@1852
   225
    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
krista@1852
   226
    final_ptr = dest_msg ? dest_msg : msg_ptr;
krista@1852
   227
  
krista@1852
   228
    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
krista@1852
   229
    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
krista@1852
   230
    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
krista@1852
   231
krista@2046
   232
    assert(strcmp("p≡p", final_ptr->shortmsg) == 0);
krista@1852
   233
krista@2046
   234
    cout << "Test 3: Subject remains intact as desired." << endl << endl;
krista@1852
   235
krista@1852
   236
    if (final_ptr == dest_msg)
krista@1852
   237
        free_message(dest_msg);
krista@1852
   238
    free_message(msg_ptr);
krista@1852
   239
    free_stringlist(keylist);
krista@1852
   240
krista@2046
   241
krista@2046
   242
    cout << "----------------------------------------------------------------------------" << endl;
krista@2046
   243
    cout << "Test 4a: Encrypted mail, pEp as displayed subject, pEp subject in body text." << endl;
krista@2046
   244
    cout << "----------------------------------------------------------------------------" << endl;
krista@2046
   245
krista@2046
   246
    msg_ptr = nullptr;
krista@2046
   247
    dest_msg = nullptr;
krista@2046
   248
    final_ptr = nullptr;
krista@2046
   249
    keylist = nullptr;
krista@2046
   250
    rating = PEP_rating_unreliable;
krista@2046
   251
    
krista@2050
   252
    mailtext = slurp("test_mails/pEp_subject_pEp_replaced_w_pEp_4a.eml");
krista@2046
   253
    
krista@2046
   254
    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
krista@2046
   255
    assert(status == PEP_STATUS_OK);
krista@2046
   256
    assert(msg_ptr);
krista@2046
   257
    final_ptr = msg_ptr;
krista@2046
   258
    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
krista@2046
   259
    final_ptr = dest_msg ? dest_msg : msg_ptr;
krista@2046
   260
  
krista@2046
   261
    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
krista@2046
   262
    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
krista@2046
   263
    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
krista@2046
   264
krista@2046
   265
    assert(strcmp("pEp", final_ptr->shortmsg) == 0);
krista@2046
   266
krista@2046
   267
    cout << "Test 4a: Subject correct." << endl << endl;
krista@2046
   268
krista@2046
   269
    if (final_ptr == dest_msg)
krista@2046
   270
        free_message(dest_msg);
krista@2046
   271
    free_message(msg_ptr);
krista@2046
   272
    free_stringlist(keylist);
krista@2046
   273
krista@2046
   274
    cout << "----------------------------------------------------------------------------" << endl;
krista@2046
   275
    cout << "Test 4b: Encrypted mail, p≡p as displayed subject, pEp subject in body text." << endl;
krista@2046
   276
    cout << "----------------------------------------------------------------------------" << endl;
krista@2046
   277
krista@2046
   278
    msg_ptr = nullptr;
krista@2046
   279
    dest_msg = nullptr;
krista@2046
   280
    final_ptr = nullptr;
krista@2046
   281
    keylist = nullptr;
krista@2046
   282
    rating = PEP_rating_unreliable;
krista@2046
   283
    
krista@2050
   284
    mailtext = slurp("test_mails/pEp_subject_pEp_replaced_w_p3p_4b.eml");
krista@2046
   285
    
krista@2046
   286
    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
krista@2046
   287
    assert(status == PEP_STATUS_OK);
krista@2046
   288
    assert(msg_ptr);
krista@2046
   289
    final_ptr = msg_ptr;
krista@2046
   290
    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
krista@2046
   291
    final_ptr = dest_msg ? dest_msg : msg_ptr;
krista@2046
   292
  
krista@2046
   293
    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
krista@2046
   294
    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
krista@2046
   295
    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
krista@2046
   296
krista@2046
   297
    assert(strcmp("pEp", final_ptr->shortmsg) == 0);
krista@2046
   298
krista@2046
   299
    cout << "Test 4b: Subject correct." << endl << endl;
krista@2046
   300
krista@2046
   301
    if (final_ptr == dest_msg)
krista@2046
   302
        free_message(dest_msg);
krista@2046
   303
    free_message(msg_ptr);
krista@2046
   304
    free_stringlist(keylist);
krista@2046
   305
krista@2046
   306
    cout << "----------------------------------------------------------------------------" << endl;
krista@2046
   307
    cout << "Test 4c: Encrypted mail, pEp as displayed subject, p≡p subject in body text." << endl;
krista@2046
   308
    cout << "----------------------------------------------------------------------------" << endl;
krista@2046
   309
krista@2046
   310
    msg_ptr = nullptr;
krista@2046
   311
    dest_msg = nullptr;
krista@2046
   312
    final_ptr = nullptr;
krista@2046
   313
    keylist = nullptr;
krista@2046
   314
    rating = PEP_rating_unreliable;
krista@2046
   315
    
krista@2050
   316
    mailtext = slurp("test_mails/pEp_subject_p3p_replaced_w_pEp_4c.eml");
krista@2046
   317
    
krista@2046
   318
    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
krista@2046
   319
    assert(status == PEP_STATUS_OK);
krista@2046
   320
    assert(msg_ptr);
krista@2046
   321
    final_ptr = msg_ptr;
krista@2046
   322
    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
krista@2046
   323
    final_ptr = dest_msg ? dest_msg : msg_ptr;
krista@2046
   324
  
krista@2046
   325
    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
krista@2046
   326
    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
krista@2046
   327
    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
krista@2046
   328
krista@2046
   329
    assert(strcmp("p≡p", final_ptr->shortmsg) == 0);
krista@2046
   330
krista@2046
   331
    cout << "Test 4c: Subject correct." << endl << endl;
krista@2046
   332
krista@2046
   333
    if (final_ptr == dest_msg)
krista@2046
   334
        free_message(dest_msg);
krista@2046
   335
    free_message(msg_ptr);
krista@2046
   336
    free_stringlist(keylist);
krista@2046
   337
krista@2046
   338
    cout << "----------------------------------------------------------------------------" << endl;
krista@2046
   339
    cout << "Test 4d: Encrypted mail, p≡p as displayed subject, p≡p subject in body text." << endl;
krista@2046
   340
    cout << "----------------------------------------------------------------------------" << endl;
krista@2046
   341
krista@2046
   342
    msg_ptr = nullptr;
krista@2046
   343
    dest_msg = nullptr;
krista@2046
   344
    final_ptr = nullptr;
krista@2046
   345
    keylist = nullptr;
krista@2046
   346
    rating = PEP_rating_unreliable;
krista@2046
   347
    
krista@2050
   348
    mailtext = slurp("test_mails/pEp_subject_p3p_replaced_w_p3p_4d.eml");
krista@2046
   349
    
krista@2046
   350
    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
krista@2046
   351
    assert(status == PEP_STATUS_OK);
krista@2046
   352
    assert(msg_ptr);
krista@2046
   353
    final_ptr = msg_ptr;
krista@2046
   354
    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
krista@2046
   355
    final_ptr = dest_msg ? dest_msg : msg_ptr;
krista@2046
   356
  
krista@2046
   357
    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
krista@2046
   358
    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
krista@2046
   359
    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
krista@2046
   360
krista@2046
   361
    assert(strcmp("p≡p", final_ptr->shortmsg) == 0);
krista@2046
   362
krista@2046
   363
    cout << "Test 4d: Subject correct, in any event." << endl << endl;
krista@2046
   364
krista@2046
   365
    if (final_ptr == dest_msg)
krista@2046
   366
        free_message(dest_msg);
krista@2046
   367
    free_message(msg_ptr);
krista@2046
   368
    free_stringlist(keylist);
krista@2046
   369
krista@2046
   370
krista@2046
   371
    cout << "-------------------------------------------------------------------------" << endl;
krista@2046
   372
    cout << "Test 5a: Unencrypted variant where pEp in the subject line is the subject." << endl;
krista@2046
   373
    cout << "-------------------------------------------------------------------------" << endl;
krista@2046
   374
krista@2046
   375
    msg_ptr = nullptr;
krista@2046
   376
    dest_msg = nullptr;
krista@2046
   377
    final_ptr = nullptr;
krista@2046
   378
    keylist = nullptr;
krista@2046
   379
    rating = PEP_rating_unreliable;
krista@2046
   380
    
krista@2050
   381
    mailtext = slurp("test_mails/pEp_unencrypted_pEp_subject_5a.eml");
krista@2046
   382
    
krista@2046
   383
    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
krista@2046
   384
    assert(status == PEP_STATUS_OK);
krista@2046
   385
    assert(msg_ptr);
krista@2046
   386
    final_ptr = msg_ptr;
krista@2046
   387
    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
krista@2046
   388
    final_ptr = dest_msg ? dest_msg : msg_ptr;
krista@2046
   389
  
krista@2046
   390
    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
krista@2046
   391
    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
krista@2046
   392
    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
krista@2046
   393
krista@2046
   394
    assert(strcmp("pEp", final_ptr->shortmsg) == 0);
krista@2046
   395
krista@2046
   396
    cout << "Test 5a: Subject remains intact." << endl << endl;
krista@2046
   397
krista@2046
   398
    if (final_ptr == dest_msg)
krista@2046
   399
        free_message(dest_msg);
krista@2046
   400
    free_message(msg_ptr);
krista@2046
   401
    free_stringlist(keylist);
krista@2046
   402
krista@2046
   403
krista@2046
   404
    cout << "--------------------------------------------------------------------------" << endl;
krista@2046
   405
    cout << "Test 5b: Unencrypted variant where p≡p in the subject line is the subject." << endl;
krista@2046
   406
    cout << "--------------------------------------------------------------------------" << endl;
krista@2046
   407
krista@2046
   408
    msg_ptr = nullptr;
krista@2046
   409
    dest_msg = nullptr;
krista@2046
   410
    final_ptr = nullptr;
krista@2046
   411
    keylist = nullptr;
krista@2046
   412
    rating = PEP_rating_unreliable;
krista@2046
   413
    
krista@2050
   414
    mailtext = slurp("test_mails/pEp_unencrypted_p3p_subject_5b.eml");
krista@2046
   415
    
krista@2046
   416
    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
krista@2046
   417
    assert(status == PEP_STATUS_OK);
krista@2046
   418
    assert(msg_ptr);
krista@2046
   419
    final_ptr = msg_ptr;
krista@2046
   420
    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
krista@2046
   421
    final_ptr = dest_msg ? dest_msg : msg_ptr;
krista@2046
   422
  
krista@2046
   423
    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
krista@2046
   424
    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
krista@2046
   425
    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
krista@2046
   426
krista@2046
   427
    assert(strcmp("p≡p", final_ptr->shortmsg) == 0);
krista@2046
   428
krista@2046
   429
    cout << "Test 5b: Subject remains intact." << endl << endl;
krista@2046
   430
krista@2046
   431
    if (final_ptr == dest_msg)
krista@2046
   432
        free_message(dest_msg);
krista@2046
   433
    free_message(msg_ptr);
krista@2046
   434
    free_stringlist(keylist);
krista@2050
   435
krista@2050
   436
    cout << "----------------------------------------------------------------------------------------------------------------------" << endl;
krista@2050
   437
    cout << "Test 6: Normal unencrypted email where a subject line exists in the text but the subject is not a replacement subject." << endl;
krista@2050
   438
    cout << "----------------------------------------------------------------------------------------------------------------------" << endl;
krista@2050
   439
krista@2050
   440
    msg_ptr = nullptr;
krista@2050
   441
    dest_msg = nullptr;
krista@2050
   442
    final_ptr = nullptr;
krista@2050
   443
    keylist = nullptr;
krista@2050
   444
    rating = PEP_rating_unreliable;
krista@2050
   445
    
krista@2050
   446
    mailtext = slurp("test_mails/pEp_subject_normal_unencrypted_6.eml");
krista@2050
   447
    
krista@2050
   448
    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
krista@2050
   449
    assert(status == PEP_STATUS_OK);
krista@2050
   450
    assert(msg_ptr);
krista@2050
   451
    final_ptr = msg_ptr;
krista@2050
   452
    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
krista@2050
   453
    final_ptr = dest_msg ? dest_msg : msg_ptr;
krista@2050
   454
  
krista@2050
   455
    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
krista@2050
   456
    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
krista@2050
   457
    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
krista@2050
   458
krista@2050
   459
    assert(strcmp("This is just a normal subject, really", final_ptr->shortmsg) == 0);
krista@2050
   460
krista@2050
   461
    cout << "Test 6: Subject remains intact." << endl << endl;
krista@2050
   462
krista@2050
   463
    if (final_ptr == dest_msg)
krista@2050
   464
        free_message(dest_msg);
krista@2050
   465
    free_message(msg_ptr);
krista@2050
   466
    free_stringlist(keylist);
krista@1852
   467
        
krista@1852
   468
    cout << "calling release()\n";
krista@1852
   469
    release(session);
krista@1852
   470
    return 0;
krista@1852
   471
}