TextMessage.cpp
author Volker Birk <vb@pep-project.org>
Tue, 12 May 2015 21:20:18 +0200
changeset 21 775a847a9d09
parent 20 f77dd13806ff
child 22 ce807ab55768
permissions -rw-r--r--
bugfix
vb@8
     1
// TextMessage.cpp : Implementation of CTextMessage
vb@8
     2
vb@8
     3
#include "stdafx.h"
vb@8
     4
#include "TextMessage.h"
vb@8
     5
vb@10
     6
using namespace pEp::utility;
vb@8
     7
vb@8
     8
// CTextMessage
vb@8
     9
vb@8
    10
STDMETHODIMP CTextMessage::InterfaceSupportsErrorInfo(REFIID riid)
vb@8
    11
{
vb@8
    12
	static const IID* const arr[] = 
vb@8
    13
	{
vb@8
    14
		&IID_ITextMessage
vb@8
    15
	};
vb@8
    16
vb@8
    17
	for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
vb@8
    18
	{
vb@8
    19
		if (InlineIsEqualGUID(*arr[i],riid))
vb@8
    20
			return S_OK;
vb@8
    21
	}
vb@8
    22
	return S_FALSE;
vb@8
    23
}
vb@8
    24
vb@8
    25
vb@8
    26
STDMETHODIMP CTextMessage::get_from(pEp_identity_s* pVal)
vb@8
    27
{
vb@13
    28
    assert(pVal);
vb@13
    29
vb@8
    30
    try {
vb@8
    31
        copy_identity(pVal, msg->from);
vb@8
    32
    }
vb@8
    33
    catch (bad_alloc& e) {
vb@8
    34
        return E_OUTOFMEMORY;
vb@8
    35
    }
vb@8
    36
    catch (exception& e) {
vb@8
    37
        return E_FAIL;
vb@8
    38
    }
vb@8
    39
vb@8
    40
    return S_OK;
vb@8
    41
}
vb@8
    42
vb@8
    43
vb@8
    44
STDMETHODIMP CTextMessage::put_from(pEp_identity_s* newVal)
vb@8
    45
{
vb@13
    46
    assert(newVal);
vb@13
    47
vb@8
    48
    ::pEp_identity *_from;
vb@8
    49
    
vb@8
    50
    try {
vb@8
    51
        _from = new_identity(newVal);
vb@8
    52
    }
vb@8
    53
    catch (bad_alloc& e) {
vb@8
    54
        return E_OUTOFMEMORY;
vb@8
    55
    }
vb@8
    56
    catch (exception& e)
vb@8
    57
    {
vb@8
    58
        return E_FAIL;
vb@8
    59
    }
vb@8
    60
vb@8
    61
    ::free_identity(msg->from);
vb@8
    62
    msg->from = _from;
vb@8
    63
    return S_OK;
vb@8
    64
}
vb@13
    65
vb@13
    66
STDMETHODIMP CTextMessage::get_to(LPSAFEARRAY * pVal)
vb@13
    67
{
vb@13
    68
    assert(pVal);
vb@13
    69
vb@13
    70
    int len = identity_list_length(msg->to);
vb@13
    71
vb@13
    72
    LPSAFEARRAY sa = newSafeArray<pEp_identity_s>(len);
vb@13
    73
    if (sa == NULL)
vb@13
    74
        return E_OUTOFMEMORY;
vb@13
    75
vb@13
    76
    pEp_identity_s *cs = accessData<pEp_identity_s>(sa);    
vb@13
    77
vb@13
    78
    identity_list *il = msg->to;
vb@13
    79
    ULONG i;
vb@13
    80
    for (i = 0, il = msg->to; il && il->ident; il = il->next, i++) {
vb@13
    81
        try {
vb@13
    82
            copy_identity(&cs[i], il->ident);
vb@13
    83
        }
vb@13
    84
        catch (bad_alloc& e) {
vb@13
    85
            SafeArrayUnaccessData(sa);
vb@13
    86
            SafeArrayDestroy(sa);
vb@13
    87
            return E_OUTOFMEMORY;
vb@13
    88
        }
vb@13
    89
        catch (exception& e) {
vb@13
    90
            SafeArrayUnaccessData(sa);
vb@13
    91
            SafeArrayDestroy(sa);
vb@13
    92
            return E_FAIL;
vb@13
    93
        }
vb@13
    94
    }
vb@13
    95
vb@13
    96
    SafeArrayUnaccessData(sa);
vb@13
    97
vb@13
    98
    *pVal = sa;
vb@13
    99
    return S_OK;
vb@13
   100
}
vb@13
   101
vb@13
   102
