merged
authorEdouard Tisserant
Wed, 01 Apr 2015 17:27:46 +0200
changeset 169a0dec157c6c4
parent 168 5ddaec401f66
parent 167 04f883e99ed1
child 170 de3f8287972e
child 171 38c8e257b393
child 176 c4a5d7381459
merged
     1.1 --- a/src/etpan_mime.c	Wed Apr 01 16:36:52 2015 +0200
     1.2 +++ b/src/etpan_mime.c	Wed Apr 01 17:27:46 2015 +0200
     1.3 @@ -646,8 +646,8 @@
     1.4      for (cur = clist_begin(list); cur != NULL ; cur = clist_next(cur)) {
     1.5          struct mailmime_parameter * param = clist_content(cur);
     1.6          if (param &&
     1.7 -                param->pa_name && strcmp(name, param->pa_name) == 0 &&
     1.8 -                param->pa_value && strcmp(value, param->pa_value) == 0)
     1.9 +                param->pa_name && strcasecmp(name, param->pa_name) == 0 &&
    1.10 +                param->pa_value && strcasecmp(value, param->pa_value) == 0)
    1.11              return true;
    1.12      }
    1.13  
    1.14 @@ -665,7 +665,7 @@
    1.15              MAILMIME_COMPOSITE_TYPE_MULTIPART) {
    1.16          if (subtype)
    1.17              return content->ct_subtype &&
    1.18 -                    strcmp(content->ct_subtype, subtype) == 0;
    1.19 +                    strcasecmp(content->ct_subtype, subtype) == 0;
    1.20          else
    1.21              return true;
    1.22      }
    1.23 @@ -696,7 +696,7 @@
    1.24              MAILMIME_DISCRETE_TYPE_TEXT) {
    1.25          if (subtype)
    1.26              return content->ct_subtype &&
    1.27 -                    strcmp(content->ct_subtype, subtype) == 0;
    1.28 +                    strcasecmp(content->ct_subtype, subtype) == 0;
    1.29          else
    1.30              return true;
    1.31      }
    1.32 @@ -765,7 +765,7 @@
    1.33              for (cur = clist_begin(content->ct_parameters); cur; cur =
    1.34                      clist_next(cur)) {
    1.35                  struct mailmime_parameter * param = clist_content(cur);
    1.36 -                if (param && param->pa_name && strcmp(param->pa_name,
    1.37 +                if (param && param->pa_name && strcasecmp(param->pa_name,
    1.38                              "charset") == 0) {
    1.39                      _charset = param->pa_value;
    1.40                      break;
     2.1 --- a/src/message_api.c	Wed Apr 01 16:36:52 2015 +0200
     2.2 +++ b/src/message_api.c	Wed Apr 01 17:27:46 2015 +0200
     2.3 @@ -53,15 +53,23 @@
     2.4          }
     2.5          else {
     2.6              size_t n = line_end - src;
     2.7 +
     2.8              if (*(line_end - 1) == '\r')
     2.9 -                _shortmsg = strndup(src + 9, n - 1);
    2.10 +                _shortmsg = strndup(src + 9, n - 10);
    2.11              else
    2.12 -                _shortmsg = strndup(src + 9, n);
    2.13 +                _shortmsg = strndup(src + 9, n - 9);
    2.14 +
    2.15              if (_shortmsg == NULL)
    2.16                  goto enomem;
    2.17 -            _longmsg = strdup(src + n);
    2.18 -            if (_longmsg == NULL)
    2.19 -                goto enomem;
    2.20 +
    2.21 +            while (*(src + n) && (*(src + n) == '\n' || *(src + n) == '\r'))
    2.22 +                ++n;
    2.23 +
    2.24 +            if (*(src + n)) {
    2.25 +                _longmsg = strdup(src + n);
    2.26 +                if (_longmsg == NULL)
    2.27 +                    goto enomem;
    2.28 +            }
    2.29          }
    2.30      }
    2.31      else {
    2.32 @@ -651,7 +659,7 @@
    2.33              if (status != PEP_STATUS_OK)
    2.34                  goto pep_error;
    2.35  
    2.36 -            if (src->shortmsg) {
    2.37 +            if (src->shortmsg && strcmp(src->shortmsg, "pEp") != 0) {
    2.38                  free(msg->shortmsg);
    2.39                  msg->shortmsg = strdup(src->shortmsg);
    2.40                  if (msg->shortmsg == NULL)
    2.41 @@ -680,6 +688,7 @@
    2.42                      goto enomem;
    2.43                  msg->longmsg = ptext;
    2.44              }
    2.45 +            break;
    2.46  
    2.47          default:
    2.48              // BUG: must implement more
    2.49 @@ -712,6 +721,7 @@
    2.50                  free_message(msg);
    2.51                  msg = _msg;
    2.52              }
    2.53 +            break;
    2.54      }
    2.55  
    2.56      if (free_src)
     3.1 --- a/test/Makefile	Wed Apr 01 16:36:52 2015 +0200
     3.2 +++ b/test/Makefile	Wed Apr 01 17:27:46 2015 +0200
     3.3 @@ -18,7 +18,7 @@
     3.4  .PHONY: clean
     3.5  
     3.6  clean:
     3.7 -	rm -f *.o $(TARGET) *.a *~ $(UNIT_TESTS)
     3.8 +	rm -f *.o $(TARGET) *.a *~ $(UNIT_TESTS) pep_Dokument_Titel.pdf
     3.9  
    3.10  test: pEpEngineTest
    3.11  	LD_LIBRARY_PATH=~/lib:../src ./pEpEngineTest
     4.1 --- a/test/message_api_test.cc	Wed Apr 01 16:36:52 2015 +0200
     4.2 +++ b/test/message_api_test.cc	Wed Apr 01 17:27:46 2015 +0200
     4.3 @@ -1,4 +1,6 @@
     4.4 +#include "platform.h"
     4.5  #include <iostream>
     4.6 +#include <fstream>
     4.7  #include <assert.h>
     4.8  #include "message_api.h"
     4.9  
    4.10 @@ -53,10 +55,22 @@
    4.11      message *msg3;
    4.12      PEP_STATUS status3 = mime_decode_message(text2, &msg3);
    4.13      assert(status3 == PEP_STATUS_OK);
    4.14 +    string string3 = text2;
    4.15 +    free(text2);
    4.16 +
    4.17 +    unlink("msg4.asc");
    4.18 +    ofstream outFile3("msg4.asc");
    4.19 +    outFile3.write(string3.c_str(), string3.size());
    4.20 +    outFile3.close();
    4.21 +
    4.22 +    message *msg4;
    4.23 +    PEP_STATUS status4 = decrypt_message(session, enc_msg2, PEP_MIME_none, &msg4);
    4.24 +    assert(status4 == PEP_STATUS_OK);
    4.25 +    assert(msg4);
    4.26  
    4.27      cout << "freeing messages…\n";
    4.28 +    free_message(msg4);
    4.29      free_message(msg3);
    4.30 -    free(text2);
    4.31      free_message(msg2);
    4.32      free_message(enc_msg2);
    4.33      cout << "done.\n";
     5.1 --- a/test/mime_test.cc	Wed Apr 01 16:36:52 2015 +0200
     5.2 +++ b/test/mime_test.cc	Wed Apr 01 17:27:46 2015 +0200
     5.3 @@ -9,6 +9,47 @@
     5.4  
     5.5  using namespace std;
     5.6  
     5.7 +void test_mime_decoding(string filename) {
     5.8 +    cout << "opening " << filename << " for reading\n";
     5.9 +    ifstream inFile3 (filename);
    5.10 +    assert(inFile3.is_open());
    5.11 +
    5.12 +    string mimetext3;
    5.13 +
    5.14 +    cout << "reading mime sample\n";
    5.15 +    while (!inFile3.eof()) {
    5.16 +        static string line;
    5.17 +        getline(inFile3, line);
    5.18 +        mimetext3 += line + "\n";
    5.19 +    }
    5.20 +    inFile3.close();
    5.21 +
    5.22 +    cout << "decoding message…\n";
    5.23 +    message *msg3;
    5.24 +    PEP_STATUS status3 = mime_decode_message(mimetext3.c_str(), &msg3);
    5.25 +    assert(status3 == PEP_STATUS_OK);
    5.26 +    assert(msg3);
    5.27 +    cout << "decoded.\n\n";
    5.28 +    cout << "Subject: " << msg3->shortmsg << "\n\n";
    5.29 +    if (msg3->longmsg)
    5.30 +        cout << msg3->longmsg << "\n\n";
    5.31 +    if (msg3->longmsg_formatted)
    5.32 +        cout << msg3->longmsg_formatted << "\n\n";
    5.33 +    bloblist_t *_b;
    5.34 +    for (_b = msg3->attachments; _b; _b = _b->next) {
    5.35 +        cout << "attachment of type " << _b->mime_type << "\n";
    5.36 +        if (_b->filename) {
    5.37 +            cout << "filename: " << _b->filename << "\n";
    5.38 +            unlink(_b->filename);
    5.39 +            ofstream outFile3(_b->filename);
    5.40 +            outFile3.write(_b->data, _b->size);
    5.41 +            outFile3.close();
    5.42 +        }
    5.43 +    }
    5.44 +
    5.45 +    free_message(msg3);
    5.46 +}
    5.47 +
    5.48  int main() {
    5.49      cout << "\n*** mime_test ***\n\n";
    5.50  
    5.51 @@ -47,44 +88,9 @@
    5.52      free(result2);
    5.53      free_message(msg2);
    5.54  
    5.55 -    cout << "opening mime_sample.txt for reading\n";
    5.56 -    ifstream inFile3 ("mime_sample.txt");
    5.57 -    assert(inFile3.is_open());
    5.58 -
    5.59 -    string mimetext3;
    5.60 -
    5.61 -    cout << "reading mime sample\n";
    5.62 -    while (!inFile3.eof()) {
    5.63 -        static string line;
    5.64 -        getline(inFile3, line);
    5.65 -        mimetext3 += line + "\n";
    5.66 -    }
    5.67 -    inFile3.close();
    5.68 -
    5.69 -    cout << "decoding message…\n";
    5.70 -    message *msg3;
    5.71 -    PEP_STATUS status3 = mime_decode_message(mimetext3.c_str(), &msg3);
    5.72 -    assert(status3 == PEP_STATUS_OK);
    5.73 -    assert(msg3);
    5.74 -    cout << "decoded.\n\n";
    5.75 -    cout << "Subject: " << msg3->shortmsg << "\n\n";
    5.76 -    if (msg3->longmsg)
    5.77 -        cout << msg3->longmsg << "\n\n";
    5.78 -    if (msg3->longmsg_formatted)
    5.79 -        cout << msg3->longmsg_formatted << "\n\n";
    5.80 -    bloblist_t *_b;
    5.81 -    for (_b = msg3->attachments; _b; _b = _b->next) {
    5.82 -        cout << "attachment of type " << _b->mime_type << "\n";
    5.83 -        if (_b->filename) {
    5.84 -            cout << "filename: " << _b->filename << "\n";
    5.85 -            unlink(_b->filename);
    5.86 -            ofstream outFile3(_b->filename);
    5.87 -            outFile3.write(_b->data, _b->size);
    5.88 -            outFile3.close();
    5.89 -        }
    5.90 -    }
    5.91 -
    5.92 -    free_message(msg3);
    5.93 +    test_mime_decoding("msg1.asc");
    5.94 +    test_mime_decoding("msg2.asc");
    5.95 +    test_mime_decoding("msg3.asc");
    5.96  
    5.97      cout << "calling release()\n";
    5.98      release(session);