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