STDMETHODIMP CTextMessage::put_to(SAFEARRAY * newVal)
vb@13
   103
{
vb@13
   104
    assert(newVal);
vb@13
   105
vb@13
   106
    if (newVal == NULL)
vb@13
   107
        return E_INVALIDARG;
vb@13
   108
vb@13
   109
    identity_list *il = new_identity_list(NULL);
vb@13
   110
    if (il == NULL)
vb@13
   111
        return E_OUTOFMEMORY;
vb@13
   112
vb@13
   113
    pEp_identity_s *cs;
vb@13
   114
    HRESULT hr = SafeArrayAccessData(newVal, (void **) &cs);
vb@13
   115
    assert(SUCCEEDED(hr) && cs);
vb@13
   116
    if (cs == NULL) {
vb@13
   117
        free_identity_list(il);
vb@13
   118
        return E_FAIL;
vb@13
   119
    }
vb@13
   120
vb@13
   121
    identity_list *_il;
vb@13
   122
    LONG i, lbound, ubound;
vb@13
   123
    SafeArrayGetLBound(newVal, 1, &lbound);
vb@13
   124
    SafeArrayGetUBound(newVal, 1, &ubound);
vb@13
   125
vb@13
   126
    for (i = lbound, _il = il; i <= ubound; i++) {
vb@13
   127
        pEp_identity * ident;
vb@13
   128
        try {
vb@13
   129
            ident = new_identity(&cs[i]);
vb@13
   130
        }
vb@13
   131
        catch (bad_alloc& e) {
vb@13
   132
            SafeArrayUnaccessData(newVal);
vb@13
   133
            free_identity_list(il);
vb@13
   134
            return E_OUTOFMEMORY;
vb@13
   135
        }
vb@13
   136
        catch (exception& e) {
vb@13
   137
            SafeArrayUnaccessData(newVal);
vb@13
   138
            free_identity_list(il);
vb@13
   139
            return E_FAIL;
vb@13
   140
        }
vb@13
   141
        _il = identity_list_add(_il, ident);
vb@13
   142
        if (_il == NULL) {
vb@13
   143
            SafeArrayUnaccessData(newVal);
vb@13
   144
            free_identity_list(il);
vb@13
   145
            return E_OUTOFMEMORY;
vb@13
   146
        }
vb@13
   147
    }
vb@13
   148
vb@13
   149
    SafeArrayUnaccessData(newVal);
vb@13
   150
    
vb@13
   151
    free_identity_list(msg->to);
vb@13
   152
    msg->to = il;
vb@13
   153
vb@13
   154
    return S_OK;
vb@13
   155
}
vb@15
   156
vb@15
   157
STDMETHODIMP CTextMessage::get_recv_by(pEp_identity_s* pVal)
vb@15
   158
{
vb@15
   159
    assert(pVal);
vb@15
   160
vb@15
   161
    try {
vb@15
   162
        copy_identity(pVal, msg->recv_by);
vb@15
   163
    }
vb@15
   164
    catch (bad_alloc& e) {
vb@15
   165
        return E_OUTOFMEMORY;
vb@15
   166
    }
vb@15
   167
    catch (exception& e) {
vb@15
   168
        return E_FAIL;
vb@15
   169
    }
vb@15
   170
vb@15
   171
    return S_OK;
vb@15
   172
}
vb@15
   173
vb@15
   174
vb@15
   175
STDMETHODIMP CTextMessage::put_recv_by(pEp_identity_s* newVal)
vb@15
   176
{
vb@15
   177
    assert(newVal);
vb@15
   178
vb@15
   179
    ::pEp_identity *_recv_by;
vb@15
   180
vb@15
   181
    try {
vb@15
   182
        _recv_by = new_identity(newVal);
vb@15
   183
    }
vb@15
   184
    catch (bad_alloc& e) {
vb@15
   185
        return E_OUTOFMEMORY;
vb@15
   186
    }
vb@15
   187
    catch (exception& e) {
vb@15
   188
        return E_FAIL;
vb@15
   189
    }
vb@15
   190
vb@15
   191
    ::free_identity(msg->recv_by);
vb@15
   192
    msg->recv_by = _recv_by;
vb@15
   193
    return S_OK;
vb@15
   194
}
vb@15
   195
vb@15
   196
STDMETHODIMP CTextMessage::get_cc(LPSAFEARRAY * pVal)
vb@15
   197
{
vb@15
   198
    assert(pVal);
vb@15
   199
vb@15
   200
    int len = identity_list_length(msg->cc);
vb@15
   201
vb@15
   202
    LPSAFEARRAY sa = newSafeArray<pEp_identity_s>(len);
vb@15
   203
    if (sa == NULL)
vb@15
   204
        return E_OUTOFMEMORY;
vb@15
   205
vb@15
   206
    pEp_identity_s *cs = accessData<pEp_identity_s>(sa);
vb@15
   207
vb@15
   208
    identity_list *il = msg->cc;
vb@15
   209
    ULONG i;
vb@15
   210
    for (i = 0, il = msg->cc; il && il->ident; il = il->next, i++) {
vb@15
   211
        try {
vb@15
   212
            copy_identity(&cs[i], il->ident);
vb@15
   213
        }
vb@15
   214
        catch (bad_alloc& e) {
vb@15
   215
            SafeArrayUnaccessData(sa);
vb@15
   216
            SafeArrayDestroy(sa);
vb@15
   217
            return E_OUTOFMEMORY;
vb@15
   218
        }
vb@15
   219
        catch (exception& e) {
vb@15
   220
            SafeArrayUnaccessData(sa);
vb@15
   221
            SafeArrayDestroy(sa);
vb@15
   222
            return E_FAIL;
vb@15
   223
        }
vb@15
   224
    }
vb@15
   225
vb@15
   226
    SafeArrayUnaccessData(sa);
vb@15
   227
vb@15
   228
    *pVal = sa;
vb@15
   229
    return S_OK;
vb@15
   230
}
vb@15
   231
vb@15
   232
