From 8be6df34347ad0c986fdb9e34cc320f4035dce6b Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Tue, 12 Feb 2008 11:59:36 +0000 Subject: [PATCH] inetcomm: Implement IMimeMessage_CountBodies. --- dlls/inetcomm/mimeole.c | 26 ++++++++++++++++++++++++-- dlls/inetcomm/tests/mimeole.c | 9 +++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/dlls/inetcomm/mimeole.c b/dlls/inetcomm/mimeole.c index 099d2b6c039..d6b42740676 100644 --- a/dlls/inetcomm/mimeole.c +++ b/dlls/inetcomm/mimeole.c @@ -1889,14 +1889,36 @@ static HRESULT WINAPI MimeMessage_MoveBody( return E_NOTIMPL; } +static void count_children(body_t *body, boolean recurse, ULONG *count) +{ + body_t *child; + + LIST_FOR_EACH_ENTRY(child, &body->children, body_t, entry) + { + (*count)++; + if(recurse) count_children(child, recurse, count); + } +} + static HRESULT WINAPI MimeMessage_CountBodies( IMimeMessage *iface, HBODY hParent, boolean fRecurse, ULONG *pcBodies) { - FIXME("(%p)->(%p, %s, %p)\n", iface, hParent, fRecurse ? "TRUE" : "FALSE", pcBodies); - return E_NOTIMPL; + HRESULT hr; + MimeMessage *This = (MimeMessage *)iface; + body_t *body; + + TRACE("(%p)->(%p, %s, %p)\n", iface, hParent, fRecurse ? "TRUE" : "FALSE", pcBodies); + + hr = find_body(&This->body_tree, hParent, &body); + if(hr != S_OK) return hr; + + *pcBodies = 1; + count_children(body, fRecurse, pcBodies); + + return S_OK; } static HRESULT WINAPI MimeMessage_FindFirst( diff --git a/dlls/inetcomm/tests/mimeole.c b/dlls/inetcomm/tests/mimeole.c index 3d49e61db46..c40952f35f2 100644 --- a/dlls/inetcomm/tests/mimeole.c +++ b/dlls/inetcomm/tests/mimeole.c @@ -212,6 +212,7 @@ static void test_CreateMessage(void) HBODY hbody; IMimeBody *body; BODYOFFSETS offsets; + ULONG count; hr = MimeOleCreateMessage(NULL, &msg); ok(hr == S_OK, "ret %08x\n", hr); @@ -224,6 +225,14 @@ static void test_CreateMessage(void) hr = IMimeMessage_Load(msg, stream); ok(hr == S_OK, "ret %08x\n", hr); + hr = IMimeMessage_CountBodies(msg, HBODY_ROOT, TRUE, &count); + ok(hr == S_OK, "ret %08x\n", hr); + ok(count == 3, "got %d\n", count); + + hr = IMimeMessage_CountBodies(msg, HBODY_ROOT, FALSE, &count); + ok(hr == S_OK, "ret %08x\n", hr); + ok(count == 3, "got %d\n", count); + hr = IMimeMessage_BindToObject(msg, HBODY_ROOT, &IID_IMimeBody, (void**)&body); ok(hr == S_OK, "ret %08x\n", hr); hr = IMimeBody_GetOffsets(body, &offsets);