TextMessage.cpp
author Volker Birk <vb@pep-project.org>
Tue, 12 May 2015 14:13:52 +0200
changeset 20 f77dd13806ff
parent 15 b1c2c371379c
child 21 775a847a9d09
permissions -rw-r--r--
bug fixing
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@15
   501
    }
vb@15
   502
vb@15
   503
    *pVal = val.Detach();
vb@15
   504
vb@15
   505
    return S_OK;
vb@15
   506
}
vb@15
   507
vb@15
   508
STDMETHODIMP CTextMessage::put_id(BSTR newVal)
vb@15
   509
{
vb@15
   510
    assert(newVal);
vb@15
   511
vb@15
   512
    string val;
vb@15
   513
vb@15
   514
    try {
vb@15
   515
        val = utf8_string(newVal);
vb@15
   516
    }
vb@15
   517
    catch (bad_alloc& e) {
vb@15
   518
        return E_OUTOFMEMORY;
vb@15
   519
    }
vb@15
   520
    catch (exception& e) {
vb@15
   521
        return E_FAIL;
vb@15
   522
    }
vb@15
   523
vb@15
   524
    if (msg->id)
vb@15
   525
        free(msg->id);
vb@15
   526
vb@15
   527
    msg->id = _strdup(val.c_str());
vb@15
   528
    if (msg->id == NULL)
vb@15
   529
        return E_OUTOFMEMORY;
vb@15
   530
vb@15
   531
    return S_OK;
vb@15
   532
}
vb@15
   533
vb@15
   534
STDMETHODIMP CTextMessage::get_shortmsg(BSTR * pVal)
vb@15
   535
{
vb@15
   536
    assert(pVal);
vb@15
   537
vb@15
   538
    _bstr_t val;
vb@15
   539
vb@15
   540
    if (msg->shortmsg) {
vb@15
   541
        try {
vb@15
   542
            val = utf16_bstr(msg->shortmsg);
vb@15
   543
        }
vb@15
   544
        catch (bad_alloc& e) {
vb@15
   545
            return E_OUTOFMEMORY;
vb@15
   546
        }
vb@15
   547
        catch (exception& e) {
vb@15
   548
            return E_FAIL;
vb@15
   549
        }
vb@15
   550
    }
vb@15
   551
vb@15
   552
    *pVal = val.Detach();
vb@15
   553
vb@15
   554
    return S_OK;
vb@15
   555
}
vb@15
   556
vb@15
   557
STDMETHODIMP CTextMessage::put_shortmsg(BSTR newVal)
vb@15
   558
{
vb@15
   559
    assert(newVal);
vb@15
   560
vb@15
   561
    string val;
vb@15
   562
vb@15
   563
    try {
vb@15
   564
        val = utf8_string(newVal);
vb@15
   565
    }
vb@15
   566
    catch (bad_alloc& e) {
vb@15
   567
        return E_OUTOFMEMORY;
vb@15
   568
    }
vb@15
   569
    catch (exception& e) {
vb@15
   570
        return E_FAIL;
vb@15
   571
    }
vb@15
   572
vb@15
   573
    if (msg->shortmsg)
vb@15
   574
        free(msg->shortmsg);
vb@15
   575
vb@15
   576
    msg->shortmsg = _strdup(val.c_str());
vb@15
   577
    if (msg->shortmsg == NULL)
vb@15
   578
        return E_OUTOFMEMORY;
vb@15
   579
vb@15
   580
    return S_OK;
vb@15
   581
}
vb@15
   582
vb@15
   583
STDMETHODIMP CTextMessage::get_longmsg(BSTR * pVal)
vb@15
   584
{
vb@15
   585
    assert(pVal);
vb@15
   586
vb@15
   587
    _bstr_t val;
vb@15
   588
vb@15
   589
    if (msg->longmsg) {
vb@15
   590
        try {
vb@15
   591
            val = utf16_bstr(msg->longmsg);
vb@15
   592
        }
vb@15
   593
        catch (bad_alloc& e) {
vb@15
   594
            return E_OUTOFMEMORY;
vb@15
   595
        }
vb@15
   596
        catch (exception& e) {
vb@15
   597
            return E_FAIL;
vb@15
   598
        }
vb@15
   599
    }
vb@15
   600
vb@15
   601
    *pVal = val.Detach();
vb@15
   602
vb@15
   603
    return S_OK;
vb@15
   604
}
vb@15
   605