STDMETHODIMP CTextMessage::put_cc(SAFEARRAY * newVal)
vb@15
   233
{
vb@15
   234
    assert(newVal);
vb@15
   235
vb@15
   236
    if (newVal == NULL)
vb@15
   237
        return E_INVALIDARG;
vb@15
   238
vb@15
   239
    identity_list *il = new_identity_list(NULL);
vb@15
   240
    if (il == NULL)
vb@15
   241
        return E_OUTOFMEMORY;
vb@15
   242
vb@15
   243
    pEp_identity_s *cs;
vb@15
   244
    HRESULT hr = SafeArrayAccessData(newVal, (void **) &cs);
vb@15
   245
    assert(SUCCEEDED(hr) && cs);
vb@15
   246
    if (cs == NULL) {
vb@15
   247
        free_identity_list(il);
vb@15
   248
        return E_FAIL;
vb@15
   249
    }
vb@15
   250
vb@15
   251
    identity_list *_il;
vb@15
   252
    LONG i, lbound, ubound;
vb@15
   253
    SafeArrayGetLBound(newVal, 1, &lbound);
vb@15
   254
    SafeArrayGetUBound(newVal, 1, &ubound);
vb@15
   255
vb@15
   256
    for (i = lbound, _il = il; i <= ubound; i++) {
vb@15
   257
        pEp_identity * ident;
vb@15
   258
        try {
vb@15
   259
            ident = new_identity(&cs[i]);
vb@15
   260
        }
vb@15
   261
        catch (bad_alloc& e) {
vb@15
   262
            SafeArrayUnaccessData(newVal);
vb@15
   263
            free_identity_list(il);
vb@15
   264
            return E_OUTOFMEMORY;
vb@15
   265
        }
vb@15
   266
        catch (exception& e) {
vb@15
   267
            SafeArrayUnaccessData(newVal);
vb@15
   268
            free_identity_list(il);
vb@15
   269
            return E_FAIL;
vb@15
   270
        }
vb@15
   271
        _il = identity_list_add(_il, ident);
vb@15
   272
        if (_il == NULL) {
vb@15
   273
            SafeArrayUnaccessData(newVal);
vb@15
   274
            free_identity_list(il);
vb@15
   275
            return E_OUTOFMEMORY;
vb@15
   276
        }
vb@15
   277
    }
vb@15
   278
vb@15
   279
    SafeArrayUnaccessData(newVal);
vb@15
   280
vb@15
   281
    free_identity_list(msg->cc);
vb@15
   282
    msg->cc = il;
vb@15
   283
vb@15
   284
    return S_OK;
vb@15
   285
}
vb@15
   286
vb@15
   287
STDMETHODIMP CTextMessage::get_bcc(LPSAFEARRAY * pVal)
vb@15
   288
{
vb@15
   289
    assert(pVal);
vb@15
   290
vb@15
   291
    int len = identity_list_length(msg->bcc);
vb@15
   292
vb@15
   293
    LPSAFEARRAY sa = newSafeArray<pEp_identity_s>(len);
vb@15
   294
    if (sa == NULL)
vb@15
   295
        return E_OUTOFMEMORY;
vb@15
   296
vb@15
   297
    pEp_identity_s *cs = accessData<pEp_identity_s>(sa);
vb@15
   298
vb@15
   299
    identity_list *il = msg->bcc;
vb@15
   300
    ULONG i;
vb@15
   301
    for (i = 0, il = msg->bcc; il && il->ident; il = il->next, i++) {
vb@15
   302
        try {
vb@15
   303
            copy_identity(&cs[i], il->ident);
vb@15
   304
        }
vb@15
   305
        catch (bad_alloc& e) {
vb@15
   306
            SafeArrayUnaccessData(sa);
vb@15
   307
            SafeArrayDestroy(sa);
vb@15
   308
            return E_OUTOFMEMORY;
vb@15
   309
        }
vb@15
   310
        catch (exception& e) {
vb@15
   311
            SafeArrayUnaccessData(sa);
vb@15
   312
            SafeArrayDestroy(sa);
vb@15
   313
            return E_FAIL;
vb@15
   314
        }
vb@15
   315
    }
vb@15
   316
vb@15
   317
    SafeArrayUnaccessData(sa);
vb@15
   318
vb@15
   319
    *pVal = sa;
vb@15
   320
    return S_OK;
vb@15
   321
}
vb@15
   322
vb@15
   323
STDMETHODIMP CTextMessage::put_bcc(SAFEARRAY * newVal)
vb@15
   324
{
vb@15
   325
    assert(newVal);
vb@15
   326
vb@15
   327
    if (newVal == NULL)
vb@15
   328
        return E_INVALIDARG;
vb@15
   329
vb@15
   330
    identity_list *il = new_identity_list(NULL);
vb@15
   331
    if (il == NULL)
vb@15
   332
        return E_OUTOFMEMORY;
vb@15
   333
vb@15
   334
    pEp_identity_s *cs;
vb@15
   335
    HRESULT hr = SafeArrayAccessData(newVal, (void **) &cs);
vb@15
   336
    assert(SUCCEEDED(hr) && cs);
vb@15
   337
    if (cs == NULL) {
vb@15
   338
        free_identity_list(il);
vb@15
   339
        return E_FAIL;
vb@15
   340
    }
vb@15
   341
vb@15
   342
    identity_list *_il;
vb@15
   343
    LONG i, lbound, ubound;
vb@15
   344
    SafeArrayGetLBound(newVal, 1, &lbound);
vb@15
   345
    SafeArrayGetUBound(newVal, 1, &ubound);
vb@15
   346
vb@15
   347
    for (i = lbound, _il = il; i <= ubound; i++) {
vb@15
   348
        pEp_identity * ident;
vb@15
   349
        try {
vb@15
   350
            ident = new_identity(&cs[i]);
vb@15
   351
        }
vb@15
   352
        catch (bad_alloc& e) {
vb@15
   353
            SafeArrayUnaccessData(newVal);
vb@15
   354
            free_identity_list(il);
vb@15
   355
            return E_OUTOFMEMORY;
vb@15
   356
        }
vb@15
   357
        catch (exception& e) {
vb@15
   358
            SafeArrayUnaccessData(newVal);
vb@15
   359
            free_identity_list(il);
vb@15
   360
            return E_FAIL;
vb@15
   361
        }
vb@15
   362
        _il = identity_list_add(_il, ident);
vb@15
   363
        if (_il == NULL) {
vb@15
   364
            SafeArrayUnaccessData(newVal);
vb@15
   365
            free_identity_list(il);
vb@15
   366
            return E_OUTOFMEMORY;
vb@15
   367
        }
vb@15
   368
    }
vb@15
   369
vb@15
   370
    SafeArrayUnaccessData(newVal);
vb@15
   371
vb@15
   372
    free_identity_list(msg->bcc);
vb@15
   373
    msg->bcc = il;
vb@15
   374
vb@15
   375
    return S_OK;
vb@15
   376
}
vb@15
   377
