Jonas Reinsch 7 vuotta sitten
vanhempi
commit
06f3cdd0e2

+ 4 - 4
deltachat-ios/libraries/deltachat-core/doxygen.config

@@ -177,7 +177,7 @@ SHORT_NAMES            = NO
 # description.)
 # The default value is: NO.
 
-JAVADOC_AUTOBRIEF      = NO
+JAVADOC_AUTOBRIEF      = YES
 
 # If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first
 # line (until the first dot) of a Qt-style comment as the brief description. If
@@ -185,7 +185,7 @@ JAVADOC_AUTOBRIEF      = NO
 # requiring an explicit \brief command for a brief description.)
 # The default value is: NO.
 
-QT_AUTOBRIEF           = NO
+QT_AUTOBRIEF           = YES
 
 # The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a
 # multi-line C++ special comment block (i.e. a block of //! or /// comments) as
@@ -422,7 +422,7 @@ EXTRACT_ALL            = NO
 # be included in the documentation.
 # The default value is: NO.
 
-EXTRACT_PRIVATE        = NO
+EXTRACT_PRIVATE        = YES
 
 # If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal
 # scope will be included in the documentation.
@@ -771,7 +771,7 @@ WARN_LOGFILE           =
 # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
 # Note: If this tag is empty the current directory is searched.
 
-INPUT                  = src/mrmailbox.h src/mrmailbox.c src/mrmailbox_configure.c src/mrmsg.c src/mrcontact.c src/mrchat.c src/mrchatlist.c src/mrpoortext.c
+INPUT                  = src
 
 # This tag can be used to specify the character encoding of the source files
 # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses

+ 19 - 1
deltachat-ios/libraries/deltachat-core/src/mraheader.c

@@ -27,7 +27,10 @@
 #include "mrmimeparser.h"
 
 
