Skip to content

Commit

Permalink
Fixes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
bill-long committed May 18, 2015
1 parent 298bf6e commit f0652fc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
23 changes: 15 additions & 8 deletions MAPIFolders/CheckItemsOperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,15 @@ void CheckItemsOperation::ProcessItem(LPMAPIPROP lpMessage, LPCTSTR pwzSubject)
goto Cleanup;
}

void CheckItemsOperation::ProcessAttachmentsRecursive(LPMAPIPROP lpMAPIProp)
bool CheckItemsOperation::ProcessAttachmentsRecursive(LPMAPIPROP lpMAPIProp)
{
HRESULT hr = S_OK;
LPMAPITABLE lpTable = NULL;
LPSPropTagArray lpColSet = NULL;
LPSRowSet pRows = NULL;
LPATTACH lpAttach = NULL;
LPMESSAGE lpEmbeddedMessage = NULL;
bool bUpdatedItem = false;

CORg(((LPMESSAGE)lpMAPIProp)->GetAttachmentTable(0, &lpTable));
CORg(lpTable->QueryColumns(0, &lpColSet));
Expand Down Expand Up @@ -170,12 +171,15 @@ void CheckItemsOperation::ProcessAttachmentsRecursive(LPMAPIPROP lpMAPIProp)
}
}

*pLog << " Checking attachment: " << (pwzAttachName ? pwzAttachName : _T("<NULL>")) << "\n";

if (ulAttachMethod == ATTACH_EMBEDDED_MSG)
{
CORg(lpAttach->OpenProperty(PR_ATTACH_DATA_OBJ, (LPIID)&IID_IMessage, 0, MAPI_MODIFY, (LPUNKNOWN *)&lpEmbeddedMessage));

// Recurse first
bUpdatedItem = this->ProcessAttachmentsRecursive(lpEmbeddedMessage);

// Now check this one
*pLog << " Checking attachment: " << (pwzAttachName ? pwzAttachName : _T("<NULL>")) << "\n";
cCount = 0;
SPropValue *rgprops = NULL;
CORg(lpEmbeddedMessage->GetProps(lpPropsToRemove, MAPI_UNICODE, &cCount, &rgprops));
Expand All @@ -197,14 +201,17 @@ void CheckItemsOperation::ProcessAttachmentsRecursive(LPMAPIPROP lpMAPIProp)
// If we found any one of the specified props, just send a delete for all of them
LPSPropProblemArray problemArray = NULL;
CORg(lpEmbeddedMessage->DeleteProps(lpPropsToRemove, &problemArray));
CORg(lpEmbeddedMessage->SaveChanges(NULL));
CORg(lpAttach->SaveChanges(NULL));
CORg(lpMAPIProp->SaveChanges(NULL));
bUpdatedItem = true;
MAPIFreeBuffer(problemArray);
*pLog << "Done.\n";
}

this->ProcessAttachmentsRecursive(lpEmbeddedMessage);
if (bUpdatedItem)
{
CORg(lpEmbeddedMessage->SaveChanges(NULL));
CORg(lpAttach->SaveChanges(NULL));
CORg(lpMAPIProp->SaveChanges(NULL));
}

lpEmbeddedMessage->Release();
lpEmbeddedMessage = NULL;
Expand All @@ -220,7 +227,7 @@ void CheckItemsOperation::ProcessAttachmentsRecursive(LPMAPIPROP lpMAPIProp)
if (lpColSet) MAPIFreeBuffer(lpColSet);
if (lpTable) lpTable->Release();
if (lpAttach) lpAttach->Release();
return;
return bUpdatedItem;

Error:
goto Cleanup;
Expand Down
2 changes: 1 addition & 1 deletion MAPIFolders/CheckItemsOperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CheckItemsOperation :
~CheckItemsOperation();
HRESULT Initialize() override;
void ProcessItem(LPMAPIPROP item, LPCTSTR itemSubject);
void CheckItemsOperation::ProcessAttachmentsRecursive(LPMAPIPROP lpMessage);
bool CheckItemsOperation::ProcessAttachmentsRecursive(LPMAPIPROP lpMessage);

private:
bool fix;
Expand Down
Binary file modified MAPIFolders/MAPIFolders.rc
Binary file not shown.

0 comments on commit f0652fc

Please sign in to comment.