vb@15
   378
STDMETHODIMP CTextMessage::get_reply_to(LPSAFEARRAY * pVal)
vb@15
   379
{
vb@15
   380
    assert(pVal);
vb@15
   381
vb@15
   382
    int len = identity_list_length(msg->reply_to);
vb@15
   383
vb@15
   384
    LPSAFEARRAY sa = newSafeArray<pEp_identity_s>(len);
vb@15
   385
    if (sa == NULL)
vb@15
   386
        return E_OUTOFMEMORY;
vb@15
   387
vb@15
   388
    pEp_identity_s *cs = accessData<pEp_identity_s>(sa);
vb@15
   389
vb@15
   390
    identity_list *il = msg->reply_to;
vb@15
   391
    ULONG i;
vb@15
   392
    for (i = 0, il = msg->reply_to; il && il->ident; il = il->next, i++) {
vb@15
   393
        try {
vb@15
   394
            copy_identity(&cs[i], il->ident);
vb@15
   395
        }
vb@15
   396
        catch (bad_alloc& e) {
vb@15
   397
            SafeArrayUnaccessData(sa);
vb@15
   398
            SafeArrayDestroy(sa);
vb@15
   399
            return E_OUTOFMEMORY;
vb@15
   400
        }
vb@15
   401
        catch (exception& e) {
vb@15
   402
            SafeArrayUnaccessData(sa);
vb@15
   403
            SafeArrayDestroy(sa);
vb@15
   404
            return E_FAIL;
vb@15
   405
        }
vb@15
   406
    }
vb@15
   407
vb@15
   408
    SafeArrayUnaccessData(sa);
vb@15
   409
vb@15
   410
    *pVal = sa;
vb@15
   411
    return S_OK;
vb@15
   412
}
vb@15
   413
vb@15
   414
STDMETHODIMP CTextMessage::put_reply_to(SAFEARRAY * newVal)
vb@15
   415
{
vb@15
   416
    assert(newVal);
vb@15
   417
vb@15
   418
    if (newVal == NULL)
vb@15
   419
        return E_INVALIDARG;
vb@15
   420
vb@15
   421
    identity_list *il = new_identity_list(NULL);
vb@15
   422
    if (il == NULL)
vb@15
   423
        return E_OUTOFMEMORY;
vb@15
   424
vb@15
   425
    pEp_identity_s *cs;
vb@15
   426
    HRESULT hr = SafeArrayAccessData(newVal, (void **) &cs);
vb@15
   427
    assert(SUCCEEDED(hr) && cs);
vb@15
   428
    if (cs == NULL) {
vb@15
   429
        free_identity_list(il);
vb@15
   430
        return E_FAIL;
vb@15
   431
    }
vb@15
   432
vb@15
   433
    identity_list *_il;
vb@15
   434
    LONG i, lbound, ubound;
vb@15
   435
    SafeArrayGetLBound(newVal, 1, &lbound);
vb@15
   436
    SafeArrayGetUBound(newVal, 1, &ubound);
vb@15
   437
vb@15
   438
    for (i = lbound, _il = il; i <= ubound; i++) {
vb@15
   439
        pEp_identity * ident;
vb@15
   440
        try {
vb@15
   441
            ident = new_identity(&cs[i]);
vb@15
   442
        }
vb@15
   443
        catch (bad_alloc& e) {
vb@15
   444
            SafeArrayUnaccessData(newVal);
vb@15
   445
            free_identity_list(il);
vb@15
   446
            return E_OUTOFMEMORY;
vb@15
   447
        }
vb@15
   448
        catch (exception& e) {
vb@15
   449
            SafeArrayUnaccessData(newVal);
vb@15
   450
            free_identity_list(il);
vb@15
   451
            return E_FAIL;
vb@15
   452
        }
vb@15
   453
        _il = identity_list_add(_il, ident);
vb@15
   454
        if (_il == NULL) {
vb@15
   455
            SafeArrayUnaccessData(newVal);
vb@15
   456
            free_identity_list(il);
vb@15
   457
            return E_OUTOFMEMORY;
vb@15
   458
        }
vb@15
   459
    }
vb@15
   460
vb@15
   461
    SafeArrayUnaccessData(newVal);
vb@15
   462
vb@15
   463
    free_identity_list(msg->reply_to);
vb@15
   464
    msg->reply_to = il;
vb@15
   465
vb@15
   466
    return S_OK;
vb@15
   467
}
vb@15
   468
vb@15
   469