-static void mraheader_empty(mraheader_t* ths)
+/**
+ * @private @memberof mraheader_t
+ */
+void mraheader_empty(mraheader_t* ths)
 {
 	if( ths == NULL ) {
 		return;
@@ -50,6 +53,9 @@ static void mraheader_empty(mraheader_t* ths)
  ******************************************************************************/
 
 
+/**
+ * @memberof mraheader_t
+ */
 char* mraheader_render(const mraheader_t* ths)
 {
 	int            success = 0;
@@ -145,6 +151,9 @@ static int add_attribute(mraheader_t* ths, const char* name, const char* value /
 }
 
 
+/**
+ * @memberof mraheader_t
+ */
 int mraheader_set_from_string(mraheader_t* ths, const char* header_str__)
 {
 	/* according to RFC 5322 (Internet Message Format), the given string may contain `\r\n` before any whitespace.
@@ -218,6 +227,9 @@ cleanup:
  ******************************************************************************/
 
 
+/**
+ * @memberof mraheader_t
+ */
 mraheader_t* mraheader_new()
 {
 	mraheader_t* ths = NULL;
@@ -232,6 +244,9 @@ mraheader_t* mraheader_new()
 }
 
 
+/**
+ * @memberof mraheader_t
+ */
 void mraheader_unref(mraheader_t* ths)
 {
 	if( ths==NULL ) {
@@ -244,6 +259,9 @@ void mraheader_unref(mraheader_t* ths)
 }
 
 
+/**
+ * @memberof mraheader_t
+ */
 mraheader_t* mraheader_new_from_imffields(const char* wanted_from, const struct mailimf_fields* header)
 {
 	clistiter*   cur;

+ 5 - 4
deltachat-ios/libraries/deltachat-core/src/mraheader.h

@@ -27,12 +27,12 @@ extern "C" {
 #endif
 
 
-/*******************************************************************************
- * Handle Autocrypt:-headers - Library-private
- ******************************************************************************/
-
 #include "mrkey.h"
 
+
+/**
+ * Parse and create [Autocrypt-headers](https://autocrypt.org/en/latest/level1.html#the-autocrypt-header); library-internal.
+ */
 typedef struct mraheader_t
 {
 	char*          m_addr;
@@ -43,6 +43,7 @@ typedef struct mraheader_t
 
 mraheader_t* mraheader_new               (); /* the returned pointer is ref'd and must be unref'd after usage */
 mraheader_t* mraheader_new_from_imffields(const char* wanted_from, const struct mailimf_fields* mime);
+void         mraheader_empty             (mraheader_t*);
 void         mraheader_unref             (mraheader_t*);
 
 int          mraheader_set_from_string   (mraheader_t*, const char* header_str);

+ 144 - 30
deltachat-ios/libraries/deltachat-core/src/mrchat.c

@@ -418,35 +418,37 @@ cleanup:
 
 
 /**
- * mrmailbox_marknoticed_chat() marks all message in a whole chat as NOTICED.
- * NOTICED messages are no longer FRESH and do not count as being unseen.
+ * Mark all message in a chat as _noticed_.
+ * _Noticed_ messages are no longer _fresh_ and do not count as being unseen.
  * IMAP/MDNs is not done for noticed messages.  See also mrmailbox_marknoticed_contact()
  * and mrmailbox_markseen_msgs()
  *
  * @memberof mrmailbox_t
  *
  * @param mailbox The mailbox object as returned from mrmailbox_new().
+ *
+ * @param chat_id The chat ID of which all messages should be marked as being noticed.
+ *
+ * @return None.
  */
-int mrmailbox_marknoticed_chat(mrmailbox_t* ths, uint32_t chat_id)
+void mrmailbox_marknoticed_chat(mrmailbox_t* mailbox, uint32_t chat_id)
 {
 	/* marking a chat as "seen" is done by marking all fresh chat messages as "noticed" -
 	"noticed" messages are not counted as being unread but are still waiting for being marked as "seen" using mrmailbox_markseen_msgs() */
 	sqlite3_stmt* stmt;
 
-	if( ths == NULL ) {
-		return 0;
+	if( mailbox == NULL ) {
+		return;
 	}
 
-	mrsqlite3_lock(ths->m_sql);
+	mrsqlite3_lock(mailbox->m_sql);
 
-		stmt = mrsqlite3_predefine__(ths->m_sql, UPDATE_msgs_SET_state_WHERE_chat_id_AND_state,
+		stmt = mrsqlite3_predefine__(mailbox->m_sql, UPDATE_msgs_SET_state_WHERE_chat_id_AND_state,
 			"UPDATE msgs SET state=" MR_STRINGIFY(MR_STATE_IN_NOTICED) " WHERE chat_id=? AND state=" MR_STRINGIFY(MR_STATE_IN_FRESH) ";");
 		sqlite3_bind_int(stmt, 1, chat_id);
 		sqlite3_step(stmt);
 
-	mrsqlite3_unlock(ths->m_sql);
-
-	return 1;
+	mrsqlite3_unlock(mailbox->m_sql);
 }
 
 
@@ -480,47 +482,52 @@ uint32_t mrmailbox_get_chat_id_by_contact_id(mrmailbox_t* mailbox, uint32_t cont
  * @memberof mrmailbox_t
  *
  * @param mailbox The mailbox object as returned from mrmailbox_new().
+ *
+ * @param contact_id The contact ID to create the chat for.  If there is already
+ *     a chat with this contact, the already existing ID is returned.
+ *
+ * @return The created or reused chat ID on success. 0 on errors.
  */
-uint32_t mrmailbox_create_chat_by_contact_id(mrmailbox_t* ths, uint32_t contact_id)
+uint32_t mrmailbox_create_chat_by_contact_id(mrmailbox_t* mailbox, uint32_t contact_id)
 {
 	uint32_t      chat_id = 0;
 	int           send_event = 0, locked = 0;
 
-	if( ths == NULL ) {
+	if( mailbox == NULL ) {
 		return 0;
 	}
 
-	mrsqlite3_lock(ths->m_sql);
+	mrsqlite3_lock(mailbox->m_sql);
 	locked = 1;
 
-		chat_id = mrmailbox_lookup_real_nchat_by_contact_id__(ths, contact_id);
+		chat_id = mrmailbox_lookup_real_nchat_by_contact_id__(mailbox, contact_id);
 		if( chat_id ) {
-			mrmailbox_log_warning(ths, 0, "Chat with contact %i already exists.", (int)contact_id);
+			mrmailbox_log_warning(mailbox, 0, "Chat with contact %i already exists.", (int)contact_id);
 			goto cleanup;
 		}
 
-        if( 0==mrmailbox_real_contact_exists__(ths, contact_id) ) {
-			mrmailbox_log_warning(ths, 0, "Cannot create chat, contact %i does not exist.", (int)contact_id);
+        if( 0==mrmailbox_real_contact_exists__(mailbox, contact_id) ) {
+			mrmailbox_log_warning(mailbox, 0, "Cannot create chat, contact %i does not exist.", (int)contact_id);
 			goto cleanup;
         }
 
-		chat_id = mrmailbox_create_or_lookup_nchat_by_contact_id__(ths, contact_id);
+		chat_id = mrmailbox_create_or_lookup_nchat_by_contact_id__(mailbox, contact_id);
 		if( chat_id ) {
 			send_event = 1;
 		}
 
-		mrmailbox_scaleup_contact_origin__(ths, contact_id, MR_ORIGIN_CREATE_CHAT);
+		mrmailbox_scaleup_contact_origin__(mailbox, contact_id, MR_ORIGIN_CREATE_CHAT);
 
-	mrsqlite3_unlock(ths->m_sql);
+	mrsqlite3_unlock(mailbox->m_sql);
 	locked = 0;
 
 cleanup:
 	if( locked ) {
-		mrsqlite3_unlock(ths->m_sql);
+		mrsqlite3_unlock(mailbox->m_sql);
 	}
 
 	if( send_event ) {
-		ths->m_cb(ths, MR_EVENT_MSGS_CHANGED, 0, 0);
+		mailbox->m_cb(mailbox, MR_EVENT_MSGS_CHANGED, 0, 0);
 	}
 
 	return chat_id;
@@ -630,10 +637,9 @@ cleanup:
 
 
 /**
- * mrmailbox_get_chat_contacts() returns contact IDs, the result must be
- * carray_free()'d.
+ * Get contact IDs belonging to a chat.
  *
- * - for normal chats, the function always returns exactly one contact
+ * - for normal chats, the function always returns exactly one contact,
  *   MR_CONTACT_ID_SELF is _not_ returned.
  *
  * - for group chats all members are returned, MR_CONTACT_ID_SELF is returned
@@ -646,6 +652,10 @@ cleanup:
  * @memberof mrmailbox_t
  *
  * @param mailbox The mailbox object as returned from mrmailbox_new().
+ *
+ * @param chat_id Chat ID to get the belonging contact IDs for.
+ *
+ * @return an array of contact IDs belonging to the chat; must be freed using carray_free() when done.
  */
 carray* mrmailbox_get_chat_contacts(mrmailbox_t* mailbox, uint32_t chat_id)
 {
@@ -745,7 +755,7 @@ void mrchat_empty(mrchat_t* ths)
 
 
 /**
- * Returns message IDs of fresh messages, Typically used for implementing
+ * Returns the message IDs of all _fresh_ messages of any chat. Typically used for implementing
  * notification summaries.  The result must be free()'d.
  *
  * @memberof mrmailbox_t
@@ -802,7 +812,7 @@ cleanup:
 
 
 /**
- * mrmailbox_get_chat_msgs() returns a view on a chat.
+ * Get all message IDs belonging to a chat.
  * The function returns an array of message IDs, which must be carray_free()'d by
  * the caller.  Optionally, some special markers added to the ID-array may help to
  * implement virtual lists:
@@ -1054,13 +1064,17 @@ cleanup:
 
 
 /**
- * save message in database and send it, the given message object is not unref'd
- * by the function but some fields are set up! Sends the event
- * MR_EVENT_MSGS_CHANGED on succcess.
+ * Save a draft for a chat.
  *
  * @memberof mrmailbox_t
  *
  * @param mailbox The mailbox object as returned from mrmailbox_new().
+ *
+ * @param chat_id The chat ID to save the draft for.
+ *
+ * @param msg The message text to save as a draft.
+ *
+ * @return None.
  */
 void mrmailbox_set_draft(mrmailbox_t* mailbox, uint32_t chat_id, const char* msg)
 {
@@ -1843,6 +1857,27 @@ int mrmailbox_add_contact_to_chat__(mrmailbox_t* mailbox, uint32_t chat_id, uint
 }
 
 
+/**
+ * Create a new group chat.
+ *
+ * After creation, the groups has one member with the
+ * ID MR_CONTACT_ID_SELF and is in _unpromoted_ state.  This means, you can
+ * add or remove members, change the name, the group image and so on without
+ * messages being send to all group members.
+ *
+ * This changes as soon as the first message is sent to the group members and
+ * the group becomes _promoted_.  After that, all changes are synced with all
+ * group members by sending status message.
+ *
+ * @memberof mrmailbox_t
+ *
+ * @param mailbox Mailbox object as created by mrmailbox_new().
+ *
+ * @param name The name of the group chat to create.
+ *     The name may be changed later using mrmailbox_set_chat_name().
+ *
+ * @return The chat ID of the new group chat, 0 on errors.
+ */
 uint32_t mrmailbox_create_group_chat(mrmailbox_t* mailbox, const char* chat_name)
 {
 	uint32_t      chat_id = 0;
@@ -1893,6 +1928,22 @@ cleanup:
 }
 
 
+/**
+ * Set group name.
+ *
+ * If the group is already _promoted_ (any message was sent to the group),
+ * all group members are informed by a special message that is sent automatically by this function.
+ *
+ * @memberof mrmailbox_t
+ *
+ * @param chat_id The chat ID to set the name for.  Must be a group chat.
+ *
+ * @param name New name of the group.
+ *
+ * @param mailbox Mailbox object as created by mrmailbox_new().
+ *
+ * @return 1=success, 0=error
+ */
 int mrmailbox_set_chat_name(mrmailbox_t* mailbox, uint32_t chat_id, const char* new_name)
 {
 	/* the function only sets the names of group chats; normal chats get their names from the contacts */
@@ -1953,6 +2004,23 @@ cleanup:
 }
 
 
+/**
+ * Set group image.
+ *
+ * If the group is already _promoted_ (any message was sent to the group),
+ * all group members are informed by a special message that is sent automatically by this function.
+ *
+ * @memberof mrmailbox_t
+ *
+ * @param mailbox Mailbox object as created by mrmailbox_new().
+ *
+ * @param chat_id The chat ID to set the image for.
+ *
+ * @param image Full path of the image to use as the group image.  If you pass NULL here,
+ *     the group image is deleted (for promoted groups, all members are informed about this change anyway).
+ *
+ * @return 1=success, 0=error
+ */
 int mrmailbox_set_chat_image(mrmailbox_t* mailbox, uint32_t chat_id, const char* new_image /*NULL=remove image*/)
 {
 	int       success = 0, locked = 0;;
@@ -2028,6 +2096,20 @@ int mrmailbox_is_contact_in_chat__(mrmailbox_t* mailbox, uint32_t chat_id, uint3
 }
 
 
+/**
+ * Check if a given contact ID is a member of a group chat.
+ *
+ * @memberof mrmailbox_t
+ *
+ * @param mailbox Mailbox object as created by mrmailbox_new().
+ *
+ * @param chat_id The chat ID to check.
+ *
+ * @param contact_id The contact ID to check.  To check if yourself is member
+ *     of the chat, pass MR_CONTACT_ID_SELF (1) here.
+ *
+ * @return 1=contact ID is member of chat ID, 0=contact is not in chat
+ */
 int mrmailbox_is_contact_in_chat(mrmailbox_t* mailbox, uint32_t chat_id, uint32_t contact_id)
 {
 	/* this function works for group and for normal chats, however, it is more useful for group chats.
@@ -2042,6 +2124,22 @@ int mrmailbox_is_contact_in_chat(mrmailbox_t* mailbox, uint32_t chat_id, uint32_
 }
 
 
+/**
+ * Add a member to a group.
+ *
+ * If the group is already _promoted_ (any message was sent to the group),
+ * all group members are informed by a special message that is sent automatically by this function.
+ *
+ * @memberof mrmailbox_t
+ *
+ * @param mailbox Mailbox object as created by mrmailbox_new().
+ *
+ * @param chat_id The chat ID to add the contact to.  Must be a group chat.
+ *
+ * @param contact_id The contact ID to add to the chat.
+ *
+ * @return 1=member added to group, 0=error
+ */
 int mrmailbox_add_contact_to_chat(mrmailbox_t* mailbox, uint32_t chat_id, uint32_t contact_id /*may be MR_CONTACT_ID_SELF*/)
 {
 	int          success = 0, locked = 0;
@@ -2109,6 +2207,22 @@ cleanup:
 }
 
 
+/**
+ * Remove a member from a group.
+ *
+ * If the group is already _promoted_ (any message was sent to the group),
+ * all group members are informed by a special message that is sent automatically by this function.
+ *
+ * @memberof mrmailbox_t
+ *
+ * @param mailbox Mailbox object as created by mrmailbox_new().
+ *
+ * @param chat_id The chat ID to remove the contact from.  Must be a group chat.
+ *
+ * @param contact_id The contact ID to remove from the chat.
+ *
+ * @return 1=member removed from group, 0=error
+ */
 int mrmailbox_remove_contact_from_chat(mrmailbox_t* mailbox, uint32_t chat_id, uint32_t contact_id /*may be MR_CONTACT_ID_SELF*/)
 {
 	int          success = 0, locked = 0;

+ 74 - 0
deltachat-ios/libraries/deltachat-core/src/mrchat.h

@@ -0,0 +1,74 @@
+/*******************************************************************************
+ *
+ *                              Delta Chat Core
+ *                      Copyright (C) 2017 Björn Petersen
+ *                   Contact: r10s@b44t.com, http://b44t.com
+ *
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see http://www.gnu.org/licenses/ .
+ *
+ ******************************************************************************/
+
+
+#ifndef __MRCHAT_H__
+#define __MRCHAT_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+typedef struct mrmailbox_t mrmailbox_t;
+typedef struct mrparam_t   mrparam_t;
+
+
+/**
+ * Create and access chat objects. Chat objects are created using eg. mrmailbox_get_chat() and
+ * are not updated on database changes;  if you want an update, you have to recreate the
+ * object.
+ */
+typedef struct mrchat_t
+{
+	#define         MR_CHAT_ID_DEADDROP         1 /* messages send from unknown/unwanted users to us, chats_contacts is not set up. This group may be shown normally. */
+	#define         MR_CHAT_ID_TO_DEADDROP      2 /* messages send from us to unknown/unwanted users (this may happen when deleting chats or when using CC: in the email-program) */
+	#define         MR_CHAT_ID_TRASH            3 /* messages that should be deleted get this chat_id; the messages are deleted from the working thread later then. This is also needed as rfc724_mid should be preset as long as the message is not deleted on the server (otherwise it is downloaded again) */
+	#define         MR_CHAT_ID_MSGS_IN_CREATION 4 /* a message is just in creation but not yet assigned to a chat (eg. we may need the message ID to set up blobs; this avoids unready message to be send and shown) */
+	#define         MR_CHAT_ID_STARRED          5 /* virtual chat containing all starred messages */
+	#define         MR_CHAT_ID_ARCHIVED_LINK    6 /* a link at the end of the chatlist, if present the UI should show the button "Archived chats" */
+	#define         MR_CHAT_ID_LAST_SPECIAL     9 /* larger chat IDs are "real" chats, their messages are "real" messages. */
+	uint32_t        m_id;
+
+	#define         MR_CHAT_TYPE_UNDEFINED      0
+	#define         MR_CHAT_TYPE_NORMAL       100 /* a normal chat is a chat with a single contact, chats_contacts contains one record for the user, MR_CONTACT_ID_SELF is not added. */
+	#define         MR_CHAT_TYPE_GROUP        120 /* a group chat, chats_contacts conain all group members, incl. MR_CONTACT_ID_SELF */
+	int             m_type;
+
+	char*           m_name;                       /**< NULL if unset */
+	time_t          m_draft_timestamp;            /**< 0 if there is no draft */
+	char*           m_draft_text;                 /**< NULL if unset */
+	mrmailbox_t*    m_mailbox;                    /**< != NULL */
+	int             m_archived;                   /**< 1=chat archived, this state should always be shown the UI, eg. the search will also return archived chats */
+	mrparam_t*      m_param;                      /**< != NULL */
+
+	/** @privatesection */
+	char*           m_grpid;                      /* NULL if unset */
+} mrchat_t;
+
+
+void            mrchat_unref                (mrchat_t*);
+char*           mrchat_get_subtitle         (mrchat_t*);
+
+
+#ifdef __cplusplus
+} /* /extern "C" */
+#endif
+#endif /* __MRCHAT_H__ */

+ 61 - 0
deltachat-ios/libraries/deltachat-core/src/mrchatlist.h

@@ -0,0 +1,61 @@
+/*******************************************************************************
+ *
+ *                              Delta Chat Core
+ *                      Copyright (C) 2017 Björn Petersen
+ *                   Contact: r10s@b44t.com, http://b44t.com
+ *
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see http://www.gnu.org/licenses/ .
+ *
+ ******************************************************************************/
+
+
+#ifndef __MRCHATLIST_H__
+#define __MRCHATLIST_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+typedef struct mrmailbox_t  mrmailbox_t;
+typedef struct mrpoortext_t mrpoortext_t;
+typedef struct mrchat_t     mrchat_t;
+
+
+/**
+ * Chatlist objects contain a chat IDs and, if possible, message IDs belonging to them.
+ * Chatlist objects are created eg. using mrmailbox_get_chatlist().
+ * The chatlist object is not updated.  If you want an update, you have to recreate
+ * the object.
+ */
+typedef struct mrchatlist_t
+{
+	mrmailbox_t*    m_mailbox; /**< The mailbox, the chatlist belongs to */
+
+	/** @privatesection */
+	size_t          m_cnt;
+	carray*         m_chatNlastmsg_ids;
+} mrchatlist_t;
+
+
+void            mrchatlist_unref            (mrchatlist_t*);
+size_t          mrchatlist_get_cnt          (mrchatlist_t*);
+uint32_t        mrchatlist_get_chat_id      (mrchatlist_t*, size_t index);
+uint32_t        mrchatlist_get_msg_id       (mrchatlist_t*, size_t index);
+mrpoortext_t*   mrchatlist_get_summary      (mrchatlist_t*, size_t index, mrchat_t*);
+
+
+#ifdef __cplusplus
+} /* /extern "C" */
+#endif
+#endif /* __MRCHATLIST_H__ */

+ 139 - 6
deltachat-ios/libraries/deltachat-core/src/mrcontact.c

@@ -306,6 +306,13 @@ cleanup:
 }
 
 
+/**
+ * Library-internal.
+ *
+ * Calling this function is not thread-safe, locking is up to the caller.
+ *
+ * @private @memberof mrcontact_t
+ */
 int mrcontact_load_from_db__(mrcontact_t* ths, mrsqlite3_t* sql, uint32_t contact_id)
 {
 	int           success = 0;
@@ -345,6 +352,21 @@ cleanup:
  ******************************************************************************/
 
 
+ /**
+ * Add a single contact. and return the ID.
+ *
+ * @memberof mrmailbox_t
+ *
+ * @param mailbox The mailbox object as created by mrmailbox_new().
+ *
+ * @param name Name of the contact to add.
+ *
+ * @param addr E-mail-address of the contact to add. If the email address
+ *     already exists, the name is updated and the origin is increased to
+ *     "manually created".
+ *
+ * @return Contact ID of the created or reused contact.
+ */
 uint32_t mrmailbox_create_contact(mrmailbox_t* mailbox, const char* name, const char* addr)
 {
 	uint32_t contact_id = 0;
@@ -366,6 +388,21 @@ cleanup:
 }
 
 
+/**
+ * Add a number of contacts. The contacts must be added as
+ *
+ *
+ * @memberof mrmailbox_t
+ *
+ * @param mailbox the mailbox object as created by mrmailbox_new().
+ *
+ * @param address_book A multi-line string in the format in the format
+ *     `Name one\nAddress one\nName two\Address two`.  If an email address
+ *      already exists, the name is updated and the origin is increased to
+ *      "manually created".
+ *
+ * @return The number of modified or added contacts.
+ */
 int mrmailbox_add_address_book(mrmailbox_t* ths, const char* adr_book) /* format: Name one\nAddress one\nName two\Address two */
 {
 	carray* lines = NULL;
@@ -406,6 +443,21 @@ cleanup:
 }
 
 
+/**
+ * Returns known and unblocked contacts.
+ *
+ * To get information about a single contact, see mrmailbox_get_contact().
+ *
+ * @memberof mrmailbox_t
+ *
+ * @param mailbox The mailbox object as created by mrmailbox_new().
+ *
+ * @param query A string to filter the list.  Typically used to implement an
+ *     incremental search.  NULL for no filtering.
+ *
+ * @return An array containing all contact IDs.  Must be carray_free()'d
+ *     after usage.
+ */
 carray* mrmailbox_get_known_contacts(mrmailbox_t* mailbox, const char* query)
 {
 	int           locked = 0;
@@ -460,6 +512,16 @@ cleanup:
 }
 
 
+/**
+ * Get blocked contacts.
+ *
+ * @memberof mrmailbox_t
+ *
+ * @param mailbox The mailbox object as created by mrmailbox_new().
+ *
+ * @return An array containing all blocked contact IDs.  Must be carray_free()'d
+ *     after usage.
+ */
 carray* mrmailbox_get_blocked_contacts(mrmailbox_t* mailbox)
 {
 	carray*       ret = carray_new(100);
@@ -487,6 +549,13 @@ cleanup:
 }
 
 
+/**
+ * Get the number of blocked contacts.
+ *
+ * @memberof mrmailbox_t
+ *
+ * @param mailbox The mailbox object as created by mrmailbox_new().
+ */
 int mrmailbox_get_blocked_count(mrmailbox_t* mailbox)
 {
 	int           ret = 0, locked = 0;
@@ -517,6 +586,18 @@ cleanup:
 }
 
 
+/**
+ * Get a single contact object.  For a list, see eg. mrmailbox_get_known_contacts().
+ *
+ * @memberof mrmailbox_t
+ *
+ * @param mailbox The mailbox object as created by mrmailbox_new().
+ *
+ * @param contact_id ID of the contact to get the object for.
+ *
+ * @return The contact object, must be freed using mrcontact_unref() when no
+ *     longer used.  NULL on errors.
+ */
 mrcontact_t* mrmailbox_get_contact(mrmailbox_t* ths, uint32_t contact_id)
 {
 	mrcontact_t* ret = mrcontact_new();
@@ -576,14 +657,29 @@ void mrmailbox_marknoticed_contact(mrmailbox_t* mailbox, uint32_t contact_id)
 }
 
 
-int mrmailbox_block_contact(mrmailbox_t* mailbox, uint32_t contact_id, int new_blocking)
+/**
+ * Block or unblock a contact.
+ *
+ * May result in a MR_EVENT_BLOCKING_CHANGED event.
+ *
+ * @memberof mrmailbox_t
+ *
+ * @param mailbox The mailbox object as created by mrmailbox_new().
+ *
+ * @param contact_id The ID of the contact to block or unblock.
+ *
+ * @param block 1=block contact, 0=unblock contact
+ *
+ * @return None.
+ */
+void mrmailbox_block_contact(mrmailbox_t* mailbox, uint32_t contact_id, int new_blocking)
 {
-	int success = 0, locked = 0, send_event = 0, transaction_pending = 0;
+	int locked = 0, send_event = 0, transaction_pending = 0;
 	mrcontact_t*  contact = mrcontact_new();
 	sqlite3_stmt* stmt;
 
 	if( mailbox == NULL ) {
-		return 0;
+		return;
 	}
 
 	mrsqlite3_lock(mailbox->m_sql);
@@ -632,8 +728,6 @@ int mrmailbox_block_contact(mrmailbox_t* mailbox, uint32_t contact_id, int new_b
 		mailbox->m_cb(mailbox, MR_EVENT_CONTACTS_CHANGED, 0, 0);
 	}
 
-	success = 1;
-
 cleanup:
 	if( transaction_pending ) {
 		mrsqlite3_rollback__(mailbox->m_sql);
@@ -644,7 +738,6 @@ cleanup:
 	}
 
 	mrcontact_unref(contact);
-	return success;
 }
 
 
@@ -657,6 +750,19 @@ static void cat_fingerprint(mrstrbuilder_t* ret, const char* addr, const char* f
 }
 
 
+/**
+ * Get encryption info.
+ * Get a multi-line encryption info, containing your fingerprint and the
+ * fingerprint of the contact, used eg. to compare the fingerprints.
+ *
+ * @memberof mrmailbox_t
+ *
+ * @param mailbox The mailbox object as created by mrmailbox_new().
+ *
+ * @param contact_id ID of the contact to get the encryption info for.
+ *
+ * @return multi-line text, must be free()'d after usage.
+ */
 char* mrmailbox_get_contact_encrinfo(mrmailbox_t* mailbox, uint32_t contact_id)
 {
 	int             locked = 0;
@@ -773,6 +879,18 @@ cleanup:
 }
 
 
+/**
+ * Delete a contact.  The contact is deleted from the local device.  It may happen that this is not
+ * possible as the contact is in used.  In this case, the contact can be blocked.
+ *
+ * @memberof mrmailbox_t
+ *
+ * @param mailbox The mailbox object as created by mrmailbox_new().
+ *
+ * @param contact_id ID of the contact to delete.
+ *
+ * @return 1=success, 0=error
+ */
 int mrmailbox_delete_contact(mrmailbox_t* mailbox, uint32_t contact_id)
 {
 	int           locked = 0, success = 0;
@@ -842,6 +960,11 @@ int mrmailbox_contact_addr_equals__(mrmailbox_t* mailbox, uint32_t contact_id, c
 }
 
 
+/**
+ * Create a new contact object in memory.
+ *
+ * @memberof mrcontact_t
+ */
 mrcontact_t* mrcontact_new()
 {
 	mrcontact_t* ths = NULL;
@@ -854,6 +977,11 @@ mrcontact_t* mrcontact_new()
 }
 
 
+/**
+ * Free a contact object.
+ *
+ * @memberof mrcontact_t
+ */
 void mrcontact_unref(mrcontact_t* ths)
 {
 	if( ths==NULL ) {
@@ -865,6 +993,11 @@ void mrcontact_unref(mrcontact_t* ths)
 }
 
 
+/**
+ * Empty a contact object.
+ *
+ * @memberof mrcontact_t
+ */
 void mrcontact_empty(mrcontact_t* ths)
 {
 	if( ths == NULL ) {

+ 62 - 0
deltachat-ios/libraries/deltachat-core/src/mrcontact.h

@@ -0,0 +1,62 @@
+/*******************************************************************************
+ *
+ *                              Delta Chat Core
+ *                      Copyright (C) 2017 Björn Petersen
+ *                   Contact: r10s@b44t.com, http://b44t.com
+ *
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see http://www.gnu.org/licenses/ .
+ *
+ ******************************************************************************/
+
+
+#ifndef __MRCONTACT_H__
+#define __MRCONTACT_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+typedef struct mrsqlite3_t mrsqlite3_t;
+
+
+/**
+ * The contact object.
+ * The contact object is not updated.  If you want an update, you have to recreate
+ * the object.
+ */
+typedef struct mrcontact_t
+{
+	#define         MR_CONTACT_ID_SELF         1
+	#define         MR_CONTACT_ID_SYSTEM       2
+	#define         MR_CONTACT_ID_LAST_SPECIAL 9
+	uint32_t        m_id;
+
+	char*           m_name;     /* may be NULL or empty, this name should not be spreaded as it may be "Daddy" and so on; initially set to m_authname */
+	char*           m_authname; /* may be NULL or empty, this is the name authorized by the sender, only this name may be speaded to others, eg. in To:-lists; for displaying in the app, use m_name */
+	char*           m_addr;     /* may be NULL or empty */
+	int             m_origin;
+	int             m_blocked;
+} mrcontact_t;
+
+
+mrcontact_t* mrcontact_new                    (); /* the returned pointer is ref'd and must be unref'd after usage */
+void         mrcontact_empty                  (mrcontact_t*);
+void         mrcontact_unref                  (mrcontact_t*);
+int          mrcontact_load_from_db__         (mrcontact_t*, mrsqlite3_t*, uint32_t contact_id);
+
+
+#ifdef __cplusplus
+} /* /extern "C" */
+#endif
+#endif /* __MRCONTACT_H__ */

+ 10 - 11
deltachat-ios/libraries/deltachat-core/src/mrmailbox.c

@@ -868,7 +868,7 @@ static void cb_receive_imf(mrimap_t* imap, const char* imf_raw_not_terminated, s
 
 
 /**
- * mrmailbox_new() creates a new mailbox object.  After creation it is usually
+ * Create a new mailbox object.  After creation it is usually
  * opened, connected and mails are fetched.
  * After usage, the object should be deleted using mrmailbox_unref().
  *
@@ -941,12 +941,12 @@ mrmailbox_t* mrmailbox_new(mrmailboxcb_t cb, void* userdata, const char* os_name
 
 
 /**
- * After usage, the mailbox object should be freed using mrmailbox_unref().
+ * Free a mailbox object.
  * If app runs can only be terminated by a forced kill, this may be superfluous.
  *
  * @memberof mrmailbox_t
  *
- * @param mailbox the mailbox object as created by mrmailbox_new()
+ * @param mailbox the mailbox object as created by mrmailbox_new().
  *
  * @return none
  */
@@ -1190,7 +1190,7 @@ int mrmailbox_set_config(mrmailbox_t* ths, const char* key, const char* value)
 
 
 /**
- * Get a configuration option set by mrmailbox_set_config()
+ * Get a configuration option.  The configuration option is typically set by mrmailbox_set_config() or by the library itself.
  *
  * @memberof mrmailbox_t
  *
@@ -1220,7 +1220,7 @@ char* mrmailbox_get_config(mrmailbox_t* ths, const char* key, const char* def)
 
 
 /**
- * Similar to mrmailbox_set_config() but sets an integer instead of a string.
+ * Configure the mailbox.  Similar to mrmailbox_set_config() but sets an integer instead of a string.
  * If there is already a key with a string set, this is overwritten by the given integer value.
  *
  * @memberof mrmailbox_t
@@ -1243,7 +1243,7 @@ int mrmailbox_set_config_int(mrmailbox_t* ths, const char* key, int32_t value)
 
 
 /**
- * Similar as mrmailbox_get_config() but gets the value as an integer instead of a string.
+ * Get a configuration option. Similar as mrmailbox_get_config() but gets the value as an integer instead of a string.
  *
  * @memberof mrmailbox_t
  */
@@ -1279,15 +1279,14 @@ char* mrmailbox_get_blobdir(mrmailbox_t* mailbox)
 
 
 /**
- * mrmailbox_get_info() returns a multi-line output about the current
- * configuration and the last log entries. the returned string must be free()'d,
- * returns NULL on errors.
+ * Get information about the mailbox.  The information is returned by a multi-line string and contains information about the current
+ * configuration and the last log entries.
  *
  * @memberof mrmailbox_t
  *
  * @param mailbox Mailbox object as returned by mrmailbox_new().
  *
- * @return String which must be free()'d after usage.
+ * @return String which must be free()'d after usage.  Never returns NULL.
  */
 char* mrmailbox_get_info(mrmailbox_t* mailbox)
 {
@@ -1481,7 +1480,7 @@ int mrmailbox_reset_tables(mrmailbox_t* ths, int bits)
 
 
 /**
- * Use mrmailbox_get_version_str() to find out the version of the Delta Chat core library.
+ * Find out the version of the Delta Chat core library.
  *
  * @memberof mrmailbox_t
  *

+ 31 - 309
deltachat-ios/libraries/deltachat-core/src/mrmailbox.h

@@ -33,14 +33,14 @@ extern "C" {
 
 
 #include <libetpan/libetpan.h> /* defines uint16_t etc. */
+#include "mrchatlist.h"
+#include "mrchat.h"
+#include "mrmsg.h"
+#include "mrcontact.h"
+#include "mrpoortext.h"
+#include "mrparam.h"
 
 typedef struct mrmailbox_t  mrmailbox_t;
-typedef struct mrchatlist_t mrchatlist_t;
-typedef struct mrchat_t     mrchat_t;
-typedef struct mrmsg_t      mrmsg_t;
-typedef struct mrcontact_t  mrcontact_t;
-typedef struct mrpoortext_t mrpoortext_t;
-typedef struct mrparam_t    mrparam_t;
 typedef struct mrimap_t     mrimap_t;
 typedef struct mrsmtp_t     mrsmtp_t;
 typedef struct mrsqlite3_t  mrsqlite3_t;
@@ -51,7 +51,7 @@ typedef struct mrsqlite3_t  mrsqlite3_t;
  *
  * @memberof mrmailbox_t
  *
- * @param mailbox the mailbox object as created by mrmailbox_new
+ * @param mailbox the mailbox object as returned by mrmailbox_new().
  *
  * @param event one of the MR_EVENT_* constants
  *
@@ -65,8 +65,8 @@ typedef uintptr_t (*mrmailboxcb_t) (mrmailbox_t*, int event, uintptr_t data1, ui
 
 
 /**
- * mrmailbox_t represents a single mailbox, normally, typically only one
- * instance of this class is present.
+ * A single mailbox; typically only one instance of this class is present.
+ *
  * Each mailbox is linked to an IMAP/POP3 account and uses a separate
  * SQLite database for offline functionality and for mailbox-related
  * settings.
@@ -112,12 +112,10 @@ typedef struct mrmailbox_t
 mrmailbox_t*    mrmailbox_new               (mrmailboxcb_t, void* userdata, const char* os_name);
 void            mrmailbox_unref             (mrmailbox_t*);
 
-
 int             mrmailbox_open              (mrmailbox_t*, const char* dbfile, const char* blobdir);
 void            mrmailbox_close             (mrmailbox_t*);
 int             mrmailbox_is_open           (const mrmailbox_t*);
 
-
 int             mrmailbox_set_config        (mrmailbox_t*, const char* key, const char* value);
 char*           mrmailbox_get_config        (mrmailbox_t*, const char* key, const char* def);
 int             mrmailbox_set_config_int    (mrmailbox_t*, const char* key, int32_t value);
@@ -125,97 +123,37 @@ int32_t         mrmailbox_get_config_int    (mrmailbox_t*, const char* key, int3
 char*           mrmailbox_get_blobdir       (mrmailbox_t*);
 char*           mrmailbox_get_version_str   (void);
 
-
 void            mrmailbox_configure_and_connect(mrmailbox_t*);
 void            mrmailbox_configure_cancel  (mrmailbox_t*);
 int             mrmailbox_is_configured     (mrmailbox_t*);
 
-
 void            mrmailbox_connect           (mrmailbox_t*);
 void            mrmailbox_disconnect        (mrmailbox_t*);
 
-
 int             mrmailbox_restore           (mrmailbox_t*, time_t seconds_to_restore); /* not really implemented */
 char*           mrmailbox_get_info          (mrmailbox_t*);
 
 
-/*******************************************************************************
- * Handle chatlists
- ******************************************************************************/
-
-
-/**
- * Chatlist objects contain a chat IDs and, if possible, message IDs belonging to them.
- * Chatlist objects are created eg. using mrmailbox_get_chatlist().
- * The chatlist object is not updated.  If you want an update, you have to recreate
- * the object.
- */
-typedef struct mrchatlist_t
-{
-	mrmailbox_t*    m_mailbox; /**< The mailbox, the chatlist belongs to */
-
-	/** @privatesection */
-	size_t          m_cnt;
-	carray*         m_chatNlastmsg_ids;
-} mrchatlist_t;
-
-
+/* Handle chatlists */
 #define         MR_GCL_ARCHIVED_ONLY        0x01
 #define         MR_GCL_NO_SPECIALS          0x02
 mrchatlist_t*   mrmailbox_get_chatlist      (mrmailbox_t*, int flags, const char* query);
 
 
-void            mrchatlist_unref            (mrchatlist_t*);
-size_t          mrchatlist_get_cnt          (mrchatlist_t*);
-uint32_t        mrchatlist_get_chat_id      (mrchatlist_t*, size_t index);
-uint32_t        mrchatlist_get_msg_id       (mrchatlist_t*, size_t index);
-mrpoortext_t*   mrchatlist_get_summary      (mrchatlist_t*, size_t index, mrchat_t*);
-
-
-/**
- * the poortext object and some function accessing it.  A poortext object
- * contains some strings together with their meaning and some attributes.  The
- * object is mainly used for summary returns of chats and chatlists
- */
-typedef struct mrpoortext_t
-{
-	int             m_text1_meaning;   /**< One of MR_TEXT1_NORMAL, MR_TEXT1_DRAFT, MR_TEXT1_USERNAME or MR_TEXT1_SELF */
-	char*           m_text1;           /**< may be NULL */
-	char*           m_text2;           /**< may be NULL */
-	time_t          m_timestamp;       /**< may be 0 */
-	int             m_state;           /**< may be 0 */
-} mrpoortext_t;
-
-
-#define         MR_TEXT1_NORMAL    0 /**< @memberof mrpoortext_t */
-#define         MR_TEXT1_DRAFT     1 /**< @memberof mrpoortext_t */
-#define         MR_TEXT1_USERNAME  2 /**< @memberof mrpoortext_t */
-#define         MR_TEXT1_SELF      3 /**< @memberof mrpoortext_t */
-
-
-void            mrpoortext_unref            (mrpoortext_t*);
-
-
-/*******************************************************************************
- * Handle chats
- ******************************************************************************/
-
-
+/* Handle chats */
 uint32_t        mrmailbox_create_chat_by_contact_id (mrmailbox_t*, uint32_t contact_id);
 uint32_t        mrmailbox_get_chat_id_by_contact_id (mrmailbox_t*, uint32_t contact_id);
 
-
 uint32_t        mrmailbox_send_text_msg     (mrmailbox_t*, uint32_t chat_id, const char* text_to_send);
 uint32_t        mrmailbox_send_msg          (mrmailbox_t*, uint32_t chat_id, mrmsg_t*);
 void            mrmailbox_set_draft         (mrmailbox_t*, uint32_t chat_id, const char*);
 
-
 #define         MR_GCM_ADDDAYMARKER         0x01
 carray*         mrmailbox_get_chat_msgs     (mrmailbox_t*, uint32_t chat_id, uint32_t flags, uint32_t marker1before);
 int             mrmailbox_get_total_msg_count (mrmailbox_t*, uint32_t chat_id);
 int             mrmailbox_get_fresh_msg_count (mrmailbox_t*, uint32_t chat_id);
 carray*         mrmailbox_get_fresh_msgs    (mrmailbox_t*);
-int             mrmailbox_marknoticed_chat  (mrmailbox_t*, uint32_t chat_id);
+void            mrmailbox_marknoticed_chat  (mrmailbox_t*, uint32_t chat_id);
 carray*         mrmailbox_get_chat_media    (mrmailbox_t*, uint32_t chat_id, int msg_type, int or_msg_type);
 uint32_t        mrmailbox_get_next_media    (mrmailbox_t*, uint32_t curr_msg_id, int dir);
 
@@ -228,81 +166,16 @@ carray*         mrmailbox_search_msgs       (mrmailbox_t*, uint32_t chat_id, con
 mrchat_t*       mrmailbox_get_chat          (mrmailbox_t*, uint32_t chat_id);
 
 
-/**
- * Chat objects are created using eg. mrmailbox_get_chat().
- * The chat object is not updated.  If you want an update, you have to recreate the
- * object.
- */
-typedef struct mrchat_t
-{
-	#define         MR_CHAT_ID_DEADDROP         1 /* messages send from unknown/unwanted users to us, chats_contacts is not set up. This group may be shown normally. */
-	#define         MR_CHAT_ID_TO_DEADDROP      2 /* messages send from us to unknown/unwanted users (this may happen when deleting chats or when using CC: in the email-program) */
-	#define         MR_CHAT_ID_TRASH            3 /* messages that should be deleted get this chat_id; the messages are deleted from the working thread later then. This is also needed as rfc724_mid should be preset as long as the message is not deleted on the server (otherwise it is downloaded again) */
-	#define         MR_CHAT_ID_MSGS_IN_CREATION 4 /* a message is just in creation but not yet assigned to a chat (eg. we may need the message ID to set up blobs; this avoids unready message to be send and shown) */
-	#define         MR_CHAT_ID_STARRED          5 /* virtual chat containing all starred messages */
-	#define         MR_CHAT_ID_ARCHIVED_LINK    6 /* a link at the end of the chatlist, if present the UI should show the button "Archived chats" */
-	#define         MR_CHAT_ID_LAST_SPECIAL     9 /* larger chat IDs are "real" chats, their messages are "real" messages. */
-	uint32_t        m_id;
-
-	#define         MR_CHAT_TYPE_UNDEFINED      0
-	#define         MR_CHAT_TYPE_NORMAL       100 /* a normal chat is a chat with a single contact, chats_contacts contains one record for the user, MR_CONTACT_ID_SELF is not added. */
-	#define         MR_CHAT_TYPE_GROUP        120 /* a group chat, chats_contacts conain all group members, incl. MR_CONTACT_ID_SELF */
-	int             m_type;
-
-	char*           m_name;                       /**< NULL if unset */
-	time_t          m_draft_timestamp;            /**< 0 if there is no draft */
-	char*           m_draft_text;                 /**< NULL if unset */
-	mrmailbox_t*    m_mailbox;                    /**< != NULL */
-	int             m_archived;                   /**< 1=chat archived, this state should always be shown the UI, eg. the search will also return archived chats */
-	mrparam_t*      m_param;                      /**< != NULL */
-
-	/** @privatesection */
-	char*           m_grpid;                      /* NULL if unset */
-} mrchat_t;
-
-
-void            mrchat_unref                (mrchat_t*);
-char*           mrchat_get_subtitle         (mrchat_t*);
-
-
-/*******************************************************************************
- * Handle group chats
- ******************************************************************************/
-
-
-/* Create a new group chat.  After creation, the groups has one member with the
-ID MR_CONTACT_ID_SELF. */
+/* Handle group chats */
 uint32_t        mrmailbox_create_group_chat (mrmailbox_t*, const char* name);
-
-
-/* Check of a given contact_id is a member of a group chat defined by chat_id.
-Returns values: 1=contact is in chat, 0=contact is not in chat */
 int             mrmailbox_is_contact_in_chat (mrmailbox_t*, uint32_t chat_id, uint32_t contact_id);
-
-
-/* Add/remove a given contact_id to a  groupchat defined by chat_id. */
-int             mrmailbox_add_contact_to_chat      (mrmailbox_t*, uint32_t chat_id, uint32_t contact_id);
+int             mrmailbox_add_contact_to_chat (mrmailbox_t*, uint32_t chat_id, uint32_t contact_id);
 int             mrmailbox_remove_contact_from_chat (mrmailbox_t*, uint32_t chat_id, uint32_t contact_id);
-
-
-/* Set the name of a group chat.  The name is changed locally _and_ for all
-members of the chat.  the latter is done by a special message send to all
-users. */
 int             mrmailbox_set_chat_name     (mrmailbox_t*, uint32_t chat_id, const char* name);
-
-
-/* Set the group image of a group chat or delete it by passing NULL to the
-`image` parameter.
-The image is changed locally _and_ for all members of the chat.  The latter is
-done by a special message send to all users. */
 int             mrmailbox_set_chat_image    (mrmailbox_t*, uint32_t chat_id, const char* image);
 
 
-/*******************************************************************************
- * Handle messages
- ******************************************************************************/
-
-
+/* Handle messages */
 char*           mrmailbox_get_msg_info      (mrmailbox_t*, uint32_t msg_id);
 void            mrmailbox_delete_msgs       (mrmailbox_t*, const uint32_t* msg_ids, int msg_cnt);
 void            mrmailbox_forward_msgs      (mrmailbox_t*, const uint32_t* msg_ids, int msg_cnt, uint32_t chat_id);
@@ -312,174 +185,19 @@ void            mrmailbox_star_msgs         (mrmailbox_t*, const uint32_t* msg_i
 mrmsg_t*        mrmailbox_get_msg           (mrmailbox_t*, uint32_t msg_id);
 
 
-/**
- * The message object and some function for helping accessing it.  The message
- * object is not updated.  If you want an update, you have to recreate the
- * object.
- */
-typedef struct mrmsg_t
-{
-	#define         MR_MSG_ID_MARKER1       1 /**< any user-defined marker */
-	#define         MR_MSG_ID_DAYMARKER     9 /**< in a list, the next message is on a new day, useful to show headlines */
-	#define         MR_MSG_ID_LAST_SPECIAL  9
-	uint32_t        m_id;
-
-	uint32_t        m_from_id;                /**< contact, 0=unset, 1=self .. >9=real contacts */
-	uint32_t        m_to_id;                  /**< contact, 0=unset, 1=self .. >9=real contacts */
-	uint32_t        m_chat_id;                /**< the chat, the message belongs to: 0=unset, 1=unknwon sender .. >9=real chats */
-	time_t          m_timestamp;              /**< unix time the message was sended */
-
-	#define         MR_MSG_UNDEFINED        0
-	#define         MR_MSG_TEXT            10
-	#define         MR_MSG_IMAGE           20 /**< param: MRP_FILE, MRP_WIDTH, MRP_HEIGHT */
-	#define         MR_MSG_GIF             21 /**< param: MRP_FILE, MRP_WIDTH, MRP_HEIGHT */
-	#define         MR_MSG_AUDIO           40 /**< param: MRP_FILE, MRP_DURATION */
-	#define         MR_MSG_VOICE           41 /**< param: MRP_FILE, MRP_DURATION */
-	#define         MR_MSG_VIDEO           50 /**< param: MRP_FILE, MRP_WIDTH, MRP_HEIGHT, MRP_DURATION */
-	#define         MR_MSG_FILE            60 /**< param: MRP_FILE */
-	int             m_type;
-
-	#define         MR_STATE_UNDEFINED      0
-	#define         MR_STATE_IN_FRESH      10 /**< incoming message, not noticed nor seen */
-	#define         MR_STATE_IN_NOTICED    13 /**< incoming message noticed (eg. chat opened but message not yet read - noticed messages are not counted as unread but did not marked as read nor resulted in MDNs) */
-	#define         MR_STATE_IN_SEEN       16 /**< incoming message marked as read on IMAP and MDN may be send */
-	#define         MR_STATE_OUT_PENDING   20 /**< hit "send" button - but the message is pending in some way, maybe we're offline (no checkmark) */
-	#define         MR_STATE_OUT_ERROR     24 /**< unrecoverable error (recoverable errors result in pending messages) */
-	#define         MR_STATE_OUT_DELIVERED 26 /**< outgoing message successfully delivered to server (one checkmark) */
-	#define         MR_STATE_OUT_MDN_RCVD  28 /**< outgoing message read (two checkmarks; this requires goodwill on the receiver's side) */
-	int             m_state;
-
-	char*           m_text;                   /**< message text or NULL if unset */
-	mrparam_t*      m_param;                  /**< MRP_FILE, MRP_WIDTH, MRP_HEIGHT etc. depends on the type, != NULL */
-	int             m_starred;
-
-	/** @privatesection */
-	int             m_is_msgrmsg;
-	mrmailbox_t*    m_mailbox;                /* may be NULL, set on loading from database and on sending */
-	char*           m_rfc724_mid;
-	char*           m_server_folder;
-	uint32_t        m_server_uid;
-} mrmsg_t;
-
-
-mrmsg_t*        mrmsg_new                   ();
-void            mrmsg_unref                 (mrmsg_t*);
-void            mrmsg_empty                 (mrmsg_t*);
-mrpoortext_t*   mrmsg_get_summary           (mrmsg_t*, mrchat_t*);
-char*           mrmsg_get_summarytext       (mrmsg_t*, int approx_characters);
-int             mrmsg_show_padlock          (mrmsg_t*);
-char*           mrmsg_get_fullpath          (mrmsg_t*);
-char*           mrmsg_get_filename          (mrmsg_t*);
-mrpoortext_t*   mrmsg_get_mediainfo         (mrmsg_t*);
-int             mrmsg_is_increation         (mrmsg_t*);
-void            mrmsg_save_param_to_disk    (mrmsg_t*);
-
-
-/* Only sets the text field, MR_MSG_TEXT must be set additionally.
-Previously texts are free()'d. */
-void            mrmsg_set_text              (mrmsg_t*, const char* text);
-
 
-/*******************************************************************************
- * Handle contacts
- ******************************************************************************/
-
-
-/* create a single contact and return the ID.  If the contact's email address
-already exists, the name is updated and the origin is increased to
-"manually created". */
+/* Handle contacts */
 uint32_t        mrmailbox_create_contact    (mrmailbox_t*, const char* name, const char* addr);
-
-
-/* add a number of contacts in the format:
-`Name one\nAddress one\nName two\Address two`
-If the contact's email address already exists, the name is updated and the
-origin is increased to "manually created". */
 int             mrmailbox_add_address_book  (mrmailbox_t*, const char*);
-
-
-/* returns known and unblocked contacts, the result must be carray_free()'d.
-To get information about a single contact, see mrmailbox_get_contact() */
 carray*         mrmailbox_get_known_contacts (mrmailbox_t*, const char* query);
-
-
-/* Contact blocking handling.
-mrmailbox_block_contact() may result in a MR_EVENT_BLOCKING_CHANGED event. */
 int             mrmailbox_get_blocked_count (mrmailbox_t*);
 carray*         mrmailbox_get_blocked_contacts (mrmailbox_t*);
-int             mrmailbox_block_contact     (mrmailbox_t*, uint32_t contact_id, int block);
-
-
-/* get a multi-line encryption info, used to compare the fingerprints. */
+void            mrmailbox_block_contact     (mrmailbox_t*, uint32_t contact_id, int block);
 char*           mrmailbox_get_contact_encrinfo (mrmailbox_t*, uint32_t contact_id);
-
-
-/* delete a contact from the local device.  It may happen that this is not
-possible as the contact is used.  In this case, the contact can be blocked. */
 int             mrmailbox_delete_contact    (mrmailbox_t*, uint32_t contact_id);
-
-
-/* Get a single contact object of the type mrcontact_t - for a list, see mrmailbox_get_known_contacts() */
 mrcontact_t*    mrmailbox_get_contact       (mrmailbox_t*, uint32_t contact_id);
 
 
-/* The contact object and some function for helping accessing it.
-The contact object is not updated.  If you want an update, you have to recreate
-the object. */
-typedef struct mrcontact_t
-{
-	#define         MR_CONTACT_ID_SELF         1
-	#define         MR_CONTACT_ID_SYSTEM       2
-	#define         MR_CONTACT_ID_LAST_SPECIAL 9
-	uint32_t        m_id;
-
-	char*           m_name;     /* may be NULL or empty, this name should not be spreaded as it may be "Daddy" and so on; initially set to m_authname */
-	char*           m_authname; /* may be NULL or empty, this is the name authorized by the sender, only this name may be speaded to others, eg. in To:-lists; for displaying in the app, use m_name */
-	char*           m_addr;     /* may be NULL or empty */
-	int             m_origin;
-	int             m_blocked;
-} mrcontact_t;
-void            mrcontact_unref             (mrcontact_t*);
-
-
-/*******************************************************************************
- * Additional parameter handling
- ******************************************************************************/
-
-
-int             mrparam_exists              (mrparam_t*, int key);
-char*           mrparam_get                 (mrparam_t*, int key, const char* def); /* the value may be an empty string, "def" is returned only if the value unset.  The result must be free()'d in any case. */
-int32_t         mrparam_get_int             (mrparam_t*, int key, int32_t def);
-void            mrparam_set                 (mrparam_t*, int key, const char* value);
-void            mrparam_set_int             (mrparam_t*, int key, int32_t value);
-
-
-/* Parameters availalble */
-#define MRP_FILE              'f'  /* for msgs */
-#define MRP_WIDTH             'w'  /* for msgs */
-#define MRP_HEIGHT            'h'  /* for msgs */
-#define MRP_DURATION          'd'  /* for msgs */
-#define MRP_MIMETYPE          'm'  /* for msgs */
-#define MRP_AUTHORNAME        'N'  /* for msgs: name of author or artist */
-#define MRP_TRACKNAME         'n'  /* for msgs: name of author or artist */
-#define MRP_GUARANTEE_E2EE    'c'  /* for msgs: 'c'rypted in original/guarantee E2EE or the message is not send */
-#define MRP_ERRONEOUS_E2EE    'e'  /* for msgs: decrypted with validation errors or without mutual set, if neither 'c' nor 'e' are preset, the messages is only transport encrypted */
-#define MRP_WANTS_MDN         'r'  /* for msgs: an incoming message which requestes a MDN (aka read receipt) */
-#define MRP_FORWARDED         'a'  /* for msgs */
-#define MRP_SYSTEM_CMD        'S'  /* for msgs */
-#define MRP_SYSTEM_CMD_PARAM  'E'  /* for msgs */
-
-#define MRP_SERVER_FOLDER     'Z'  /* for jobs */
-#define MRP_SERVER_UID        'z'  /* for jobs */
-#define MRP_TIMES             't'  /* for jobs: times a job was tried */
-#define MRP_TIMES_INCREATION  'T'  /* for jobs: times a job was tried, used for increation */
-
-#define MRP_REFERENCES        'R'  /* for groups and chats: References-header last used for a chat */
-#define MRP_UNPROMOTED        'U'  /* for groups */
-#define MRP_PROFILE_IMAGE     'i'  /* for groups and contacts */
-#define MRP_DEL_AFTER_SEND    'P'  /* for groups and msgs: physically delete group after message sending if msg-value matches group-value */
-
-
 /*******************************************************************************
  * Events
  ******************************************************************************/
@@ -631,10 +349,6 @@ nested or unsynchronized calls */
  ******************************************************************************/
 
 
-/* mrmailbox_imex() imports and exports export keys, backup etc.
-Function, sends MR_EVENT_IMEX_* events.
-To avoid double slashes, the given directory should not end with a slash.
-_what_ to export is defined by a MR_IMEX_* constant */
 #define MR_IMEX_CANCEL                      0
 #define MR_IMEX_EXPORT_SELF_KEYS            1 /**< param1 is a directory where the keys are written to */
 #define MR_IMEX_IMPORT_SELF_KEYS            2 /**< param1 is a directory where the keys are searched in and read from */
@@ -644,21 +358,29 @@ _what_ to export is defined by a MR_IMEX_* constant */
 #define MR_BAK_PREFIX                      "delta-chat"
 #define MR_BAK_SUFFIX                      "bak"
 void            mrmailbox_imex              (mrmailbox_t*, int what, const char* param1, const char* setup_code);
-
-
-/* returns backup_file or NULL, may only be used on fresh installations (mrmailbox_is_configured() returns 0); returned strings must be free()'d */
 char*           mrmailbox_imex_has_backup   (mrmailbox_t*, const char* dir);
 
 
-/* Check if the user is authorized by the given password in some way. This is to promt for the password eg. before exporting keys/backup. */
+/**
+ * Check if the user is authorized by the given password in some way.
+ * This is to promt for the password eg. before exporting keys/backup.
+ *
+ * @memberof mrmailbox_t
+ *
+ * @param mailbox Mailbox object as created by mrmailbox_new().
+ *
+ * @param pw Password to check.
+ *
+ * @return 1=user is authorized, 0=user is not authorized.
+ */
 int             mrmailbox_check_password    (mrmailbox_t*, const char* pw);
 
 
-/* should be written down by the user, forwareded to mrmailbox_imex() for encryption then, must be wiped and free()'d after usage */
+
 char*           mrmailbox_create_setup_code (mrmailbox_t*);
 
 
-/* mainly for testing, import a folder with eml-files, a single eml-file, e-mail plus public key, ... NULL for the last command */
+
 int             mrmailbox_poke_spec         (mrmailbox_t*, const char* spec);
 
 

+ 1 - 1
deltachat-ios/libraries/deltachat-core/src/mrmailbox_configure.c

@@ -645,7 +645,7 @@ exit_:
 
 
 /**
- * mrmailbox_configure_and_connect() configures and connects a mailbox.
+ * Configure and connect a mailbox.
  *
  * - Before your call this function, you should set at least `addr` and `mail_pw`
  *   using mrmailbox_set_config().

+ 80 - 21
deltachat-ios/libraries/deltachat-core/src/mrmailbox_imex.c

@@ -84,10 +84,23 @@ cleanup:
 }
 
 
-int mrmailbox_poke_spec(mrmailbox_t* mailbox, const char* spec__) /* spec is a file, a directory or NULL for the last import */
+/**
+ * Import a file to the database.
+ * For testing, import a folder with eml-files, a single eml-file, e-mail plus public key and so on.
+ * For normal importing, use mrmailbox_imex().
+ *
+ * @private @memberof mrmailbox_t
+ *
+ * @param mailbox Mailbox object as created by mrmailbox_new().
+ *
+ * @param spec The file or directory to import. NULL for the last command.
+ *
+ * @return 1=success, 0=error.
+ */
+int mrmailbox_poke_spec(mrmailbox_t* mailbox, const char* spec)
 {
 	int            success = 0;
-	char*          spec = NULL;
+	char*          real_spec = NULL;
 	char*          suffix = NULL;
 	DIR*           dir = NULL;
 	struct dirent* dir_entry;
@@ -104,54 +117,54 @@ int mrmailbox_poke_spec(mrmailbox_t* mailbox, const char* spec__) /* spec is a f
 	}
 
 	/* if `spec` is given, remember it for later usage; if it is not given, try to use the last one */
-	if( spec__ )
+	if( spec )
 	{
-		spec = safe_strdup(spec__);
+		real_spec = safe_strdup(spec);
 		mrsqlite3_lock(mailbox->m_sql);
-			mrsqlite3_set_config__(mailbox->m_sql, "import_spec", spec);
+			mrsqlite3_set_config__(mailbox->m_sql, "import_spec", real_spec);
 		mrsqlite3_unlock(mailbox->m_sql);
 	}
 	else {
 		mrsqlite3_lock(mailbox->m_sql);
-			spec = mrsqlite3_get_config__(mailbox->m_sql, "import_spec", NULL); /* may still NULL */
+			real_spec = mrsqlite3_get_config__(mailbox->m_sql, "import_spec", NULL); /* may still NULL */
 		mrsqlite3_unlock(mailbox->m_sql);
-		if( spec == NULL ) {
+		if( real_spec == NULL ) {
 			mrmailbox_log_error(mailbox, 0, "Import: No file or folder given.");
 			goto cleanup;
 		}
 	}
 
-	suffix = mr_get_filesuffix_lc(spec);
+	suffix = mr_get_filesuffix_lc(real_spec);
 	if( suffix && strcmp(suffix, "eml")==0 ) {
 		/* import a single file */
-		if( mrmailbox_poke_eml_file(mailbox, spec) ) { /* errors are logged in any case */
+		if( mrmailbox_poke_eml_file(mailbox, real_spec) ) { /* errors are logged in any case */
 			read_cnt++;
 		}
 	}
 	else if( suffix && (strcmp(suffix, "pem")==0||strcmp(suffix, "asc")==0) ) {
 		/* import a publix key */
-		char* separator = strchr(spec, ' ');
+		char* separator = strchr(real_spec, ' ');
 		if( separator==NULL ) {
 			mrmailbox_log_error(mailbox, 0, "Import: Key files must be specified as \"<addr> <key-file>\".");
 			goto cleanup;
 		}
 		*separator = 0;
-		if( poke_public_key(mailbox, spec, separator+1) ) {
+		if( poke_public_key(mailbox, real_spec, separator+1) ) {
 			read_cnt++;
 		}
 		*separator = ' ';
 	}
 	else {
 		/* import a directory */
-		if( (dir=opendir(spec))==NULL ) {
-			mrmailbox_log_error(mailbox, 0, "Import: Cannot open directory \"%s\".", spec);
+		if( (dir=opendir(real_spec))==NULL ) {
+			mrmailbox_log_error(mailbox, 0, "Import: Cannot open directory \"%s\".", real_spec);
 			goto cleanup;
 		}
 
 		while( (dir_entry=readdir(dir))!=NULL ) {
 			name = dir_entry->d_name; /* name without path; may also be `.` or `..` */
 			if( strlen(name)>=4 && strcmp(&name[strlen(name)-4], ".eml")==0 ) {
-				char* path_plus_name = mr_mprintf("%s/%s", spec, name);
+				char* path_plus_name = mr_mprintf("%s/%s", real_spec, name);
 				mrmailbox_log_info(mailbox, 0, "Import: %s", path_plus_name);
 				if( mrmailbox_poke_eml_file(mailbox, path_plus_name) ) { /* no abort on single errors errors are logged in any case */
 					read_cnt++;
@@ -161,7 +174,7 @@ int mrmailbox_poke_spec(mrmailbox_t* mailbox, const char* spec__) /* spec is a f
 		}
 	}
 
-	mrmailbox_log_info(mailbox, 0, "Import: %i items read from \"%s\".", read_cnt, spec);
+	mrmailbox_log_info(mailbox, 0, "Import: %i items read from \"%s\".", read_cnt, real_spec);
 	if( read_cnt > 0 ) {
 		mailbox->m_cb(mailbox, MR_EVENT_MSGS_CHANGED, 0, 0); /* even if read_cnt>0, the number of messages added to the database may be 0. While we regard this issue using IMAP, we ignore it here. */
 	}
@@ -174,7 +187,7 @@ cleanup:
 	if( dir ) {
 		closedir(dir);
 	}
-	free(spec);
+	free(real_spec);
 	free(suffix);
 	return success;
 }
@@ -820,6 +833,19 @@ cleanup:
  ******************************************************************************/
 
 
+/**
+ * Check if there is a backup file.
+ *
+ * May only be used on fresh installations (mrmailbox_is_configured() returns 0).
+ *
+ * @memberof mrmailbox_t
+ *
+ * @param mailbox Mailbox object as created by mrmailbox_new().
+ *
+ * @param dir Directory to search backups in.
+ *
+ * @return String with the backup file or NULL; returned strings must be free()'d.
+ */
 char* mrmailbox_imex_has_backup(mrmailbox_t* mailbox, const char* dir_name)
 {
 	char*          ret = NULL;
@@ -1059,6 +1085,26 @@ cleanup:
 }
 
 
+/**
+ * Import/export things.
+ *
+ * mrmailbox_imex() imports and exports export keys, backup etc.
+ * Function, sends MR_EVENT_IMEX_* events.
+ * To avoid double slashes, the given directory should not end with a slash.
+ * _what_ to export is defined by a MR_IMEX_* constant.
+ *
+ * @memberof mrmailbox_t
+ *
+ * @param mailbox Mailbox object as created by mrmailbox_new().
+ *
+ * @param what One of the MR_IMEX_* constants.
+ *
+ * @param param1 Meaning depends on the MR_IMEX_* constants.
+ *
+ * @param setup_code Setup-code to encrypt/decrypt data.
+ *
+ * @return None.
+ */
 void mrmailbox_imex(mrmailbox_t* mailbox, int what, const char* param1, const char* setup_code)
 {
 	mrimexthreadparam_t* thread_param;
@@ -1137,11 +1183,24 @@ cleanup:
 }
 
 
-/* create an "Autocrypt Level 1" setup code in the form
-1234-1234-1234-
-1234-1234-1234-
-1234-1234-1234
-Linebreaks and spaces MUST NOT be added to the setup code, but the "-" are. */
+/**
+ * Create random setup code.
+ *
+ * The created "Autocrypt Level 1" setup code has the following form:
+ *
+ *     1234-1234-1234-
+ *     1234-1234-1234-
+ *     1234-1234-1234
+ *
+ * Linebreaks and spaces are not added to the setup code, but the "-" are.
+ * Should be given to  mrmailbox_imex() for encryption, should be wiped and free()'d after usage.
+ *
+ * @memberof mrmailbox_t
+ *
+ * @param mailbox Mailbox object as created by mrmailbox_new().
+ *
+ * @return Setup code, must be free()'d after usage.
+ */
 char* mrmailbox_create_setup_code(mrmailbox_t* mailbox)
 {
 	#define   CODE_ELEMS 9

+ 0 - 35
deltachat-ios/libraries/deltachat-core/src/mrmailbox_internal.h

@@ -185,9 +185,6 @@ void         mr_get_authorNtitle_from_filename(const char* pathNfilename, char**
 #define MR_ORIGIN_MIN_VERIFIED        (MR_ORIGIN_INCOMING_REPLY_TO) /* contacts with at least this origin value are verified and known not to be spam */
 #define MR_ORIGIN_MIN_START_NEW_NCHAT (0x7FFFFFFF)                  /* contacts with at least this origin value start a new "normal" chat, defaults to off */
 
-mrcontact_t* mrcontact_new                    (); /* the returned pointer is ref'd and must be unref'd after usage */
-void         mrcontact_empty                  (mrcontact_t*);
-int          mrcontact_load_from_db__         (mrcontact_t*, mrsqlite3_t*, uint32_t id);
 size_t       mrmailbox_get_real_contact_cnt__ (mrmailbox_t*);
 uint32_t     mrmailbox_add_or_lookup_contact__(mrmailbox_t*, const char* display_name /*can be NULL*/, const char* addr_spec, int origin, int* sth_modified);
 int          mrmailbox_get_contact_origin__   (mrmailbox_t*, uint32_t id, int* ret_blocked);
@@ -199,38 +196,6 @@ void         mr_normalize_name                (char* full_name);
 char*        mr_get_first_name                (const char* full_name); /* returns part before the space or after a comma; the result must be free()'d */
 
 
-/*******************************************************************************
- * Internal poortext handling
- ******************************************************************************/
-
-
-mrpoortext_t* mrpoortext_new       ();
-void          mrpoortext_empty     (mrpoortext_t*);
-
-#define MR_SUMMARY_CHARACTERS 160 /* in practice, the user additinally cuts the string himself pixel-accurate */
-void mrpoortext_fill(mrpoortext_t*, const mrmsg_t*, const mrchat_t*, const mrcontact_t*);
-
-
-/*******************************************************************************
- * Internal additional parameter handling
- ******************************************************************************/
-
-
-/* The parameter object as used eg. by mrchat_t or mrmsg_t.
-To access the single parameters use the setter and getter functions with an
-MRP_* contant */
-typedef struct mrparam_t
-{
-	char*           m_packed;    /* != NULL */
-} mrparam_t;
-
-
-mrparam_t*    mrparam_new          ();
-void          mrparam_empty        (mrparam_t*);
-void          mrparam_unref        (mrparam_t*);
-void          mrparam_set_packed   (mrparam_t*, const char*); /* overwrites all existing parameters */
-
-
 /*******************************************************************************
  * Internal stock string handling
  ******************************************************************************/

+ 18 - 1
deltachat-ios/libraries/deltachat-core/src/mrmsg.c

@@ -350,6 +350,23 @@ cleanup:
 }
 
 
+/**
+ * Set the text of a message object.
+ *
+ * The text is _not_ modified in the database, this function is only a helper to
+ * set up a message object to be sent afterwards. The type of the message object
+ * is not changed implicitly to MR_MSG_TEXT when using this function. Previously
+ * set texts are free()'d.
+ *
+ * @memberof mrmsg_t
+ *
+ * @param msg Message to set the text for.
+ *
+ * @param text Text to set.  The function creates a copy of the given text so
+ *     that it can be free()'d just after this function is called.
+ *
+ * @return None.
+ */
 void mrmsg_set_text(mrmsg_t* msg, const char* text)
 {
 	if( msg==NULL || text==NULL ) {
@@ -367,7 +384,7 @@ void mrmsg_set_text(mrmsg_t* msg, const char* text)
  *
  * @memberof mrmailbox_t
  *
- * @param mailbox the mailbox object as created by mrmailbox_new()
+ * @param mailbox the mailbox object as created by mrmailbox_new().
  *
  * @param msg_id the message id for which information should be generated
  *

+ 101 - 0
deltachat-ios/libraries/deltachat-core/src/mrmsg.h

@@ -0,0 +1,101 @@
+/*******************************************************************************
+ *
+ *                              Delta Chat Core
+ *                      Copyright (C) 2017 Björn Petersen
+ *                   Contact: r10s@b44t.com, http://b44t.com
+ *
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see http://www.gnu.org/licenses/ .
+ *
+ ******************************************************************************/
+
+
+#ifndef __MRMSG_H__
+#define __MRMSG_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+typedef struct mrmailbox_t mrmailbox_t;
+typedef struct mrparam_t   mrparam_t;
+
+
+/**
+ * The message object and some function for helping accessing it.  The message
+ * object is not updated.  If you want an update, you have to recreate the
+ * object.
+ */
+typedef struct mrmsg_t
+{
+	#define         MR_MSG_ID_MARKER1       1 /**< any user-defined marker */
+	#define         MR_MSG_ID_DAYMARKER     9 /**< in a list, the next message is on a new day, useful to show headlines */
+	#define         MR_MSG_ID_LAST_SPECIAL  9
+	uint32_t        m_id;
+
+	uint32_t        m_from_id;                /**< contact, 0=unset, 1=self .. >9=real contacts */
+	uint32_t        m_to_id;                  /**< contact, 0=unset, 1=self .. >9=real contacts */
+	uint32_t        m_chat_id;                /**< the chat, the message belongs to: 0=unset, 1=unknwon sender .. >9=real chats */
+	time_t          m_timestamp;              /**< unix time the message was sended */
+
+	#define         MR_MSG_UNDEFINED        0
+	#define         MR_MSG_TEXT            10
+	#define         MR_MSG_IMAGE           20 /**< param: MRP_FILE, MRP_WIDTH, MRP_HEIGHT */
+	#define         MR_MSG_GIF             21 /**< param: MRP_FILE, MRP_WIDTH, MRP_HEIGHT */
+	#define         MR_MSG_AUDIO           40 /**< param: MRP_FILE, MRP_DURATION */
+	#define         MR_MSG_VOICE           41 /**< param: MRP_FILE, MRP_DURATION */
+	#define         MR_MSG_VIDEO           50 /**< param: MRP_FILE, MRP_WIDTH, MRP_HEIGHT, MRP_DURATION */
+	#define         MR_MSG_FILE            60 /**< param: MRP_FILE */
+	int             m_type;
+
+	#define         MR_STATE_UNDEFINED      0
+	#define         MR_STATE_IN_FRESH      10 /**< incoming message, not noticed nor seen */
+	#define         MR_STATE_IN_NOTICED    13 /**< incoming message noticed (eg. chat opened but message not yet read - noticed messages are not counted as unread but did not marked as read nor resulted in MDNs) */
+	#define         MR_STATE_IN_SEEN       16 /**< incoming message marked as read on IMAP and MDN may be send */
+	#define         MR_STATE_OUT_PENDING   20 /**< hit "send" button - but the message is pending in some way, maybe we're offline (no checkmark) */
+	#define         MR_STATE_OUT_ERROR     24 /**< unrecoverable error (recoverable errors result in pending messages) */
+	#define         MR_STATE_OUT_DELIVERED 26 /**< outgoing message successfully delivered to server (one checkmark) */
+	#define         MR_STATE_OUT_MDN_RCVD  28 /**< outgoing message read (two checkmarks; this requires goodwill on the receiver's side) */
+	int             m_state;
+
+	char*           m_text;                   /**< message text or NULL if unset */
+	mrparam_t*      m_param;                  /**< MRP_FILE, MRP_WIDTH, MRP_HEIGHT etc. depends on the type, != NULL */
+	int             m_starred;
+
+	/** @privatesection */
+	int             m_is_msgrmsg;
+	mrmailbox_t*    m_mailbox;                /* may be NULL, set on loading from database and on sending */
+	char*           m_rfc724_mid;
+	char*           m_server_folder;
+	uint32_t        m_server_uid;
+} mrmsg_t;
+
+
+mrmsg_t*        mrmsg_new                   ();
+void            mrmsg_unref                 (mrmsg_t*);
+void            mrmsg_empty                 (mrmsg_t*);
+mrpoortext_t*   mrmsg_get_summary           (mrmsg_t*, mrchat_t*);
+char*           mrmsg_get_summarytext       (mrmsg_t*, int approx_characters);
+int             mrmsg_show_padlock          (mrmsg_t*);
+char*           mrmsg_get_fullpath          (mrmsg_t*);
+char*           mrmsg_get_filename          (mrmsg_t*);
+mrpoortext_t*   mrmsg_get_mediainfo         (mrmsg_t*);
+int             mrmsg_is_increation         (mrmsg_t*);
+void            mrmsg_save_param_to_disk    (mrmsg_t*);
+void            mrmsg_set_text              (mrmsg_t*, const char* text);
+
+
+#ifdef __cplusplus
+} /* /extern "C" */
+#endif
+#endif /* __MRMSG_H__ */

+ 63 - 34
deltachat-ios/libraries/deltachat-core/src/mrparam.c

@@ -69,77 +69,96 @@ static char* find_param(char* ths, int key, char** ret_p2)
  ******************************************************************************/
 
 
+/**
+ * @memberof mrparam_t
+ */
 mrparam_t* mrparam_new()
 {
-	mrparam_t* ths;
+	mrparam_t* param;
 
-	if( (ths=calloc(1, sizeof(mrparam_t)))==NULL ) {
+	if( (param=calloc(1, sizeof(mrparam_t)))==NULL ) {
 		exit(28); /* cannot allocate little memory, unrecoverable error */
 	}
 
-	ths->m_packed = calloc(1, 1);
+	param->m_packed = calloc(1, 1);
 
-    return ths;
+    return param;
 }
 
 
-void mrparam_unref(mrparam_t* ths)
+/**
+ * @memberof mrparam_t
+ */
+void mrparam_unref(mrparam_t* param)
 {
-	if( ths==NULL ) {
+	if( param==NULL ) {
 		return;
 	}
 
-	mrparam_empty(ths);
-	free(ths->m_packed);
-	free(ths);
+	mrparam_empty(param);
+	free(param->m_packed);
+	free(param);
 }
 
 
-void mrparam_empty(mrparam_t* ths)
+/**
+ * @memberof mrparam_t
+ */
+void mrparam_empty(mrparam_t* param)
 {
-	if( ths == NULL ) {
+	if( param == NULL ) {
 		return;
 	}
 
-	ths->m_packed[0] = 0;
+	param->m_packed[0] = 0;
 }
 
 
-void mrparam_set_packed(mrparam_t* ths, const char* packed)
+/**
+ * @memberof mrparam_t
+ */
+void mrparam_set_packed(mrparam_t* param, const char* packed)
 {
-	if( ths == NULL ) {
+	if( param == NULL ) {
 		return;
 	}
 
-	mrparam_empty(ths);
+	mrparam_empty(param);
 
 	if( packed ) {
-		free(ths->m_packed);
-		ths->m_packed = safe_strdup(packed);
+		free(param->m_packed);
+		param->m_packed = safe_strdup(packed);
 	}
 }
 
 
-int mrparam_exists(mrparam_t* ths, int key)
+/**
+ * @memberof mrparam_t
+ */
+int mrparam_exists(mrparam_t* param, int key)
 {
 	char *p2;
 
-	if( ths == NULL || key == 0 ) {
+	if( param == NULL || key == 0 ) {
 		return 0;
 	}
 
-	return find_param(ths->m_packed, key, &p2)? 1 : 0;
+	return find_param(param->m_packed, key, &p2)? 1 : 0;
 }
 
-char* mrparam_get(mrparam_t* ths, int key, const char* def)
+
+/**
+ * @memberof mrparam_t
+ */
+char* mrparam_get(mrparam_t* param, int key, const char* def)
 {
 	char *p1, *p2, bak, *ret;
 
-	if( ths == NULL || key == 0 ) {
+	if( param == NULL || key == 0 ) {
 		return def? safe_strdup(def) : NULL;
 	}
 
-	p1 = find_param(ths->m_packed, key, &p2);
+	p1 = find_param(param->m_packed, key, &p2);
 	if( p1 == NULL ) {
 		return def? safe_strdup(def) : NULL;
 	}
@@ -155,13 +174,16 @@ char* mrparam_get(mrparam_t* ths, int key, const char* def)
 }
 
 
-int32_t mrparam_get_int(mrparam_t* ths, int key, int32_t def)
+/**
+ * @memberof mrparam_t
+ */
+int32_t mrparam_get_int(mrparam_t* param, int key, int32_t def)
 {
-	if( ths == NULL || key == 0 ) {
+	if( param == NULL || key == 0 ) {
 		return def;
 	}
 
-    char* str = mrparam_get(ths, key, NULL);
+    char* str = mrparam_get(param, key, NULL);
     if( str == NULL ) {
 		return def;
     }
@@ -171,15 +193,19 @@ int32_t mrparam_get_int(mrparam_t* ths, int key, int32_t def)
 }
 
 
-void mrparam_set(mrparam_t* ths, int key, const char* value)
+/**
+ * @memberof mrparam_t
+ *
+ */
+void mrparam_set(mrparam_t* param, int key, const char* value)
 {
 	char *old1, *old2, *new1 = NULL;
 
-	if( ths == NULL || key == 0 ) {
+	if( param == NULL || key == 0 ) {
 		return;
 	}
 
-	old1 = ths->m_packed;
+	old1 = param->m_packed;
 	old2 = NULL;
 
 	/* remove existing parameter from packed string, if any */
@@ -218,14 +244,17 @@ void mrparam_set(mrparam_t* ths, int key, const char* value)
 			old2?         old2 : "");
 	}
 
-	free(ths->m_packed);
-	ths->m_packed = new1;
+	free(param->m_packed);
+	param->m_packed = new1;
 }
 
 
-void mrparam_set_int(mrparam_t* ths, int key, int32_t value)
+/**
+ * @memberof mrparam_t
+ */
+void mrparam_set_int(mrparam_t* param, int key, int32_t value)
 {
-	if( ths == NULL || key == 0 ) {
+	if( param == NULL || key == 0 ) {
 		return;
 	}
 
@@ -233,6 +262,6 @@ void mrparam_set_int(mrparam_t* ths, int key, int32_t value)
     if( value_str == NULL ) {
 		return;
     }
-    mrparam_set(ths, key, value_str);
+    mrparam_set(param, key, value_str);
     free(value_str);
 }

+ 87 - 0
deltachat-ios/libraries/deltachat-core/src/mrparam.h

@@ -0,0 +1,87 @@
+/*******************************************************************************
+ *
+ *                              Delta Chat Core
+ *                      Copyright (C) 2017 Björn Petersen
+ *                   Contact: r10s@b44t.com, http://b44t.com
+ *
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see http://www.gnu.org/licenses/ .
+ *
+ ******************************************************************************/
+
+
+#ifndef __MRPARAM_H__
+#define __MRPARAM_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * Handle key=value parameters.
+ * The parameter object is used eg. by mrchat_t or mrmsg_t.
+ * To access the single parameters use the setter and getter functions with an
+ * MRP_* constant.
+ */
+typedef struct mrparam_t
+{
+	/** @privatesection */
+	char*           m_packed;    /**< Always set, never NULL. */
+} mrparam_t;
+
+
+#define MRP_FILE              'f'  /* for msgs */
+#define MRP_WIDTH             'w'  /* for msgs */
+#define MRP_HEIGHT            'h'  /* for msgs */
+#define MRP_DURATION          'd'  /* for msgs */
+#define MRP_MIMETYPE          'm'  /* for msgs */
+#define MRP_AUTHORNAME        'N'  /* for msgs: name of author or artist */
+#define MRP_TRACKNAME         'n'  /* for msgs: name of author or artist */
+#define MRP_GUARANTEE_E2EE    'c'  /* for msgs: 'c'rypted in original/guarantee E2EE or the message is not send */
+#define MRP_ERRONEOUS_E2EE    'e'  /* for msgs: decrypted with validation errors or without mutual set, if neither 'c' nor 'e' are preset, the messages is only transport encrypted */
+#define MRP_WANTS_MDN         'r'  /* for msgs: an incoming message which requestes a MDN (aka read receipt) */
+#define MRP_FORWARDED         'a'  /* for msgs */
+#define MRP_SYSTEM_CMD        'S'  /* for msgs */
+#define MRP_SYSTEM_CMD_PARAM  'E'  /* for msgs */
+
+#define MRP_SERVER_FOLDER     'Z'  /* for jobs */
+#define MRP_SERVER_UID        'z'  /* for jobs */
+#define MRP_TIMES             't'  /* for jobs: times a job was tried */
+#define MRP_TIMES_INCREATION  'T'  /* for jobs: times a job was tried, used for increation */
+
+#define MRP_REFERENCES        'R'  /* for groups and chats: References-header last used for a chat */
+#define MRP_UNPROMOTED        'U'  /* for groups */
+#define MRP_PROFILE_IMAGE     'i'  /* for groups and contacts */
+#define MRP_DEL_AFTER_SEND    'P'  /* for groups and msgs: physically delete group after message sending if msg-value matches group-value */
+
+
+/* user functions */
+int             mrparam_exists       (mrparam_t*, int key);
+char*           mrparam_get          (mrparam_t*, int key, const char* def); /* the value may be an empty string, "def" is returned only if the value unset.  The result must be free()'d in any case. */
+int32_t         mrparam_get_int      (mrparam_t*, int key, int32_t def);
+void            mrparam_set          (mrparam_t*, int key, const char* value);
+void            mrparam_set_int      (mrparam_t*, int key, int32_t value);
+
+/* library-private */
+mrparam_t*      mrparam_new          ();
+void            mrparam_empty        (mrparam_t*);
+void            mrparam_unref        (mrparam_t*);
+void            mrparam_set_packed   (mrparam_t*, const char*);
+
+
+
+
+#ifdef __cplusplus
+} /* /extern "C" */
+#endif
+#endif /* __MRPARAM_H__ */

+ 63 - 0
deltachat-ios/libraries/deltachat-core/src/mrpoortext.h

@@ -0,0 +1,63 @@
+/*******************************************************************************
+ *
+ *                              Delta Chat Core
+ *                      Copyright (C) 2017 Björn Petersen
+ *                   Contact: r10s@b44t.com, http://b44t.com
+ *
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see http://www.gnu.org/licenses/ .
+ *
+ ******************************************************************************/
+
+
+#ifndef __MRPOORTEXT_H__
+#define __MRPOORTEXT_H__
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * the poortext object and some function accessing it.  A poortext object
+ * contains some strings together with their meaning and some attributes.  The
+ * object is mainly used for summary returns of chats and chatlists
+ */
+typedef struct mrpoortext_t
+{
+	int             m_text1_meaning;   /**< One of MR_TEXT1_NORMAL, MR_TEXT1_DRAFT, MR_TEXT1_USERNAME or MR_TEXT1_SELF */
+	char*           m_text1;           /**< may be NULL */
+	char*           m_text2;           /**< may be NULL */
+	time_t          m_timestamp;       /**< may be 0 */
+	int             m_state;           /**< may be 0 */
+} mrpoortext_t;
+
+
+#define         MR_TEXT1_NORMAL    0 /**< @memberof mrpoortext_t */
+#define         MR_TEXT1_DRAFT     1 /**< @memberof mrpoortext_t */
+#define         MR_TEXT1_USERNAME  2 /**< @memberof mrpoortext_t */
+#define         MR_TEXT1_SELF      3 /**< @memberof mrpoortext_t */
+
+
+mrpoortext_t*   mrpoortext_new       ();
+void            mrpoortext_empty     (mrpoortext_t*);
+void            mrpoortext_unref     (mrpoortext_t*);
+
+
+#define MR_SUMMARY_CHARACTERS 160 /* in practice, the user additionally cuts the string himself pixel-accurate */
+void            mrpoortext_fill      (mrpoortext_t*, const mrmsg_t*, const mrchat_t*, const mrcontact_t*);
+
+
+#ifdef __cplusplus
+} /* /extern "C" */
+#endif
+#endif /* __MRPOORTEXT_H__ */

+ 14 - 20
deltachat-ios/libraries/deltachat-core/src/mrsqlite3.h

@@ -20,12 +20,6 @@
  ******************************************************************************/
 
 
-/* NB: In general, function names ending with a `__` implie that _no_
-locking takes place inside the functions!  So the caller must make sure, the
-database is locked as needed.  Of course, the same is true if you call any
-sqlite3-function directly. */
-
-
 #ifndef __MRSQLITE3_H__
 #define __MRSQLITE3_H__
 #ifdef __cplusplus
@@ -157,22 +151,22 @@ enum
 };
 
 
+/**
+ * Library-internal.
+ *
+ * In general, function names ending with two underscores (`__`) implie that _no_
+ * locking takes place inside the functions!  So the caller must make sure, the
+ * database is locked as needed.  Of course, the same is true if you call any
+ * sqlite3-function directly.
+ */
 typedef struct mrsqlite3_t
 {
-	/* prepared statements - this is the favourite way for the caller to use SQLite */
-	sqlite3_stmt* m_pd[PREDEFINED_CNT];
-
-	/* m_sqlite is the database given as dbfile to Open() */
-	sqlite3*      m_cobj;
-
-	/* helper for MrSqlite3Transaction */
-	int           m_transactionCount;
-
-	mrmailbox_t*  m_mailbox; /* used for logging and to acquire wakelocks, there may be N mrsqlite3_t objects per mrmailbox! In practise, we use 2 on backup, 1 otherwise. */
-
-	/* the user must make sure, only one thread uses sqlite at the same time!
-	for this purpose, all calls must be enclosed by a locked m_critical; use mrsqlite3_lock() for this purpose */
-	pthread_mutex_t m_critical_;
+	/** @privatesection */
+	sqlite3_stmt* m_pd[PREDEFINED_CNT]; /**< prepared statements - this is the favourite way for the caller to use SQLite */
+	sqlite3*      m_cobj;               /**< is the database given as dbfile to Open() */
+	int           m_transactionCount;   /**< helper for transactions */
+	mrmailbox_t*  m_mailbox;            /**< used for logging and to acquire wakelocks, there may be N mrsqlite3_t objects per mrmailbox! In practise, we use 2 on backup, 1 otherwise. */
+	pthread_mutex_t m_critical_;        /**< the user must make sure, only one thread uses sqlite at the same time! for this purpose, all calls must be enclosed by a locked m_critical; use mrsqlite3_lock() for this purpose */
 
 } mrsqlite3_t;