Kaynağa Gözat

add deltachat core upstream changed

Jonas Reinsch 7 yıl önce
ebeveyn
işleme
a6cd4a90fc
62 değiştirilmiş dosya ile 1121 ekleme ve 1433 silme
  1. 2 0
      deltachat-ios/libraries/deltachat-core/deltachat-core.cbp
  2. 9 15
      deltachat-ios/libraries/deltachat-core/src/main.c
  3. 7 20
      deltachat-ios/libraries/deltachat-core/src/mraheader.c
  4. 3 6
      deltachat-ios/libraries/deltachat-core/src/mraheader.h
  5. 2 15
      deltachat-ios/libraries/deltachat-core/src/mrapeerstate.c
  6. 0 5
      deltachat-ios/libraries/deltachat-core/src/mrapeerstate.h
  7. 8 17
      deltachat-ios/libraries/deltachat-core/src/mrchat.c
  8. 0 109
      deltachat-ios/libraries/deltachat-core/src/mrchat.h
  9. 26 17
      deltachat-ios/libraries/deltachat-core/src/mrchatlist.c
  10. 0 63
      deltachat-ios/libraries/deltachat-core/src/mrchatlist.h
  11. 14 19
      deltachat-ios/libraries/deltachat-core/src/mrcmdline.c
  12. 0 60
      deltachat-ios/libraries/deltachat-core/src/mrcmdline.h
  13. 2 10
      deltachat-ios/libraries/deltachat-core/src/mrcontact.c
  14. 0 101
      deltachat-ios/libraries/deltachat-core/src/mrcontact.h
  15. 0 5
      deltachat-ios/libraries/deltachat-core/src/mrdehtml.c
  16. 0 5
      deltachat-ios/libraries/deltachat-core/src/mrdehtml.h
  17. 1 7
      deltachat-ios/libraries/deltachat-core/src/mrimap.c
  18. 5 7
      deltachat-ios/libraries/deltachat-core/src/mrimap.h
  19. 1 10
      deltachat-ios/libraries/deltachat-core/src/mrjob.c
  20. 0 5
      deltachat-ios/libraries/deltachat-core/src/mrjob.h
  21. 1 9
      deltachat-ios/libraries/deltachat-core/src/mrkey.c
  22. 1 5
      deltachat-ios/libraries/deltachat-core/src/mrkey.h
  23. 1 9
      deltachat-ios/libraries/deltachat-core/src/mrkeyring.c
  24. 0 5
      deltachat-ios/libraries/deltachat-core/src/mrkeyring.h
  25. 1 8
      deltachat-ios/libraries/deltachat-core/src/mrloginparam.c
  26. 0 5
      deltachat-ios/libraries/deltachat-core/src/mrloginparam.h
  27. 6 15
      deltachat-ios/libraries/deltachat-core/src/mrmailbox.c
  28. 633 171
      deltachat-ios/libraries/deltachat-core/src/mrmailbox.h
  29. 1 8
      deltachat-ios/libraries/deltachat-core/src/mrmailbox_configure.c
  30. 1 9
      deltachat-ios/libraries/deltachat-core/src/mrmailbox_e2ee.c
  31. 1 8
      deltachat-ios/libraries/deltachat-core/src/mrmailbox_imex.c
  32. 264 0
      deltachat-ios/libraries/deltachat-core/src/mrmailbox_internal.h
  33. 10 19
      deltachat-ios/libraries/deltachat-core/src/mrmailbox_log.c
  34. 1 9
      deltachat-ios/libraries/deltachat-core/src/mrmailbox_tools.c
  35. 1 8
      deltachat-ios/libraries/deltachat-core/src/mrmimefactory.c
  36. 0 4
      deltachat-ios/libraries/deltachat-core/src/mrmimefactory.h
  37. 1 9
      deltachat-ios/libraries/deltachat-core/src/mrmimeparser.c
  38. 5 11
      deltachat-ios/libraries/deltachat-core/src/mrmimeparser.h
  39. 21 21
      deltachat-ios/libraries/deltachat-core/src/mrmsg.c
  40. 0 140
      deltachat-ios/libraries/deltachat-core/src/mrmsg.h
  41. 5 7
      deltachat-ios/libraries/deltachat-core/src/mrosnative.c
  42. 0 5
      deltachat-ios/libraries/deltachat-core/src/mrosnative.h
  43. 1 7
      deltachat-ios/libraries/deltachat-core/src/mrparam.c
  44. 0 90
      deltachat-ios/libraries/deltachat-core/src/mrparam.h
  45. 17 23
      deltachat-ios/libraries/deltachat-core/src/mrpgp.c
  46. 0 6
      deltachat-ios/libraries/deltachat-core/src/mrpgp.h
  47. 1 8
      deltachat-ios/libraries/deltachat-core/src/mrpoortext.c
  48. 0 71
      deltachat-ios/libraries/deltachat-core/src/mrpoortext.h
  49. 14 4
      deltachat-ios/libraries/deltachat-core/src/mrsaxparser.c
  50. 0 16
      deltachat-ios/libraries/deltachat-core/src/mrsaxparser.h
  51. 0 5
      deltachat-ios/libraries/deltachat-core/src/mrsimplify.c
  52. 3 7
      deltachat-ios/libraries/deltachat-core/src/mrsimplify.h
  53. 2 9
      deltachat-ios/libraries/deltachat-core/src/mrsmtp.c
  54. 1 7
      deltachat-ios/libraries/deltachat-core/src/mrsmtp.h
  55. 17 29
      deltachat-ios/libraries/deltachat-core/src/mrsqlite3.c
  56. 7 13
      deltachat-ios/libraries/deltachat-core/src/mrsqlite3.h
  57. 5 7
      deltachat-ios/libraries/deltachat-core/src/mrstock.c
  58. 0 106
      deltachat-ios/libraries/deltachat-core/src/mrstock.h
  59. 1 10
      deltachat-ios/libraries/deltachat-core/src/mrtools.c
  60. 4 6
      deltachat-ios/libraries/deltachat-core/src/mrtools.h
  61. 14 22
      deltachat-ios/libraries/deltachat-core/src/stress.c
  62. 0 6
      deltachat-ios/libraries/deltachat-core/src/stress.h

+ 2 - 0
deltachat-ios/libraries/deltachat-core/deltachat-core.cbp

@@ -465,6 +465,7 @@
 		<Unit filename="src/mrmailbox.c">
 			<Option compilerVar="CC" />
 		</Unit>
+		<Unit filename="src/mrmailbox.h" />
 		<Unit filename="src/mrmailbox_configure.c">
 			<Option compilerVar="CC" />
 		</Unit>
@@ -474,6 +475,7 @@
 		<Unit filename="src/mrmailbox_imex.c">
 			<Option compilerVar="CC" />
 		</Unit>
+		<Unit filename="src/mrmailbox_internal.h" />
 		<Unit filename="src/mrmailbox_log.c">
 			<Option compilerVar="CC" />
 		</Unit>

+ 9 - 15
deltachat-ios/libraries/deltachat-core/src/main.c

@@ -17,26 +17,20 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    main.c
- * Purpose: Testing frame; if used as a lib, this file is obsolete.
- *
- *******************************************************************************
- *
- * Usage:  messenger-backend <databasefile>
- * (for "Code::Blocks, use Project / Set programs' arguments")
- * all further options can be set using the set-command (type ? for help).
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
-#include <stdio.h>
+/* This is a CLI program and a little testing frame.  This file must not be
+included when using Delta Chat Core as a library.
+
+Usage:  messenger-backend <databasefile>
+(for "Code::Blocks, use Project / Set programs' arguments")
+all further options can be set using the set-command (type ? for help). */
+
+
 #include <string.h>
 #include "mrmailbox.h"
-#include "mrcmdline.h"
-#include "mrtools.h"
+#include "mrmailbox_internal.h"
 #include "stress.h"
 
 

+ 7 - 20
deltachat-ios/libraries/deltachat-core/src/mraheader.c

@@ -17,34 +17,16 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mraheader.c
- * Purpose: Handle Autocrypt:-headers
- *
- *******************************************************************************
- *
- * Delta Chat aims to implement Autocrypt-Level0, see
- * https://autocrypt.readthedocs.io/en/latest/level0.html for details.
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
-#include <string.h>
 #include <ctype.h>
-#include "mrmailbox.h"
-#include "mrtools.h"
+#include "mrmailbox_internal.h"
 #include "mraheader.h"
 #include "mrapeerstate.h"
 #include "mrmimeparser.h"
 
 
-/*******************************************************************************
- * Parse Header
- ******************************************************************************/
-
-
 static void mraheader_empty(mraheader_t* ths)
 {
 	if( ths == NULL ) {
@@ -63,6 +45,11 @@ static void mraheader_empty(mraheader_t* ths)
 }
 
 
+/*******************************************************************************
+ * Render Autocrypt Header
+ ******************************************************************************/
+
+
 char* mraheader_render(const mraheader_t* ths)
 {
 	int            success = 0;
@@ -102,7 +89,7 @@ cleanup:
 
 
 /*******************************************************************************
- * Parse Header
+ * Parse Autocrypt Header
  ******************************************************************************/
 
 

+ 3 - 6
deltachat-ios/libraries/deltachat-core/src/mraheader.h

@@ -17,11 +17,6 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mraheader.h
- * Purpose: Handle Autocrypt:-headers
- *
  ******************************************************************************/
 
 
@@ -32,7 +27,9 @@ extern "C" {
 #endif
 
 
-/*** library-private **********************************************************/
+/*******************************************************************************
+ * Handle Autocrypt:-headers - Library-private
+ ******************************************************************************/
 
 #include "mrkey.h"
 

+ 2 - 15
deltachat-ios/libraries/deltachat-core/src/mrapeerstate.c

@@ -17,29 +17,16 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrapeerstate.c
- * Purpose: mrapeerstate_t represents the state of an Autocrypt peer
- *
- *******************************************************************************
- *
- * Delta Chat aims to implement Autocrypt-Level0, see
- * https://autocrypt.readthedocs.io/en/latest/level0.html for details.
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
-#include <string.h>
-#include "mrmailbox.h"
-#include "mrtools.h"
+#include "mrmailbox_internal.h"
 #include "mrapeerstate.h"
 #include "mraheader.h"
 
 
 /*******************************************************************************
- * Load/save
+ * mrapeerstate_t represents the state of an Autocrypt peer - Load/save
  ******************************************************************************/
 
 

+ 0 - 5
deltachat-ios/libraries/deltachat-core/src/mrapeerstate.h

@@ -17,11 +17,6 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrapeerstate.h
- * Purpose: mrapeerstate_t represents the state of an Autocrypt peer
- *
  ******************************************************************************/
 
 

+ 8 - 17
deltachat-ios/libraries/deltachat-core/src/mrchat.c

@@ -17,19 +17,10 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrchat.c
- * Purpose: mrchat_t represents a single chat, see header for details.
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
-#include <string.h>
-#include "mrmailbox.h"
-#include "mrtools.h"
-#include "mrcontact.h"
+#include "mrmailbox_internal.h"
 #include "mrapeerstate.h"
 #include "mrjob.h"
 #include "mrsmtp.h"
@@ -51,7 +42,7 @@ int mrmailbox_get_fresh_msg_count__(mrmailbox_t* mailbox, uint32_t chat_id)
 	sqlite3_stmt* stmt = NULL;
 
 	stmt = mrsqlite3_predefine__(mailbox->m_sql, SELECT_COUNT_FROM_msgs_WHERE_state_AND_chat_id,
-		"SELECT COUNT(*) FROM msgs WHERE state=" MR_STRINGIFY(MR_IN_FRESH) " AND chat_id=?;"); /* we have an index over the state-column, this should be sufficient as there are typically only few fresh messages */
+		"SELECT COUNT(*) FROM msgs WHERE state=" MR_STRINGIFY(MR_STATE_IN_FRESH) " AND chat_id=?;"); /* we have an index over the state-column, this should be sufficient as there are typically only few fresh messages */
 	sqlite3_bind_int(stmt, 1, chat_id);
 
 	if( sqlite3_step(stmt) != SQLITE_ROW ) {
@@ -67,7 +58,7 @@ uint32_t mrmailbox_get_last_deaddrop_fresh_msg__(mrmailbox_t* mailbox)
 	sqlite3_stmt* stmt = NULL;
 
 	stmt = mrsqlite3_predefine__(mailbox->m_sql, SELECT_id_FROM_msgs_WHERE_fresh_AND_deaddrop,
-		"SELECT id FROM msgs WHERE state=" MR_STRINGIFY(MR_IN_FRESH) " AND chat_id=" MR_STRINGIFY(MR_CHAT_ID_DEADDROP) " ORDER BY timestamp DESC, id DESC;"); /* we have an index over the state-column, this should be sufficient as there are typically only few fresh messages */
+		"SELECT id FROM msgs WHERE state=" MR_STRINGIFY(MR_STATE_IN_FRESH) " AND chat_id=" MR_STRINGIFY(MR_CHAT_ID_DEADDROP) " ORDER BY timestamp DESC, id DESC;"); /* we have an index over the state-column, this should be sufficient as there are typically only few fresh messages */
 
 	if( sqlite3_step(stmt) != SQLITE_ROW ) {
 		return 0;
@@ -404,7 +395,7 @@ int mrmailbox_marknoticed_chat(mrmailbox_t* ths, uint32_t chat_id)
 	mrsqlite3_lock(ths->m_sql);
 
 		stmt = mrsqlite3_predefine__(ths->m_sql, UPDATE_msgs_SET_state_WHERE_chat_id_AND_state,
-			"UPDATE msgs SET state=" MR_STRINGIFY(MR_IN_NOTICED) " WHERE chat_id=? AND state=" MR_STRINGIFY(MR_IN_FRESH) ";");
+			"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);
 
@@ -671,7 +662,7 @@ carray* mrmailbox_get_fresh_msgs(mrmailbox_t* mailbox)
 			"SELECT m.id"
 				" FROM msgs m"
 				" LEFT JOIN contacts ct ON m.from_id=ct.id"
-				" WHERE m.state=" MR_STRINGIFY(MR_IN_FRESH) " AND m.chat_id!=? AND ct.blocked=0"
+				" WHERE m.state=" MR_STRINGIFY(MR_STATE_IN_FRESH) " AND m.chat_id!=? AND ct.blocked=0"
 				" ORDER BY m.timestamp DESC,m.id DESC;"); /* the list starts with the newest messages*/
 		sqlite3_bind_int(stmt, 1, show_deaddrop? 0 : MR_CHAT_ID_DEADDROP);
 
@@ -1213,7 +1204,7 @@ static void mark_as_error(mrmailbox_t* mailbox, mrmsg_t* msg)
 	}
 
 	mrsqlite3_lock(mailbox->m_sql);
-		mrmailbox_update_msg_state__(mailbox, msg->m_id, MR_OUT_ERROR);
+		mrmailbox_update_msg_state__(mailbox, msg->m_id, MR_STATE_OUT_ERROR);
 	mrsqlite3_unlock(mailbox->m_sql);
 	mailbox->m_cb(mailbox, MR_EVENT_MSGS_CHANGED, msg->m_chat_id, 0);
 }
@@ -1290,7 +1281,7 @@ void mrmailbox_send_msg_to_smtp(mrmailbox_t* mailbox, mrjob_t* job)
 			free(emlname);
 		}
 