STDMETHODIMP CTextMessage::get_dir(pEp_msg_direction *pVal)
vb@15
   470
{
vb@15
   471
    assert(pVal);
vb@15
   472
vb@15
   473
    *pVal = (pEp_msg_direction) msg->dir;
vb@15
   474
vb@15
   475
    return S_OK;
vb@15
   476
}
vb@15
   477
vb@15
   478
STDMETHODIMP CTextMessage::put_dir(pEp_msg_direction newVal)
vb@15
   479
{
vb@15
   480
    msg->dir = (PEP_msg_direction) newVal;
vb@15
   481
vb@15
   482
    return S_OK;
vb@15
   483
}
vb@15
   484
vb@15
   485
STDMETHODIMP CTextMessage::get_id(BSTR * pVal)
vb@15
   486
{
vb@15
   487
    assert(pVal);
vb@15
   488
vb@15
   489
    _bstr_t val;
vb@15
   490
vb@15
   491
    if (msg->id) {
vb@15
   492
        try {
vb@15
   493
            val = utf16_bstr(msg->id);
vb@15
   494
        }
vb@15
   495
        catch (bad_alloc& e) {
vb@15
   496
            return E_OUTOFMEMORY;
vb@15
   497
        }
vb@15
   498
        catch (exception& e) {
vb@15
   499
            return E_FAIL;
vb@15
   500
        }
vb@21
   501
        *pVal = val.Detach();
vb@15
   502
    }
vb@15
   503
vb@15
   504
    return S_OK;
vb@15
   505
}
vb@15
   506
vb@15
   507
STDMETHODIMP CTextMessage::put_id(BSTR newVal)
vb@15
   508
{
vb@15
   509
    assert(newVal);
vb@15
   510
vb@15
   511
    string val;
vb@15
   512
vb@15
   513
    try {
vb@15
   514
        val = utf8_string(newVal);
vb@15
   515
    }
vb@15
   516
    catch (bad_alloc& e) {
vb@15
   517
        return E_OUTOFMEMORY;
vb@15
   518
    }
vb@15
   519
    catch (exception& e) {
vb@15
   520
        return E_FAIL;
vb@15
   521
    }
vb@15
   522
vb@15
   523
    if (msg->id)
vb@15
   524
        free(msg->id);
vb@15
   525
vb@15
   526
    msg->id = _strdup(val.c_str());
vb@15
   527
    if (msg->id == NULL)
vb@15
   528
        return E_OUTOFMEMORY;
vb@15
   529
vb@15
   530
    return S_OK;
vb@15
   531
}
vb@15
   532
vb@15
   533
STDMETHODIMP CTextMessage::get_shortmsg(BSTR * pVal)
vb@15
   534
{
vb@15
   535
    assert(pVal);
vb@15
   536
vb@15
   537
    _bstr_t val;
vb@15
   538
vb@15
   539
    if (msg->shortmsg) {
vb@15
   540
        try {
vb@15
   541
            val = utf16_bstr(msg->shortmsg);
vb@15
   542
        }
vb@15
   543
        catch (bad_alloc& e) {
vb@15
   544
            return E_OUTOFMEMORY;
vb@15
   545
        }
vb@15
   546
        catch (exception& e) {
vb@15
   547
            return E_FAIL;
vb@15
   548
        }
vb@21
   549
        *pVal = val.Detach();
vb@15
   550
    }
vb@15
   551
vb@15
   552
    return S_OK;
vb@15
   553
}
vb@15
   554
vb@15
   555
STDMETHODIMP CTextMessage::put_shortmsg(BSTR newVal)
vb@15
   556
{
vb@15
   557
    assert(newVal);
vb@15
   558
vb@15
   559
    string val;
vb@15
   560
vb@15
   561
    try {
vb@15
   562
        val = utf8_string(newVal);
vb@15
   563
    }
vb@15
   564
    catch (bad_alloc& e) {
vb@15
   565
        return E_OUTOFMEMORY;
vb@15
   566
    }
vb@15
   567
    catch (exception& e) {
vb@15
   568
        return E_FAIL;
vb@15
   569
    }
vb@15
   570
vb@15
   571
    if (msg->shortmsg)
vb@15
   572
        free(msg->shortmsg);
vb@15
   573
vb@15
   574
    msg->shortmsg = _strdup(val.c_str());
vb@15
   575
    if (msg->shortmsg == NULL)
vb@15
   576
        return E_OUTOFMEMORY;
vb@15
   577
vb@15
   578
    return S_OK;
vb@15
   579
}
vb@15
   580
vb@15
   581
STDMETHODIMP CTextMessage::get_longmsg(BSTR * pVal)
vb@15
   582
{
vb@15
   583
    assert(pVal);
vb@15
   584
vb@15
   585
    _bstr_t val;
vb@15
   586
vb@15
   587
    if (msg->longmsg) {
vb@15
   588
        try {
vb@15
   589
            val = utf16_bstr(msg->longmsg);
vb@15
   590
        }
vb@15
   591
        catch (bad_alloc& e) {
vb@15
   592
            return E_OUTOFMEMORY;
vb@15
   593
        }
vb@15
   594
        catch (exception& e) {
vb@15
   595
            return E_FAIL;
vb@15
   596
        }
vb@21
   597
        *pVal = val.Detach();
vb@15
   598
    }
vb@15
   599
vb@15
   600
    return S_OK;
vb@15
   601
}
vb@15
   602
vb@15
   603
