Getting incorrect attachment counts from IMESSAGE::GetAttachmentTable() API

Agarwal, Mayank 1 Reputation point
2020-07-27T08:28:48.283+00:00

Hi All,

VC++, Visual Studio 2019

I am facing issues in accessing attachment counts, Here is the code flow:

LPMAPITABLE pATbl = NULL;
LPSRowSet pRow = NULL;

static SizedSPropTagArray(NUM_COLS, sptCols) = { NUM_COLS, PR_ENTRYID,
PR_MESSAGE_FLAGS,
PR_CREATION_TIME,
PR_SUBJECT };

enum { AttNum, AttType, AttFilename, NUM_ATT_COLS };
static SizedSPropTagArray(NUM_ATT_COLS, sptNum) = { NUM_ATT_COLS,
    PR_ATTACH_NUM,
    PR_ATTACH_METHOD,
    PR_ATTACH_LONG_FILENAME };

hr = pMessage->GetAttachmentTable(0, &pATbl);

hr = HrQueryAllRows(pATbl, (LPSPropTagArray)&sptNum,
NULL, NULL, 0, &pRow);

This above code is just to mentions the API used.

in case if my mail has 1 attachment, pRow->cRows value is 1.

when I try to access the attachment name it gives the correct attachment name. (success Scenario)

But in case if the mail has 1 attachment and it is digitally signed also, then also pRow->cRows value is 1. And when I try to access the attachment name it gives the incorrect attachment name(smime.p7m). (this smime.p7m is the attachment file name of the digital signature which gets added automatically)

Query: in case of digitally signed mail, why it is not showing 2 attachments? and How can I avoid this digital signature file programmatically.

Kindly guide or suggest me, I am stuck.

Thanks in advance.

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
39,624 questions
{count} votes

1 answer

Sort by: Most helpful
  1. David Lowndes 4,716 Reputation points
    2020-07-27T16:49:22.683+00:00

    It's a long time since I've done any MAPI, but I think you need to determine the message type via PR_MESSAGE_CLASS, and if it's a signed message, the smime.p7m attachment can be treated as a message itself, and it then has the underlying attachments.

    OutlookSpy is an essential tool for examining and validating such inner workings.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.