From e15ff2ef86c4913e6f463896edfcf98a64642c06 Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Tue, 12 Feb 2008 11:49:47 +0000 Subject: [PATCH] inetcomm: Implement IMimeMessage_GetBody. --- dlls/inetcomm/mimeole.c | 78 ++++++++++++++++++++++++++++++++++- dlls/inetcomm/tests/mimeole.c | 27 ++++++++++++ 2 files changed, 103 insertions(+), 2 deletions(-) diff --git a/dlls/inetcomm/mimeole.c b/dlls/inetcomm/mimeole.c index bdce35bdaee..099d2b6c039 100644 --- a/dlls/inetcomm/mimeole.c +++ b/dlls/inetcomm/mimeole.c @@ -1777,6 +1777,71 @@ static HRESULT WINAPI MimeMessage_SaveBody( return E_NOTIMPL; } +static HRESULT get_body(MimeMessage *msg, BODYLOCATION location, HBODY pivot, body_t **out) +{ + body_t *root = LIST_ENTRY(list_head(&msg->body_tree), body_t, entry); + body_t *body; + HRESULT hr; + struct list *list; + + if(location == IBL_ROOT) + { + *out = root; + return S_OK; + } + + hr = find_body(&msg->body_tree, pivot, &body); + + if(hr == S_OK) + { + switch(location) + { + case IBL_PARENT: + *out = body->parent; + break; + + case IBL_FIRST: + list = list_head(&body->children); + if(list) + *out = LIST_ENTRY(list, body_t, entry); + else + hr = MIME_E_NOT_FOUND; + break; + + case IBL_LAST: + list = list_tail(&body->children); + if(list) + *out = LIST_ENTRY(list, body_t, entry); + else + hr = MIME_E_NOT_FOUND; + break; + + case IBL_NEXT: + list = list_next(&body->parent->children, &body->entry); + if(list) + *out = LIST_ENTRY(list, body_t, entry); + else + hr = MIME_E_NOT_FOUND; + break; + + case IBL_PREVIOUS: + list = list_prev(&body->parent->children, &body->entry); + if(list) + *out = LIST_ENTRY(list, body_t, entry); + else + hr = MIME_E_NOT_FOUND; + break; + + default: + hr = E_FAIL; + break; + } + } + + return hr; +} + + static HRESULT WINAPI MimeMessage_InsertBody( IMimeMessage *iface, BODYLOCATION location, @@ -1793,8 +1858,17 @@ static HRESULT WINAPI MimeMessage_GetBody( HBODY hPivot, LPHBODY phBody) { - FIXME("(%p)->(%d, %p, %p)\n", iface, location, hPivot, phBody); - return E_NOTIMPL; + MimeMessage *This = (MimeMessage *)iface; + body_t *body; + HRESULT hr; + + TRACE("(%p)->(%d, %p, %p)\n", iface, location, hPivot, phBody); + + hr = get_body(This, location, hPivot, &body); + + if(hr == S_OK) *phBody = body->hbody; + + return hr; } static HRESULT WINAPI MimeMessage_DeleteBody( diff --git a/dlls/inetcomm/tests/mimeole.c b/dlls/inetcomm/tests/mimeole.c index 5f5fa0c5105..3d49e61db46 100644 --- a/dlls/inetcomm/tests/mimeole.c +++ b/dlls/inetcomm/tests/mimeole.c @@ -209,6 +209,7 @@ static void test_CreateMessage(void) IStream *stream; LARGE_INTEGER pos; LONG ref; + HBODY hbody; IMimeBody *body; BODYOFFSETS offsets; @@ -233,6 +234,32 @@ static void test_CreateMessage(void) ok(offsets.cbBodyEnd == 666, "got %d\n", offsets.cbBodyEnd); IMimeBody_Release(body); + hr = IMimeMessage_GetBody(msg, IBL_ROOT, NULL, &hbody); + hr = IMimeMessage_GetBody(msg, IBL_FIRST, hbody, &hbody); + ok(hr == S_OK, "ret %08x\n", hr); + hr = IMimeMessage_BindToObject(msg, hbody, &IID_IMimeBody, (void**)&body); + ok(hr == S_OK, "ret %08x\n", hr); + hr = IMimeBody_GetOffsets(body, &offsets); + ok(hr == S_OK, "ret %08x\n", hr); + ok(offsets.cbBoundaryStart == 405, "got %d\n", offsets.cbBoundaryStart); + ok(offsets.cbHeaderStart == 428, "got %d\n", offsets.cbHeaderStart); + ok(offsets.cbBodyStart == 518, "got %d\n", offsets.cbBodyStart); + ok(offsets.cbBodyEnd == 523, "got %d\n", offsets.cbBodyEnd); + IMimeBody_Release(body); + + hr = IMimeMessage_GetBody(msg, IBL_NEXT, hbody, &hbody); + ok(hr == S_OK, "ret %08x\n", hr); + hr = IMimeMessage_BindToObject(msg, hbody, &IID_IMimeBody, (void**)&body); + ok(hr == S_OK, "ret %08x\n", hr); + hr = IMimeBody_GetOffsets(body, &offsets); + ok(hr == S_OK, "ret %08x\n", hr); + ok(offsets.cbBoundaryStart == 525, "got %d\n", offsets.cbBoundaryStart); + ok(offsets.cbHeaderStart == 548, "got %d\n", offsets.cbHeaderStart); + ok(offsets.cbBodyStart == 629, "got %d\n", offsets.cbBodyStart); + ok(offsets.cbBodyEnd == 639, "got %d\n", offsets.cbBodyEnd); + IMimeBody_Release(body); + + IMimeMessage_Release(msg); ref = IStream_AddRef(stream);