1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-05 02:29:28 +02:00
This commit is contained in:
B. Petersen 2017-11-15 17:12:43 +01:00
parent 76d950ae74
commit ed1da4f70f
27 changed files with 45 additions and 78 deletions

View file

@ -83,7 +83,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
<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 &lt;mrmailbox.h&gt;</span></div><div class="line"></div><div class="line">uintptr_t my_delta_handler(<a class="code" href="structmrmailbox__t.html">mrmailbox_t</a>* nb, <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>* mb = <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>(mb, <span class="stringliteral">&quot;addr&quot;</span>, <span class="stringliteral">&quot;alice@delta.chat&quot;</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>(mb, <span class="stringliteral">&quot;mail_pw&quot;</span>, <span class="stringliteral">&quot;***&quot;</span>);</div><div class="line"></div><div class="line"><a class="code" href="structmrmailbox__t.html#af204aadf66e8adf5403987c5dcf85387">mrmailbox_configure_and_connect</a>(mb);</div></div><!-- fragment --><p>If this works, you'll receive the event <a class="el" href="mrevent_8h.html#a3be5f7ee95e6d0a8066e7a839f38c30f" title="Configurartion enden. ">MR_EVENT_CONFIGURE_ENDED</a> with <code>data1</code> set to <code>1</code> - and you can start sending your first message:</p>
<div class="fragment"><div class="line"><a class="code" href="structmrmailbox__t.html">mrmailbox_t</a>* mb = <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>(mb, <span class="stringliteral">&quot;addr&quot;</span>, <span class="stringliteral">&quot;alice@delta.chat&quot;</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>(mb, <span class="stringliteral">&quot;mail_pw&quot;</span>, <span class="stringliteral">&quot;***&quot;</span>);</div><div class="line"></div><div class="line"><a class="code" href="structmrmailbox__t.html#a42ca741cc08785585f1dc74d515be5ef">mrmailbox_configure_and_connect</a>(mb);</div></div><!-- fragment --><p>After that, 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>(mb, <span class="stringliteral">&quot;bob@delta.chat&quot;</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>(mb, contact_id);</div><div class="line"></div><div class="line"><a class="code" href="structmrmailbox__t.html#a3f9ac5fb9ff2dcbaafdddb5d955ac39b">mrmailbox_send_text_msg</a>(mb, chat_id, <span class="stringliteral">&quot;Hi, here is my first message!&quot;</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">carray* msglist = <a class="code" href="structmrmailbox__t.html#a5d3be6ed21d43cc93f250a1e7faf979b">mrmailbox_get_chat_msgs</a>(mb, chat_id, 0, 0);</div><div class="line"><span class="keywordflow">for</span>( <span class="keywordtype">size_t</span> i = 0; i &lt; carray_count(msglist); i++ )</div><div class="line">{</div><div class="line"> uint32_t msg_id = carray_get_uint32(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>(mb, msg_id);</div><div class="line"></div><div class="line"> printf(<span class="stringliteral">&quot;message %i: %s\n&quot;</span>, i+1, msg-&gt;<a class="code" href="structmrmsg__t.html#ae54dcd4036371597d7f8bbd75303527a">m_text</a>);</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>