STDMETHODIMP CTextMessage::put_longmsg(BSTR newVal)
vb@15
   604
{
vb@15
   605
    assert(newVal);
vb@15
   606
vb@15
   607
    string val;
vb@15
   608
vb@15
   609
    try {
vb@15
   610
        val = utf8_string(newVal);
vb@15
   611
    }
vb@15
   612
    catch (bad_alloc& e) {
vb@15
   613
        return E_OUTOFMEMORY;
vb@15
   614
    }
vb@15
   615
    catch (exception& e) {
vb@15
   616
        return E_FAIL;
vb@15
   617
    }
vb@15
   618
vb@15
   619
    if (msg->longmsg)
vb@15
   620
        free(msg->longmsg);
vb@15
   621
vb@15
   622
    msg->longmsg = _strdup(val.c_str());
vb@15
   623
    if (msg->longmsg == NULL)
vb@15
   624
        return E_OUTOFMEMORY;
vb@15
   625
vb@15
   626
    return S_OK;
vb@15
   627
}
vb@15
   628
vb@15
   629
STDMETHODIMP CTextMessage::get_longmsg_formatted(BSTR * pVal)
vb@15
   630
{
vb@15
   631
    assert(pVal);
vb@15
   632
vb@15
   633
    _bstr_t val;
vb@15
   634
vb@15
   635
    if (msg->longmsg_formatted) {
vb@15
   636
        try {
vb@15
   637
            val = utf16_bstr(msg->longmsg_formatted);
vb@15
   638
        }
vb@15
   639
        catch (bad_alloc& e) {
vb@15
   640
            return E_OUTOFMEMORY;
vb@15
   641
        }
vb@15
   642
        catch (exception& e) {
vb@15
   643
            return E_FAIL;
vb@15
   644
        }
vb@21
   645
        *pVal = val.Detach();
vb@15
   646
    }
vb@15
   647
vb@15
   648
    return S_OK;
vb@15
   649
}
vb@15
   650
vb@15
   651
STDMETHODIMP CTextMessage::put_longmsg_formatted(BSTR newVal)
vb@15
   652
{
vb@15
   653
    assert(newVal);
vb@15
   654
vb@15
   655
    string val;
vb@15
   656
vb@15
   657
    try {
vb@15
   658
        val = utf8_string(newVal);
vb@15
   659
    }
vb@15
   660
    catch (bad_alloc& e) {
vb@15
   661
        return E_OUTOFMEMORY;
vb@15
   662
    }
vb@15
   663
    catch (exception& e) {
vb@15
   664
        return E_FAIL;
vb@15
   665
    }
vb@15
   666
vb@15
   667
    if (msg->longmsg_formatted)
vb@15
   668
        free(msg->longmsg_formatted);
vb@15
   669
vb@15
   670
    msg->longmsg_formatted = _strdup(val.c_str());
vb@15
   671
    if (msg->longmsg_formatted == NULL)
vb@15
   672
        return E_OUTOFMEMORY;
vb@15
   673
vb@15
   674
    return S_OK;
vb@15
   675
}
vb@15
   676
vb@15
   677
STDMETHODIMP CTextMessage::add_attachment(SAFEARRAY * data, BSTR mime_type, BSTR filename)
vb@15
   678
{
vb@15
   679
    assert(data);
vb@15
   680
    if (data == NULL)
vb@15
   681
        return E_INVALIDARG;
vb@15
   682
vb@15
   683
    CComSafeArray<BYTE> sa_data(data);
vb@15
   684
    size_t len = sa_data.GetCount();
vb@15
   685
vb@15
   686
    char *_data = (char *) malloc(sa_data.GetCount());
vb@15
   687
    assert(_data);
vb@15
   688
    if (_data == NULL)
vb@15
   689
        return E_OUTOFMEMORY;
vb@15
   690
vb@15
   691
    memcpy(_data, sa_data.m_psa->pvData, len);
vb@15
   692
    sa_data.Detach();
vb@15
   693
vb@15
   694
    string _mime_type;
vb@15
   695
    if (mime_type) {
vb@15
   696
        try {
vb@15
   697
            _mime_type = utf8_string(mime_type);
vb@15
   698
        }
vb@15
   699
        catch (bad_alloc& e) {
vb@15
   700
            free(_data);
vb@15
   701
            return E_OUTOFMEMORY;
vb@15
   702
        }
vb@15
   703
        catch (exception& e) {
vb@15
   704
            free(_data);
vb@15
   705
            return E_FAIL;
vb@15
   706
        }
vb@15
   707
    }
vb@15
   708
vb@15
   709
    string _filename;
vb@15
   710
    if (filename) {
vb@15
   711
        try {
vb@15
   712
            _filename = utf8_string(filename);
vb@15
   713
        }
vb@15
   714
        catch (bad_alloc& e) {
vb@15
   715
            free(_data);
vb@15
   716
            return E_OUTOFMEMORY;
vb@15
   717
        }
vb@15
   718
        catch (exception& e) {
vb@15
   719
            free(_data);
vb@15
   720
            return E_FAIL;
vb@15
   721
        }
vb@15
   722
    }
vb@15
   723
vb@15
   724
    bloblist_t *blob = bloblist_add(msg->attachments, _data, len, _mime_type.c_str(), _filename.c_str());
vb@15
   725
    if (blob == NULL) {
vb@15
   726
        free(_data);
vb@15
   727
        return E_OUTOFMEMORY;
vb@15
   728
    }
vb@15
   729
vb@20
   730
    if (msg->attachments == NULL)
vb@20
   731
        msg->attachments = blob;
vb@20
   732
vb@15
   733
    return S_OK;
vb@15
   734
}
vb@15
   735