-		mrmailbox_update_msg_state__(mailbox, mimefactory.m_msg->m_id, MR_OUT_DELIVERED);
+		mrmailbox_update_msg_state__(mailbox, mimefactory.m_msg->m_id, MR_STATE_OUT_DELIVERED);
 		if( mimefactory.m_out_encrypted && mrparam_get_int(mimefactory.m_msg->m_param, MRP_GUARANTEE_E2EE, 0)==0 ) {
 			mrparam_set_int(mimefactory.m_msg->m_param, MRP_GUARANTEE_E2EE, 1); /* can upgrade to E2EE - fine! */
 			mrmsg_save_param_to_disk__(mimefactory.m_msg);
@@ -1387,7 +1378,7 @@ uint32_t mrchat_send_msg__(mrchat_t* ths, const mrmsg_t* msg, time_t timestamp)
 	sqlite3_bind_int  (stmt,  4, to_id);
 	sqlite3_bind_int64(stmt,  5, timestamp);
 	sqlite3_bind_int  (stmt,  6, msg->m_type);
-	sqlite3_bind_int  (stmt,  7, MR_OUT_PENDING);
+	sqlite3_bind_int  (stmt,  7, MR_STATE_OUT_PENDING);
 	sqlite3_bind_text (stmt,  8, msg->m_text? msg->m_text : "",  -1, SQLITE_STATIC);
 	sqlite3_bind_text (stmt,  9, msg->m_param->m_packed, -1, SQLITE_STATIC);
 	if( sqlite3_step(stmt) != SQLITE_DONE ) {

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

@@ -1,109 +0,0 @@
-/*******************************************************************************
- *
- *                              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/ .
- *
- *******************************************************************************
- *
- * File:    mrchat.h
- * Purpose: mrchat_t represents a single chat - this is a conversation with
- *          a single user or a group
- *
- ******************************************************************************/
-
-
-#ifndef __MRCHAT_H__
-#define __MRCHAT_H__
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#include "mrmsg.h"
-typedef struct mrjob_t mrjob_t;
-
-
-/* chat type */
-#define MR_CHAT_UNDEFINED    0
-#define MR_CHAT_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_GROUP      120 /* a group chat, chats_contacts conain all group members, incl. MR_CONTACT_ID_SELF */
-
-
-/* specical chat IDs */
-#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. */
-
-
-typedef struct mrchat_t
-{
-	uint32_t        m_id;
-	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 */
-	char*           m_grpid;           /* NULL if unset */
-	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 */
-} mrchat_t;
-
-
-mrchat_t*     mrchat_new                   (mrmailbox_t*); /* result must be unref'd */
-void          mrchat_empty                 (mrchat_t*);
-void          mrchat_unref                 (mrchat_t*);
-char*         mrchat_get_subtitle          (mrchat_t*); /* either the email-address or the number of group members, the result must be free()'d! */
-int           mrchat_get_total_msg_count   (mrchat_t*);
-int           mrchat_get_fresh_msg_count   (mrchat_t*);
-int           mrchat_set_draft             (mrchat_t*, const char*); /* Save draft in object and, if changed, in database.  May result in "MR_EVENT_MSGS_UPDATED".  Returns true/false. */
-uint32_t      mrchat_send_msg              (mrchat_t*, mrmsg_t*); /* save message in database and send it, the given message object is not unref'd by the function but some fields are set up! */
-
-
-/*** library-private **********************************************************/
-
-uint32_t      mrchat_send_msg__                      (mrchat_t*, const mrmsg_t*, time_t);
-int           mrchat_load_from_db__                  (mrchat_t*, uint32_t id);
-int           mrchat_update_param__                  (mrchat_t*);
-void          mrmailbox_unarchive_chat__             (mrmailbox_t*, uint32_t chat_id);
-size_t        mrmailbox_get_chat_cnt__               (mrmailbox_t*);
-uint32_t      mrmailbox_create_or_lookup_nchat_by_contact_id__(mrmailbox_t*, uint32_t contact_id);
-uint32_t      mrmailbox_lookup_real_nchat_by_contact_id__(mrmailbox_t*, uint32_t contact_id);
-int           mrmailbox_get_total_msg_count__        (mrmailbox_t*, uint32_t chat_id);
-int           mrmailbox_get_fresh_msg_count__        (mrmailbox_t*, uint32_t chat_id);
-uint32_t      mrmailbox_get_last_deaddrop_fresh_msg__(mrmailbox_t*);
-void          mrmailbox_send_msg_to_smtp             (mrmailbox_t*, mrjob_t*);
-void          mrmailbox_send_msg_to_imap             (mrmailbox_t*, mrjob_t*);
-int           mrmailbox_add_contact_to_chat__        (mrmailbox_t*, uint32_t chat_id, uint32_t contact_id);
-int           mrmailbox_is_contact_in_chat__         (mrmailbox_t*, uint32_t chat_id, uint32_t contact_id);
-int           mrmailbox_get_chat_contact_count__     (mrmailbox_t*, uint32_t chat_id);
-int           mrmailbox_group_explicitly_left__      (mrmailbox_t*, const char* grpid);
-void          mrmailbox_set_group_explicitly_left__  (mrmailbox_t*, const char* grpid);
-
-#define APPROX_SUBJECT_CHARS 32  /* as we do not cut inside words, this results in about 32-42 characters.
-								 Do not use too long subjects - we add a tag after the subject which gets truncated by the clients otherwise.
-								 It should also be very clear, the subject is _not_ the whole message.
-								 The value is also used for CC:-summaries */
-
-
-#ifdef __cplusplus
-} /* /extern "C" */
-#endif
-#endif /* __MRCHAT_H__ */

+ 26 - 17
deltachat-ios/libraries/deltachat-core/src/mrchatlist.c

@@ -17,18 +17,10 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrchatlist.c
- * Purpose: See header
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
-#include <string.h>
-#include "mrmailbox.h"
-#include "mrtools.h"
+#include "mrmailbox_internal.h"
 
 
 /*******************************************************************************
@@ -188,7 +180,7 @@ mrmsg_t* mrchatlist_get_msg_by_index(mrchatlist_t* ths, size_t index)
 }
 
 
-mrpoortext_t* mrchatlist_get_summary_by_index(mrchatlist_t* chatlist, size_t index, mrchat_t* chat)
+mrpoortext_t* mrchatlist_get_summary_by_index(mrchatlist_t* chatlist, size_t index, mrchat_t* chat /*may be NULL*/)
 {
 	/* The summary is created by the chat, not by the last message.
 	This is because we may want to display drafts here or stuff as
@@ -197,21 +189,34 @@ mrpoortext_t* mrchatlist_get_summary_by_index(mrchatlist_t* chatlist, size_t ind
 	message. */
 
 	mrpoortext_t* ret = mrpoortext_new();
+	int           locked = 0;
 	uint32_t      lastmsg_id = 0;
 	mrmsg_t*      lastmsg = NULL;
 	mrcontact_t*  lastcontact = NULL;
+	mrchat_t*     chat_to_delete = NULL;
 
-	if( chatlist == NULL || index >= chatlist->m_cnt || chat == NULL ) {
-		ret->m_text2 = safe_strdup("ErrNoChat");
+	if( chatlist == NULL || index >= chatlist->m_cnt ) {
+		ret->m_text2 = safe_strdup("ErrBadChatlistIndex");
 		goto cleanup;
 	}
 
 	lastmsg_id = (uint32_t)(uintptr_t)carray_get(chatlist->m_chatNlastmsg_ids, index*IDS_PER_RESULT+1);
 
 	/* load data from database */
-	if( lastmsg_id )
-	{
-		mrsqlite3_lock(chatlist->m_mailbox->m_sql);
+	mrsqlite3_lock(chatlist->m_mailbox->m_sql);
+	locked = 1;
+
+		if( chat==NULL ) {
+			chat = mrchat_new(chatlist->m_mailbox);
+			chat_to_delete = chat;
+			if( !mrchat_load_from_db__(chat, (uint32_t)(uintptr_t)carray_get(chatlist->m_chatNlastmsg_ids, index*IDS_PER_RESULT)) ) {
+				ret->m_text2 = safe_strdup("ErrCannotReadChat");
+				goto cleanup;
+			}
+		}
+
+		if( lastmsg_id )
+		{
 
 			lastmsg = mrmsg_new();
 			mrmsg_load_from_db__(lastmsg, chatlist->m_mailbox, lastmsg_id);
@@ -222,8 +227,10 @@ mrpoortext_t* mrchatlist_get_summary_by_index(mrchatlist_t* chatlist, size_t ind
 				mrcontact_load_from_db__(lastcontact, chatlist->m_mailbox->m_sql, lastmsg->m_from_id);
 			}
 
-		mrsqlite3_unlock(chatlist->m_mailbox->m_sql);
-	}
+		}
+
+	mrsqlite3_unlock(chatlist->m_mailbox->m_sql);
+	locked = 0;
 
 	if( chat->m_id == MR_CHAT_ID_ARCHIVED_LINK )
 	{
@@ -254,8 +261,10 @@ mrpoortext_t* mrchatlist_get_summary_by_index(mrchatlist_t* chatlist, size_t ind
 	}
 
 cleanup:
+	if( locked ) { mrsqlite3_unlock(chatlist->m_mailbox->m_sql); }
 	mrmsg_unref(lastmsg);
 	mrcontact_unref(lastcontact);
+	mrchat_unref(chat_to_delete);
 	return ret;
 }
 

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

@@ -1,63 +0,0 @@
-/*******************************************************************************
- *
- *                              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/ .
- *
- *******************************************************************************
- *
- * File:    mrchatlist.h
- * Purpose: list of chats
- *
- ******************************************************************************/
-
-
-#ifndef __MRCHATLIST_H__
-#define __MRCHATLIST_H__
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-typedef struct mrpoortext_t mrpoortext_t;
-
-
-typedef struct mrchatlist_t
-{
-	size_t       m_cnt;
-	carray*      m_chatNlastmsg_ids;
-	mrmailbox_t* m_mailbox;
-} mrchatlist_t;
-
-
-mrchatlist_t* mrchatlist_new                 (mrmailbox_t*);
-void          mrchatlist_unref               (mrchatlist_t*);
-void          mrchatlist_empty               (mrchatlist_t*);
-size_t        mrchatlist_get_cnt             (mrchatlist_t*);
-mrchat_t*     mrchatlist_get_chat_by_index   (mrchatlist_t*, size_t index); /* result must be unref'd */
-mrmsg_t*      mrchatlist_get_msg_by_index    (mrchatlist_t*, size_t index); /* result must be unref'd */
-mrpoortext_t* mrchatlist_get_summary_by_index(mrchatlist_t*, size_t index, mrchat_t*); /* result must be unref'd, the 3rd parameter is only to speed up things */
-
-
-/*** library-private **********************************************************/
-
-int           mrchatlist_load_from_db__    (mrchatlist_t*, int listflags, const char* query);
-
-
-#ifdef __cplusplus
-} /* /extern "C" */
-#endif
-#endif /* __MRCHATLIST_H__ */

+ 14 - 19
deltachat-ios/libraries/deltachat-core/src/mrcmdline.c

@@ -17,20 +17,15 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrcmdline.c
- * Purpose: implement mrmailbox_cmdline(), this file is optional
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
-#include <string.h>
-#include "mrmailbox.h"
-#include "mrcmdline.h"
+/* If you do not want to use mrmailbox_cmdline(), this file MAY NOT included to
+your library */
+
+
+#include "mrmailbox_internal.h"
 #include "mrapeerstate.h"
-#include "mrtools.h"
 #include "mrkey.h"
 
 
@@ -53,10 +48,10 @@ static void log_msglist(mrmailbox_t* mailbox, carray* msglist)
 
 			const char* statestr = "";
 			switch( msg->m_state ) {
-				case MR_OUT_PENDING:   statestr = " o";   break;
-				case MR_OUT_DELIVERED: statestr = " √";   break;
-				case MR_OUT_MDN_RCVD:  statestr = " √√";  break;
-				case MR_OUT_ERROR:     statestr = " ERR"; break;
+				case MR_STATE_OUT_PENDING:   statestr = " o";   break;
+				case MR_STATE_OUT_DELIVERED: statestr = " √";   break;
+				case MR_STATE_OUT_MDN_RCVD:  statestr = " √√";  break;
+				case MR_STATE_OUT_ERROR:     statestr = " ERR"; break;
 			}
 
 			char* temp2 = mr_timestamp_to_str(msg->m_timestamp);
@@ -67,7 +62,7 @@ static void log_msglist(mrmailbox_t* mailbox, carray* msglist)
 					msg->m_text,
 					mrmsg_show_padlock(msg)? "\xF0\x9F\x94\x92" : "",
 					msg->m_starred? " \xE2\x98\x85" : "",
-					msg->m_from_id==1? "" : (msg->m_state==MR_IN_SEEN? "[SEEN]" : (msg->m_state==MR_IN_NOTICED? "[NOTICED]":"[FRESH]")),
+					msg->m_from_id==1? "" : (msg->m_state==MR_STATE_IN_SEEN? "[SEEN]" : (msg->m_state==MR_STATE_IN_NOTICED? "[NOTICED]":"[FRESH]")),
 					mrparam_get_int(msg->m_param, MRP_SYSTEM_CMD, 0)? "[SYSTEM]" : "",
 					statestr,
 					temp2);
@@ -421,10 +416,10 @@ char* mrmailbox_cmdline(mrmailbox_t* mailbox, const char* cmdline)
 							statestr = " [Archived]";
 						}
 						else switch( poortext->m_state ) {
-							case MR_OUT_PENDING:   statestr = " o";   break;
-							case MR_OUT_DELIVERED: statestr = " √";   break;
-							case MR_OUT_MDN_RCVD:  statestr = " √√";  break;
-							case MR_OUT_ERROR:     statestr = " ERR"; break;
+							case MR_STATE_OUT_PENDING:   statestr = " o";   break;
+							case MR_STATE_OUT_DELIVERED: statestr = " √";   break;
+							case MR_STATE_OUT_MDN_RCVD:  statestr = " √√";  break;
+							case MR_STATE_OUT_ERROR:     statestr = " ERR"; break;
 						}
 
 						char* timestr = mr_timestamp_to_str(poortext->m_timestamp);

+ 0 - 60
deltachat-ios/libraries/deltachat-core/src/mrcmdline.h

@@ -1,60 +0,0 @@
-/*******************************************************************************
- *
- *                              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/ .
- *
- *******************************************************************************
- *
- * File:    mrcmdline.ch
- * Purpose: declare mrmailbox_cmdline(), this file is optional
- *
- ******************************************************************************/
-
-
-#ifndef __MRCMDLINE_H__
-#define __MRCMDLINE_H__
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#include "mrmailbox.h"
-
-
-/* Execute a simple command.
-- This function is not neeed for the normal program flow but only for debugging purposes
-  to give users some special power to the database and to the connection.
-- For security reasons, the first command must be `auth <password>`; once authorized, this is
-  is valid for _all_ exising and future mailbox objects.  You can skip the authorisation process
-  by calling mrmailbox_cmdline_skip_auth()
-- The returned result may contain multiple lines  separated by `\n` and must be
-  free()'d if no longer needed.
-- some commands may use mrmailbox_log_info() for additional output.
-- The command `help` gives an overview */
-char* mrmailbox_cmdline (mrmailbox_t*, const char* cmd);
-
-
-/* If the command line authorisation (see mrmailbox_cmdline()) is not desired, eg. for a command line client,
-you can skip this using mrmailbox_cmdline_skip_auth().*/
-void mrmailbox_cmdline_skip_auth();
-
-
-#ifdef __cplusplus
-} /* /extern "C" */
-#endif
-#endif /* __MRCMDLINE_H__ */
-

+ 2 - 10
deltachat-ios/libraries/deltachat-core/src/mrcontact.c

@@ -17,19 +17,11 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrcontact.c
- * Purpose: mrcontact_t represents a single contact, see header for details.
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
-#include <string.h>
-#include "mrmailbox.h"
+#include "mrmailbox_internal.h"
 #include "mrmimeparser.h"
-#include "mrcontact.h"
 #include "mrloginparam.h"
 #include "mrpgp.h"
 #include "mrapeerstate.h"
@@ -554,7 +546,7 @@ mrcontact_t* mrmailbox_get_contact(mrmailbox_t* ths, uint32_t contact_id)
 static void marknoticed_contact__(mrmailbox_t* mailbox, uint32_t contact_id)
 {
 	sqlite3_stmt* stmt = mrsqlite3_predefine__(mailbox->m_sql, UPDATE_msgs_SET_state_WHERE_from_id_AND_state,
-		"UPDATE msgs SET state=" MR_STRINGIFY(MR_IN_NOTICED) " WHERE from_id=? AND state=" MR_STRINGIFY(MR_IN_FRESH) ";");
+		"UPDATE msgs SET state=" MR_STRINGIFY(MR_STATE_IN_NOTICED) " WHERE from_id=? AND state=" MR_STRINGIFY(MR_STATE_IN_FRESH) ";");
 	sqlite3_bind_int(stmt, 1, contact_id);
 	sqlite3_step(stmt);
 }

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

