/openchange-1.0-BORG/doc/doxygen/libmapi-examples.doxy

# · Unknown · 110 lines · 85 code · 25 blank · 0 comment · 0 complexity · d3436b2fc1235fa2cbba5c002f5fac2e MD5 · raw file

  1. /** \example mapi_sample1.c
  2. This example shows a very basic MAPI program, including setup, login,
  3. and teardown.
  4. The first MAPI library function called is MAPIInitialize(). As its
  5. name suggests, this function initializes MAPI library: It creates the
  6. MAPI global context, opens the profile database store (database path
  7. passed as function parameter) and initialize Samba4 transport
  8. layer. This function must be called prior any other MAPI
  9. library operations.
  10. Once MAPI is initialized, we need to create a connection to Exchange and
  11. open MAPI sessions with the user credentials. This is the purpose of
  12. MapiLogonEx() which needs to be executed prior doing any effective
  13. code. This function takes a pointer on a mapi_session structure,
  14. the profile username and an optional password in case you decided to
  15. store it outside the profile. In the example above, we retrieve the
  16. default profile name from the database using GetDefaultProfile()
  17. Note that MapiLogonEx() opens connections to both the EMSMDB and
  18. EMSABP store providers. If you intend to interact with a single
  19. provider, use MapiLogonProvider() instead.
  20. Finally we call MAPIUninitialize() prior to leaving the
  21. function. This opaque function will clean up the memory allocated
  22. during the session and stored within the global MAPI context.
  23. */
  24. /** \example fetchmail.c
  25. This example shows how to fetch mail from the server.
  26. We initialize MAPI library with the profiles database path, retrieve
  27. the default profile name and open connections to both the Exchange
  28. message store provider (EMSMDB) and Exchange Address Book provider
  29. (EMSABP).
  30. \section ex-fetchmail-openstore Open the message store
  31. Now we have
  32. opened a connection to the Exchange message store provider, we can
  33. open the user mailbox store with OpenMsgStore() This function
  34. will return a set of pre-defined folder unique IDs (stored on double
  35. values) and a \em pointer to the upper object we can access in MAPI
  36. hierarchy.
  37. \section ex-fetchmail-openinbox Opening the Inbox folder
  38. We now open the Inbox folder. Since OpenMsgStore() returns a set
  39. of \em common folders identifiers we store in the message store
  40. object (obj_store), we can retrieve them using the convenient
  41. GetDefaultFolder() function. This function doesn't generate any
  42. network traffic, but returns the folder identifier associated with the
  43. constant passed as argument (here olFolderInbox).
  44. We could have used MAPI tables and GetHierarchyTable() function to
  45. find Inbox folder identifier. We would have had to retrieve the
  46. Top Information Store hierarchy table, customize the view with
  47. PR_FID (Folder ID MAPI property) and PR_DISPLAY_NAME, find the
  48. IPM_SUBTREE folder identifier, open it, retrieve the Hierarchy Table,
  49. call SetColumns() with PR_FID and finally browse table rows until
  50. we found the Inbox folder.folders to store emails within
  51. IPM_SUBTREE folder hierarchy.
  52. \section ex-fetchmail-retrievecontentstable Retrieve contents table
  53. Once the Inbox folder is opened, we can call GetContentsTable() to
  54. create the view needed to list all the children objects. In the
  55. current example we suppose we will only retrieve IPM.Post objects
  56. (emails).
  57. \section ex-fetchmail-customview Customizing the MAPI view
  58. We now customize the MAPI view and set the columns with the property
  59. tags we want to access: PR_FID (Folder Identifier) and
  60. PR_MID (Message identifier). MAPI uses unique and permanent
  61. identifiers to classify objects. These identifiers are double values
  62. (8 bytes) and never change until you move the object to another
  63. location.
  64. We now enter the last step of the fetching process:
  65. - Call QueryPosition() to retrieve the current cursor position in the
  66. contents table. The function returns the approximate fractional
  67. position with a Numerator and Denominator. Denominator is the total
  68. number of rows in the table.
  69. - Recursively call QueryRows() with the TBL_ADVANCE flag to fetch table rows.
  70. - Iterate through QueryRows results
  71. - Retrieve columns values for each row with the convenient find_SPropValue_data()
  72. - Open the message given its folder and message ids.
  73. - Call GetPropsAll() rather than GetProps() to retrieve all properties associated with a given object
  74. - Call one of OpenChange mapidump API function to display nice messages dump on standard output.
  75. We finally release mapi objects and clean up the MAPI library before returning
  76. */
  77. /** \example fetchappointment.c
  78. This example shows how to fetch an appointment from the server.
  79. This is very similar to the fetchmail.c example, except two minor changes:
  80. - We change the default folder constant from olFolderInbox to
  81. olFolderContact so any further operations are performed on a child of
  82. the calendar folder.
  83. - We use mapidump_appointment() rather than mapidump_message() to dump
  84. appointments on standard output.
  85. */