vb@15
   736
STDMETHODIMP CTextMessage::has_attachments(boolean *result)
vb@15
   737
{
vb@15
   738
    assert(result);
vb@15
   739
vb@15
   740
    if (msg->attachments == NULL || msg->attachments->data == NULL) {
vb@15
   741
        m_next_attachment = NULL;
vb@15
   742
        *result = false;
vb@15
   743
        return S_OK;
vb@15
   744
    }
vb@15
   745
vb@15
   746
    m_next_attachment = msg->attachments;
vb@15
   747
    *result = true;
vb@15
   748
vb@15
   749
    return S_OK;
vb@15
   750
}
vb@15
   751
vb@15
   752
STDMETHODIMP CTextMessage::next_attachment(SAFEARRAY ** data, BSTR * mime_type, BSTR * filename, boolean *result)
vb@15
   753
{
vb@15
   754
    assert(data);
vb@15
   755
    assert(mime_type);
vb@15
   756
    assert(filename);
vb@15
   757
    assert(result);
vb@15
   758
vb@15
   759
    if (m_next_attachment == NULL)
vb@15
   760
        return E_ILLEGAL_METHOD_CALL;
vb@15
   761
vb@15
   762
    CComSafeArray<BYTE> sa;
vb@15
   763
    try {
vb@15
   764
        sa.Create(m_next_attachment->size);
vb@15
   765
    }
vb@15
   766
    catch (bad_alloc& e) {
vb@15
   767
        return E_OUTOFMEMORY;
vb@15
   768
    }
vb@15
   769
vb@15
   770
    memcpy(sa.m_psa->pvData, m_next_attachment->data, m_next_attachment->size);
vb@15
   771
vb@15
   772
    _bstr_t _mime_type;
vb@15
   773
    if (m_next_attachment->mime_type) {
vb@15
   774
        try {
vb@15
   775
            _mime_type = utf16_bstr(m_next_attachment->mime_type);
vb@15
   776
        }
vb@15
   777
        catch (bad_alloc& e) {
vb@15
   778
            return E_OUTOFMEMORY;
vb@15
   779
        }
vb@15
   780
        catch (exception& e) {
vb@15
   781
            return E_FAIL;
vb@15
   782
        }
vb@15
   783
    }
vb@15
   784
vb@15
   785
    _bstr_t _filename;
vb@15
   786
    if (m_next_attachment->filename) {
vb@15
   787
        try {
vb@15
   788
            _filename = utf16_bstr(m_next_attachment->filename);
vb@15
   789
        }
vb@15
   790
        catch (bad_alloc& e) {
vb@15
   791
            return E_OUTOFMEMORY;
vb@15
   792
        }
vb@15
   793
        catch (exception& e) {
vb@15
   794
            return E_FAIL;
vb@15
   795
        }
vb@15
   796
    }
vb@15
   797
vb@15
   798
    *data = sa.Detach();
vb@15
   799
    *mime_type = _mime_type.Detach();
vb@15
   800
    *filename = _filename.Detach();
vb@15
   801
vb@15
   802
    m_next_attachment = m_next_attachment->next;
vb@15
   803
    *result = m_next_attachment != NULL;
vb@15
   804
vb@15
   805
    return S_OK;
vb@15
   806
}
vb@15
   807
vb@15
   808
STDMETHODIMP CTextMessage::get_sent(hyper * result)
vb@15
   809
{
vb@15
   810
    assert(result);
vb@15
   811
vb@15
   812
    if (msg->sent == NULL)
vb@15
   813
        return E_NOT_SET;
vb@15
   814
vb@15
   815
    *result = mktime(msg->sent);
vb@15
   816
    return S_OK;
vb@15
   817
}
vb@15
   818
vb@15
   819
STDMETHODIMP CTextMessage::put_sent(hyper val)
vb@15
   820
{
vb@15
   821
    ::timestamp * ts = new_timestamp(val);
vb@15
   822
    if (ts == NULL)
vb@15
   823
        return E_OUTOFMEMORY;
vb@15
   824
vb@15
   825
    if (msg->sent)
vb@15
   826
        free_timestamp(msg->sent);
vb@15
   827
    msg->sent = ts;
vb@15
   828
vb@15
   829
    return S_OK;
vb@15
   830
}
vb@15
   831
vb@15
   832
STDMETHODIMP CTextMessage::get_recv(hyper * result)
vb@15
   833
{
vb@15
   834
    assert(result);
vb@15
   835
vb@15
   836
    if (msg->recv == NULL)
vb@15
   837
        return E_NOT_SET;
vb@15
   838
vb@15
   839
    *result = mktime(msg->recv);
vb@15
   840
    return S_OK;
vb@15
   841
}
vb@15
   842
vb@15
   843
STDMETHODIMP CTextMessage::put_recv(hyper val)
vb@15
   844
{
vb@15
   845
    ::timestamp * ts = new_timestamp(val);
vb@15
   846
    if (ts == NULL)
vb@15
   847
        return E_OUTOFMEMORY;
vb@15
   848
vb@15
   849
    if (msg->recv)
vb@15
   850
        free_timestamp(msg->recv);
vb@15
   851
    msg->recv = ts;
vb@15
   852
vb@15
   853
    return S_OK;
vb@15
   854
}
vb@15
   855
vb@15
   856