vb@15
   606
STDMETHODIMP CTextMessage::put_longmsg(BSTR newVal)
vb@15
   607
{
vb@15
   608
    assert(newVal);
vb@15
   609
vb@15
   610
    string val;
vb@15
   611
vb@15
   612
    try {
vb@15
   613
        val = utf8_string(newVal);
vb@15
   614
    }
vb@15
   615
    catch (bad_alloc& e) {
vb@15
   616
        return E_OUTOFMEMORY;
vb@15
   617
    }
vb@15
   618
    catch (exception& e) {
vb@15
   619
        return E_FAIL;
vb@15
   620
    }
vb@15
   621
vb@15
   622
    if (msg->longmsg)
vb@15
   623
        free(msg->longmsg);
vb@15
   624
vb@15
   625
    msg->longmsg = _strdup(val.c_str());
vb@15
   626
    if (msg->longmsg == NULL)
vb@15
   627
        return E_OUTOFMEMORY;
vb@15
   628
vb@15
   629
    return S_OK;
vb@15
   630
}
vb@15
   631
vb@15
   632
STDMETHODIMP CTextMessage::get_longmsg_formatted(BSTR * pVal)
vb@15
   633
{
vb@15
   634
    assert(pVal);
vb@15
   635
vb@15
   636
    _bstr_t val;
vb@15
   637
vb@15
   638
    if (msg->longmsg_formatted) {
vb@15
   639
        try {
vb@15
   640
            val = utf16_bstr(msg->longmsg_formatted);
vb@15
   641
        }
vb@15
   642
        catch (bad_alloc& e) {
vb@15
   643
            return E_OUTOFMEMORY;
vb@15
   644
        }
vb@15
   645
        catch (exception& e) {
vb@15
   646
            return E_FAIL;
vb@15
   647
        }
vb@15
   648
    }
vb@15
   649
vb@15
   650
    *pVal = val.Detach();
vb@15
   651
vb@15
   652
    return S_OK;
vb@15
   653
}
vb@15
   654
vb@15
   655
STDMETHODIMP CTextMessage::put_longmsg_formatted(BSTR newVal)
vb@15
   656
{
vb@15
   657
    assert(newVal);
vb@15
   658
vb@15
   659
    string val;
vb@15
   660
vb@15
   661
    try {
vb@15
   662
        val = utf8_string(newVal);
vb@15
   663
    }
vb@15
   664
    catch (bad_alloc& e) {
vb@15
   665
        return E_OUTOFMEMORY;
vb@15
   666
    }
vb@15
   667
    catch (exception& e) {
vb@15
   668
        return E_FAIL;
vb@15
   669
    }
vb@15
   670
vb@15
   671
    if (msg->longmsg_formatted)
vb@15
   672
        free(msg->longmsg_formatted);
vb@15
   673
vb@15
   674
    msg->longmsg_formatted = _strdup(val.c_str());
vb@15
   675
    if (msg->longmsg_formatted == NULL)
vb@15
   676
        return E_OUTOFMEMORY;
vb@15
   677
vb@15
   678
    return S_OK;
vb@15
   679
}
vb@15
   680
vb@15
   681
