test/apple_mail_test.cc
author Krista Grothoff <krista@pep-project.org>
Wed, 18 Jan 2017 13:02:00 +0100
changeset 1543 44866373e733
child 1545 42f8c8f29df3
permissions -rw-r--r--
Added test case for Patrick's trust issue - we can add additional apple mails to it if we have problems with detached sigs, but so far, trusted status works as it should from the TCs we have so far.
krista@1543
     1
#include <iostream>
krista@1543
     2
#include <iostream>
krista@1543
     3
#include <fstream>
krista@1543
     4
#include <string>
krista@1543
     5
#include <cstring> // for strcmp()
krista@1543
     6
#include <assert.h>
krista@1543
     7
#include "blacklist.h"
krista@1543
     8
#include "keymanagement.h"
krista@1543
     9
#include "message_api.h"
krista@1543
    10
#include "mime.h"
krista@1543
    11
krista@1543
    12
using namespace std;
krista@1543
    13
krista@1543
    14
int main(int argc, char** argv) {
krista@1543
    15
    
krista@1543
    16
    const char* mailfile = "test_mails/apple_mail_TC_signed_encrypted.eml";
krista@1543
    17
    
krista@1543
    18
    PEP_SESSION session;
krista@1543
    19
    
krista@1543
    20
    cout << "calling init()\n";
krista@1543
    21
    PEP_STATUS status1 = init(&session);   
krista@1543
    22
    assert(status1 == PEP_STATUS_OK);
krista@1543
    23
    assert(session);
krista@1543
    24
    cout << "init() completed.\n";
krista@1543
    25
krista@1543
    26
        
krista@1543
    27
    ifstream infile(mailfile);
krista@1543
    28
    string mailtext;
krista@1543
    29
    while (!infile.eof()) {
krista@1543
    30
        static string line;
krista@1543
    31
        getline(infile, line);
krista@1543
    32
        mailtext += line + "\n";
krista@1543
    33
    }
krista@1543
    34
    infile.close(); 
krista@1543
    35
krista@1543
    36
    pEp_identity * me = new_identity("pep.test.recip@kgrothoff.org", NULL, PEP_OWN_USERID, "pEp Test Recipient");    
krista@1543
    37
    me->me = true;    
krista@1543
    38
    PEP_STATUS status = update_identity(session, me);
krista@1543
    39
krista@1543
    40
    pEp_identity * you = new_identity("pep.test.apple@pep-project.org", NULL, "TOFU_pep.test.apple@pep-project.org", "pEp Test Recipient");    
krista@1543
    41
    you->me = false;    
krista@1543
    42
    status = update_identity(session, you);
krista@1543
    43
krista@1543
    44
    trust_personal_key(session, you);
krista@1543
    45
    
krista@1543
    46
    status = update_identity(session, you);
krista@1543
    47
    
krista@1543
    48
    message* msg_ptr = nullptr;
krista@1543
    49
    message* dest_msg = nullptr;
krista@1543
    50
    message* final_ptr = nullptr;
krista@1543
    51
    stringlist_t* keylist = nullptr;
krista@1543
    52
    PEP_rating rating;
krista@1543
    53
    PEP_decrypt_flags_t flags;
krista@1543
    54
    
krista@1543
    55
    status = mime_decode_message(mailtext.c_str(), mailtext.length(), &msg_ptr);
krista@1543
    56
    assert(status == PEP_STATUS_OK);
krista@1543
    57
    assert(msg_ptr);
krista@1543
    58
    final_ptr = msg_ptr;
krista@1543
    59
    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
krista@1543
    60
    final_ptr = dest_msg ? dest_msg : msg_ptr;
krista@1543
    61
  
krista@1543
    62
    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
krista@1543
    63
    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
krista@1543
    64
    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
krista@1543
    65
krista@1543
    66
    assert(color_from_rating(rating) == PEP_color_green);
krista@1543
    67
krista@1543
    68
    if (final_ptr == dest_msg)
krista@1543
    69
    	free_message(dest_msg);
krista@1543
    70
    free_message(msg_ptr);
krista@1543
    71
    free_stringlist(keylist);
krista@1543
    72
krista@1543
    73
    msg_ptr = nullptr;
krista@1543
    74
    dest_msg = nullptr;
krista@1543
    75
    final_ptr = nullptr;
krista@1543
    76
    keylist = nullptr;
krista@1543
    77
    rating = PEP_rating_unreliable;
krista@1543
    78
    
krista@1543
    79
    const char* mailfile2 = "test_mails/apple_mail_TC_html_signed_encrypted.eml";
krista@1543
    80
    
krista@1543
    81
    ifstream infile2(mailfile2);
krista@1543
    82
    string mailtext2;
krista@1543
    83
    while (!infile2.eof()) {
krista@1543
    84
        static string line;
krista@1543
    85
        getline(infile2, line);
krista@1543
    86
        mailtext2 += line + "\n";
krista@1543
    87
    }
krista@1543
    88
    infile2.close(); 
krista@1543
    89
    
krista@1543
    90
    status = mime_decode_message(mailtext2.c_str(), mailtext2.length(), &msg_ptr);
krista@1543
    91
    assert(status == PEP_STATUS_OK);
krista@1543
    92
    assert(msg_ptr);
krista@1543
    93
    final_ptr = msg_ptr;
krista@1543
    94
    status = decrypt_message(session, msg_ptr, &dest_msg, &keylist, &rating, &flags);
krista@1543
    95
    final_ptr = dest_msg ? dest_msg : msg_ptr;
krista@1543
    96
  
krista@1543
    97
    cout << "shortmsg: " << final_ptr->shortmsg << endl << endl;
krista@1543
    98
    cout << "longmsg: " << final_ptr->longmsg << endl << endl;
krista@1543
    99
    cout << "longmsg_formatted: " << (final_ptr->longmsg_formatted ? final_ptr->longmsg_formatted : "(empty)") << endl << endl;
krista@1543
   100
krista@1543
   101
    assert(color_from_rating(rating) == PEP_color_green);
krista@1543
   102
krista@1543
   103
    if (final_ptr == dest_msg)
krista@1543
   104
    	free_message(dest_msg);
krista@1543
   105
    free_message(msg_ptr);
krista@1543
   106
    free_stringlist(keylist);
krista@1543
   107
krista@1543
   108
    
krista@1543
   109
    cout << "calling release()\n";
krista@1543
   110
    release(session);
krista@1543
   111
    return 0;
krista@1543
   112
}