Delta Chat Core C-API
Getting started

This document describes how to handle the Delta Chat core library.For general information about Delta Chat itself, see https://delta.chat and https://github.com/deltachat.

Let's start.

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:

#include <mrmailbox.h>
uintptr_t my_delta_handler(mrmailbox_t* mailbox, int event, uintptr_t data1, uintptr_t data2)
{
return 0; // for unhandled events, it is always safe to return 0
}

After that, you can create and configure a mrmailbox_t object easily as follows:

mrmailbox_t* mailbox = mrmailbox_new(my_delta_handler, NULL, NULL);
mrmailbox_set_config(mailbox, "addr", "alice@delta.chat"); // use some real test credentials here
mrmailbox_set_config(mailbox, "mail_pw", "***");

mrmailbox_configure_and_connect() may take a while and saves the result in the database. On subsequent starts, you can call mrmailbox_connect() instead if mrmailbox_is_configured() returns true.

However, now you can send your first message:

uint32_t contact_id = mrmailbox_create_contact(mailbox, NULL, "bob@delta.chat"); // use a real testing address here
uint32_t chat_id = mrmailbox_create_chat_by_contact_id(mailbox, contact_id);
mrmailbox_send_text_msg(mailbox, chat_id, "Hi, here is my first message!");

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:

mrarray_t* msglist = mrmailbox_get_chat_msgs(mailbox, chat_id, 0, 0);
for( size_t i = 0; i < mrarray_get_cnt(msglist); i++ )
{
uint32_t msg_id = mrarray_get_id(msglist, i);
mrmsg_t* msg = mrmailbox_get_msg(mailbox, msg_id);
char* text = mrmsg_get_text(msg);
printf("message %i: %s\n", i+1, text);
free(text);
}
mrarray_unref(msglist);

This will output the following two lines:

Message 1: Hi, here is my first message!
Message 2: Got it!

I think, you got the idea. For further reading, please dive into the mrmailbox_t class.

Class reference

For a class reference, see the "Classes" link atop.

Further hints

Here are some additional, unsorted hints that may be useful. If you need any further assistance, please do not hesitate to contact us at r10s@.nosp@m.b44t.nosp@m..com.

The following points are important mainly for the authors of the library itself:

Please keep in mind, that your derived work must be released under a GPL-compatible licence. For details, please have a look at the LICENSE file accompanying the source code.

See you.