CpEpEngine.cpp
changeset 19 3cfb847e13cd
parent 18 79c848166413
child 20 f77dd13806ff
     1.1 --- a/CpEpEngine.cpp	Tue May 05 10:27:36 2015 +0200
     1.2 +++ b/CpEpEngine.cpp	Fri May 08 10:07:08 2015 +0200
     1.3 @@ -888,11 +888,12 @@
     1.4      return S_OK;
     1.5  }
     1.6  
     1.7 -STDMETHODIMP CpEpEngine::decrypt_message(ITextMessage * src, ITextMessage ** dst, SAFEARRAY ** keylist)
     1.8 +STDMETHODIMP CpEpEngine::decrypt_message(ITextMessage * src, ITextMessage ** dst, SAFEARRAY ** keylist, pEp_color *rating)
     1.9  {
    1.10      assert(src);
    1.11      assert(dst);
    1.12      assert(keylist);
    1.13 +    assert(rating);
    1.14  
    1.15      CTextMessage *_src = dynamic_cast<CTextMessage *>(src);
    1.16      assert(_src);
    1.17 @@ -902,45 +903,58 @@
    1.18  
    1.19      ::message *msg_dst;
    1.20      ::stringlist_t *_keylist;
    1.21 -    PEP_STATUS status = ::decrypt_message(get_session(), _src->msg, PEP_MIME_none, &msg_dst, &_keylist);
    1.22 -    if (status != PEP_STATUS_OK)
    1.23 -        FAIL(L"cannot decrypt message");
    1.24 +    ::PEP_color _rating;
    1.25  
    1.26 -    assert(msg_dst);
    1.27 +    PEP_STATUS status = ::decrypt_message(get_session(), _src->msg, PEP_MIME_none, &msg_dst, &_keylist, &_rating);
    1.28 +    if (status != PEP_STATUS_OK && (status < PEP_UNENCRYPTED || status > PEP_CANNOT_DECRYPT_UNKNOWN))
    1.29 +        return FAIL(L"decrypt message failed");
    1.30  
    1.31 -    ITextMessage *i_dst;
    1.32 -    HRESULT hr = CTextMessage::CreateInstance(&i_dst);
    1.33 -    assert(hr == S_OK);
    1.34 +    if (msg_dst) {
    1.35 +        ITextMessage *i_dst;
    1.36 +        HRESULT hr = CTextMessage::CreateInstance(&i_dst);
    1.37 +        assert(hr == S_OK);
    1.38  
    1.39 -    if (hr != S_OK) {
    1.40 -        ::free_message(msg_dst);
    1.41 -        ::free_stringlist(_keylist);
    1.42 -        return hr;
    1.43 +        if (hr != S_OK) {
    1.44 +            ::free_message(msg_dst);
    1.45 +            ::free_stringlist(_keylist);
    1.46 +            return hr;
    1.47 +        }
    1.48 +
    1.49 +        CTextMessage *_dst = dynamic_cast<CTextMessage *>(i_dst);
    1.50 +        assert(_dst);
    1.51 +
    1.52 +        ::free_message(_dst->msg);
    1.53 +        _dst->msg = msg_dst;
    1.54 +
    1.55 +        *dst = i_dst;
    1.56 +    }
    1.57 +    else {
    1.58 +        *dst = NULL;
    1.59      }
    1.60  
    1.61 -    CTextMessage *_dst = dynamic_cast<CTextMessage *>(i_dst);
    1.62 -    assert(_dst);
    1.63 +    if (_keylist) {
    1.64 +        ULONG len = ::stringlist_length(_keylist);
    1.65 +        CComSafeArray<BSTR> sa;
    1.66 +        sa.Create(len);
    1.67  
    1.68 -    ::free_message(_dst->msg);
    1.69 -    _dst->msg = msg_dst;
    1.70 +        ::stringlist_t *_kl;
    1.71 +        ULONG i;
    1.72 +        for (_kl = _keylist, i = 0; _kl && _kl->value; _kl = _kl->next, i++)
    1.73 +            sa.SetAt(i, utf16_bstr(_kl->value).Detach(), false);
    1.74 +        ::free_stringlist(_keylist);
    1.75  
    1.76 -    ULONG len = ::stringlist_length(_keylist);
    1.77 -    CComSafeArray<BSTR> sa;
    1.78 -    sa.Create(len);
    1.79 +        *keylist = sa.Detach();
    1.80 +    }
    1.81 +    else {
    1.82 +        *keylist = NULL;
    1.83 +    }
    1.84  
    1.85 -    ::stringlist_t *_kl;
    1.86 -    ULONG i;
    1.87 -    for (_kl = _keylist, i = 0; _kl && _kl->value; _kl = _kl->next, i++)
    1.88 -        sa.SetAt(i, utf16_bstr(_kl->value).Detach(), false);
    1.89 -    ::free_stringlist(_keylist);
    1.90 -
    1.91 -    *dst = i_dst;
    1.92 -    *keylist = sa.Detach();
    1.93 +    *rating = (pEp_color) _rating;
    1.94  
    1.95      return S_OK;
    1.96  }
    1.97  
    1.98 -STDMETHODIMP CpEpEngine::message_color(ITextMessage *msg, pEp_color * pVal)
    1.99 +STDMETHODIMP CpEpEngine::outgoing_message_color(ITextMessage *msg, pEp_color * pVal)
   1.100  {
   1.101      assert(msg);
   1.102      assert(pVal);
   1.103 @@ -948,10 +962,13 @@
   1.104      CTextMessage *_msg = dynamic_cast<CTextMessage *>(msg);
   1.105      assert(_msg);
   1.106  
   1.107 +    if (_msg->msg->dir != PEP_dir_outgoing)
   1.108 +        return E_INVALIDARG;
   1.109 +
   1.110      PEP_color _color;
   1.111 -    PEP_STATUS status = ::message_color(get_session(), _msg->msg, &_color);
   1.112 +    PEP_STATUS status = ::outgoing_message_color(get_session(), _msg->msg, &_color);
   1.113      if (status != PEP_STATUS_OK)
   1.114 -        FAIL(L"cannot get message color");
   1.115 +        return FAIL(L"cannot get message color");
   1.116  
   1.117      *pVal = (pEp_color) _color;
   1.118      return S_OK;
   1.119 @@ -978,7 +995,7 @@
   1.120      PEP_STATUS status = ::identity_color(get_session(), _ident, &_color);
   1.121      free_identity(_ident);
   1.122      if (status != PEP_STATUS_OK)
   1.123 -        FAIL(L"cannot get message color");
   1.124 +        return FAIL(L"cannot get message color");
   1.125  
   1.126      *pVal = (pEp_color) _color;
   1.127      return S_OK;