STDMETHODIMP CTextMessage::add_attachment(SAFEARRAY * data, BSTR mime_type, BSTR filename)
vb@15
   682
{
vb@15
   683
    assert(data);
vb@15
   684
    if (data == NULL)
vb@15
   685
        return E_INVALIDARG;
vb@15
   686
vb@15
   687
    CComSafeArray<BYTE> sa_data(data);
vb@15
   688
    size_t len = sa_data.GetCount();
vb@15
   689
vb@15
   690
    char *_data = (char *) malloc(sa_data.GetCount());
vb@15
   691
    assert(_data);
vb@15
   692
    if (_data == NULL)
vb@15
   693
        return E_OUTOFMEMORY;
vb@15
   694
vb@15
   695
    memcpy(_data, sa_data.m_psa->pvData, len);
vb@15
   696
    sa_data.Detach();
vb@15
   697
vb@15
   698
    string _mime_type;
vb@15
   699
    if (mime_type) {
vb@15
   700
        try {
vb@15
   701
            _mime_type = utf8_string(mime_type);
vb@15
   702
        }
vb@15
   703
        catch (bad_alloc& e) {
vb@15
   704
            free(_data);
vb@15
   705
            return E_OUTOFMEMORY;
vb@15
   706
        }
vb@15
   707
        catch (exception& e) {
vb@15
   708
            free(_data);
vb@15
   709
            return E_FAIL;
vb@15
   710
        }
vb@15
   711
    }
vb@15
   712
vb@15
   713
    string _filename;
vb@15
   714
    if (filename) {
vb@15
   715
        try {
vb@15
   716
            _filename = utf8_string(filename);
vb@15
   717
        }
vb@15
   718
        catch (bad_alloc& e) {
vb@15
   719
            free(_data);
vb@15
   720
            return E_OUTOFMEMORY;
vb@15
   721
        }
vb@15
   722
        catch (exception& e) {
vb@15
   723
            free(_data);
vb@15
   724
            return E_FAIL;
vb@15
   725
        }
vb@15
   726
    }
vb@15
   727
vb@15
   728
    bloblist_t *blob = bloblist_add(msg->attachments, _data, len, _mime_type.c_str(), _filename.c_str());
vb@15
   729
    if (blob == NULL) {
vb@15
   730
        free(_data);
vb@15
   731
        return E_OUTOFMEMORY;
vb@15
   732
    }
vb@15
   733
vb@20
   734
    if (msg->attachments == NULL)
vb@20
   735
        msg->attachments = blob;
vb@20
   736
vb@15
   737
    return S_OK;
vb@15
   738
}
vb@15
   739
vb@15
   740
STDMETHODIMP CTextMessage::has_attachments(boolean *result)
vb@15
   741
{
vb@15
   742
    assert(result);
vb@15
   743
vb@15
   744
    if (msg->attachments == NULL || msg->attachments->data == NULL) {
vb@15
   745
        m_next_attachment = NULL;
vb@15
   746
        *result = false;
vb@15
   747
        return S_OK;
vb@15
   748
    }
vb@15
   749
vb@15
   750
    m_next_attachment = msg->attachments;
vb@15
   751
    *result = true;
vb@15
   752
vb@15
   753
    return S_OK;
vb@15
   754
}
vb@15
   755
vb@15
   756
STDMETHODIMP CTextMessage::next_attachment(SAFEARRAY ** data, BSTR * mime_type, BSTR * filename, boolean *result)
vb@15
   757
{
vb@15
   758
    assert(data);
vb@15
   759
    assert(mime_type);
vb@15
   760
    assert(filename);
vb@15
   761
    assert(result);
vb@15
   762
vb@15
   763
    if (m_next_attachment == NULL)
vb@15
   764
        return E_ILLEGAL_METHOD_CALL;
vb@15
   765
vb@15
   766
    CComSafeArray<BYTE> sa;
vb@15
   767
    try {
vb@15
   768
        sa.Create(m_next_attachment->size);
vb@15
   769
    }
vb@15
   770
    catch (bad_alloc& e) {
vb@15
   771
        return E_OUTOFMEMORY;
vb@15
   772
    }
vb@15
   773
vb@15
   774
    memcpy(sa.m_psa->pvData, m_next_attachment->data, m_next_attachment->size);
vb@15
   775
vb@15
   776
    _bstr_t _mime_type;
vb@15
   777
    if (m_next_attachment->mime_type) {
vb@15
   778
        try {
vb@15
   779
            _mime_type = utf16_bstr(m_next_attachment->mime_type);
vb@15
   780
        }
vb@15
   781
        catch (bad_alloc& e) {
vb@15
   782
            return E_OUTOFMEMORY;
vb@15
   783
        }
vb@15
   784
        catch (exception& e) {
vb@15
   785
            return E_FAIL;
vb@15
   786
        }
vb@15
   787
    }
vb@15
   788
vb@15
   789
    _bstr_t _filename;
vb@15
   790
    if (m_next_attachment->filename) {
vb@15
   791
        try {
vb@15
   792
            _filename = utf16_bstr(m_next_attachment->filename);
vb@15
   793
        }
vb@15
   794
        catch (bad_alloc& e) {
vb@15
   795
            return E_OUTOFMEMORY;
vb@15
   796
        }
vb@15
   797
        catch (exception& e) {
vb@15
   798
            return E_FAIL;
vb@15
   799
        }
vb@15
   800
    }
vb@15
   801
vb@15
   802
    *data = sa.Detach();
vb@15
   803
    *mime_type = _mime_type.Detach();
vb@15
   804
    *filename = _filename.Detach();
vb@15
   805
vb@15
   806
    m_next_attachment = m_next_attachment->next;
vb@15
   807
    *result = m_next_attachment != NULL;
vb@15
   808
vb@15
   809
    return S_OK;
vb@15
   810
}
vb@15
   811
