Receiving a Message: CMC Sample

The following code example demonstrates how you can list, retrieve, and delete the first unread message in the Inbox.

/* Local variables used */

CMC_message_summary     *pMsgSummary;
CMC_message             *pMessage;
CMC_uint32              iCount;
CMC_session_id          Session;
CMC_return_code         Status;

/* Read the first unread message and delete it. */

iCount  = 5; /* Maximum number of messages to get summary info about. */

Status = cmc_list(
              Session,               /* Session handle                */
              NULL,                  /* List ALL message types.       */
              CMC_LIST_UNREAD_ONLY,  /* Get only unread messages.     */
              NULL,                  /* Starting at the top           */
              &iCount,               /* Input/output message count    */
              0,                     /* No UI will be used.           */
              &pMsgSummary,          /* Return message summary list.  */
              NULL);                 /* No extensions                 */
    /* Error handling */

Status = cmc_read(
              Session,                            /* Session ID       */
              pMsgSummary->message_reference,     /* Message to read  */
              CMC_MSG_AND_ATT_HDRS_ONLY,    /* Don't get attach files.*/
              &pMessage,                          /* Returned message */
              0,                                  /* No UI            */
              NULL);                              /* No extensions    */
    /* Error handling */

Status = cmc_act_on(
              Session,                           /* Session ID        */
              pMsgSummary->message_reference,    /* Message to delete */
              CMC_ACT_ON_DELETE,                 /* Message to read   */
              0,                                 /* No flags          */
              0,                                 /* No UI             */
              NULL);                             /* No extensions     */
    /* Error handling */

/* Free the memory returned by the implementation. */

Status = cmc_free(pMsgSummary);
Status = cmc_free(pMessage);


/* Do the same thing without the list call, because the read call can 
   get the first unread message. */

Status = cmc_read(
             Session,                  /* Session ID                  */
             NULL,                     /* Read the first message.     */
             CMC_READ_FIRST_UNREAD_MESSAGE | /* Get first unread msg. */
             CMC_MSG_AND_ATT_HDRS_ONLY,/* Don't get attach files.     */
             &pMessage,                /* Returned message            */
             0,                        /* No UI                       */
             NULL);                    /* No extensions               */
    /* Error handling */

Status = cmc_act_on(
              Session,                           /* Session ID        */
              pMessage->message_reference,       /* Message to delete */
              CMC_ACT_ON_DELETE,                 /* Message to read   */
              0,                                 /* No flags          */
              0,                                 /* No UI             */
              NULL);                             /* No extensions     */
    /* Error handling */

/* Free the memory returned by the implementation. */

Status = cmc_free(pMessage);