Delta Chat Core C-API
mrimap.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 /* Purpose: Reading from IMAP servers with no dependencies to the database.
24 mrmailbox_t is only used for logging and to get information about
25 the online state. */
26 
27 
28 #ifndef __MRIMAP_H__
29 #define __MRIMAP_H__
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 
35 typedef struct mrloginparam_t mrloginparam_t;
36 typedef struct mrimap_t mrimap_t;
37 
38 #define MR_IMAP_SEEN 0x0001L
39 
40 typedef char* (*mr_get_config_t) (mrimap_t*, const char*, const char*);
41 typedef void (*mr_set_config_t) (mrimap_t*, const char*, const char*);
42 typedef void (*mr_receive_imf_t) (mrimap_t*, const char* imf_raw_not_terminated, size_t imf_raw_bytes, const char* server_folder, uint32_t server_uid, uint32_t flags);
43 
44 
48 typedef struct mrimap_t
49 {
52  char* m_imap_server;
53  int m_imap_port;
54  char* m_imap_user;
55  char* m_imap_pw;
56  int m_server_flags;
57 
58  int m_connected; /* initally connected and watch thread installed */
59  mailimap* m_hEtpan; /* normally, if connected, m_hEtpan is also set; however, if a reconnection is required, we may lost this handle */
60  pthread_mutex_t m_hEtpanmutex;
61  int m_idle_set_up;
62  char* m_selected_folder;
63  int m_should_reconnect;
64 
65  int m_can_idle;
66  int m_has_xlist;
67  char* m_moveto_folder;/* Folder, where reveived chat messages should go to. Normally "Chats" but may be NULL to leave them in the INBOX */
68  char* m_sent_folder; /* Folder, where send messages should go to. Normally "Chats". */
69  pthread_mutex_t m_idlemutex; /* set, if idle is not possible; morover, the interrupted IDLE thread waits a second before IDLEing again; this allows several jobs to be executed */
70  pthread_mutex_t m_inwait_mutex; /* only used to wait for mailstream_wait_idle()/mailimap_idle_done() to terminate. */
71 
72  pthread_t m_watch_thread;
73  pthread_cond_t m_watch_cond;
74  pthread_mutex_t m_watch_condmutex;
75  int m_watch_condflag;
76  int m_watch_do_exit;
77 
78  time_t m_enter_watch_wait_time;
79 
80  pthread_t m_heartbeat_thread;
81  pthread_cond_t m_heartbeat_cond;
82  pthread_mutex_t m_heartbeat_condmutex;
83 
84  struct mailimap_fetch_type* m_fetch_type_uid;
85  struct mailimap_fetch_type* m_fetch_type_body;
86  struct mailimap_fetch_type* m_fetch_type_flags;
87 
88  mr_get_config_t m_get_config;
89  mr_set_config_t m_set_config;
90  mr_receive_imf_t m_receive_imf;
91  void* m_userData;
92  mrmailbox_t* m_mailbox;
93 
94  int m_log_connect_errors;
95 } mrimap_t;
96 
97 
98 mrimap_t* mrimap_new (mr_get_config_t, mr_set_config_t, mr_receive_imf_t, void* userData, mrmailbox_t*);
99 void mrimap_unref (mrimap_t*);
100 
101 int mrimap_connect (mrimap_t*, const mrloginparam_t*);
102 void mrimap_disconnect (mrimap_t*);
103 int mrimap_is_connected (mrimap_t*);
104 int mrimap_fetch (mrimap_t*);
105 
106 int mrimap_append_msg (mrimap_t*, time_t timestamp, const char* data_not_terminated, size_t data_bytes, char** ret_server_folder, uint32_t* ret_server_uid);
107 
108 #define MR_MS_ALSO_MOVE 0x01
109 #define MR_MS_SET_MDNSent_FLAG 0x02
110 #define MR_MS_MDNSent_JUST_SET 0x10
111 int mrimap_markseen_msg (mrimap_t*, const char* folder, uint32_t server_uid, int ms_flags, char** ret_server_folder, uint32_t* ret_server_uid, int* ret_ms_flags); /* only returns 0 on connection problems; we should try later again in this case */
112 
113 int mrimap_delete_msg (mrimap_t*, const char* rfc724_mid, const char* folder, uint32_t server_uid); /* only returns 0 on connection problems; we should try later again in this case */
114 
115 void mrimap_heartbeat (mrimap_t*);
116 
117 #ifdef __cplusplus
118 } /* /extern "C" */
119 #endif
120 #endif /* __MRIMAP_H__ */
121 
An object representing a single mailbox.