@@ -1,101 +0,0 @@
-/*******************************************************************************
- *
- *                              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/ .
- *
- *******************************************************************************
- *
- * File:    mrcontact.h
- * Purpose: mrcontact_t represents a single contact - if in doubt a contact is
- *          every (email-)adresses the user has _send_ a mail to (only receiving
- *          is not sufficient).
- *          For the future, we plan to use the systems address books and/or a
- *          CardDAV server, too.
- *
- ******************************************************************************/
-
-
-#ifndef __MRCONTACT_H__
-#define __MRCONTACT_H__
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* specical contact IDs */
-#define MR_CONTACT_ID_SELF         1
-#define MR_CONTACT_ID_SYSTEM       2
-#define MR_CONTACT_ID_LAST_SPECIAL 9
-
-
-/* contact origins */
-#define MR_ORIGIN_UNSET                         0
-#define MR_ORIGIN_INCOMING_UNKNOWN_FROM      0x10 /* From: of incoming messages of unknown sender */
-#define MR_ORIGIN_INCOMING_UNKNOWN_CC        0x20 /* Cc: of incoming messages of unknown sender */
-#define MR_ORIGIN_INCOMING_UNKNOWN_TO        0x40 /* To: of incoming messages of unknown sender */
-#define MR_ORIGIN_INCOMING_REPLY_TO         0x100 /* Reply-To: of incoming message of known sender */
-#define MR_ORIGIN_INCOMING_CC               0x200 /* Cc: of incoming message of known sender */
-#define MR_ORIGIN_INCOMING_TO               0x400 /* additional To:'s of incoming message of known sender */
-#define MR_ORIGIN_CREATE_CHAT               0x800 /* a chat was manually created for this user, but no message yet sent */
-#define MR_ORIGIN_OUTGOING_BCC             0x1000 /* message send by us */
-#define MR_ORIGIN_OUTGOING_CC              0x2000 /* message send by us */
-#define MR_ORIGIN_OUTGOING_TO              0x4000 /* message send by us */
-#define MR_ORIGIN_INTERNAL                0x40000 /* internal use */
-#define MR_ORIGIN_ADRESS_BOOK             0x80000 /* address is in our address book */
-#define MR_ORIGIN_MANUALLY_CREATED       0x100000 /* contact added by mrmailbox_create_contact() */
-
-#define MR_ORIGIN_MIN_CONTACT_LIST    (MR_ORIGIN_INCOMING_REPLY_TO) /* contacts with at least this origin value are shown in the contact list */
-#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 */
-
-
-typedef struct mrcontact_t
-{
-	uint32_t            m_magic;
-	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_unref           (mrcontact_t*);
-void         mrcontact_empty           (mrcontact_t*);
-
-
-/*** library-private **********************************************************/
-
-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);
-int          mrmailbox_is_contact_blocked__   (mrmailbox_t*, uint32_t id);
-int          mrmailbox_real_contact_exists__  (mrmailbox_t*, uint32_t id);
-int          mrmailbox_contact_addr_equals__  (mrmailbox_t*, uint32_t contact_id, const char* other_addr);
-void         mrmailbox_scaleup_contact_origin__(mrmailbox_t*, uint32_t contact_id, int origin);
-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 */
-
-
-#ifdef __cplusplus
-} /* /extern "C" */
-#endif
-#endif /* __MRCONTACT_H__ */
-

+ 0 - 5
deltachat-ios/libraries/deltachat-core/src/mrdehtml.c

@@ -17,11 +17,6 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrdehtml.c
- * Purpose: Convert HTML to plain text
- *
  ******************************************************************************/
 
 

+ 0 - 5
deltachat-ios/libraries/deltachat-core/src/mrdehtml.h

@@ -17,11 +17,6 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrdehtml.h
- * Purpose: Convert HTML to plain text
- *
  ******************************************************************************/
 
 

+ 1 - 7
deltachat-ios/libraries/deltachat-core/src/mrimap.c

@@ -17,11 +17,6 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrimap.c
- * Purpose: Reading from IMAP servers, see header for details.
- *
  ******************************************************************************/
 
 
@@ -30,10 +25,9 @@
 #include <sys/stat.h>
 #include <string.h>
 #include <unistd.h> /* for sleep() */
-#include "mrmailbox.h"
+#include "mrmailbox_internal.h"
 #include "mrimap.h"
 #include "mrosnative.h"
-#include "mrtools.h"
 #include "mrloginparam.h"
 
 #define LOCK_HANDLE   pthread_mutex_lock(&ths->m_hEtpanmutex); mrmailbox_wake_lock(ths->m_mailbox); handle_locked = 1;

+ 5 - 7
deltachat-ios/libraries/deltachat-core/src/mrimap.h

@@ -17,16 +17,14 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrimap.h
- * Purpose: Reading from IMAP servers with no dependencies to the database.
- *          mrmailbox_t is only used for logging and to get information about
- *          the online state.
- *
  ******************************************************************************/
 
 
+/* Purpose: Reading from IMAP servers with no dependencies to the database.
+mrmailbox_t is only used for logging and to get information about 
+the online state. */
+
+
 #ifndef __MRIMAP_H__
 #define __MRIMAP_H__
 #ifdef __cplusplus

+ 1 - 10
deltachat-ios/libraries/deltachat-core/src/mrjob.c

@@ -17,20 +17,11 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrjob.c
- * Purpose: Handle jobs
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
-#include <memory.h>
-#include "mrmailbox.h"
+#include "mrmailbox_internal.h"
 #include "mrjob.h"
-#include "mrchat.h"
-#include "mrmsg.h"
 #include "mrosnative.h"
 
 

+ 0 - 5
deltachat-ios/libraries/deltachat-core/src/mrjob.h

@@ -16,11 +16,6 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrjob.h
- * Purpose: Handle jobs
- *
  ******************************************************************************/
 
 

+ 1 - 9
deltachat-ios/libraries/deltachat-core/src/mrkey.c

@@ -17,19 +17,11 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrkey.c
- * Purpose: Handle keys
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
-#include <string.h>
+#include "mrmailbox_internal.h"
 #include <memory.h>
-#include <sqlite3.h>
-#include "mrmailbox.h"
 #include "mrkey.h"
 #include "mrpgp.h"
 #include "mrtools.h"

+ 1 - 5
deltachat-ios/libraries/deltachat-core/src/mrkey.h

@@ -17,11 +17,6 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrkey.h
- * Purpose: Handle keys
- *
  ******************************************************************************/
 
 