STDMETHODIMP CTextMessage::get_references(SAFEARRAY ** pVal)
vb@15
   857
{
vb@15
   858
    assert(pVal);
vb@15
   859
vb@15
   860
    CComSafeArray<BSTR> sa;
vb@15
   861
    try {
vb@15
   862
        if (msg->references) {
vb@15
   863
            sa = string_array(msg->references);
vb@15
   864
        }
vb@15
   865
        else {
vb@15
   866
            sa.Create(0UL);
vb@15
   867
        }
vb@15
   868
    }
vb@15
   869
    catch (bad_alloc& e) {
vb@15
   870
        return E_OUTOFMEMORY;
vb@15
   871
    }
vb@15
   872
    catch (exception& e) {
vb@15
   873
        return E_FAIL;
vb@15
   874
    }
vb@15
   875
    
vb@15
   876
    *pVal = sa.Detach();
vb@15
   877
    return S_OK;
vb@15
   878
}
vb@15
   879
vb@15
   880
STDMETHODIMP CTextMessage::put_references(SAFEARRAY * newVal)
vb@15
   881
{
vb@15
   882
    assert(newVal);
vb@15
   883
vb@15
   884
    stringlist_t *sl;
vb@15
   885
    
vb@15
   886
    try {
vb@15
   887
        sl = new_stringlist(newVal);
vb@15
   888
    }
vb@15
   889
    catch (bad_alloc& e) {
vb@15
   890
        return E_OUTOFMEMORY;
vb@15
   891
    }
vb@15
   892
    catch (exception& e) {
vb@15
   893
        return E_FAIL;
vb@15
   894
    }
vb@15
   895
vb@15
   896
    if (msg->references)
vb@15
   897
        free_stringlist(msg->references);
vb@15
   898
vb@15
   899
    msg->references = sl;
vb@15
   900
vb@15
   901
    return S_OK;
vb@15
   902
}
vb@15
   903
vb@15
   904
STDMETHODIMP CTextMessage::get_keywords(SAFEARRAY ** pVal)
vb@15
   905
{
vb@15
   906
    assert(pVal);
vb@15
   907
vb@15
   908
    CComSafeArray<BSTR> sa;
vb@15
   909
    try {
vb@15
   910
        if (msg->keywords) {
vb@15
   911
            sa = string_array(msg->keywords);
vb@15
   912
        }
vb@15
   913
        else {
vb@15
   914
            sa.Create(0UL);
vb@15
   915
        }
vb@15
   916
    }
vb@15
   917
    catch (bad_alloc& e) {
vb@15
   918
        return E_OUTOFMEMORY;
vb@15
   919
    }
vb@15
   920
    catch (exception& e) {
vb@15
   921
        return E_FAIL;
vb@15
   922
    }
vb@15
   923
vb@15
   924
    *pVal = sa.Detach();
vb@15
   925
    return S_OK;
vb@15
   926
}
vb@15
   927
vb@15
   928
STDMETHODIMP CTextMessage::put_keywords(SAFEARRAY * newVal)
vb@15
   929
{
vb@15
   930
    assert(newVal);
vb@15
   931
vb@15
   932
    stringlist_t *sl;
vb@15
   933
vb@15
   934
    try {
vb@15
   935
        sl = new_stringlist(newVal);
vb@15
   936
    }
vb@15
   937
    catch (bad_alloc& e) {
vb@15
   938
        return E_OUTOFMEMORY;
vb@15
   939
    }
vb@15
   940
    catch (exception& e) {
vb@15
   941
        return E_FAIL;
vb@15
   942
    }
vb@15
   943
vb@15
   944
    if (msg->keywords)
vb@15
   945
        free_stringlist(msg->keywords);
vb@15
   946
vb@15
   947
    msg->keywords = sl;
vb@15
   948
vb@15
   949
    return S_OK;
vb@15
   950
}
vb@15
   951
vb@15
   952
STDMETHODIMP CTextMessage::get_comments(BSTR * pVal)
vb@15
   953
{
vb@15
   954
    assert(pVal);
vb@15
   955
vb@15
   956
    _bstr_t val;
vb@15
   957
vb@15
   958
    if (msg->comments) {
vb@15
   959
        try {
vb@15
   960
            val = utf16_bstr(msg->comments);
vb@15
   961
        }
vb@15
   962
        catch (bad_alloc& e) {
vb@15
   963
            return E_OUTOFMEMORY;
vb@15
   964
        }
vb@15
   965
        catch (exception& e) {
vb@15
   966
            return E_FAIL;
vb@15
   967
        }
vb@21
   968
        *pVal = val.Detach();
vb@15
   969
    }
vb@15
   970
vb@15
   971
    return S_OK;
vb@15
   972
}
vb@15
   973
vb@15
   974
STDMETHODIMP CTextMessage::put_comments(BSTR newVal)
vb@15
   975
{
vb@15
   976
    assert(newVal);
vb@15
   977
vb@15
   978
    string val;
vb@15
   979
vb@15
   980
    try {
vb@15
   981
        val = utf8_string(newVal);
vb@15
   982
    }
vb@15
   983
    catch (bad_alloc& e) {
vb@15
   984
        return E_OUTOFMEMORY;
vb@15
   985
    }
vb@15
   986
    catch (exception& e) {
vb@15
   987
        return E_FAIL;
vb@15
   988
    }
vb@15
   989
vb@15
   990
    if (msg->comments)
vb@15
   991
        free(msg->comments);
vb@15
   992
vb@15
   993
    msg->comments = _strdup(val.c_str());
vb@15
   994
    if (msg->comments == NULL)
vb@15
   995
        return E_OUTOFMEMORY;
vb@15
   996
vb@15
   997
    return S_OK;
vb@15
   998
}