vb@15
   812
STDMETHODIMP CTextMessage::get_sent(hyper * result)
vb@15
   813
{
vb@15
   814
    assert(result);
vb@15
   815
vb@15
   816
    if (msg->sent == NULL)
vb@15
   817
        return E_NOT_SET;
vb@15
   818
vb@15
   819
    *result = mktime(msg->sent);
vb@15
   820
    return S_OK;
vb@15
   821
}
vb@15
   822
vb@15
   823
STDMETHODIMP CTextMessage::put_sent(hyper val)
vb@15
   824
{
vb@15
   825
    ::timestamp * ts = new_timestamp(val);
vb@15
   826
    if (ts == NULL)
vb@15
   827
        return E_OUTOFMEMORY;
vb@15
   828
vb@15
   829
    if (msg->sent)
vb@15
   830
        free_timestamp(msg->sent);
vb@15
   831
    msg->sent = ts;
vb@15
   832
vb@15
   833
    return S_OK;
vb@15
   834
}
vb@15
   835
vb@15
   836
STDMETHODIMP CTextMessage::get_recv(hyper * result)
vb@15
   837
{
vb@15
   838
    assert(result);
vb@15
   839
vb@15
   840
    if (msg->recv == NULL)
vb@15
   841
        return E_NOT_SET;
vb@15
   842
vb@15
   843
    *result = mktime(msg->recv);
vb@15
   844
    return S_OK;
vb@15
   845
}
vb@15
   846
vb@15
   847
STDMETHODIMP CTextMessage::put_recv(hyper val)
vb@15
   848
{
vb@15
   849
    ::timestamp * ts = new_timestamp(val);
vb@15
   850
    if (ts == NULL)
vb@15
   851
        return E_OUTOFMEMORY;
vb@15
   852
vb@15
   853
    if (msg->recv)
vb@15
   854
        free_timestamp(msg->recv);
vb@15
   855
    msg->recv = ts;
vb@15
   856
vb@15
   857
    return S_OK;
vb@15
   858
}
vb@15
   859
vb@15
   860
STDMETHODIMP CTextMessage::get_references(SAFEARRAY ** pVal)
vb@15
   861
{
vb@15
   862
    assert(pVal);
vb@15
   863
vb@15
   864
    CComSafeArray<BSTR> sa;
vb@15
   865
    try {
vb@15
   866
        if (msg->references) {
vb@15
   867
            sa = string_array(msg->references);
vb@15
   868
        }
vb@15
   869
        else {
vb@15
   870
            sa.Create(0UL);
vb@15
   871
        }
vb@15
   872
    }
vb@15
   873
    catch (bad_alloc& e) {
vb@15
   874
        return E_OUTOFMEMORY;
vb@15
   875
    }
vb@15
   876
    catch (exception& e) {
vb@15
   877
        return E_FAIL;
vb@15
   878
    }
vb@15
   879
    
vb@15
   880
    *pVal = sa.Detach();
vb@15
   881
    return S_OK;
vb@15
   882
}
vb@15
   883
vb@15
   884
STDMETHODIMP CTextMessage::put_references(SAFEARRAY * newVal)
vb@15
   885
{
vb@15
   886
    assert(newVal);
vb@15
   887
vb@15
   888
    stringlist_t *sl;
vb@15
   889
    
vb@15
   890
    try {
vb@15
   891
        sl = new_stringlist(newVal);
vb@15
   892
    }
vb@15
   893
    catch (bad_alloc& e) {
vb@15
   894
        return E_OUTOFMEMORY;
vb@15
   895
    }
vb@15
   896
    catch (exception& e) {
vb@15
   897
        return E_FAIL;
vb@15
   898
    }
vb@15
   899
vb@15
   900
    if (msg->references)
vb@15
   901
        free_stringlist(msg->references);
vb@15
   902
vb@15
   903
    msg->references = sl;
vb@15
   904
vb@15
   905
    return S_OK;
vb@15
   906
}
vb@15
   907