@@ -35,6 +30,7 @@ extern "C" {
 /*** library-private **********************************************************/
 
 typedef struct mrmailbox_t mrmailbox_t;
+typedef struct sqlite3_stmt sqlite3_stmt;
 
 
 #define MR_PUBLIC  0

+ 1 - 9
deltachat-ios/libraries/deltachat-core/src/mrkeyring.c

@@ -17,19 +17,11 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrkeyring.c
- * Purpose: Handle keys
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
-#include <string.h>
+#include "mrmailbox_internal.h"
 #include <memory.h>
-#include <sqlite3.h>
-#include "mrmailbox.h"
 #include "mrkey.h"
 #include "mrkeyring.h"
 #include "mrtools.h"

+ 0 - 5
deltachat-ios/libraries/deltachat-core/src/mrkeyring.h

@@ -17,11 +17,6 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrkeyring.h
- * Purpose: Handle keys
- *
  ******************************************************************************/
 
 

+ 1 - 8
deltachat-ios/libraries/deltachat-core/src/mrloginparam.c

@@ -17,18 +17,11 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrloginparam.c
- * Purpose: Handle IMAP/POP3/SMTP parameters, see header for details.
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
-#include "mrmailbox.h"
+#include "mrmailbox_internal.h"
 #include "mrloginparam.h"
-#include "mrtools.h"
 
 
 /*******************************************************************************

+ 0 - 5
deltachat-ios/libraries/deltachat-core/src/mrloginparam.h

@@ -17,11 +17,6 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrloginparam.h
- * Purpose: Handle IMAP/POP3/SMTP parameters
- *
  ******************************************************************************/
 
 

+ 6 - 15
deltachat-ios/libraries/deltachat-core/src/mrmailbox.c

@@ -17,27 +17,18 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrmailbox.c
- * Purpose: mrmailbox_t represents a single mailbox, see header for details.
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
-#include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h> /* for getpid() */
 #include <unistd.h>    /* for getpid() */
-#include <sqlite3.h>
 #include <openssl/opensslv.h>
-#include "mrmailbox.h"
+#include "mrmailbox_internal.h"
 #include "mrimap.h"
 #include "mrsmtp.h"
 #include "mrmimeparser.h"
 #include "mrmimefactory.h"
-#include "mrcontact.h"
 #include "mrtools.h"
 #include "mrjob.h"
 #include "mrloginparam.h"
@@ -488,7 +479,7 @@ static void receive_imf(mrmailbox_t* ths, const char* imf_raw_not_terminated, si
 			(of course, the user can add other chats manually later) */
 			if( incoming )
 			{
-				state = (flags&MR_IMAP_SEEN)? MR_IN_SEEN : MR_IN_FRESH;
+				state = (flags&MR_IMAP_SEEN)? MR_STATE_IN_SEEN : MR_STATE_IN_FRESH;
 				to_id = MR_CONTACT_ID_SELF;
 
 				/* test if there is a normal chat with the sender - if so, this allows us to create groups in the next step */
@@ -538,9 +529,9 @@ static void receive_imf(mrmailbox_t* ths, const char* imf_raw_not_terminated, si
 
 					if( chat_id == 0 ) {
 						chat_id = MR_CHAT_ID_DEADDROP;
-						if( state == MR_IN_FRESH ) {
+						if( state == MR_STATE_IN_FRESH ) {
 							if( incoming_origin<MR_ORIGIN_MIN_VERIFIED && mime_parser->m_is_send_by_messenger==0 ) {
-								state = MR_IN_NOTICED; /* degrade state for unknown senders and non-delta messages (the latter may be removed if we run into spam problems, currently this is fine) (noticed messages do count as being unread; therefore, the deaddrop will not popup in the chatlist) */
+								state = MR_STATE_IN_NOTICED; /* degrade state for unknown senders and non-delta messages (the latter may be removed if we run into spam problems, currently this is fine) (noticed messages do count as being unread; therefore, the deaddrop will not popup in the chatlist) */
 							}
 						}
 					}
@@ -548,7 +539,7 @@ static void receive_imf(mrmailbox_t* ths, const char* imf_raw_not_terminated, si
 			}
 			else /* outgoing */
 			{
-				state = MR_OUT_DELIVERED; /* the mail is on the IMAP server, probably it is also deliverd.  We cannot recreate other states (read, error). */
+				state = MR_STATE_OUT_DELIVERED; /* the mail is on the IMAP server, probably it is also deliverd.  We cannot recreate other states (read, error). */
 				from_id = MR_CONTACT_ID_SELF;
 				if( carray_count(to_ids) >= 1 ) {
 					to_id   = (uint32_t)(uintptr_t)carray_get(to_ids, 0);
@@ -677,7 +668,7 @@ static void receive_imf(mrmailbox_t* ths, const char* imf_raw_not_terminated, si
 			{
 				create_event_to_send = 0;
 			}
-			else if( incoming && state==MR_IN_FRESH )
+			else if( incoming && state==MR_STATE_IN_FRESH )
 			{
 				if( from_id_blocked ) {
 					create_event_to_send = 0;

+ 633 - 171
deltachat-ios/libraries/deltachat-core/src/mrmailbox.h

@@ -17,24 +17,6 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrmailbox.h
- * Purpose: mrmailbox_t represents a single mailbox, normally, 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.
- *
- *******************************************************************************
- *
- * NB: Objects returned by mrmailbox_t (or other classes) typically reflect
- * the state of the system when the objects are _created_ - treat them as if
- * they're strings. Eg. mrmsg_get_state() does _always_ return the state of the
- * time the objects is created.
- * If you want an _updated state_, you have to recreate the object reflecting
- * the message - or use methods that explicitly force reloading.
- *
  ******************************************************************************/
 
 
@@ -46,17 +28,19 @@ extern "C" {
 
 
 #include <libetpan/libetpan.h> /* defines uint16_t etc. */
-#include "mrsqlite3.h"
-#include "mrchat.h"
-#include "mrchatlist.h"
-#include "mrmsg.h"
-#include "mrcontact.h"
-#include "mrpoortext.h"
-#include "mrstock.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 mrimap_t mrimap_t;
 typedef struct mrsmtp_t mrsmtp_t;
 typedef struct mrmimeparser_t mrmimeparser_t;
+typedef struct mrsqlite3_t mrsqlite3_t;
+typedef struct mrparam_t mrparam_t;
+typedef uintptr_t (*mrmailboxcb_t) (mrmailbox_t*, int event, uintptr_t data1, uintptr_t data2);
 
 
 #define MR_VERSION_MAJOR    0
@@ -64,49 +48,16 @@ typedef struct mrmimeparser_t mrmimeparser_t;
 #define MR_VERSION_REVISION 7
 
 
-/* Callback function that is called on updates, state changes etc. with one of the MR_EVENT_* codes
-- The callback MAY be called from _any_ thread, not only the main/GUI thread!
-- The callback MUST NOT call any mrmailbox_* and related functions unless stated otherwise!
-- The callback SHOULD return _fast_, for GUI updates etc. you should
-  post yourself an asynchronous message to your GUI thread.
-- If not mentioned otherweise, the callback should return 0. */
-typedef uintptr_t (*mrmailboxcb_t) (mrmailbox_t*, int event, uintptr_t data1, uintptr_t data2);
-
-#define MR_EVENT_INFO                     100  /* Information, should not be reported, can be logged */
-#define MR_EVENT_WARNING                  300  /* Warning, should not be reported, should be logged */
-#define MR_EVENT_ERROR                    400  /* Error, must be reported to the user by a non-disturbing bubble or so. */
-
-#define MR_EVENT_MSGS_CHANGED             2000 /* one or more messages changed for some reasons in the database - added or removed.  For added messages: data1=chat_id, data2=msg_id */
-#define MR_EVENT_INCOMING_MSG             2005 /* For fresh messages from the INBOX, MR_EVENT_INCOMING_MSG is send; data1=chat_id, data2=msg_id */
-#define MR_EVENT_MSG_DELIVERED            2010 /* a single message is send successfully (state changed from PENDING/SENDING to DELIVERED); data1=chat_id, data2=msg_id */
-#define MR_EVENT_MSG_READ                 2015 /* a single message is read by the receiver (state changed from DELIVERED to READ); data1=chat_id, data2=msg_id */
-
-#define MR_EVENT_CHAT_MODIFIED            2020 /* group name/image changed or members added/removed */
-
-#define MR_EVENT_CONTACTS_CHANGED         2030 /* contact(s) created, renamed, blocked or deleted */
-
-#define MR_EVENT_CONFIGURE_ENDED          2040 /* connection state changed, data1=0:failed-not-connected, 1:configured-and-connected */
-#define MR_EVENT_CONFIGURE_PROGRESS       2041 /* data1=percent */
-
-#define MR_EVENT_IMEX_ENDED               2050 /* mrmailbox_imex() done: data1=0:failed, 1=success */
-#define MR_EVENT_IMEX_PROGRESS            2051 /* data1=permille */
-#define MR_EVENT_IMEX_FILE_WRITTEN        2052 /* file written, event may be needed to make the file public to some system services, data1=file name, data2=mime type */
-
-/* Functions that should be provided by the frontends */
-#define MR_EVENT_IS_ONLINE                2080
-#define MR_EVENT_GET_STRING               2091 /* get a string from the frontend, data1=MR_STR_*, ret=string which will be free()'d by the backend */
-#define MR_EVENT_GET_QUANTITY_STRING      2092 /* get a string from the frontend, data1=MR_STR_*, data2=quantity, ret=string which will free()'d by the backend */
-#define MR_EVENT_HTTP_GET                 2100 /* synchronous http/https(!) call, data1=url, ret=content which will be free()'d by the backend, 0 on errors */
-#define MR_EVENT_WAKE_LOCK                2110 /* acquire wakeLock (data1=1) or release it (data1=0), the backend does not make nested or unsynchronized calls */
-
-/* Error codes */
-#define MR_ERR_SELF_NOT_IN_GROUP  1
-#define MR_ERR_NONETWORK          2
-
-
+/* mrmailbox_t represents a single mailbox, normally, 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. */
 typedef struct mrmailbox_t
 {
-	/* the following members should be treated as library private */
+	void*            m_userdata;
+
+	/* the following members should be treated as library-private */
 	mrsqlite3_t*     m_sql;      /* != NULL */
 	char*            m_dbfile;
 	char*            m_blobdir;
@@ -121,7 +72,6 @@ typedef struct mrmailbox_t
 	int              m_job_do_exit;
 
 	mrmailboxcb_t    m_cb;
-	void*            m_userdata;
 
 	char*            m_os_name;
 
@@ -143,9 +93,24 @@ typedef struct mrmailbox_t
 
 /* mrmailbox_new() creates a new mailbox object.  After creation it is usually
 opened, connected and mails are fetched; see the corresponding functions below.
-The os name is only for decorative use and is shown eg. in the X-Mailer header
+After usage, the object should be deleted using mrmailbox_unref().
+
+The first parameter is a callback function that is called for events (update,
+state changes etc.) and to get some information form the client (eg. translation
+for a given string)
+- The callback MAY be called from _any_ thread, not only the main/GUI thread!
+- The callback MUST NOT call any mrmailbox_* and related functions unless stated otherwise!
+- The callback SHOULD return _fast_, for GUI updates etc. you should
+  post yourself an asynchronous message to your GUI thread, if needed.
+- If not mentioned otherweise, the callback should return 0.
+
+`userdata` can be used by the client for any purpuse.  He finds it
+later in mailbox->m_userdata
+
+`os_name` is only for decorative use and is shown eg. in the X-Mailer header
 in the form "Delta Chat <version> for <osName>" */
-mrmailbox_t*         mrmailbox_new                  (mrmailboxcb_t, void* userData, const char* osName);
+mrmailbox_t*         mrmailbox_new                  (mrmailboxcb_t, void* userdata, const char* os_name);
+
 
 /* After usage, the mailbox object must be freed using mrmailbox_unref().
 If app runs can only be terminated by a forced kill, this may be superfluous. */
@@ -162,6 +127,16 @@ void                 mrmailbox_close                (mrmailbox_t*);
 int                  mrmailbox_is_open              (const mrmailbox_t*);
 
 
+/* Handle configurations as:
+- addr
+- mail_server, mail_user, mail_pw, mail_port,
+- send_server, send_user, send_pw, send_port, server_flags */
+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);
+int32_t              mrmailbox_get_config_int       (mrmailbox_t*, const char* key, int32_t def);
+
+
 /* mrmailbox_configure_and_connect() configures and connects a mailbox.
 - Before your call this function, you should set at least `addr` and `mail_pw`
   using mrmailbox_set_config().
@@ -187,29 +162,127 @@ int                  mrmailbox_fetch                (mrmailbox_t*);
 int                  mrmailbox_restore              (mrmailbox_t*, time_t seconds_to_restore);
 
 
+/* multi-line output; the returned string must be free()'d, returns NULL on errors */
+char*                mrmailbox_get_info             (mrmailbox_t*);
+
+
+/* the return value must be free()'d */
+char*                mrmailbox_get_version_str      (void);
+
+
+/*******************************************************************************
+ * Handle chatlists
+ ******************************************************************************/
+
+
 /* Get a list of chats. Handle chats.  The result must be unref'd */
 #define              MR_GCL_ARCHIVED_ONLY 0x01
 #define              MR_GCL_NO_SPECIALS   0x02 /* do not add deaddrop and archive link to list (may be used eg. for selecting chats on forwarding) */
 mrchatlist_t*        mrmailbox_get_chatlist              (mrmailbox_t*, int flags, const char* query);
 
-/* Handle chats. */
-mrchat_t*            mrmailbox_get_chat                  (mrmailbox_t*, uint32_t chat_id); /* the result must be unref'd */
-uint32_t             mrmailbox_get_chat_id_by_contact_id (mrmailbox_t*, uint32_t contact_id); /* does a chat with a given single user exist? */
-uint32_t             mrmailbox_create_chat_by_contact_id (mrmailbox_t*, uint32_t contact_id); /* create a normal chat with a single user */
-carray*              mrmailbox_get_chat_media            (mrmailbox_t*, uint32_t chat_id, int msg_type, int or_msg_type); /* returns message IDs, the result must be carray_free()'d */
-carray*              mrmailbox_get_fresh_msgs            (mrmailbox_t*); /* returns message IDs, typically used for implementing notification summaries, the result must be free()'d */
-int                  mrmailbox_archive_chat              (mrmailbox_t*, uint32_t chat_id, int archive); /* 1=archive, 0=unarchive */
+
+/* The chatlist object and some function for helping accessing it.
+The chatlist object is not updated.  If you want an update, you have to recreate the object. */
+typedef struct mrchatlist_t
+{
+	size_t           m_cnt;
+	carray*          m_chatNlastmsg_ids;
+	mrmailbox_t*     m_mailbox;
+} mrchatlist_t;
+void                 mrchatlist_unref                    (mrchatlist_t*);
+size_t               mrchatlist_get_cnt                  (mrchatlist_t*);
+mrchat_t*            mrchatlist_get_chat_by_index        (mrchatlist_t*, size_t index); /* result must be unref'd */
+mrmsg_t*             mrchatlist_get_msg_by_index         (mrchatlist_t*, size_t index); /* result must be unref'd */
+
+
+/* Get a summary for a chatlist index. The last parameter can be set to speed up
+things if the chat object is already available; if not, it is faster to pass NULL
+here.  The result must be freed using mrpoortext_unref().  The returned summary
+has the following format:
+- m_text1:         contains the username or the strings "Me", "Draft" and so on.
+                   the string may be colored by having a look at m_text1_meaning.
+                   If there is no such name, the element is NULL (eg. for "No messages")
+- m_text1_meaning: one of the
+- m_text2          contains an excerpt of the message text or strings as "No messages".
+                   may be NULL of there is no such text (eg. for the archive)
+- m_timestamp      the timestamp of the message.  May be 0 if there is no
+                   message
+- m_state          the state of the message as one of the MR_STATE_*
+                   identifiers.  0 if there is no message.
+*/
+mrpoortext_t*        mrchatlist_get_summary_by_index     (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
+{
+	#define          MR_TEXT1_NORMAL    0
+	#define          MR_TEXT1_DRAFT     1
+	#define          MR_TEXT1_USERNAME  2
+	#define          MR_TEXT1_SELF      3
+	int              m_text1_meaning;
+
+	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;
+void                 mrpoortext_unref                    (mrpoortext_t*);
+
+
+/*******************************************************************************
+ * Handle chats
+ ******************************************************************************/
+
+
+/* specical chat IDs */
+#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. */
+
+
+/* does a chat with a given single user exist? */
+uint32_t             mrmailbox_get_chat_id_by_contact_id (mrmailbox_t*, uint32_t contact_id);
+
+
+/* create a normal chat with a single user */
+uint32_t             mrmailbox_create_chat_by_contact_id (mrmailbox_t*, uint32_t contact_id);
+
+
+/* returns message IDs, the result must be carray_free()'d */
+carray*              mrmailbox_get_chat_media            (mrmailbox_t*, uint32_t chat_id, int msg_type, int or_msg_type);
+
+
+/* returns message IDs, typically used for implementing notification summaries, the result must be free()'d */
+carray*              mrmailbox_get_fresh_msgs            (mrmailbox_t*);
+
+
+/* Archived a chat, 1=archive, 0=unarchive
+Archived chats are not returned in the default chatlist returned by mrmailbox_get_chatlist(0, NULL);
+instead, if there are _any_ archived chats, the pseudo-chat with the chat_id MR_CHAT_ID_ARCHIVED_LINK will be returned by
+mrmailbox_get_chatlist(0, NULL).  To get a list of archived chats, use mrmailbox_get_chatlist(MR_GCL_ARCHIVED_ONLY, NULL). */
+int                  mrmailbox_archive_chat              (mrmailbox_t*, uint32_t chat_id, int archive);
 
 
 /* Delete a chat:
 - messages are deleted from the device and the chat database entry is deleted
 - messages are _not_ deleted from the server
-- the chat is not blocked, so new messages from the user/the group may appear and the user may create the chat again
-	- this is also one of the reasons, why groups are _not left_ -  this would be unexpected as deleting a normal chat also does not prevent new mails
-	- moreover, there may be valid reasons only to leave a group and only to delete a group
-	- another argument is, that leaving a group requires sending a message to all group members - esp. for groups not used for a longer time, this is really unexpected
-- to leave a chat, use the `function int mrmailbox_remove_contact_from_chat(mailbox, chat_id, MR_CONTACT_ID_SELF)`
-*/
+- the chat is not blocked, so new messages from the user/the group may appear
+  and the user may create the chat again
+	- this is also one of the reasons, why groups are _not left_ -  this would
+	  be unexpected as deleting a normal chat also does not prevent new mails
+	- moreover, there may be valid reasons only to leave a group and only to
+	  delete a group
+	- another argument is, that leaving a group requires sending a message to
+	  all group members - esp. for groups not used for a longer time, this is
+	  really unexpected
+- to leave a chat, use the `function int mrmailbox_remove_contact_from_chat(mailbox, chat_id, MR_CONTACT_ID_SELF)` */
 int                  mrmailbox_delete_chat               (mrmailbox_t*, uint32_t chat_id);
 
 
@@ -225,49 +298,130 @@ uint32_t             mrmailbox_get_next_media            (mrmailbox_t*, uint32_t
 carray*              mrmailbox_get_chat_contacts         (mrmailbox_t*, uint32_t chat_id);
 
 
-/* Handle group chats. */
+/* mrmailbox_get_chat_msgs() returns a view on 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:
+- If you add the flag MR_GCM_ADD_DAY_MARKER, the marker MR_MSG_ID_DAYMARKER will
+  be added before each day (regarding the local timezone)
+- If you specify marker1before, the id MR_MSG_ID_MARKER1 will be added just
+before the given ID.*/
+#define MR_GCM_ADDDAYMARKER 0x01
+carray*              mrmailbox_get_chat_msgs             (mrmailbox_t*, uint32_t chat_id, uint32_t flags, uint32_t marker1before);
+
+
+/* Search messages containing the given query string.
+Searching can be done globally (chat_id=0) or in a specified chat only (chat_id
+set).
+- The function returns an array of messages IDs which must be carray_free()'d
+  by the caller.
+- If nothing can be found, the function returns NULL.
+Global chat results are typically displayed using mrmsg_get_summary(), chat
+search results may just hilite the corresponding messages and present a
+prev/next button. */
+carray*              mrmailbox_search_msgs               (mrmailbox_t*, uint32_t chat_id, const char* query);
+
+
+/* Get a chat object of type mrchat_t by a chat_id.
+To access the mrchat_t object, see mrchat.h
+The result must be unref'd using mrchat_unref(). */
+mrchat_t*            mrmailbox_get_chat                  (mrmailbox_t*, uint32_t chat_id);
+
+
+/* The chat object and some function for helping accessing it.
+The chat object is not updated.  If you want an update, you have to recreate the object. */
+typedef struct mrchat_t
+{
+	uint32_t          m_id;
+
+	#define          MR_CHAT_UNDEFINED    0
+	#define          MR_CHAT_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_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 */
+	char*            m_grpid;           /* NULL if unset */
+	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 */
+} mrchat_t;
+void          mrchat_unref                 (mrchat_t*);
+char*         mrchat_get_subtitle          (mrchat_t*); /* either the email-address or the number of group members, the result must be free()'d! */
+int           mrchat_get_total_msg_count   (mrchat_t*);
+int           mrchat_get_fresh_msg_count   (mrchat_t*);
+int           mrchat_set_draft             (mrchat_t*, const char*); /* Save draft in object and, if changed, in database.  May result in "MR_EVENT_MSGS_UPDATED".  Returns true/false. */
+
+
+/* save message in database and send it, the given message object is not unref'd by the function but some fields are set up! */
+uint32_t      mrchat_send_msg              (mrchat_t*, mrmsg_t*);
+
+
+
+/*******************************************************************************
+ * Handle group chats
+ ******************************************************************************/
+
+
+/* Create a new group chat.  After creation, the groups has one member with the ID MR_CONTACT_ID_SELF. */
 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_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);
-int                  mrmailbox_set_chat_image            (mrmailbox_t*, uint32_t chat_id, const char* image); /* set image to NULL to remove it */
 
 
-/* mrmailbox_get_chat_msgs() returns a view on 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:
-- If you add the flag MR_GCM_ADD_DAY_MARKER, the marker MR_MSG_ID_DAYMARKER will be added before each day (regarding the local timezone)
-- If you specify marker1before, the id MR_MSG_ID_MARKER1 will be added just before the given ID.*/
-#define MR_GCM_ADDDAYMARKER 0x01
-carray* mrmailbox_get_chat_msgs (mrmailbox_t*, uint32_t chat_id, uint32_t flags, uint32_t marker1before);
+/* 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);
 
 
-/* Search messages containing the given query string.
-Searching can be done globally (chat_id=0) or in a specified chat only (chat_id set).
-- The function returns an array of messages IDs which must be carray_free()'d by the caller.
-- If nothing can be found, the function returns NULL.  */
-carray*  mrmailbox_search_msgs (mrmailbox_t*, uint32_t chat_id, const char* query);
+/* 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.  IMAP/MDNs is not done for noticed messages.
+See also mrmailbox_marknoticed_contact() and mrmailbox_markseen_msgs() */
+int                  mrmailbox_marknoticed_chat     (mrmailbox_t*, uint32_t chat_id);
+
+
+/*******************************************************************************
+ * Handle messages
+ ******************************************************************************/
 
 
-/* Get messages - for a list, see mrmailbox_get_chatlist() */
-mrmsg_t*             mrmailbox_get_msg              (mrmailbox_t*, uint32_t msg_id); /* the result must be unref'd */
-char*                mrmailbox_get_msg_info         (mrmailbox_t*, uint32_t msg_id); /* the result must be free()'d */
+/* Get an informational text for a single message. the text is multiline and may contain eg. the raw text of the message.
+The result must be unref'd using free(). */
+char*                mrmailbox_get_msg_info         (mrmailbox_t*, uint32_t msg_id);
+
+
+/* Delete a list of messages. The messages are deleted on the current device and on the IMAP server. */
 int                  mrmailbox_delete_msgs          (mrmailbox_t*, const uint32_t* msg_ids, int msg_cnt);
-int                  mrmailbox_forward_msgs         (mrmailbox_t*, const uint32_t* msg_ids, int msg_cnt, uint32_t chat_id);
 
 
-/* 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.  IMAP/MDNs is not done for noticed messages. */
-int                  mrmailbox_marknoticed_chat     (mrmailbox_t*, uint32_t chat_id);
+/* Forward a list of messages to another chat. */
+int                  mrmailbox_forward_msgs         (mrmailbox_t*, const uint32_t* msg_ids, int msg_cnt, uint32_t chat_id);
 
 
-/* mrmailbox_marknoticed_contact() marks all messages send by the given contact as NOTICED. */
+/* mrmailbox_marknoticed_contact() marks all messages send by the given contact as NOTICED.
+See also mrmailbox_marknoticed_chat() and mrmailbox_markseen_msgs() */
 int                  mrmailbox_marknoticed_contact  (mrmailbox_t*, uint32_t contact_id);
 
 
 /* mrmailbox_markseen_msgs() marks a message as SEEN, updates the IMAP state and sends MDNs.
-if the message is not in a real chat (eg. a contact request), the message is only marked as NOTICED and no IMAP/MDNs is done. */
+if the message is not in a real chat (eg. a contact request), the message is only marked as NOTICED and no IMAP/MDNs is done.
+See also mrmailbox_marknoticed_chat() and mrmailbox_marknoticed_contact() */
 int                  mrmailbox_markseen_msgs        (mrmailbox_t*, const uint32_t* msg_ids, int msg_cnt);
 
 
@@ -275,101 +429,409 @@ int                  mrmailbox_markseen_msgs        (mrmailbox_t*, const uint32_
 int                  mrmailbox_star_msgs            (mrmailbox_t*, const uint32_t* msg_ids, int msg_cnt, int star);
 
 
-/* handle contacts. */
-carray*              mrmailbox_get_known_contacts   (mrmailbox_t*, const char* query); /* returns known and unblocked contacts, the result must be carray_free()'d */
-mrcontact_t*         mrmailbox_get_contact          (mrmailbox_t*, uint32_t contact_id);
+/* Get a single message object of the type mrmsg_t - for a list, see mrmailbox_get_chatlist() */
+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;
+	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*); /* this also free()s all strings; so if you set up the object yourself, make sure to use strdup()! */
+void                 mrmsg_empty                  (mrmsg_t*);
+
+
+/* Get a summary for a message. The last parameter can be set to speed up
+things if the chat object is already available; if not, it is faster to pass NULL
+here.  The result must be freed using mrpoortext_unref().
+Typically used to display a search result.
+The returned summary is similar to mrchatlist_get_summary(), however, without
+"draft", "no messages" and so on. */
+mrpoortext_t*        mrmsg_get_summary            (mrmsg_t*, mrchat_t*);
+
+
+/* Get a message summary as a single line of text.  Typically used for
+notifications.  The returned value must be free()'d. */
+char*                mrmsg_get_summarytext        (mrmsg_t*, int approx_characters);
+
+
+/* Check if a padlock should be shown beside the message. */
+int                  mrmsg_show_padlock           (mrmsg_t*);
+
+
+/* Returns base file name without part, if appropriate.  The returned value must
+be free()'d */
+char*                mrmsg_get_filename           (mrmsg_t*);
+
+
+/* Returns real author (as text1, this is not always the sender, NULL if
+unknown) and title (text2, NULL if unknown) */
+mrpoortext_t*        mrmsg_get_mediainfo          (mrmsg_t*);
+
+
+/* check if a message is still in creation. */
+int                  mrmsg_is_increation          (mrmsg_t*);
+
+
+/* can be used to add some additional, persistent information to a messages record */
+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
+ ******************************************************************************/
+
+
+/* specical contact IDs */
+#define MR_CONTACT_ID_SELF         1
+#define MR_CONTACT_ID_SYSTEM       2
+#define MR_CONTACT_ID_LAST_SPECIAL 9
+
+
+/* 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);
+
+
+/* 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". */
 uint32_t             mrmailbox_create_contact       (mrmailbox_t*, const char* name, const char* addr);
+
+
+/* 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); /* may or may not result in a MR_EVENT_BLOCKING_CHANGED event */
+int                  mrmailbox_block_contact        (mrmailbox_t*, uint32_t contact_id, int block);
+
+
+/* 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*);
+
+
+/* get a multi-line encryption info, used to compare the fingerprints. */
 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);
 
 
-/* Handle configurations as:
-- addr
-- mail_server, mail_user, mail_pw, mail_port,
-- send_server, send_user, send_pw, send_port, server_flags */
-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);
-int32_t              mrmailbox_get_config_int       (mrmailbox_t*, const char* key, int32_t def);
+/* 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
+{
+	uint32_t         m_magic;
+	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
+ ******************************************************************************/
+
+
+/* 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;
+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
+ ******************************************************************************/
+
+
+/* The following events may be passed to the callback given to mrmailbox_new() */
+
 
+/* Information, should not be reported, can be logged,
+data1=0, data2=info string */
+#define MR_EVENT_INFO                     100
 
-/* Import/export keys, backup etc.
-To avoid double slashes, the given directory should not end with a slash. */
+
+/* Warning, should not be reported, should be logged
+data1=0, data2=warning string */
+#define MR_EVENT_WARNING                  300
+
+
+/* Error, must be reported to the user by a non-disturbing bubble or so.
+data1=error code MR_ERR_*, see below, data2=error string */
+#define MR_EVENT_ERROR                    400
+
+
+/* one or more messages changed for some reasons in the database - added or removed.
+For added messages: data1=chat_id, data2=msg_id */
+#define MR_EVENT_MSGS_CHANGED             2000
+
+
+/* For fresh messages from the INBOX, MR_EVENT_INCOMING_MSG is send;
+data1=chat_id, data2=msg_id */
+#define MR_EVENT_INCOMING_MSG             2005
+
+
+/* a single message is send successfully (state changed from PENDING/SENDING to DELIVERED);
+data1=chat_id, data2=msg_id */
+#define MR_EVENT_MSG_DELIVERED            2010
+
+
+/* a single message is read by the receiver (state changed from DELIVERED to READ);
+data1=chat_id, data2=msg_id */
+#define MR_EVENT_MSG_READ                 2015
+
+
+/* group name/image changed or members added/removed */
+#define MR_EVENT_CHAT_MODIFIED            2020
+
+
+/* contact(s) created, renamed, blocked or deleted */
+#define MR_EVENT_CONTACTS_CHANGED         2030
+
+
+/* connection state changed,
+data1=0:failed-not-connected, 1:configured-and-connected */
+#define MR_EVENT_CONFIGURE_ENDED          2040
+
+
+/* data1=percent */
+#define MR_EVENT_CONFIGURE_PROGRESS       2041
+
+
+/* mrmailbox_imex() done:
+data1=0:failed, 1=success */
+#define MR_EVENT_IMEX_ENDED               2050
+
+
+/* data1=permille */
+#define MR_EVENT_IMEX_PROGRESS            2051
+
+
+/* file written, event may be needed to make the file public to some system services
+data1=file name, data2=mime type */
+#define MR_EVENT_IMEX_FILE_WRITTEN        2052
+
+
+/* The following events are functions that should be provided by the frontends */
+
+
+/* check, if the system is online currently
+ret=0: not online, ret=1: online */
+#define MR_EVENT_IS_ONLINE                2080
+
+
+/* get a string from the frontend, data1=MR_STR_*, ret=string which will be free()'d by the backend */
+#define MR_EVENT_GET_STRING               2091
+
+
+/* synchronous http/https(!) call, data1=url, ret=content which will be free()'d by the backend, 0 on errors */
+#define MR_EVENT_GET_QUANTITY_STRING      2092
+
+
+/* synchronous http/https(!) call, data1=url, ret=content which will be free()'d by the backend, 0 on errors */
+#define MR_EVENT_HTTP_GET                 2100
+
+/* acquire wakeLock (data1=1) or release it (data1=0), the backend does not make nested or unsynchronized calls */
+#define MR_EVENT_WAKE_LOCK                2110
+
+
+/* Error codes */
+#define MR_ERR_SELF_NOT_IN_GROUP          1
+#define MR_ERR_NONETWORK                  2
+
+
+/* Strings requested by MR_EVENT_GET_STRING and MR_EVENT_GET_QUANTITY_STRING */
+#define MR_STR_FREE_                      0
+#define MR_STR_NOMESSAGES                 1
+#define MR_STR_SELF                       2
+#define MR_STR_DRAFT                      3
+#define MR_STR_MEMBER                     4
+#define MR_STR_CONTACT                    6
+#define MR_STR_VOICEMESSAGE               7
+#define MR_STR_DEADDROP                   8
+#define MR_STR_IMAGE                      9
+#define MR_STR_VIDEO                      10
+#define MR_STR_AUDIO                      11
+#define MR_STR_FILE                       12
+#define MR_STR_STATUSLINE                 13
+#define MR_STR_NEWGROUPDRAFT              14
+#define MR_STR_MSGGRPNAME                 15
+#define MR_STR_MSGGRPIMGCHANGED           16
+#define MR_STR_MSGADDMEMBER               17
+#define MR_STR_MSGDELMEMBER               18
+#define MR_STR_MSGGROUPLEFT               19
+#define MR_STR_ERROR                      20
+#define MR_STR_SELFNOTINGRP               21
+#define MR_STR_NONETWORK                  22
+#define MR_STR_GIF                        23
+#define MR_STR_ENCRYPTEDMSG               24
+#define MR_STR_ENCR_E2E                   25
+#define MR_STR_ENCR_TRANSP                27
+#define MR_STR_ENCR_NONE                  28
+#define MR_STR_FINGERPRINTS               30
+#define MR_STR_READRCPT                   31
+#define MR_STR_READRCPT_MAILBODY          32
+#define MR_STR_MSGGRPIMGDELETED           33
+#define MR_STR_E2E_FINE                   34
+#define MR_STR_E2E_NO_AUTOCRYPT           35
+#define MR_STR_E2E_DIS_BY_YOU             36
+#define MR_STR_E2E_DIS_BY_RCPT            37
+#define MR_STR_ARCHIVEDCHATS              40
+#define MR_STR_STARREDMSGS                41
+
+
+/*******************************************************************************
+ * Import/export and Tools
+ ******************************************************************************/
+
+
+/* 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 */
 #define MR_IMEX_EXPORT_BACKUP              11 /* param1 is a directory where the backup is written to */
 #define MR_IMEX_IMPORT_BACKUP              12 /* param1 is the file with the backup to import */
 #define MR_IMEX_EXPORT_SETUP_MESSAGE       20 /* param1 is a directory where the setup file is written to */
-#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); /* user import/export function, sends MR_EVENT_IMEX_* events */
-char*                mrmailbox_imex_has_backup      (mrmailbox_t*, const char* dir); /* returns backup_file or NULL, may only be used on fresh installations (mrmailbox_is_configured() returns 0); returned strings must be free()'d */
-int                  mrmailbox_check_password       (mrmailbox_t*, const char* pw); /* 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. */
-char*                mrmailbox_create_setup_code    (mrmailbox_t*); /* should be written down by the user, forwareded to mrmailbox_imex() for encryption then, must be wiped and free()'d after usage */
-int                  mrmailbox_poke_spec            (mrmailbox_t*, const char* spec);          /* mainly for testing, import a folder with eml-files, a single eml-file, e-mail plus public key, ... NULL for the last command */
-
+#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);
 
-/* Misc. */
-char*                mrmailbox_get_info             (mrmailbox_t*); /* multi-line output; the returned string must be free()'d, returns NULL on errors */
-int                  mrmailbox_add_address_book     (mrmailbox_t*, const char*); /* format: Name one\nAddress one\nName two\Address two */
-char*                mrmailbox_get_version_str      (void); /* the return value must be free()'d */
-int                  mrmailbox_reset_tables         (mrmailbox_t*, int bits); /* reset tables but leaves server configuration, 1=jobs, 2=e2ee, 8=rest but server config */
 
+/* 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);
 
-/* The library tries itself to stay alive. For this purpose there is an additional
-"heartbeat" thread that checks if the IDLE-thread is up and working. This check is done about every minute.
-However, depending on the operating system, this thread may be delayed or stopped, if this is the case you can
-force additional checks manually by just calling mrmailbox_heartbeat() about every minute.
-If in doubt, call this function too often, not too less :-) */
-void                 mrmailbox_heartbeat            (mrmailbox_t*);
 
+/* 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. */
+int                  mrmailbox_check_password       (mrmailbox_t*, const char* pw);
 
-/*** library-private **********************************************************/
 
-#define MR_E2EE_DEFAULT_ENABLED  1
-#define MR_MDNS_DEFAULT_ENABLED  1
+/* 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*);
 
-void                 mrmailbox_connect_to_imap      (mrmailbox_t*, mrjob_t*);
-void                 mrmailbox_wake_lock            (mrmailbox_t*);
-void                 mrmailbox_wake_unlock          (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);
 
-/* end-to-end-encryption */
-typedef struct mrmailbox_e2ee_helper_t {
-	int   m_encryption_successfull;
-	void* m_cdata_to_free;
-} mrmailbox_e2ee_helper_t;
-
-void mrmailbox_e2ee_encrypt             (mrmailbox_t*, const clist* recipients_addr, int e2ee_guaranteed, int encrypt_to_self, struct mailmime* in_out_message, mrmailbox_e2ee_helper_t*);
-int  mrmailbox_e2ee_decrypt             (mrmailbox_t*, struct mailmime* in_out_message, int* ret_validation_errors); /* returns 1 if sth. was decrypted, 0 in other cases */
-void mrmailbox_e2ee_thanks              (mrmailbox_e2ee_helper_t*); /* frees data referenced by "mailmime" but not freed by mailmime_free(). After calling mre2ee_unhelp(), in_out_message cannot be used any longer! */
-int  mrmailbox_ensure_secret_key_exists (mrmailbox_t*); /* makes sure, the private key exists, needed only for exporting keys and the case no message was sent before */
 
+/* The library tries itself to stay alive. For this purpose there is an additional
+"heartbeat" thread that checks if the IDLE-thread is up and working. This check is done about every minute.
+However, depending on the operating system, this thread may be delayed or stopped, if this is the case you can
+force additional checks manually by just calling mrmailbox_heartbeat() about every minute.
+If in doubt, call this function too often, not too less :-) */
+void                 mrmailbox_heartbeat            (mrmailbox_t*);
 
-/* logging */
-void mrmailbox_log_error           (mrmailbox_t*, int code, const char* msg, ...);
-void mrmailbox_log_error_if        (int* condition, mrmailbox_t*, int code, const char* msg, ...);
-void mrmailbox_log_warning         (mrmailbox_t*, int code, const char* msg, ...);
-void mrmailbox_log_info            (mrmailbox_t*, int code, const char* msg, ...);
-void mrmailbox_log_vprintf         (mrmailbox_t*, int event, int code, const char* msg, va_list);
-int  mrmailbox_get_thread_index    (void);
 
+/* Execute a simple command.
+- This function is not neeed for the normal program flow but only for debugging purposes
+  to give users some special power to the database and to the connection.
+- For security reasons, the first command must be `auth <password>`; once authorized, this is
+  is valid for _all_ exising and future mailbox objects.  You can skip the authorisation process
+  by calling mrmailbox_cmdline_skip_auth()
+- The returned result may contain multiple lines  separated by `\n` and must be
+  free()'d if no longer needed.
+- some commands may use mrmailbox_log_info() for additional output.
+- The command `help` gives an overview */
+char*                mrmailbox_cmdline              (mrmailbox_t*, const char* cmd);
 
-/* misc. tools */
-int    mrmailbox_poke_eml_file                           (mrmailbox_t*, const char* file);
-int    mrmailbox_is_reply_to_known_message__             (mrmailbox_t* mailbox, mrmimeparser_t* mime_parser);
-int    mrmailbox_is_reply_to_messenger_message__         (mrmailbox_t* mailbox, mrmimeparser_t* mime_parser);
-time_t mrmailbox_correct_bad_timestamp__                 (mrmailbox_t* ths, uint32_t chat_id, uint32_t from_id, time_t desired_timestamp, int is_fresh_msg);
-void   mrmailbox_add_or_lookup_contacts_by_mailbox_list__(mrmailbox_t* ths, struct mailimf_mailbox_list* mb_list, int origin, carray* ids, int* check_self);
-void   mrmailbox_add_or_lookup_contacts_by_address_list__(mrmailbox_t* ths, struct mailimf_address_list* adr_list, int origin, carray* ids, int* check_self);
-int    mrmailbox_get_archived_count__                    (mrmailbox_t*);
 
-#define MR_CHAT_PREFIX      "Chat:"      /* you MUST NOT modify this or the following strings */
-#define MR_CHATS_FOLDER     "Chats"      /* if we want to support Gma'l-labels - "Chats" is a reserved word for Gma'l */
+/* If the command line authorisation (see mrmailbox_cmdline()) is not desired, eg. for a command line client,
+you can skip this using mrmailbox_cmdline_skip_auth().*/
+void                 mrmailbox_cmdline_skip_auth    ();
 
 
 #ifdef __cplusplus

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

@@ -17,23 +17,16 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrmailbox_configure.c
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
-#include <string.h>
 #include <dirent.h>
-#include "mrmailbox.h"
+#include "mrmailbox_internal.h"
 #include "mrloginparam.h"
 #include "mrimap.h"
 #include "mrsmtp.h"
 #include "mrosnative.h"
 #include "mrsaxparser.h"
-#include "mrtools.h"
 #include "mrjob.h"
 
 

+ 1 - 9
deltachat-ios/libraries/deltachat-core/src/mrmailbox_e2ee.c

@@ -17,23 +17,15 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mre2ee.c
- * Purpose: Handle End-To-End-Encryption
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
-#include <string.h>
-#include "mrmailbox.h"
+#include "mrmailbox_internal.h"
 #include "mrpgp.h"
 #include "mrapeerstate.h"
 #include "mraheader.h"
 #include "mrkeyring.h"
 #include "mrmimeparser.h"
-#include "mrtools.h"
 
 
 static struct mailmime* new_data_part(void* data, size_t data_bytes, char* default_content_type, int default_encoding)

+ 1 - 8
deltachat-ios/libraries/deltachat-core/src/mrmailbox_imex.c

@@ -17,26 +17,19 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrmailbox_imex.c - Import and Export things
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
-#include <string.h>
 #include <dirent.h>
 #include <openssl/rand.h>
 #include <libetpan/mmapstring.h>
 #include <netpgp-extra.h>
-#include "mrmailbox.h"
+#include "mrmailbox_internal.h"
 #include "mrmimeparser.h"
 #include "mrosnative.h"
 #include "mrloginparam.h"
 #include "mraheader.h"
 #include "mrapeerstate.h"
-#include "mrtools.h"
 #include "mrpgp.h"
 
 static int s_imex_do_exit = 1; /* the value 1 avoids MR_IMEX_CANCEL from stopping already stopped threads */

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

@@ -0,0 +1,264 @@
+/*******************************************************************************
+ *
+ *                              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
+
+
+/*** library-private **********************************************************/
+
+#include "mrmailbox.h"
+#include <stdlib.h>
+#include <string.h>
+#include "mrsqlite3.h"
+#include "mrtools.h"
+
+
+typedef struct mrjob_t mrjob_t;
+typedef struct mrpoortext_t mrpoortext_t;
+typedef struct mrchat_t mrchat_t;
+typedef struct mrmsg_t mrmsg_t;
+typedef struct mrmailbox_t mrmailbox_t;
+typedef struct mrmimeparser_t mrmimeparser_t;
+
+
+/*******************************************************************************
+ * Internal mailbox handling
+ ******************************************************************************/
+
+
+#define MR_E2EE_DEFAULT_ENABLED  1
+#define MR_MDNS_DEFAULT_ENABLED  1
+
+void                 mrmailbox_connect_to_imap      (mrmailbox_t*, mrjob_t*);
+void                 mrmailbox_wake_lock            (mrmailbox_t*);
+void                 mrmailbox_wake_unlock          (mrmailbox_t*);
+
+
+/* end-to-end-encryption */
+typedef struct mrmailbox_e2ee_helper_t {
+	int   m_encryption_successfull;
+	void* m_cdata_to_free;
+} mrmailbox_e2ee_helper_t;
+
+void mrmailbox_e2ee_encrypt             (mrmailbox_t*, const clist* recipients_addr, int e2ee_guaranteed, int encrypt_to_self, struct mailmime* in_out_message, mrmailbox_e2ee_helper_t*);
+int  mrmailbox_e2ee_decrypt             (mrmailbox_t*, struct mailmime* in_out_message, int* ret_validation_errors); /* returns 1 if sth. was decrypted, 0 in other cases */
+void mrmailbox_e2ee_thanks              (mrmailbox_e2ee_helper_t*); /* frees data referenced by "mailmime" but not freed by mailmime_free(). After calling mre2ee_unhelp(), in_out_message cannot be used any longer! */
+int  mrmailbox_ensure_secret_key_exists (mrmailbox_t*); /* makes sure, the private key exists, needed only for exporting keys and the case no message was sent before */
+
+
+/* logging */
+void mrmailbox_log_error           (mrmailbox_t*, int code, const char* msg, ...);
+void mrmailbox_log_error_if        (int* condition, mrmailbox_t*, int code, const char* msg, ...);
+void mrmailbox_log_warning         (mrmailbox_t*, int code, const char* msg, ...);
+void mrmailbox_log_info            (mrmailbox_t*, int code, const char* msg, ...);
+void mrmailbox_log_vprintf         (mrmailbox_t*, int event, int code, const char* msg, va_list);
+int  mrmailbox_get_thread_index    (void);
+
+/* reset tables but leaves server configuration, 1=jobs, 2=e2ee, 8=rest but server config */
+int                  mrmailbox_reset_tables         (mrmailbox_t*, int bits);
+
+/* misc. tools */
+int    mrmailbox_poke_eml_file                           (mrmailbox_t*, const char* file);
+int    mrmailbox_is_reply_to_known_message__             (mrmailbox_t*, mrmimeparser_t*);
+int    mrmailbox_is_reply_to_messenger_message__         (mrmailbox_t*, mrmimeparser_t*);
+time_t mrmailbox_correct_bad_timestamp__                 (mrmailbox_t* ths, uint32_t chat_id, uint32_t from_id, time_t desired_timestamp, int is_fresh_msg);
+void   mrmailbox_add_or_lookup_contacts_by_mailbox_list__(mrmailbox_t* ths, struct mailimf_mailbox_list* mb_list, int origin, carray* ids, int* check_self);
+void   mrmailbox_add_or_lookup_contacts_by_address_list__(mrmailbox_t* ths, struct mailimf_address_list* adr_list, int origin, carray* ids, int* check_self);
+int    mrmailbox_get_archived_count__                    (mrmailbox_t*);
+
+#define MR_CHAT_PREFIX      "Chat:"      /* you MUST NOT modify this or the following strings */
+#define MR_CHATS_FOLDER     "Chats"      /* if we want to support Gma'l-labels - "Chats" is a reserved word for Gma'l */
+
+
+/*******************************************************************************
+ * Internal chatlist handling
+ ******************************************************************************/
+
+
+mrchatlist_t* mrchatlist_new                 (mrmailbox_t*);
+void          mrchatlist_empty               (mrchatlist_t*);
+int           mrchatlist_load_from_db__    (mrchatlist_t*, int listflags, const char* query);
+
+
+/*******************************************************************************
+ * Internal chat handling
+ ******************************************************************************/
+
+
+#define MR_MSG_NEEDS_ATTACHMENT(a)         ((a)==MR_MSG_IMAGE || (a)==MR_MSG_GIF || (a)==MR_MSG_AUDIO || (a)==MR_MSG_VOICE || (a)==MR_MSG_VIDEO || (a)==MR_MSG_FILE)
+#define MR_MSG_MAKE_FILENAME_SEARCHABLE(a) ((a)==MR_MSG_AUDIO || (a)==MR_MSG_FILE || (a)==MR_MSG_VIDEO ) /* add filename.ext (without path) to m_text? this is needed for the fulltext search. The extension is useful to get all PDF, all MP3 etc. */
+#define MR_MSG_MAKE_SUFFIX_SEARCHABLE(a)   ((a)==MR_MSG_IMAGE || (a)==MR_MSG_GIF || (a)==MR_MSG_VOICE)
+
+mrchat_t*     mrchat_new                   (mrmailbox_t*); /* result must be unref'd */
+void          mrchat_empty                 (mrchat_t*);
+uint32_t      mrchat_send_msg__                      (mrchat_t*, const mrmsg_t*, time_t);
+int           mrchat_load_from_db__                  (mrchat_t*, uint32_t id);
+int           mrchat_update_param__                  (mrchat_t*);
+void          mrmailbox_unarchive_chat__             (mrmailbox_t*, uint32_t chat_id);
+size_t        mrmailbox_get_chat_cnt__               (mrmailbox_t*);
+uint32_t      mrmailbox_create_or_lookup_nchat_by_contact_id__(mrmailbox_t*, uint32_t contact_id);
+uint32_t      mrmailbox_lookup_real_nchat_by_contact_id__(mrmailbox_t*, uint32_t contact_id);
+int           mrmailbox_get_total_msg_count__        (mrmailbox_t*, uint32_t chat_id);
+int           mrmailbox_get_fresh_msg_count__        (mrmailbox_t*, uint32_t chat_id);
+uint32_t      mrmailbox_get_last_deaddrop_fresh_msg__(mrmailbox_t*);
+void          mrmailbox_send_msg_to_smtp             (mrmailbox_t*, mrjob_t*);
+void          mrmailbox_send_msg_to_imap             (mrmailbox_t*, mrjob_t*);
+int           mrmailbox_add_contact_to_chat__        (mrmailbox_t*, uint32_t chat_id, uint32_t contact_id);
+int           mrmailbox_is_contact_in_chat__         (mrmailbox_t*, uint32_t chat_id, uint32_t contact_id);
+int           mrmailbox_get_chat_contact_count__     (mrmailbox_t*, uint32_t chat_id);
+int           mrmailbox_group_explicitly_left__      (mrmailbox_t*, const char* grpid);
+void          mrmailbox_set_group_explicitly_left__  (mrmailbox_t*, const char* grpid);
+
+#define APPROX_SUBJECT_CHARS 32  /* as we do not cut inside words, this results in about 32-42 characters.
+								 Do not use too long subjects - we add a tag after the subject which gets truncated by the clients otherwise.
+								 It should also be very clear, the subject is _not_ the whole message.
+								 The value is also used for CC:-summaries */
+
+
+/*******************************************************************************
+ * Internal message handling
+ ******************************************************************************/
+
+
+#define      MR_MSG_FIELDS                    " m.id,rfc724_mid,m.server_folder,m.server_uid,m.chat_id, m.from_id,m.to_id,m.timestamp, m.type,m.state,m.msgrmsg,m.txt, m.param,m.starred "
+int          mrmsg_set_from_stmt__            (mrmsg_t*, sqlite3_stmt* row, int row_offset); /* row order is MR_MSG_FIELDS */
+int          mrmsg_load_from_db__             (mrmsg_t*, mrmailbox_t*, uint32_t id);
+void         mr_guess_msgtype_from_suffix     (const char* pathNfilename, int* ret_msgtype, char** ret_mime);
+size_t       mrmailbox_get_real_msg_cnt__     (mrmailbox_t*); /* the number of messages assigned to real chat (!=deaddrop, !=trash) */
+size_t       mrmailbox_get_deaddrop_msg_cnt__ (mrmailbox_t*);
+int          mrmailbox_rfc724_mid_cnt__       (mrmailbox_t*, const char* rfc724_mid);
+int          mrmailbox_rfc724_mid_exists__    (mrmailbox_t*, const char* rfc724_mid, char** ret_server_folder, uint32_t* ret_server_uid);
+void         mrmailbox_update_server_uid__    (mrmailbox_t*, const char* rfc724_mid, const char* server_folder, uint32_t server_uid);
+void         mrmailbox_update_msg_chat_id__   (mrmailbox_t*, uint32_t msg_id, uint32_t chat_id);
+void         mrmailbox_update_msg_state__     (mrmailbox_t*, uint32_t msg_id, int state);
+void         mrmailbox_delete_msg_on_imap     (mrmailbox_t* mailbox, mrjob_t* job);
+int          mrmailbox_mdn_from_ext__         (mrmailbox_t*, uint32_t from_id, const char* rfc724_mid, uint32_t* ret_chat_id, uint32_t* ret_msg_id); /* returns 1 if an event should be send */
+void         mrmailbox_send_mdn               (mrmailbox_t*, mrjob_t* job);
+void         mrmailbox_markseen_msg_on_imap   (mrmailbox_t* mailbox, mrjob_t* job);
+void         mrmailbox_markseen_mdn_on_imap   (mrmailbox_t* mailbox, mrjob_t* job);
+char*        mrmsg_get_summarytext_by_raw     (int type, const char* text, mrparam_t*, int approx_bytes); /* the returned value must be free()'d */
+int          mrmsg_is_increation__            (const mrmsg_t*);
+void         mrmsg_save_param_to_disk__       (mrmsg_t*);
+void         mr_get_authorNtitle_from_filename(const char* pathNfilename, char** ret_author, char** ret_title);
+
+
+/*******************************************************************************
+ * Internal contact handling
+ ******************************************************************************/
+
+
+/* contact origins */
+#define MR_ORIGIN_UNSET                         0
+#define MR_ORIGIN_INCOMING_UNKNOWN_FROM      0x10 /* From: of incoming messages of unknown sender */
+#define MR_ORIGIN_INCOMING_UNKNOWN_CC        0x20 /* Cc: of incoming messages of unknown sender */
+#define MR_ORIGIN_INCOMING_UNKNOWN_TO        0x40 /* To: of incoming messages of unknown sender */
+#define MR_ORIGIN_INCOMING_REPLY_TO         0x100 /* Reply-To: of incoming message of known sender */
+#define MR_ORIGIN_INCOMING_CC               0x200 /* Cc: of incoming message of known sender */
+#define MR_ORIGIN_INCOMING_TO               0x400 /* additional To:'s of incoming message of known sender */
+#define MR_ORIGIN_CREATE_CHAT               0x800 /* a chat was manually created for this user, but no message yet sent */
+#define MR_ORIGIN_OUTGOING_BCC             0x1000 /* message send by us */
+#define MR_ORIGIN_OUTGOING_CC              0x2000 /* message send by us */
+#define MR_ORIGIN_OUTGOING_TO              0x4000 /* message send by us */
+#define MR_ORIGIN_INTERNAL                0x40000 /* internal use */
+#define MR_ORIGIN_ADRESS_BOOK             0x80000 /* address is in our address book */
+#define MR_ORIGIN_MANUALLY_CREATED       0x100000 /* contact added by mrmailbox_create_contact() */
+
+#define MR_ORIGIN_MIN_CONTACT_LIST    (MR_ORIGIN_INCOMING_REPLY_TO) /* contacts with at least this origin value are shown in the contact list */
+#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);
+int          mrmailbox_is_contact_blocked__   (mrmailbox_t*, uint32_t id);
+int          mrmailbox_real_contact_exists__  (mrmailbox_t*, uint32_t id);
+int          mrmailbox_contact_addr_equals__  (mrmailbox_t*, uint32_t contact_id, const char* other_addr);
+void         mrmailbox_scaleup_contact_origin__(mrmailbox_t*, uint32_t contact_id, int origin);
+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
+ ******************************************************************************/
+
+
+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
+ ******************************************************************************/
+
+
+/* should be set up by mrmailbox_new() */
+extern mrmailbox_t* s_localize_mb_obj;
+
+
+/* Return the string with the given ID by calling MR_EVENT_GET_STRING.
+The result must be free()'d! */
+char* mrstock_str (int id);
+
+
+/* Replaces the first `%1$s` in the given String-ID by the given value.
+The result must be free()'d! */
+char* mrstock_str_repl_string (int id, const char* value);
+char* mrstock_str_repl_int    (int id, int value);
+
+
+/* Replaces the first `%1$s` and `%2$s` in the given String-ID by the two given strings.
+The result must be free()'d! */
+char* mrstock_str_repl_string2 (int id, const char*, const char*);
+
+
+/* Return a string with a correct plural form by callint MR_EVENT_GET_QUANTITY_STRING.
+The result must be free()'d! */
+char* mrstock_str_repl_pl (int id, int cnt);
+
+
+#ifdef __cplusplus
+} /* /extern "C" */
+#endif
+#endif /* __MRMSG_H__ */
+

+ 10 - 19
deltachat-ios/libraries/deltachat-core/src/mrmailbox_log.c

@@ -17,30 +17,21 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrmailbox_log.c
- * Purpose: Error handling.
- *
- *******************************************************************************
- *
- * Asynchronous "Thread-errors" are reported by the mrmailbox_log_error()
- * function.  These errors must be shown to the user by a bubble or so.
- *
- * "Normal" errors are usually returned by a special value (null or so) and are
- * usually not reported using mrmailbox_log_error() - its up to the caller to
- * decide, what should be reported or done.  However, these "Normal" errors
- * are usually logged by mrmailbox_log_warning().
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
-#include <stdio.h>
+/* Asynchronous "Thread-errors" are reported by the mrmailbox_log_error()
+function.  These errors must be shown to the user by a bubble or so.
+
+"Normal" errors are usually returned by a special value (null or so) and are
+usually not reported using mrmailbox_log_error() - its up to the caller to
+decide, what should be reported or done.  However, these "Normal" errors
+are usually logged by mrmailbox_log_warning(). */
+
+
 #include <stdarg.h>
 #include <memory.h>
-#include "mrmailbox.h"
-#include "mrtools.h"
+#include "mrmailbox_internal.h"
 
 
 /*******************************************************************************

+ 1 - 9
deltachat-ios/libraries/deltachat-core/src/mrmailbox_tools.c

@@ -17,19 +17,11 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrmailbox_tools.c
- * Purpose: Database and other tools for a mrmailbox_t object.
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
-#include <string.h>
-#include "mrmailbox.h"
+#include "mrmailbox_internal.h"
 #include "mrmimeparser.h"
-#include "mrtools.h"
 
 
 /*******************************************************************************

+ 1 - 8
deltachat-ios/libraries/deltachat-core/src/mrmimefactory.c

@@ -17,18 +17,11 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrmimefactory.c
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
-#include <string.h>
-#include "mrmailbox.h"
+#include "mrmailbox_internal.h"
 #include "mrmimefactory.h"
-#include "mrtools.h"
 
 #define LINEEND "\r\n" /* lineend used in IMF */
 

+ 0 - 4
deltachat-ios/libraries/deltachat-core/src/mrmimefactory.h

@@ -17,10 +17,6 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrmimefactory.h
- *
  ******************************************************************************/
 
 

+ 1 - 9
deltachat-ios/libraries/deltachat-core/src/mrmimeparser.c

@@ -17,21 +17,13 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrmimeparser.c
- * Purpose: Parse MIME body, see header for details.
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
-#include <string.h>
-#include "mrmailbox.h"
+#include "mrmailbox_internal.h"
 #include "mrmimeparser.h"
 #include "mrmimefactory.h"
 #include "mrsimplify.h"
-#include "mrtools.h"
 
 
 /*******************************************************************************

+ 5 - 11
deltachat-ios/libraries/deltachat-core/src/mrmimeparser.h

@@ -17,17 +17,14 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrmimeparser.h
- * Purpose: Parse MIME body; this is the text part of an IMF, see
- *          https://tools.ietf.org/html/rfc5322
- *          mrmimeparser_t has no deep dependencies to mrmailbox_t or to the
- *          database (mrmailbox_t is used for logging only).
- *
  ******************************************************************************/
 
 
+/* Parse MIME body; this is the text part of an IMF, see https://tools.ietf.org/html/rfc5322
+mrmimeparser_t has no deep dependencies to mrmailbox_t or to the database
+(mrmailbox_t is used for logging only). */
+
+
 #ifndef __MRMIMEPARSER_H__
 #define __MRMIMEPARSER_H__
 #ifdef __cplusplus
@@ -38,9 +35,6 @@ extern "C" {
 /*** library-private **********************************************************/
 
 
-#include "mrmsg.h"
-
-
 typedef struct mrmimepart_t
 {
 	int                 m_type; /*one of MR_MSG_* */

+ 21 - 21
deltachat-ios/libraries/deltachat-core/src/mrmsg.c

@@ -17,21 +17,12 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrmsg.c
- * Purpose: mrmsg_t represents a single message, see header for details.
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
-#include <string.h>
-#include "mrmailbox.h"
+#include "mrmailbox_internal.h"
 #include "mrimap.h"
 #include "mrsmtp.h"
-#include "mrcontact.h"
-#include "mrtools.h"
 #include "mrjob.h"
 #include "mrpgp.h"
 #include "mrmimefactory.h"
@@ -406,10 +397,10 @@ char* mrmailbox_get_msg_info(mrmailbox_t* mailbox, uint32_t msg_id)
 	mrstrbuilder_cat(&ret, "\n");
 
 	/* add "suspicious" status */
-	if( msg->m_state==MR_IN_FRESH ) {
+	if( msg->m_state==MR_STATE_IN_FRESH ) {
 		mrstrbuilder_cat(&ret, "Status: Fresh\n");
 	}
-	else if( msg->m_state==MR_IN_NOTICED ) {
+	else if( msg->m_state==MR_STATE_IN_NOTICED ) {
 		mrstrbuilder_cat(&ret, "Status: Noticed\n");
 	}
 
@@ -447,15 +438,23 @@ cleanup:
 }
 
 
-mrpoortext_t* mrmsg_get_summary(mrmsg_t* msg, const mrchat_t* chat)
+mrpoortext_t* mrmsg_get_summary(mrmsg_t* msg, mrchat_t* chat)
 {
 	mrpoortext_t* ret = mrpoortext_new();
 	mrcontact_t*  contact = NULL;
+	mrchat_t*     chat_to_delete = NULL;
 
-	if( msg==NULL || chat==NULL ) {
+	if( msg==NULL ) {
 		goto cleanup;
 	}
 
+	if( chat == NULL ) {
+		if( (chat=mrmailbox_get_chat(msg->m_mailbox, msg->m_chat_id)) == NULL ) {
+			goto cleanup;
+		}
+		chat_to_delete = chat;
+	}
+
 	if( msg->m_from_id != MR_CONTACT_ID_SELF  &&  chat->m_type == MR_CHAT_GROUP ) {
 		contact = mrmailbox_get_contact(chat->m_mailbox, msg->m_from_id);
 	}
@@ -464,6 +463,7 @@ mrpoortext_t* mrmsg_get_summary(mrmsg_t* msg, const mrchat_t* chat)
 
 cleanup:
 	mrcontact_unref(contact);
+	mrchat_unref(chat_to_delete);
 	return ret;
 }
 
@@ -1041,8 +1041,8 @@ int mrmailbox_markseen_msgs(mrmailbox_t* mailbox, const uint32_t* msg_ids, int m
 		for( i = 0; i < msg_cnt; i++ )
 		{
 			sqlite3_stmt* stmt = mrsqlite3_predefine__(mailbox->m_sql, UPDATE_msgs_SET_seen_WHERE_id_AND_chat_id_AND_freshORnoticed,
-				"UPDATE msgs SET state=" MR_STRINGIFY(MR_IN_SEEN)
-				" WHERE id=? AND chat_id>" MR_STRINGIFY(MR_CHAT_ID_LAST_SPECIAL) " AND (state=" MR_STRINGIFY(MR_IN_FRESH) " OR state=" MR_STRINGIFY(MR_IN_NOTICED) ");");
+				"UPDATE msgs SET state=" MR_STRINGIFY(MR_STATE_IN_SEEN)
+				" WHERE id=? AND chat_id>" MR_STRINGIFY(MR_CHAT_ID_LAST_SPECIAL) " AND (state=" MR_STRINGIFY(MR_STATE_IN_FRESH) " OR state=" MR_STRINGIFY(MR_STATE_IN_NOTICED) ");");
 			sqlite3_bind_int(stmt, 1, msg_ids[i]);
 			sqlite3_step(stmt);
 			if( sqlite3_changes(mailbox->m_sql->m_cobj) )
@@ -1055,8 +1055,8 @@ int mrmailbox_markseen_msgs(mrmailbox_t* mailbox, const uint32_t* msg_ids, int m
 			{
 				/* message may be in contact requests, mark as NOTICED, this does not force IMAP updated nor send MDNs */
 				sqlite3_stmt* stmt2 = mrsqlite3_predefine__(mailbox->m_sql, UPDATE_msgs_SET_noticed_WHERE_id_AND_fresh,
-					"UPDATE msgs SET state=" MR_STRINGIFY(MR_IN_NOTICED)
-					" WHERE id=? AND state=" MR_STRINGIFY(MR_IN_FRESH) ";");
+					"UPDATE msgs SET state=" MR_STRINGIFY(MR_STATE_IN_NOTICED)
+					" WHERE id=? AND state=" MR_STRINGIFY(MR_STATE_IN_FRESH) ";");
 				sqlite3_bind_int(stmt2, 1, msg_ids[i]);
 				sqlite3_step(stmt2);
 				if( sqlite3_changes(mailbox->m_sql->m_cobj) ) {
@@ -1101,14 +1101,14 @@ int mrmailbox_mdn_from_ext__(mrmailbox_t* mailbox, uint32_t from_id, const char*
 	int chat_type  = sqlite3_column_int(stmt, 2);
 	int msg_state  = sqlite3_column_int(stmt, 3);
 
-	if( msg_state!=MR_OUT_PENDING && msg_state!=MR_OUT_DELIVERED ) {
+	if( msg_state!=MR_STATE_OUT_PENDING && msg_state!=MR_STATE_OUT_DELIVERED ) {
 		return 0; /* eg. already marked as MDNS_RCVD. however, it is importent, that the message ID is set above as this will allow the caller eg. to move the message away */
 	}
 
 	/* normal chat? that's quite easy. */
 	if( chat_type == MR_CHAT_NORMAL )
 	{
-		mrmailbox_update_msg_state__(mailbox, *ret_msg_id, MR_OUT_MDN_RCVD);
+		mrmailbox_update_msg_state__(mailbox, *ret_msg_id, MR_STATE_OUT_MDN_RCVD);
 		return 1; /* send event about new state */
 	}
 
@@ -1152,7 +1152,7 @@ int mrmailbox_mdn_from_ext__(mrmailbox_t* mailbox, uint32_t from_id, const char*
 	sqlite3_bind_int(stmt, 1, *ret_msg_id);
 	sqlite3_step(stmt);
 
-	mrmailbox_update_msg_state__(mailbox, *ret_msg_id, MR_OUT_MDN_RCVD);
+	mrmailbox_update_msg_state__(mailbox, *ret_msg_id, MR_STATE_OUT_MDN_RCVD);
 	return 1;
 }
 

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

@@ -1,140 +0,0 @@
-/*******************************************************************************
- *
- *                              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/ .
- *
- *******************************************************************************
- *
- * File:    mrmsg.h
- * Purpose: mrmsg_t represents a single message in a chat.  One email can
- *          result in different messages!
- *
- ******************************************************************************/
-
-
-#ifndef __MRMSG_H__
-#define __MRMSG_H__
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#include "mrparam.h"
-typedef struct mrjob_t mrjob_t;
-typedef struct mrpoortext_t mrpoortext_t;
-typedef struct mrchat_t mrchat_t;
-
-
-/* message types */
-#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 */
-
-#define MR_MSG_NEEDS_ATTACHMENT(a)         ((a)==MR_MSG_IMAGE || (a)==MR_MSG_GIF || (a)==MR_MSG_AUDIO || (a)==MR_MSG_VOICE || (a)==MR_MSG_VIDEO || (a)==MR_MSG_FILE)
-#define MR_MSG_MAKE_FILENAME_SEARCHABLE(a) ((a)==MR_MSG_AUDIO || (a)==MR_MSG_FILE || (a)==MR_MSG_VIDEO ) /* add filename.ext (without path) to m_text? this is needed for the fulltext search. The extension is useful to get all PDF, all MP3 etc. */
-#define MR_MSG_MAKE_SUFFIX_SEARCHABLE(a)   ((a)==MR_MSG_IMAGE || (a)==MR_MSG_GIF || (a)==MR_MSG_VOICE)
-
-
-/* message states */
-#define MR_STATE_UNDEFINED  0
-#define MR_IN_FRESH        10 /* incoming message, not noticed nor seen */
-#define MR_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_IN_SEEN         16 /* incoming message marked as read on IMAP and MDN may be send */
-#define MR_OUT_PENDING     20 /* hit "send" button - but the message is pending in some way, maybe we're offline (no checkmark) */
-#define MR_OUT_ERROR       24 /* unrecoverable error (recoverable errors result in pending messages) */
-#define MR_OUT_DELIVERED   26 /* outgoing message successfully delivered to server (one checkmark) */
-#define MR_OUT_MDN_RCVD    28 /* outgoing message read (two checkmarks; this requires goodwill on the receiver's side) */
-
-
-/* special message IDs (only returned if requested) */
-#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
-
-
-typedef struct mrmsg_t
-{
-	uint32_t      m_id;
-	char*         m_rfc724_mid;
-	char*         m_server_folder;
-	uint32_t      m_server_uid;
-	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 */
-
-	int           m_type;      /* MR_MSG_* */
-	int           m_state;     /* MR_STATE_* etc. */
-	int           m_is_msgrmsg;
-	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;
-
-	mrmailbox_t*  m_mailbox;   /* may be NULL, set on loading from database and on sending */
-
-} mrmsg_t;
-
-
-mrmsg_t*      mrmsg_new                    ();
-void          mrmsg_unref                  (mrmsg_t*); /* this also free()s all strings; so if you set up the object yourself, make sure to use strdup()! */
-void          mrmsg_empty                  (mrmsg_t*);
-mrpoortext_t* mrmsg_get_summary            (mrmsg_t*, const mrchat_t*);
-char*         mrmsg_get_summarytext        (mrmsg_t*, int approx_characters); /* the returned value must be free()'d */
-int           mrmsg_show_padlock           (mrmsg_t*); /* a padlock should be shown if the message is e2ee _and_ e2ee is enabled for sending. */
-char*         mrmsg_get_filename           (mrmsg_t*); /* returns base file name without part, if appropriate, the returned value must be free()'d */
-mrpoortext_t* mrmsg_get_mediainfo          (mrmsg_t*); /* returns real author (as text1, this is not always the sender, NULL if unknown) and title (text2, NULL if unknown) */
-int           mrmsg_is_increation          (mrmsg_t*);
-void          mrmsg_save_param_to_disk     (mrmsg_t*); /* can be used to add some additional, persistent information to a messages record */
-
-/* only sets the text field, MR_MSG_TEXT must be set additionally */
-void          mrmsg_set_text               (mrmsg_t*, const char* text);
-
-
-/*** library-private **********************************************************/
-
-#define      MR_MSG_FIELDS                    " m.id,rfc724_mid,m.server_folder,m.server_uid,m.chat_id, m.from_id,m.to_id,m.timestamp, m.type,m.state,m.msgrmsg,m.txt, m.param,m.starred "
-int          mrmsg_set_from_stmt__            (mrmsg_t*, sqlite3_stmt* row, int row_offset); /* row order is MR_MSG_FIELDS */
-int          mrmsg_load_from_db__             (mrmsg_t*, mrmailbox_t*, uint32_t id);
-void         mr_guess_msgtype_from_suffix     (const char* pathNfilename, int* ret_msgtype, char** ret_mime);
-size_t       mrmailbox_get_real_msg_cnt__     (mrmailbox_t*); /* the number of messages assigned to real chat (!=deaddrop, !=trash) */
-size_t       mrmailbox_get_deaddrop_msg_cnt__ (mrmailbox_t*);
-int          mrmailbox_rfc724_mid_cnt__       (mrmailbox_t*, const char* rfc724_mid);
-int          mrmailbox_rfc724_mid_exists__    (mrmailbox_t*, const char* rfc724_mid, char** ret_server_folder, uint32_t* ret_server_uid);
-void         mrmailbox_update_server_uid__    (mrmailbox_t*, const char* rfc724_mid, const char* server_folder, uint32_t server_uid);
-void         mrmailbox_update_msg_chat_id__   (mrmailbox_t*, uint32_t msg_id, uint32_t chat_id);
-void         mrmailbox_update_msg_state__     (mrmailbox_t*, uint32_t msg_id, int state);
-void         mrmailbox_delete_msg_on_imap     (mrmailbox_t* mailbox, mrjob_t* job);
-int          mrmailbox_mdn_from_ext__         (mrmailbox_t*, uint32_t from_id, const char* rfc724_mid, uint32_t* ret_chat_id, uint32_t* ret_msg_id); /* returns 1 if an event should be send */
-void         mrmailbox_send_mdn               (mrmailbox_t*, mrjob_t* job);
-void         mrmailbox_markseen_msg_on_imap   (mrmailbox_t* mailbox, mrjob_t* job);
-void         mrmailbox_markseen_mdn_on_imap   (mrmailbox_t* mailbox, mrjob_t* job);
-char*        mrmsg_get_summarytext_by_raw     (int type, const char* text, mrparam_t*, int approx_bytes); /* the returned value must be free()'d */
-int          mrmsg_is_increation__            (const mrmsg_t*);
-void         mrmsg_save_param_to_disk__       (mrmsg_t*);
-void         mr_get_authorNtitle_from_filename(const char* pathNfilename, char** ret_author, char** ret_title);
-
-
-#ifdef __cplusplus
-} /* /extern "C" */
-#endif
-#endif /* __MRMSG_H__ */
-

+ 5 - 7
deltachat-ios/libraries/deltachat-core/src/mrosnative.c

@@ -17,16 +17,14 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrosnative.c
- * Purpose: Some functions that are called by the backend under certain
- *          circumstances.  The frontents should create a copy of this file
- *          and implement the functions as needed.
- *
  ******************************************************************************/
 
 
+/* Some functions that are called by the backend under certain
+circumstances.  The frontents should create a copy of this file
+and implement the functions as needed, eg. for attaching threads in JNI. */
+
+
 #include <stdlib.h>
 #include "mrmailbox.h"
 #include "mrosnative.h"

+ 0 - 5
deltachat-ios/libraries/deltachat-core/src/mrosnative.h

@@ -17,11 +17,6 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrosnative.h
- * Purpose: OS-native depending part, eg. for attaching threads in JNI
- *
  ******************************************************************************/
 
 

+ 1 - 7
deltachat-ios/libraries/deltachat-core/src/mrparam.c

@@ -17,20 +17,14 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrparam.c
- * Purpose: Handle parameter lists, see header for details
- *
  ******************************************************************************/
 
 
 
 #include <stdlib.h>
 #include <string.h>
-#include "mrmailbox.h"
+#include "mrmailbox_internal.h"
 #include "mrtools.h"
-#include "mrparam.h"
 
 
 /*******************************************************************************

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

@@ -1,90 +0,0 @@
-/*******************************************************************************
- *
- *                              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/ .
- *
- *******************************************************************************
- *
- * File:    mrparam.h
- * Purpose: Handle parameter lists as follows:
- *          - the list is stored in a string as "a=value\nb=value"
- *          - values can contain all characters but "\n"
- *          - for efficiency, keys are limited to one character
- *          - we expect the packed string to be well formatted and do not
- *            allow spaces around the key; spaces right of the value are trimmed
- *
- ******************************************************************************/
-
-
-#ifndef __MRPARAM_H__
-#define __MRPARAM_H__
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#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 */
-
-
-typedef struct mrparam_t
-{
-	char*    m_packed;    /* != NULL */
-} mrparam_t;
-
-
-mrparam_t*    mrparam_new          ();
-void          mrparam_unref        (mrparam_t*);
-
-void          mrparam_empty        (mrparam_t*);
-void          mrparam_set_packed   (mrparam_t*, const char*); /* overwrites all existing parameters */
-
-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 **********************************************************/
-
-#ifdef __cplusplus
-} /* /extern "C" */
-#endif
-#endif /* __MRPARAM_H__ */
-

+ 17 - 23
deltachat-ios/libraries/deltachat-core/src/mrpgp.c

@@ -17,40 +17,34 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrpgp.c
- * Purpose: End-to-end-encryption and other cryptographic functions
- *          based upon OpenSSL and BSD's netpgp.
- *
- *******************************************************************************
- *
- * If we want to switch to other encryption engines, here are the functions to
- * be replaced.
- *
- * However, eg. GpgME cannot (easily) be used standalone and GnuPG's licence
- * would not allow the original creator of Delta Chat to release a proprietary
- * version, which, however, is required for the Apple store. (NB: the original
- * creator is the only person who could do this, a normal licensee is not
- * allowed to do so at all)
- *
- * So, we do not see a simple alternative - but everyone is welcome to implement
- * one :-)
- *
  ******************************************************************************/
 
 
-#include <string.h>
+/* End-to-end-encryption and other cryptographic functions based upon OpenSSL
+and BSD's netpgp.
+
+If we want to switch to other encryption engines, here are the functions to
+be replaced.
+
+However, eg. GpgME cannot (easily) be used standalone and GnuPG's licence
+would not allow the original creator of Delta Chat to release a proprietary
+version, which, however, is required for the Apple store. (NB: the original
+creator is the only person who could do this, a normal licensee is not
+allowed to do so at all)
+
+So, we do not see a simple alternative - but everyone is welcome to implement
+one :-) */
+
+
 #include <openssl/ssl.h>
 #include <openssl/rand.h>
 #include <openssl/rsa.h>
 #include <openssl/evp.h>
 #include <netpgp-extra.h>
-#include "mrmailbox.h"
+#include "mrmailbox_internal.h"
 #include "mrkey.h"
 #include "mrkeyring.h"
 #include "mrpgp.h"
-#include "mrtools.h"
 
 
 static pgp_io_t s_io;

+ 0 - 6
deltachat-ios/libraries/deltachat-core/src/mrpgp.h

@@ -17,15 +17,9 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrpgp.h
- * Purpose: Frontend for the crypto-engine
- *
  ******************************************************************************/
 
 
-
 #ifndef __MRPGP_H__
 #define __MRPGP_H__
 #ifdef __cplusplus

+ 1 - 8
deltachat-ios/libraries/deltachat-core/src/mrpoortext.c

@@ -17,17 +17,10 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrpoortext.c
- * Purpose: See header.
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
-#include "mrmailbox.h"
-#include "mrtools.h"
+#include "mrmailbox_internal.h"
 
 
 /*******************************************************************************

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

@@ -1,71 +0,0 @@
-/*******************************************************************************
- *
- *                              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/ .
- *
- *******************************************************************************
- *
- * File:    mrpoortext.h
- * Purpose: A line of text that describes eg. the last chat state as
- *          "Draft: Foo" or "Me: Foobar" (not really _richtext_, therefore
- *          _poortext_)
- *
- ******************************************************************************/
-
-
-#ifndef __MRPOORTEXT_H__
-#define __MRPOORTEXT_H__
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* additional, emphasized text */
-#define MR_TEXT1_NORMAL    0
-#define MR_TEXT1_DRAFT     1 /* the values must not be changes as used directly in the frontend */
-#define MR_TEXT1_USERNAME  2
-#define MR_TEXT1_SELF      3
-
-
-typedef struct mrpoortext_t
-{
-	char*    m_text1;         /* may be NULL */
-	int      m_text1_meaning; /* one of MR_TEXT1_* */
-	char*    m_text2;         /* may be NULL */
-	time_t   m_timestamp;     /* may be 0 */
-	int      m_state;         /* may be 0 */
-} mrpoortext_t;
-
-
-mrpoortext_t* mrpoortext_new       ();
-void          mrpoortext_unref     (mrpoortext_t*);
-
-void          mrpoortext_empty     (mrpoortext_t*);
-
-
-/*** library-private **********************************************************/
-
-
-#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*);
-
-
-#ifdef __cplusplus
-} /* /extern "C" */
-#endif
-#endif /* __MRPOORTEXT_H__ */
-

+ 14 - 4
deltachat-ios/libraries/deltachat-core/src/mrsaxparser.c

@@ -17,13 +17,23 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrsaxparser.c
- *
  ******************************************************************************/
 
 
+/* mrsaxparser_t parses XML and HTML files that may not be wellformed
+and spits out all text and tags found.
+- Attributes are recognized with single, double or no quotes
+- Whitespace ignored inside tags
+- Self-closing tags are issued as open-tag plus close-tag
+- CDATA is supoorted; DTA, comments, processing instruction are
+  skipped properly
+- The parser does not care about hierarchy, if needed this can be
+  done by the user.
+- Input and output strings must be UTF-8 encoded.
+- Tag and attribute names are converted to lower case.
+- Parsing does not stop on errors; instead errors are recovered. */
+
+
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>

+ 0 - 16
deltachat-ios/libraries/deltachat-core/src/mrsaxparser.h

@@ -17,22 +17,6 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrsaxparser.h
- * Purpose: mrsaxparser_t parses XML and HTML files that may not be wellformed
- *          and spits out all text and tags found.
- *          - Attributes are recognized with single, double or no quotes
- *          - Whitespace ignored inside tags
- *          - Self-closing tags are issued as open-tag plus close-tag
- *          - CDATA is supoorted; DTA, comments, processing instruction are
- *            skipped properly
- *          - The parser does not care about hierarchy, if needed this can be
- *            done by the user.
- *          - Input and output strings must be UTF-8 encoded.
- *          - Tag and attribute names are converted to lower case.
- *          - Parsing does not stop on errors; instead errors are recovered.
- *
  ******************************************************************************/
 
 

+ 0 - 5
deltachat-ios/libraries/deltachat-core/src/mrsimplify.c

@@ -17,11 +17,6 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrsimplify.c
- * Purpose: Simplify text, see header for details.
- *
  ******************************************************************************/
 
 

+ 3 - 7
deltachat-ios/libraries/deltachat-core/src/mrsimplify.h

@@ -17,12 +17,6 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrsimplify.h
- * Purpose: Simplify and normalise text: Remove quotes, signatures, unnecessary
- *          lineends etc.
- *
  ******************************************************************************/
 
 
@@ -44,7 +38,9 @@ typedef struct mrsimplify_t
 mrsimplify_t* mrsimplify_new           ();
 void          mrsimplify_unref         (mrsimplify_t*);
 
-/* The data returned from Simplify() must be free()'d when no longer used, private */
+/* Simplify and normalise text: Remove quotes, signatures, unnecessary
+lineends etc.
+The data returned from Simplify() must be free()'d when no longer used, private */
 char*         mrsimplify_simplify      (mrsimplify_t*, const char* txt_unterminated, int txt_bytes, int is_html);
 
 

+ 2 - 9
deltachat-ios/libraries/deltachat-core/src/mrsmtp.c

@@ -17,20 +17,13 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrsmtp.c
- * Purpose: Use SMTP servers
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
-#include <string.h>
 #include <libetpan/libetpan.h>
-#include "mrmailbox.h"
+#include "mrmailbox_internal.h"
 #include "mrsmtp.h"
-#include "mrtools.h"
+
 
 #ifndef DEBUG_SMTP
 #define DEBUG_SMTP 0

+ 1 - 7
deltachat-ios/libraries/deltachat-core/src/mrsmtp.h

@@ -17,12 +17,6 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrsmtp.h
- * Purpose: Use SMTP servers with no dependencies to mrmailbox_t only for
- *          logging.
- *
  ******************************************************************************/
 
 
@@ -48,7 +42,7 @@ typedef struct mrsmtp_t
 	int             m_log_connect_errors;
 	int             m_log_usual_error;
 
-	mrmailbox_t*    m_mailbox;
+	mrmailbox_t*    m_mailbox; /* only for logging! */
 } mrsmtp_t;
 
 mrsmtp_t*    mrsmtp_new          (mrmailbox_t*);

+ 17 - 29
deltachat-ios/libraries/deltachat-core/src/mrsqlite3.c

@@ -17,38 +17,26 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrsqlite3.c
- * Purpose: MrSqlite3 wraps around SQLite
- *
- *******************************************************************************
- *
- * Some hints to the underlying database:
- *
- * - `PRAGMA cache_size` and `PRAGMA page_size`: As we save BLOBs in external
- *   files, caching is not that important; we rely on the system defaults here
- *   (normally 2 MB cache, 1 KB page size on sqlite < 3.12.0, 4 KB for newer
- *   versions)
- *
- * - We use `sqlite3_last_insert_rowid()` to find out created records - for this
- *   purpose, the primary ID has to be marked using `INTEGER PRIMARY KEY`, see
- *   https://www.sqlite.org/c3ref/last_insert_rowid.html
- *
- * - Some words to the "param" fields:  These fields contains a string with
- *   additonal, named parameters which must not be accessed by a search and/or
- *   are very seldomly used. Moreover, this allows smart minor database updates.
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
-#include <string.h>
-#include "mrmailbox.h"
-#include "mrsqlite3.h"
-#include "mrtools.h"
-#include "mrchat.h"
-#include "mrcontact.h"
+#include "mrmailbox_internal.h"
+
+
+/* This class wraps around SQLite.  Some hints to the underlying database:
+
+- `PRAGMA cache_size` and `PRAGMA page_size`: As we save BLOBs in external
+  files, caching is not that important; we rely on the system defaults here
+  (normally 2 MB cache, 1 KB page size on sqlite < 3.12.0, 4 KB for newer
+  versions)
+
+- We use `sqlite3_last_insert_rowid()` to find out created records - for this
+  purpose, the primary ID has to be marked using `INTEGER PRIMARY KEY`, see
+  https://www.sqlite.org/c3ref/last_insert_rowid.html
+
+- Some words to the "param" fields:  These fields contains a string with
+  additonal, named parameters which must not be accessed by a search and/or
+  are very seldomly used. Moreover, this allows smart minor database updates. */
 
 
 /*******************************************************************************

+ 7 - 13
deltachat-ios/libraries/deltachat-core/src/mrsqlite3.h

@@ -17,21 +17,15 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrsqlite3.h
- * Purpose: MrSqlite3 wraps around SQLite
- *
- *******************************************************************************
- *
- * 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.
- *
  ******************************************************************************/
 
 
+/* 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
@@ -174,7 +168,7 @@ typedef struct mrsqlite3_t
 	/* helper for MrSqlite3Transaction */
 	int           m_transactionCount;
 
-	mrmailbox_t*  m_mailbox; /* used for logging and to acquire wakelocks, there may be N mrsqlite_t objects per mrmailbox! In practise, we use 2 on backup, 1 otherwise. */
+	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 */

+ 5 - 7
deltachat-ios/libraries/deltachat-core/src/mrstock.c

@@ -17,16 +17,14 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrstock.h
- * Purpose: Add translated strings that are used by the messager backend.
- *          As the logging functions may use these strings, do not log any
- *          errors from here.
- *
  ******************************************************************************/
 
 
+/* Add translated strings that are used by the messager backend.
+As the logging functions may use these strings, do not log any
+errors from here. */
+
+
 #include <stdlib.h>
 #include <memory.h>
 #include "mrmailbox.h"

+ 0 - 106
deltachat-ios/libraries/deltachat-core/src/mrstock.h

@@ -1,106 +0,0 @@
-/*******************************************************************************
- *
- *                              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/ .
- *
- *******************************************************************************
- *
- * File:    mrstock.h
- * Purpose: Add translated strings that are used by the messager backend
- *
- ******************************************************************************/
-
-
-#ifndef __MRSTOCK_H__
-#define __MRSTOCK_H__
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#define MR_STR_FREE_             0 /* the IDs must not change! */
-#define MR_STR_NOMESSAGES        1
-#define MR_STR_SELF              2
-#define MR_STR_DRAFT             3
-#define MR_STR_MEMBER            4
-#define MR_STR_CONTACT           6
-#define MR_STR_VOICEMESSAGE      7
-#define MR_STR_DEADDROP          8
-#define MR_STR_IMAGE             9
-#define MR_STR_VIDEO             10
-#define MR_STR_AUDIO             11
-#define MR_STR_FILE              12
-#define MR_STR_STATUSLINE        13
-#define MR_STR_NEWGROUPDRAFT     14
-#define MR_STR_MSGGRPNAME        15
-#define MR_STR_MSGGRPIMGCHANGED  16
-#define MR_STR_MSGADDMEMBER      17
-#define MR_STR_MSGDELMEMBER      18
-#define MR_STR_MSGGROUPLEFT      19
-#define MR_STR_ERROR             20
-#define MR_STR_SELFNOTINGRP      21
-#define MR_STR_NONETWORK         22
-#define MR_STR_GIF               23
-#define MR_STR_ENCRYPTEDMSG      24
-#define MR_STR_ENCR_E2E          25
-#define MR_STR_ENCR_TRANSP       27
-#define MR_STR_ENCR_NONE         28
-#define MR_STR_FINGERPRINTS      30
-#define MR_STR_READRCPT          31
-#define MR_STR_READRCPT_MAILBODY 32
-#define MR_STR_MSGGRPIMGDELETED  33
-#define MR_STR_E2E_FINE          34
-#define MR_STR_E2E_NO_AUTOCRYPT  35
-#define MR_STR_E2E_DIS_BY_YOU    36
-#define MR_STR_E2E_DIS_BY_RCPT   37
-#define MR_STR_ARCHIVEDCHATS     40
-#define MR_STR_STARREDMSGS       41
-
-
-/*** library-private **********************************************************/
-
-
-/* should be set up by mrmailbox_new() */
-extern mrmailbox_t* s_localize_mb_obj;
-
-
-/* Return the string with the given ID by calling MR_EVENT_GET_STRING.
-The result must be free()'d! */
-char* mrstock_str (int id);
-
-
-/* Replaces the first `%1$s` in the given String-ID by the given value.
-The result must be free()'d! */
-char* mrstock_str_repl_string (int id, const char* value);
-char* mrstock_str_repl_int    (int id, int value);
-
-
-/* Replaces the first `%1$s` and `%2$s` in the given String-ID by the two given strings.
-The result must be free()'d! */
-char* mrstock_str_repl_string2 (int id, const char*, const char*);
-
-
-/* Return a string with a correct plural form by callint MR_EVENT_GET_QUANTITY_STRING.
-The result must be free()'d! */
-char* mrstock_str_repl_pl (int id, int cnt);
-
-
-#ifdef __cplusplus
-} /* /extern "C" */
-#endif
-#endif /* __MRSTOCKSTR_H__ */
-

+ 1 - 10
deltachat-ios/libraries/deltachat-core/src/mrtools.c

@@ -17,28 +17,19 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrtools.c
- * Purpose: Some tools, see header for details.
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
-#include <string.h>
 #include <stdarg.h>
 #include <ctype.h>
 #include <fcntl.h>
 #include <unistd.h>
-#include <sqlite3.h>
 #include <sys/stat.h>
 #include <sys/types.h> /* for getpid() */
 #include <unistd.h>    /* for getpid() */
 #include <libetpan/libetpan.h>
 #include <libetpan/mailimap_types.h>
-#include "mrmailbox.h"
-#include "mrtools.h"
+#include "mrmailbox_internal.h"
 
 
 /*******************************************************************************

+ 4 - 6
deltachat-ios/libraries/deltachat-core/src/mrtools.h

@@ -17,15 +17,13 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    mrtools.h
- * Purpose: Some tools and enhancements to the used libraries, there should be
- *          no references to mrmailbox_t and other "larger" classes here.
- *
  ******************************************************************************/
 
 
+/* Some tools and enhancements to the used libraries, there should be
+no references to mrmailbox_t and other "larger" classes here. */
+
+
 #ifndef __MRTOOLS_H__
 #define __MRTOOLS_H__
 #ifdef __cplusplus

+ 14 - 22
deltachat-ios/libraries/deltachat-core/src/stress.c

@@ -17,25 +17,18 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    stress.c
- * Purpose: Stress some functions for testing; if used as a lib, this file is
- *          obsolete.
- *
- *******************************************************************************
- *
- * For memory checking, use eg.
- * $ valgrind --leak-check=full --tool=memcheck ./deltachat-core <db>
- *
  ******************************************************************************/
 
 
-#include <stdlib.h>
+/* Stress some functions for testing; if used as a lib, this file is obsolete.
+For memory checking, use eg.
+$ valgrind --leak-check=full --tool=memcheck ./deltachat-core <db>
+*/
+
+
 #include <ctype.h>
-#include <string.h>
 #include <assert.h>
-#include "mrmailbox.h"
+#include "mrmailbox_internal.h"
 #include "mrsimplify.h"
 #include "mrmimeparser.h"
 #include "mrmimefactory.h"
@@ -43,7 +36,6 @@
 #include "mrapeerstate.h"
 #include "mraheader.h"
 #include "mrkeyring.h"
-#include "mrtools.h"
 
 
 void stress_functions(mrmailbox_t* mailbox)
@@ -148,13 +140,13 @@ void stress_functions(mrmailbox_t* mailbox)
 		assert( strcmp(str, "")==0 );
 		free(str);
 
-        assert( strcmp("fresh="     MR_STRINGIFY(MR_IN_FRESH),      "fresh=10")==0 ); /* these asserts check the values, the existance of the macros and also MR_STRINGIFY() */
-        assert( strcmp("noticed="   MR_STRINGIFY(MR_IN_NOTICED),    "noticed=13")==0 );
-        assert( strcmp("seen="      MR_STRINGIFY(MR_IN_SEEN),       "seen=16")==0 );
-        assert( strcmp("pending="   MR_STRINGIFY(MR_OUT_PENDING),   "pending=20")==0 );
-        assert( strcmp("error="     MR_STRINGIFY(MR_OUT_ERROR),     "error=24")==0 );
-        assert( strcmp("delivered=" MR_STRINGIFY(MR_OUT_DELIVERED), "delivered=26")==0 );
-        assert( strcmp("mdn_rcvd="  MR_STRINGIFY(MR_OUT_MDN_RCVD),  "mdn_rcvd=28")==0 );
+        assert( strcmp("fresh="     MR_STRINGIFY(MR_STATE_IN_FRESH),      "fresh=10")==0 ); /* these asserts check the values, the existance of the macros and also MR_STRINGIFY() */
+        assert( strcmp("noticed="   MR_STRINGIFY(MR_STATE_IN_NOTICED),    "noticed=13")==0 );
+        assert( strcmp("seen="      MR_STRINGIFY(MR_STATE_IN_SEEN),       "seen=16")==0 );
+        assert( strcmp("pending="   MR_STRINGIFY(MR_STATE_OUT_PENDING),   "pending=20")==0 );
+        assert( strcmp("error="     MR_STRINGIFY(MR_STATE_OUT_ERROR),     "error=24")==0 );
+        assert( strcmp("delivered=" MR_STRINGIFY(MR_STATE_OUT_DELIVERED), "delivered=26")==0 );
+        assert( strcmp("mdn_rcvd="  MR_STRINGIFY(MR_STATE_OUT_MDN_RCVD),  "mdn_rcvd=28")==0 );
 
         assert( strcmp("deaddrop="     MR_STRINGIFY(MR_CHAT_ID_DEADDROP),         "deaddrop=1")==0 );
         assert( strcmp("to_deaddrop="  MR_STRINGIFY(MR_CHAT_ID_TO_DEADDROP),      "to_deaddrop=2")==0 );

+ 0 - 6
deltachat-ios/libraries/deltachat-core/src/stress.h

@@ -17,12 +17,6 @@
  * You should have received a copy of the GNU General Public License along with
  * this program.  If not, see http://www.gnu.org/licenses/ .
  *
- *******************************************************************************
- *
- * File:    stress.h
- * Purpose: Stress some functions for testing; if used as a lib, this file is
- *          obsolete.
- *
  ******************************************************************************/