Delta Chat Core C-API
mrmailbox-private.h
1 /*******************************************************************************
2  *
3  * Delta Chat Core
4  * Copyright (C) 2017 Björn Petersen
5  * Contact: r10s@b44t.com, http://b44t.com
6  *
7  * This program is free software: you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later
10  * version.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program. If not, see http://www.gnu.org/licenses/ .
19  *
20  ******************************************************************************/
21 
22 
23 #ifndef __MRMAILBOX_PRIVATE_H__
24 #define __MRMAILBOX_PRIVATE_H__
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 
30 typedef struct mrimap_t mrimap_t;
31 typedef struct mrsmtp_t mrsmtp_t;
32 typedef struct mrsqlite3_t mrsqlite3_t;
33 typedef struct mrjob_t mrjob_t;
34 typedef struct mrmimeparser_t mrmimeparser_t;
35 
36 
38 struct _mrmailbox
39 {
41  #define MR_MAILBOX_MAGIC 0x11a11807
42  uint32_t m_magic;
44  void* m_userdata;
46  char* m_dbfile;
47  char* m_blobdir;
49  mrsqlite3_t* m_sql;
50  mrimap_t* m_imap;
51  mrsmtp_t* m_smtp;
53  pthread_t m_job_thread;
54  pthread_cond_t m_job_cond;
55  pthread_mutex_t m_job_condmutex;
56  int m_job_condflag;
57  int m_job_do_exit;
59  mrmailboxcb_t m_cb;
61  char* m_os_name;
63  uint32_t m_cmdline_sel_chat_id;
65  int m_wake_lock;
66  pthread_mutex_t m_wake_lock_critical;
68  int m_e2ee_enabled;
70  #define MR_LOG_RINGBUF_SIZE 200
71  pthread_mutex_t m_log_ringbuf_critical;
72  char* m_log_ringbuf[MR_LOG_RINGBUF_SIZE];
74  time_t m_log_ringbuf_times[MR_LOG_RINGBUF_SIZE];
76  int m_log_ringbuf_pos;
78 };
79 
80 
81 uint32_t mrmailbox_send_msg_object (mrmailbox_t*, uint32_t chat_id, mrmsg_t*);
82 void mrmailbox_connect_to_imap (mrmailbox_t*, mrjob_t*);
83 void mrmailbox_wake_lock (mrmailbox_t*);
84 void mrmailbox_wake_unlock (mrmailbox_t*);
85 int mrmailbox_poke_eml_file (mrmailbox_t*, const char* file);
86 int mrmailbox_is_reply_to_known_message__ (mrmailbox_t*, mrmimeparser_t*);
87 int mrmailbox_is_reply_to_messenger_message__ (mrmailbox_t*, mrmimeparser_t*);
88 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);
89 void mrmailbox_add_or_lookup_contacts_by_mailbox_list__(mrmailbox_t* ths, struct mailimf_mailbox_list* mb_list, int origin, mrarray_t* ids, int* check_self);
90 void mrmailbox_add_or_lookup_contacts_by_address_list__(mrmailbox_t* ths, struct mailimf_address_list* adr_list, int origin, mrarray_t* ids, int* check_self);
91 int mrmailbox_get_archived_count__ (mrmailbox_t*);
92 int mrmailbox_reset_tables (mrmailbox_t*, int bits); /* reset tables but leaves server configuration, 1=jobs, 2=e2ee, 8=rest but server config */
93 int mrmailbox_cleanup_contacts (mrmailbox_t* ths); /* remove all contacts that are not used (e.g. in a chat, or blocked */
94 size_t mrmailbox_get_real_contact_cnt__ (mrmailbox_t*);
95 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);
96 int mrmailbox_get_contact_origin__ (mrmailbox_t*, uint32_t id, int* ret_blocked);
97 int mrmailbox_is_contact_blocked__ (mrmailbox_t*, uint32_t id);
98 int mrmailbox_real_contact_exists__ (mrmailbox_t*, uint32_t id);
99 int mrmailbox_contact_addr_equals__ (mrmailbox_t*, uint32_t contact_id, const char* other_addr);
100 void mrmailbox_scaleup_contact_origin__ (mrmailbox_t*, uint32_t contact_id, int origin);
101 void mrmailbox_unarchive_chat__ (mrmailbox_t*, uint32_t chat_id);
102 size_t mrmailbox_get_chat_cnt__ (mrmailbox_t*);
103 uint32_t mrmailbox_create_or_lookup_nchat_by_contact_id__ (mrmailbox_t*, uint32_t contact_id);
104 uint32_t mrmailbox_lookup_real_nchat_by_contact_id__ (mrmailbox_t*, uint32_t contact_id);
105 int mrmailbox_get_total_msg_count__ (mrmailbox_t*, uint32_t chat_id);
106 int mrmailbox_get_fresh_msg_count__ (mrmailbox_t*, uint32_t chat_id);
107 uint32_t mrmailbox_get_last_deaddrop_fresh_msg__ (mrmailbox_t*);
108 void mrmailbox_send_msg_to_smtp (mrmailbox_t*, mrjob_t*);
109 void mrmailbox_send_msg_to_imap (mrmailbox_t*, mrjob_t*);
110 int mrmailbox_add_contact_to_chat__ (mrmailbox_t*, uint32_t chat_id, uint32_t contact_id);
111 int mrmailbox_is_contact_in_chat__ (mrmailbox_t*, uint32_t chat_id, uint32_t contact_id);
112 int mrmailbox_get_chat_contact_count__ (mrmailbox_t*, uint32_t chat_id);
113 int mrmailbox_group_explicitly_left__ (mrmailbox_t*, const char* grpid);
114 void mrmailbox_set_group_explicitly_left__ (mrmailbox_t*, const char* grpid);
115 size_t mrmailbox_get_real_msg_cnt__ (mrmailbox_t*); /* the number of messages assigned to real chat (!=deaddrop, !=trash) */
116 size_t mrmailbox_get_deaddrop_msg_cnt__ (mrmailbox_t*);
117 int mrmailbox_rfc724_mid_cnt__ (mrmailbox_t*, const char* rfc724_mid);
118 int mrmailbox_rfc724_mid_exists__ (mrmailbox_t*, const char* rfc724_mid, char** ret_server_folder, uint32_t* ret_server_uid);
119 void mrmailbox_update_server_uid__ (mrmailbox_t*, const char* rfc724_mid, const char* server_folder, uint32_t server_uid);
120 void mrmailbox_update_msg_chat_id__ (mrmailbox_t*, uint32_t msg_id, uint32_t chat_id);
121 void mrmailbox_update_msg_state__ (mrmailbox_t*, uint32_t msg_id, int state);
122 void mrmailbox_delete_msg_on_imap (mrmailbox_t* mailbox, mrjob_t* job);
123 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 */
124 void mrmailbox_send_mdn (mrmailbox_t*, mrjob_t* job);
125 void mrmailbox_markseen_msg_on_imap (mrmailbox_t* mailbox, mrjob_t* job);
126 void mrmailbox_markseen_mdn_on_imap (mrmailbox_t* mailbox, mrjob_t* job);
127 int mrmailbox_get_thread_index (void);
128 
129 
130 /* library private: end-to-end-encryption */
131 #define MR_E2EE_DEFAULT_ENABLED 1
132 #define MR_MDNS_DEFAULT_ENABLED 1
133 
134 typedef struct mrmailbox_e2ee_helper_t {
135  int m_encryption_successfull;
136  void* m_cdata_to_free;
137 } mrmailbox_e2ee_helper_t;
138 
139 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*);
140 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 */
141 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! */
142 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 */
143 char* mrmailbox_create_setup_code (mrmailbox_t*);
144 char* mrmailbox_normalize_setup_code(mrmailbox_t*, const char* passphrase);
145 char* mrmailbox_render_setup_file (mrmailbox_t*, const char* passphrase);
146 char* mrmailbox_decrypt_setup_file(mrmailbox_t*, const char* passphrase, const char* filecontent);
147 
148 extern int mr_shall_stop_ongoing;
149 int mrmailbox_alloc_ongoing (mrmailbox_t*);
150 void mrmailbox_free_ongoing (mrmailbox_t*);
151 
152 
153 #ifdef __cplusplus
154 } /* /extern "C" */
155 #endif
156 #endif /* __MRMAILBOX_PRIVATE_H__ */
An object containing a simple array.
An object representing a single message in memory.
An object representing a single mailbox.