fetchappointment.c

This example shows how to fetch an appointment from the server.This is very similar to the fetchmail.c example, except two minor changes:

  • We change the default folder constant from olFolderInbox to olFolderContact so any further operations are performed on a child of the calendar folder.
  • We use mapidump_appointment() rather than mapidump_message() to dump appointments on standard output.
#define DEFAULT_PROFDB "%s/.openchange/profiles.ldb"
int main(int argc, char *argv[])
{
enum MAPISTATUS retval;
struct mapi_context *mapi_ctx;
TALLOC_CTX *mem_ctx;
struct mapi_session *session = NULL;
mapi_object_t obj_store;
mapi_object_t obj_folder;
mapi_object_t obj_table;
mapi_object_t obj_message;
struct mapi_SPropValue_array props_all;
struct SRowSet rowset;
struct SPropTagArray *SPropTagArray;
mapi_id_t id_inbox;
mapi_id_t *fid, *mid;
char *profname;
char *profdb;
uint32_t Numerator;
uint32_t Denominator;
uint32_t i;
mem_ctx = talloc_named(NULL, 0, "fetchappointment");
/* Initialize MAPI */
profdb = talloc_asprintf(mem_ctx, DEFAULT_PROFDB, getenv("HOME"));
retval = MAPIInitialize(&mapi_ctx, profdb);
MAPI_RETVAL_IF(retval, retval, NULL);
/* Find Default Profile */
retval = GetDefaultProfile(mapi_ctx, &profname);
MAPI_RETVAL_IF(retval, retval, NULL);
/* Log on EMSMDB and NSPI */
retval = MapiLogonEx(mapi_ctx, &session, profname, NULL);
MAPI_RETVAL_IF(retval, retval, NULL);
/* Open Message Store */
mapi_object_init(&obj_store);
retval = OpenMsgStore(session, &obj_store);
MAPI_RETVAL_IF(retval, retval, NULL);
/* Find Inbox default folder */
retval = GetDefaultFolder(&obj_store, &id_inbox, olFolderCalendar);
MAPI_RETVAL_IF(retval, retval, NULL);
/* Open Inbox folder */
mapi_object_init(&obj_folder);
retval = OpenFolder(&obj_store, id_inbox, &obj_folder);
MAPI_RETVAL_IF(retval, retval, NULL);
/* Retrieve Inbox content table */
mapi_object_init(&obj_table);
retval = GetContentsTable(&obj_folder, &obj_table, 0x0, NULL);
MAPI_RETVAL_IF(retval, retval, NULL);
/* Create the MAPI table view */
SPropTagArray = set_SPropTagArray(mem_ctx, 0x2, PR_FID, PR_MID);
retval = SetColumns(&obj_table, SPropTagArray);
MAPIFreeBuffer(SPropTagArray);
MAPI_RETVAL_IF(retval, retval, mem_ctx);
/* Get current cursor position */
retval = QueryPosition(&obj_table, &Numerator, &Denominator);
MAPI_RETVAL_IF(retval, retval, NULL);
/* Iterate through rows */
while ((retval = QueryRows(&obj_table, Denominator, TBL_ADVANCE, &rowset)) != -1 && rowset.cRows) {
for (i = 0; i < rowset.cRows; i++) {
fid = (mapi_id_t *)find_SPropValue_data(&(rowset.aRow[i]), PR_FID);
mid = (mapi_id_t *)find_SPropValue_data(&(rowset.aRow[i]), PR_MID);
mapi_object_init(&obj_message);
retval = OpenMessage(&obj_store, *fid, *mid, &obj_message, 0x0);
if (retval != MAPI_E_NOT_FOUND) {
retval = GetPropsAll(&obj_message, MAPI_UNICODE, &props_all);
mapidump_appointment(&props_all, NULL);
mapi_object_release(&obj_message);
}
}
}
/* Release MAPI objects */
mapi_object_release(&obj_table);
mapi_object_release(&obj_folder);
Logoff(&obj_store);
/* Uninitialize MAPI */
MAPIUninitialize(mapi_ctx);
talloc_free(mem_ctx);
return (0);
}
enum MAPISTATUS GetDefaultFolder(mapi_object_t *, uint64_t *, const uint32_t)
Definition: simple_mapi.c:236
struct SPropTagArray * set_SPropTagArray(TALLOC_CTX *, uint32_t,...)
Definition: property.c:47
#define PR_FID
Definition: property_altnames.h:476
_PUBLIC_ enum MAPISTATUS GetPropsAll(mapi_object_t *obj, uint32_t flags, struct mapi_SPropValue_array *properties)
Definition: IMAPIProp.c:497
void mapidump_appointment(struct mapi_SPropValue_array *, const char *)
Definition: mapidump.c:492
_PUBLIC_ enum MAPISTATUS SetColumns(mapi_object_t *obj_table, struct SPropTagArray *properties)
Definition: IMAPITable.c:51
TALLOC_CTX * mem_ctx
Definition: mapi_context.h:32
_PUBLIC_ enum MAPISTATUS MAPIFreeBuffer(void *ptr)
Definition: IUnknown.c:83
_PUBLIC_ enum MAPISTATUS OpenFolder(mapi_object_t *obj_store, mapi_id_t id_folder, mapi_object_t *obj_folder)
Definition: IMsgStore.c:48
Definition: mapi_context.h:31
_PUBLIC_ enum MAPISTATUS QueryPosition(mapi_object_t *obj_table, uint32_t *Numerator, uint32_t *Denominator)
Definition: IMAPITable.c:150
uint64_t mapi_id_t
Definition: mapi_object.h:30
#define MAPI_UNICODE
Definition: mapidefs.h:28
Definition: mapi_provider.h:47
_PUBLIC_ enum MAPISTATUS GetContentsTable(mapi_object_t *obj_container, mapi_object_t *obj_table, uint8_t TableFlags, uint32_t *RowCount)
Definition: IMAPIContainer.c:80
_PUBLIC_ enum MAPISTATUS MapiLogonEx(struct mapi_context *mapi_ctx, struct mapi_session **session, const char *profname, const char *password)
Definition: cdo_mapi.c:59
const void * find_SPropValue_data(struct SRow *, uint32_t)
Definition: property.c:363
_PUBLIC_ enum MAPISTATUS Logoff(mapi_object_t *obj_store)
Definition: IMSProvider.c:366
#define MAPI_RETVAL_IF(x, e, c)
Definition: mapicode.h:24
_PUBLIC_ enum MAPISTATUS QueryRows(mapi_object_t *obj_table, uint16_t row_count, enum QueryRowsFlags flags, enum ForwardRead forward_read, struct SRowSet *rowSet)
Definition: IMAPITable.c:244
enum MAPISTATUS mapi_object_init(mapi_object_t *)
Definition: mapi_object.c:72
_PUBLIC_ enum MAPISTATUS MAPIInitialize(struct mapi_context **_mapi_ctx, const char *profiledb)
Definition: cdo_mapi.c:221
#define PR_MID
Definition: property_altnames.h:720
_PUBLIC_ void MAPIUninitialize(struct mapi_context *mapi_ctx)
Definition: cdo_mapi.c:272
#define olFolderCalendar
Definition: mapidefs.h:241
Definition: mapi_object.h:38
_PUBLIC_ enum MAPISTATUS OpenMessage(mapi_object_t *obj_store, mapi_id_t id_folder, mapi_id_t id_message, mapi_object_t *obj_message, uint8_t ulFlags)
Definition: IStoreFolder.c:62
void mapi_object_release(mapi_object_t *)
Definition: mapi_object.c:90
_PUBLIC_ enum MAPISTATUS OpenMsgStore(struct mapi_session *session, mapi_object_t *obj_store)
Definition: IMAPISession.c:268
_PUBLIC_ enum MAPISTATUS GetDefaultProfile(struct mapi_context *mapi_ctx, char **profname)
Definition: IProfAdmin.c:1315

Creative Commons License
Creative Commons Attribution icon Creative Commons Share Alike icon
This content is licensed under the Creative Commons
Attribution ShareAlike License v. 3.0:
http://creativecommons.org/licenses/by-sa/3.0/