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 void mrmailbox_receive_imf (mrmailbox_t*, const char* imf_raw_not_terminated, size_t imf_raw_bytes, const char* server_folder, uint32_t server_uid, uint32_t flags);
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_get_archived_count__ (mrmailbox_t*);
86 size_t mrmailbox_get_real_contact_cnt__ (mrmailbox_t*);
87 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);
88 int mrmailbox_get_contact_origin__ (mrmailbox_t*, uint32_t id, int* ret_blocked);
89 int mrmailbox_is_contact_blocked__ (mrmailbox_t*, uint32_t id);
90 int mrmailbox_real_contact_exists__ (mrmailbox_t*, uint32_t id);
91 int mrmailbox_contact_addr_equals__ (mrmailbox_t*, uint32_t contact_id, const char* other_addr);
92 void mrmailbox_scaleup_contact_origin__ (mrmailbox_t*, uint32_t contact_id, int origin);
93 void mrmailbox_unarchive_chat__ (mrmailbox_t*, uint32_t chat_id);
94 size_t mrmailbox_get_chat_cnt__ (mrmailbox_t*);
95 void mrmailbox_block_chat__ (mrmailbox_t*, uint32_t chat_id, int new_blocking);
96 void mrmailbox_unblock_chat__ (mrmailbox_t*, uint32_t chat_id);
97 void mrmailbox_create_or_lookup_nchat_by_contact_id__ (mrmailbox_t*, uint32_t contact_id, int create_blocked, uint32_t* ret_chat_id, int* ret_chat_blocked);
98 void mrmailbox_lookup_real_nchat_by_contact_id__ (mrmailbox_t*, uint32_t contact_id, uint32_t* ret_chat_id, int* ret_chat_blocked);
99 int mrmailbox_get_total_msg_count__ (mrmailbox_t*, uint32_t chat_id);
100 int mrmailbox_get_fresh_msg_count__ (mrmailbox_t*, uint32_t chat_id);
101 uint32_t mrmailbox_get_last_deaddrop_fresh_msg__ (mrmailbox_t*);
102 void mrmailbox_send_msg_to_smtp (mrmailbox_t*, mrjob_t*);
103 void mrmailbox_send_msg_to_imap (mrmailbox_t*, mrjob_t*);
104 int mrmailbox_add_contact_to_chat__ (mrmailbox_t*, uint32_t chat_id, uint32_t contact_id);
105 int mrmailbox_is_contact_in_chat__ (mrmailbox_t*, uint32_t chat_id, uint32_t contact_id);
106 int mrmailbox_get_chat_contact_count__ (mrmailbox_t*, uint32_t chat_id);
107 int mrmailbox_is_group_explicitly_left__ (mrmailbox_t*, const char* grpid);
108 void mrmailbox_set_group_explicitly_left__ (mrmailbox_t*, const char* grpid);
109 size_t mrmailbox_get_real_msg_cnt__ (mrmailbox_t*); /* the number of messages assigned to real chat (!=deaddrop, !=trash) */
110 size_t mrmailbox_get_deaddrop_msg_cnt__ (mrmailbox_t*);
111 int mrmailbox_rfc724_mid_cnt__ (mrmailbox_t*, const char* rfc724_mid);
112 int mrmailbox_rfc724_mid_exists__ (mrmailbox_t*, const char* rfc724_mid, char** ret_server_folder, uint32_t* ret_server_uid);
113 void mrmailbox_update_server_uid__ (mrmailbox_t*, const char* rfc724_mid, const char* server_folder, uint32_t server_uid);
114 void mrmailbox_update_msg_chat_id__ (mrmailbox_t*, uint32_t msg_id, uint32_t chat_id);
115 void mrmailbox_update_msg_state__ (mrmailbox_t*, uint32_t msg_id, int state);
116 void mrmailbox_delete_msg_on_imap (mrmailbox_t* mailbox, mrjob_t* job);
117 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 */
118 void mrmailbox_send_mdn (mrmailbox_t*, mrjob_t* job);
119 void mrmailbox_markseen_msg_on_imap (mrmailbox_t* mailbox, mrjob_t* job);
120 void mrmailbox_markseen_mdn_on_imap (mrmailbox_t* mailbox, mrjob_t* job);
121 int mrmailbox_get_thread_index (void);
122 
123 
124 /* library private: end-to-end-encryption */
125 #define MR_E2EE_DEFAULT_ENABLED 1
126 #define MR_MDNS_DEFAULT_ENABLED 1
127 
128 typedef struct mrmailbox_e2ee_helper_t {
129  int m_encryption_successfull;
130  void* m_cdata_to_free;
131 } mrmailbox_e2ee_helper_t;
132 
133 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*);
134 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 */
135 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! */
136 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 */
137 char* mrmailbox_create_setup_code (mrmailbox_t*);
138 char* mrmailbox_normalize_setup_code(mrmailbox_t*, const char* passphrase);
139 char* mrmailbox_render_setup_file (mrmailbox_t*, const char* passphrase);
140 char* mrmailbox_decrypt_setup_file(mrmailbox_t*, const char* passphrase, const char* filecontent);
141 
142 extern int mr_shall_stop_ongoing;
143 int mrmailbox_alloc_ongoing (mrmailbox_t*);
144 void mrmailbox_free_ongoing (mrmailbox_t*);
145 
146 
147 #ifdef __cplusplus
148 } /* /extern "C" */
149 #endif
150 #endif /* __MRMAILBOX_PRIVATE_H__ */
An object representing a single message in memory.
An object representing a single mailbox.