vb@15
   908
STDMETHODIMP CTextMessage::get_keywords(SAFEARRAY ** pVal)
vb@15
   909
{
vb@15
   910
    assert(pVal);
vb@15
   911
vb@15
   912
    CComSafeArray<BSTR> sa;
vb@15
   913
    try {
vb@15
   914
        if (msg->keywords) {
vb@15
   915
            sa = string_array(msg->keywords);
vb@15
   916
        }
vb@15
   917
        else {
vb@15
   918
            sa.Create(0UL);
vb@15
   919
        }
vb@15
   920
    }
vb@15
   921
    catch (bad_alloc& e) {
vb@15
   922
        return E_OUTOFMEMORY;
vb@15
   923
    }
vb@15
   924
    catch (exception& e) {
vb@15
   925
        return E_FAIL;
vb@15
   926
    }
vb@15
   927
vb@15
   928
    *pVal = sa.Detach();
vb@15
   929
    return S_OK;
vb@15
   930
}
vb@15
   931
vb@15
   932
STDMETHODIMP CTextMessage::put_keywords(SAFEARRAY * newVal)
vb@15
   933
{
vb@15
   934
    assert(newVal);
vb@15
   935
vb@15
   936
    stringlist_t *sl;
vb@15
   937
vb@15
   938
    try {
vb@15
   939
        sl = new_stringlist(newVal);
vb@15
   940
    }
vb@15
   941
    catch (bad_alloc& e) {
vb@15
   942
        return E_OUTOFMEMORY;
vb@15
   943
    }
vb@15
   944
    catch (exception& e) {
vb@15
   945
        return E_FAIL;
vb@15
   946
    }
vb@15
   947
vb@15
   948
    if (msg->keywords)
vb@15
   949
        free_stringlist(msg->keywords);
vb@15
   950
vb@15
   951
    msg->keywords = sl;
vb@15
   952
vb@15
   953
    return S_OK;
vb@15
   954
}
vb@15
   955
vb@15
   956
STDMETHODIMP CTextMessage::get_comments(BSTR * pVal)
vb@15
   957
{
vb@15
   958
    assert(pVal);
vb@15
   959
vb@15
   960
    _bstr_t val;
vb@15
   961
vb@15
   962
    if (msg->comments) {
vb@15
   963
        try {
vb@15
   964
            val = utf16_bstr(msg->comments);
vb@15
   965
        }
vb@15
   966
        catch (bad_alloc& e) {
vb@15
   967
            return E_OUTOFMEMORY;
vb@15
   968
        }
vb@15
   969
        catch (exception& e) {
vb@15
   970
            return E_FAIL;
vb@15
   971
        }
vb@15
   972
    }
vb@15
   973
vb@15
   974
    *pVal = val.Detach();
vb@15
   975
vb@15
   976
    return S_OK;
vb@15
   977
}
vb@15
   978
vb@15
   979
STDMETHODIMP CTextMessage::put_comments(BSTR newVal)
vb@15
   980
{
vb@15
   981
    assert(newVal);
vb@15
   982
vb@15
   983
    string val;
vb@15
   984
vb@15
   985
    try {
vb@15
   986
        val = utf8_string(newVal);
vb@15
   987
    }
vb@15
   988
    catch (bad_alloc& e) {
vb@15
   989
        return E_OUTOFMEMORY;
vb@15
   990
    }
vb@15
   991
    catch (exception& e) {
vb@15
   992
        return E_FAIL;
vb@15
   993
    }
vb@15
   994
vb@15
   995
    if (msg->comments)
vb@15
   996
        free(msg->comments);
vb@15
   997
vb@15
   998
    msg->comments = _strdup(val.c_str());
vb@15
   999
    if (msg->comments == NULL)
vb@15
  1000
        return E_OUTOFMEMORY;
vb@15
  1001
vb@15
  1002
    return S_OK;
vb@15
  1003
}