Sophie

Sophie

distrib > * > 2010.0 > * > by-pkgid > 943b1476818e5ec34d7058ed3b879448 > files > 151

libmapi-devel-0.8.2-1.1481.3mdv2010.0.i586.rpm

<html>
  <head>
    <title>MAPIClientLibraries 0.8 API Documentation</title>
    <link href="doxygen.css" rel="stylesheet" type="text/css"/>
    <link href="apidocs.css" rel="stylesheet" type="text/css"/>
  </head>
  <body>
    <div id="website">
    <div class="header"></div>
      <div id="middle_side">
	<div id="right_side_home">
<!-- Generated by Doxygen 1.5.9 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
</div>
<div class="contents">
<h1>mapi_sample1.c</h1>This example shows a very basic MAPI program, including setup, login, and teardown.The first MAPI library function called is <a class="el" href="cdo__mapi_8c.html#cd55ca55043b2a1c025c370725f1292a">MAPIInitialize()</a>. As its name suggests, this function initializes MAPI library: It creates the MAPI global context, opens the profile database store (database path passed as function parameter) and initialize Samba4 transport layer. This function must be called prior any other MAPI library operations.<p>
Once MAPI is initialized, we need to create a connection to Exchange and open MAPI sessions with the user credentials. This is the purpose of <a class="el" href="cdo__mapi_8c.html#2a42a622654ad8f1020d152028efe67b">MapiLogonEx()</a> which needs to be executed prior doing any effective code. This function takes a pointer on a mapi_session structure, the profile username and an optional password in case you decided to store it outside the profile. In the example above, we retrieve the default profile name from the database using <a class="el" href="IProfAdmin_8c.html#3e503caa812de7ec2d53f03f53ee4ca1">GetDefaultProfile()</a> Note that <a class="el" href="cdo__mapi_8c.html#2a42a622654ad8f1020d152028efe67b">MapiLogonEx()</a> opens connections to both the EMSMDB and EMSABP store providers. If you intend to interact with a single provider, use <a class="el" href="cdo__mapi_8c.html#898df5110aab8e75e97574dc52acc1fa">MapiLogonProvider()</a> instead.<p>
Finally we call <a class="el" href="cdo__mapi_8c.html#b8230cc080e782e318a090786c3253de">MAPIUninitialize()</a> prior to leaving the function. This opaque function will clean up the memory allocated during the session and stored within the global MAPI context.<p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &lt;libmapi/libmapi.h&gt;</span>

<span class="preprocessor">#define   DEFAULT_PROFDB_PATH     "%s/.openchange/profiles.ldb"</span>
<span class="preprocessor"></span>
<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])
{
        TALLOC_CTX              *mem_ctx;
        <span class="keyword">enum</span> MAPISTATUS         retval;
        <span class="keyword">struct </span>mapi_session     *session = NULL;
        <span class="keywordtype">char</span>                    *profdb;
        <span class="keywordtype">char</span>                    *profname;

        mem_ctx = talloc_named(NULL, 0, <span class="stringliteral">"mapi_sample1"</span>);

        profdb = talloc_asprintf(mem_ctx, DEFAULT_PROFDB_PATH, getenv(<span class="stringliteral">"HOME"</span>));

        retval = <a name="a0"></a><a class="code" href="cdo__mapi_8c.html#cd55ca55043b2a1c025c370725f1292a">MAPIInitialize</a>(profdb);
        mapi_errstr(<span class="stringliteral">"MAPIInitialize"</span>, <a name="a1"></a><a class="code" href="IUnknown_8c.html#8237c7fc76377cb07f3f55920d6f20de">GetLastError</a>());
        <span class="keywordflow">if</span> (retval != MAPI_E_SUCCESS) <span class="keywordflow">return</span> -1;

        retval = <a name="a2"></a><a class="code" href="IProfAdmin_8c.html#3e503caa812de7ec2d53f03f53ee4ca1">GetDefaultProfile</a>(&amp;profname);
        mapi_errstr(<span class="stringliteral">"GetDefaultProfile"</span>, <a class="code" href="IUnknown_8c.html#8237c7fc76377cb07f3f55920d6f20de">GetLastError</a>());
        <span class="keywordflow">if</span> (retval != MAPI_E_SUCCESS) <span class="keywordflow">return</span> -1;

        retval = <a name="a3"></a><a class="code" href="cdo__mapi_8c.html#2a42a622654ad8f1020d152028efe67b">MapiLogonEx</a>(&amp;session, profname, NULL);
        mapi_errstr(<span class="stringliteral">"MapiLogonEx"</span>, <a class="code" href="IUnknown_8c.html#8237c7fc76377cb07f3f55920d6f20de">GetLastError</a>());
        <span class="keywordflow">if</span> (retval != MAPI_E_SUCCESS) <span class="keywordflow">return</span> -1;

        <a name="a4"></a><a class="code" href="cdo__mapi_8c.html#b8230cc080e782e318a090786c3253de">MAPIUninitialize</a>();
        talloc_free(mem_ctx);

        <span class="keywordflow">return</span> 0;
}
</pre></div> </div>
</div>
<br/>
<table style="clear:both; margin: 0.5em auto; width:80%; text-align: center; background-color:#f8f8f8; border:2px solid #e0e0e0; padding:5px;">
<tr>
<td> 
  <img alt="Creative Commons License" src="CC_SomeRightsReserved.png" width="90" height="30" border="0" /><br />
  <img alt="Creative Commons Attribution icon" src="24px-Cc-by_white.svg.png" width="24" height="24" border="0" />
  <img alt="Creative Commons Share Alike icon" src="24px-Cc-sa_white.svg.png" width="24" height="24" border="0" />
</td>
<td> <i><strong class="selflink">This content</strong> is licensed under the Creative Commons<br />
Attribution ShareAlike License v. 3.0:<br />
<a href="http://creativecommons.org/licenses/by-sa/3.0/" class="external free" title="http://creativecommons.org/licenses/by-sa/3.0/" rel="nofollow">http://creativecommons.org/licenses/by-sa/3.0/</a></i>
</td></tr></table>
<br/>
</div>
</div>
</body>
</html>