mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-04 18:29:19 +02:00
117 lines
10 KiB
HTML
117 lines
10 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
|
<meta name="generator" content="Doxygen 1.8.11"/>
|
|
<title>Delta Chat Core C-API: Getting started</title>
|
|
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="jquery.js"></script>
|
|
<script type="text/javascript" src="dynsections.js"></script>
|
|
<link href="search/search.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="search/searchdata.js"></script>
|
|
<script type="text/javascript" src="search/search.js"></script>
|
|
<script type="text/javascript">
|
|
$(document).ready(function() { init_search(); });
|
|
</script>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css" />
|
|
<link href="user.css" rel="stylesheet" type="text/css"/>
|
|
</head>
|
|
<body>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr style="height: 56px;">
|
|
<td id="projectalign" style="padding-left: 0.5em;">
|
|
<div id="projectname">Delta Chat Core C-API
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.8.11 -->
|
|
<script type="text/javascript">
|
|
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
|
</script>
|
|
<div id="navrow1" class="tabs">
|
|
<ul class="tablist">
|
|
<li class="current"><a href="index.html"><span>Main Page</span></a></li>
|
|
<li><a href="annotated.html"><span>Classes</span></a></li>
|
|
<li><a href="files.html"><span>Files</span></a></li>
|
|
<li>
|
|
<div id="MSearchBox" class="MSearchBoxInactive">
|
|
<span class="left">
|
|
<img id="MSearchSelect" src="search/mag_sel.png"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
alt=""/>
|
|
<input type="text" id="MSearchField" value="Search" accesskey="S"
|
|
onfocus="searchBox.OnSearchFieldFocus(true)"
|
|
onblur="searchBox.OnSearchFieldFocus(false)"
|
|
onkeyup="searchBox.OnSearchFieldChange(event)"/>
|
|
</span><span class="right">
|
|
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
|
|
</span>
|
|
</div>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div><!-- top -->
|
|
<!-- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
</div>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<iframe src="javascript:void(0)" frameborder="0"
|
|
name="MSearchResults" id="MSearchResults">
|
|
</iframe>
|
|
</div>
|
|
|
|
<div class="header">
|
|
<div class="headertitle">
|
|
<div class="title">Getting started </div> </div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
<div class="textblock"><p>This document describes how to handle the Delta Chat core library.For general information about Delta Chat itself, see <a href="https://delta.chat">https://delta.chat</a> and <a href="https://github.com/deltachat">https://github.com/deltachat</a>.</p>
|
|
<p>Let's start.</p>
|
|
<p>First of all, you have to define a function that is called by the library on specific events (eg. when the configuration is done or when fresh messages arrive). Your function should look like the following:</p>
|
|
<div class="fragment"><div class="line"><span class="preprocessor">#include <mrmailbox.h></span></div><div class="line"></div><div class="line">uintptr_t my_delta_handler(<a class="code" href="structmrmailbox__t.html">mrmailbox_t</a>* mailbox, <span class="keywordtype">int</span> event, uintptr_t data1, uintptr_t data2)</div><div class="line">{</div><div class="line"> <span class="keywordflow">return</span> 0; <span class="comment">// for unhandled events, it is always safe to return 0</span></div><div class="line">}</div></div><!-- fragment --><p>After that, you can create and configure a <a class="el" href="structmrmailbox__t.html" title="An object representing a single mailbox. ">mrmailbox_t</a> object easily as follows:</p>
|
|
<div class="fragment"><div class="line"><a class="code" href="structmrmailbox__t.html">mrmailbox_t</a>* mailbox = <a class="code" href="structmrmailbox__t.html#a32825e3e0a1b16679580704a4b43db1a">mrmailbox_new</a>(my_delta_handler, NULL, NULL);</div><div class="line"></div><div class="line"><a class="code" href="structmrmailbox__t.html#a19b3e9f5209bc326fc77f3944522e8ad">mrmailbox_set_config</a>(mailbox, <span class="stringliteral">"addr"</span>, <span class="stringliteral">"alice@delta.chat"</span>); <span class="comment">// use some real test credentials here</span></div><div class="line"><a class="code" href="structmrmailbox__t.html#a19b3e9f5209bc326fc77f3944522e8ad">mrmailbox_set_config</a>(mailbox, <span class="stringliteral">"mail_pw"</span>, <span class="stringliteral">"***"</span>);</div><div class="line"></div><div class="line"><a class="code" href="structmrmailbox__t.html#a42ca741cc08785585f1dc74d515be5ef">mrmailbox_configure_and_connect</a>(mailbox);</div></div><!-- fragment --><p><a class="el" href="structmrmailbox__t.html#a42ca741cc08785585f1dc74d515be5ef" title="Configure and connect a mailbox. ">mrmailbox_configure_and_connect()</a> may take a while and saves the result in the database. On subsequent starts, you can call <a class="el" href="structmrmailbox__t.html#a67eef5ffc3369b8ad09326471b0a266f" title="Connect to the mailbox using the configured settings. ">mrmailbox_connect()</a> instead if <a class="el" href="structmrmailbox__t.html#aa6e325e49ecccfc96276db6c327dba94" title="Check if the mailbox is already configured. ">mrmailbox_is_configured()</a> returns true.</p>
|
|
<p>However, now you can send your first message:</p>
|
|
<div class="fragment"><div class="line">uint32_t contact_id = <a class="code" href="structmrmailbox__t.html#aa089e97e7ca1add16c10d5cc0e902824">mrmailbox_create_contact</a>(mailbox, NULL, <span class="stringliteral">"bob@delta.chat"</span>); <span class="comment">// use a real testing address here</span></div><div class="line">uint32_t chat_id = <a class="code" href="structmrmailbox__t.html#a1386ec2c091b936b65b25b50a302173d">mrmailbox_create_chat_by_contact_id</a>(mailbox, contact_id);</div><div class="line"></div><div class="line"><a class="code" href="structmrmailbox__t.html#a3f9ac5fb9ff2dcbaafdddb5d955ac39b">mrmailbox_send_text_msg</a>(mailbox, chat_id, <span class="stringliteral">"Hi, here is my first message!"</span>);</div></div><!-- fragment --><p>Now, go to the testing address (bob) and you should have received a normal email. Answer this email in any email program with "Got it!" and you will get the message from delta as follows:</p>
|
|
<div class="fragment"><div class="line"><a class="code" href="structmrarray__t.html">mrarray_t</a>* msglist = <a class="code" href="structmrmailbox__t.html#af5ac7f527aef58f8e834f3bd740acd46">mrmailbox_get_chat_msgs</a>(mailbox, chat_id, 0, 0);</div><div class="line"><span class="keywordflow">for</span>( <span class="keywordtype">size_t</span> i = 0; i < <a class="code" href="structmrarray__t.html#a73f6d954ed1b97bbceb3cf7d8e1aeec8">mrarray_get_cnt</a>(msglist); i++ )</div><div class="line">{</div><div class="line"> uint32_t msg_id = <a class="code" href="structmrarray__t.html#a40b1e875ba256b6ccbbe65f58bbc01ec">mrarray_get_id</a>(msglist, i);</div><div class="line"> <a class="code" href="structmrmsg__t.html">mrmsg_t</a>* msg = <a class="code" href="structmrmailbox__t.html#a9ef144244e7d86ba82ce3257abf14f13">mrmailbox_get_msg</a>(mailbox, msg_id);</div><div class="line"></div><div class="line"> printf(<span class="stringliteral">"message %i: %s\n"</span>, i+1, msg->m_text);</div><div class="line">}</div></div><!-- fragment --><p>This will output the following two lines:</p>
|
|
<div class="fragment"><div class="line">Message 1: Hi, here is my first message!</div><div class="line">Message 2: Got it!</div></div><!-- fragment --><p>I think, you got the idea. For further reading, please dive into the <a class="el" href="structmrmailbox__t.html" title="An object representing a single mailbox. ">mrmailbox_t</a> class.</p>
|
|
<h2>Further hints</h2>
|
|
<p>Here are some additional, unsorted hints that may be useful. If you need any further assistance, please do not hesitate to contact us at <a href="#" onclick="location.href='mai'+'lto:'+'r10'+'s@'+'b44'+'t.'+'com'; return false;">r10s@<span style="display: none;">.nosp@m.</span>b44t<span style="display: none;">.nosp@m.</span>.com</a>.</p>
|
|
<ul>
|
|
<li>Two underscores at the end of a function-name may be a <em>hint</em>, that this function does no resource locking. Such functions must not be used.</li>
|
|
<li>For objects, C-structures are used. If not mentioned otherwise, you can read the members here directly.</li>
|
|
<li>For <code>get</code>-functions, you have to unref the return value in some way.</li>
|
|
<li>Strings in function arguments or return values are usually UTF-8 encoded</li>
|
|
<li>Threads are implemented using POSIX threads (<code>pthread_*</code> functions)</li>
|
|
<li>The issue-tracker for the core library is here: <a href="https://github.com/deltachat/deltachat-core/issues">https://github.com/deltachat/deltachat-core/issues</a></li>
|
|
</ul>
|
|
<p>The following points are important mainly for the authors of the library itself:</p>
|
|
<ul>
|
|
<li>For indentation, use tabs. Alignments that are not placed at the beginning of a line should be done with spaces.</li>
|
|
<li>For padding between functions, classes etc. use 2 empty lines</li>
|
|
<li>Source files are encoded as UTF-8 with Unix line endings (a simple <code>LF</code>, <code>0x0A</code> or <code>\n</code>)</li>
|
|
</ul>
|
|
<p>Please keep in mind, that your derived work must be released under a <b>GPL-compatible licence</b>. For details, please have a look at the <a href="https://github.com/deltachat/deltachat-core/blob/master/LICENSE">LICENSE file</a> accompanying the source code.</p>
|
|
<p>See you. </p>
|
|
</div></div><!-- contents -->
|
|
<!-- start footer part -->
|
|
<hr class="footer"/><address class="footer"><small>
|
|
Generated by  <a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="doxygen.png" alt="doxygen"/>
|
|
</a> 1.8.11
|
|
</small></address>
|
|
</body>
|
|
</html>
|