test/mime_test.cc
author Volker Birk <vb@pep-project.org>
Sat, 28 Mar 2015 10:52:40 +0100
changeset 147 b03a10242e4c
parent 113 4bee48270834
child 159 ad6d0993d1ab
permissions -rw-r--r--
readability
vb@69
     1
#include <iostream>
vb@89
     2
#include <fstream>
vb@69
     3
#include <string>
vb@69
     4
#include <assert.h>
vb@69
     5
#include "mime.h"
vb@69
     6
vb@69
     7
using namespace std;
vb@69
     8
vb@69
     9
int main() {
vb@69
    10
    cout << "\n*** mime_test ***\n\n";
vb@69
    11
vb@69
    12
    PEP_SESSION session;
vb@69
    13
    
vb@69
    14
    cout << "calling init()\n";
vb@69
    15
    PEP_STATUS status1 = init(&session);   
vb@69
    16
    assert(status1 == PEP_STATUS_OK);
vb@69
    17
    assert(session);
vb@69
    18
    cout << "init() completed.\n";
vb@69
    19
vb@69
    20
    // mime test code
vb@69
    21
vb@89
    22
    // testing multipart/alternative
vb@69
    23
vb@89
    24
    message *msg2 = new_message(PEP_dir_incoming,
vb@94
    25
            new_identity("vb@dingens.org", NULL, NULL, "Volker Birk"),
vb@94
    26
            new_identity_list(new_identity("trischa@dingens.org", NULL, NULL, "Patricia Bädnar")),
vb@89
    27
            "my sübject");
vb@89
    28
    assert(msg2);
vb@89
    29
    string text2 = "my mèssage to yoü";
vb@89
    30
    msg2->longmsg = strdup(text2.c_str());
vb@89
    31
    string html2 = "<html><body><p>my message to you</p></body></html>";
vb@89
    32
    msg2->longmsg_formatted = strdup(html2.c_str());
vb@89
    33
    assert(msg2->longmsg_formatted);
vb@89
    34
vb@69
    35
    cout << "encoding message…\n";
vb@69
    36
    char *result2;
vb@113
    37
    PEP_STATUS status2 = mime_encode_message(msg2, false, &result2);
vb@69
    38
    assert(result2);
vb@69
    39
    assert(status2 == PEP_STATUS_OK);
vb@69
    40
vb@69
    41
    cout << "result:\n";
vb@69
    42
    cout << result2 << "\n";
vb@69
    43
vb@69
    44
    free(result2);
vb@89
    45
    free_message(msg2);
vb@69
    46
vb@94
    47
    cout << "opening mime_sample.txt for reading\n";
vb@94
    48
    ifstream inFile3 ("mime_sample.txt");
vb@94
    49
    assert(inFile3.is_open());
vb@94
    50
vb@94
    51
    string mimetext3;
vb@94
    52
vb@94
    53
    cout << "reading mime sample\n";
vb@94
    54
    while (!inFile3.eof()) {
vb@94
    55
        static string line;
vb@94
    56
        getline(inFile3, line);
vb@94
    57
        mimetext3 += line + "\n";
vb@94
    58
    }
vb@94
    59
    inFile3.close();
vb@94
    60
vb@147
    61
    cout << "decoding message…\n";
vb@94
    62
    message *msg3;
vb@94
    63
    PEP_STATUS status3 = mime_decode_message(mimetext3.c_str(), &msg3);
vb@147
    64
    assert(status3 == PEP_STATUS_OK);
vb@147
    65
    assert(msg3);
vb@147
    66
    cout << "decoded.\n\n";
vb@147
    67
    cout << "Subject: " << msg3->shortmsg << "\n\n";
vb@147
    68
    if (msg3->longmsg)
vb@147
    69
        cout << msg3->longmsg << "\n\n";
vb@147
    70
    if (msg3->longmsg_formatted)
vb@147
    71
        cout << msg3->longmsg_formatted << "\n\n";
vb@147
    72
vb@147
    73
    free_message(msg3);
vb@94
    74
vb@69
    75
    cout << "calling release()\n";
vb@69
    76
    release(session);
vb@69
    77
    return 0;
vb@69
    78
}
vb@69
    79