Delta Chat Core C-API
mrmsg.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 __MRMSG_H__
24 #define __MRMSG_H__
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 
30 typedef struct mrmailbox_t mrmailbox_t;
31 typedef struct mrparam_t mrparam_t;
32 typedef struct sqlite3_stmt sqlite3_stmt;
33 
34 
40 typedef struct mrmsg_t
41 {
52  uint32_t m_id;
53  #define MR_MSG_ID_MARKER1 1
54  #define MR_MSG_ID_DAYMARKER 9
55  #define MR_MSG_ID_LAST_SPECIAL 9
56 
57 
62  uint32_t m_from_id;
63 
64 
69  uint32_t m_to_id;
70 
71 
76  uint32_t m_chat_id;
77 
78 
82  time_t m_timestamp;
83 
84 
98  int m_type;
99  #define MR_MSG_UNDEFINED 0
100  #define MR_MSG_TEXT 10
101  #define MR_MSG_IMAGE 20
102  #define MR_MSG_GIF 21
103  #define MR_MSG_AUDIO 40
104  #define MR_MSG_VOICE 41
105  #define MR_MSG_VIDEO 50
106  #define MR_MSG_FILE 60
107 
108 
128  int m_state;
129  #define MR_STATE_UNDEFINED 0
130  #define MR_STATE_IN_FRESH 10
131  #define MR_STATE_IN_NOTICED 13
132  #define MR_STATE_IN_SEEN 16
133  #define MR_STATE_OUT_PENDING 20
134  #define MR_STATE_OUT_ERROR 24
135  #define MR_STATE_OUT_DELIVERED 26
136  #define MR_STATE_OUT_MDN_RCVD 28
137 
138  char* m_text;
140  int m_starred;
144  mrmailbox_t* m_mailbox;
145  char* m_rfc724_mid;
146  char* m_server_folder;
147  uint32_t m_server_uid;
148 } mrmsg_t;
149 
150 
151 mrmsg_t* mrmsg_new ();
152 void mrmsg_unref (mrmsg_t*);
153 void mrmsg_empty (mrmsg_t*);
155 char* mrmsg_get_summarytext (mrmsg_t*, int approx_characters);
157 char* mrmsg_get_fullpath (mrmsg_t*);
158 char* mrmsg_get_filename (mrmsg_t*);
160 int mrmsg_is_increation (mrmsg_t*);
162 void mrmsg_set_text (mrmsg_t*, const char* text);
163 
164 /* library-private */
165 #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 "
166 int mrmsg_set_from_stmt__ (mrmsg_t*, sqlite3_stmt* row, int row_offset); /* row order is MR_MSG_FIELDS */
167 int mrmsg_load_from_db__ (mrmsg_t*, mrmailbox_t*, uint32_t id);
168 int mrmsg_is_increation__ (const mrmsg_t*);
169 char* mrmsg_get_summarytext_by_raw (int type, const char* text, mrparam_t*, int approx_bytes); /* the returned value must be free()'d */
170 void mrmsg_save_param_to_disk__ (mrmsg_t*);
171 void mrmsg_guess_msgtype_from_suffix (const char* pathNfilename, int* ret_msgtype, char** ret_mime);
172 void mrmsg_get_authorNtitle_from_filename (const char* pathNfilename, char** ret_author, char** ret_title);
173 
174 #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)
175 #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. */
176 #define MR_MSG_MAKE_SUFFIX_SEARCHABLE(a) ((a)==MR_MSG_IMAGE || (a)==MR_MSG_GIF || (a)==MR_MSG_VOICE)
177 
178 #define APPROX_SUBJECT_CHARS 32 /* as we do not cut inside words, this results in about 32-42 characters.
179  Do not use too long subjects - we add a tag after the subject which gets truncated by the clients otherwise.
180  It should also be very clear, the subject is _not_ the whole message.
181  The value is also used for CC:-summaries */
182 
183 
184 #ifdef __cplusplus
185 } /* /extern "C" */
186 #endif
187 #endif /* __MRMSG_H__ */
int m_is_msgrmsg
Set to 1 if the message was sent by another messenger.
Definition: mrmsg.h:141
An object representing a single mailbox.
Definition: mrmailbox.h:178
int m_type
Type of the message.
Definition: mrmsg.h:98
char * mrmsg_get_summarytext(mrmsg_t *msg, int approx_characters)
Get a message summary as a single line of text.
Definition: mrmsg.c:340
uint32_t m_chat_id
Chat ID the message belongs to.
Definition: mrmsg.h:76
mrmsg_t * mrmsg_new()
Create new message object.
Definition: mrmsg.c:41
An object representing text with some attributes.
Definition: mrpoortext.h:35
mrpoortext_t * mrmsg_get_summary(mrmsg_t *msg, mrchat_t *chat)
Get a summary for a message.
Definition: mrmsg.c:263
mrpoortext_t * mrmsg_get_mediainfo(mrmsg_t *msg)
Get real author and title.
Definition: mrmsg.c:480
An object representing a single message in memory.
Definition: mrmsg.h:40
int mrmsg_show_padlock(mrmsg_t *msg)
Check if a padlock should be shown beside the message.
Definition: mrmsg.c:302
uint32_t m_to_id
Contact ID of the recipient.
Definition: mrmsg.h:69
uint32_t m_from_id
Contact ID of the sender.
Definition: mrmsg.h:62
int m_starred
Starred-state of the message.
Definition: mrmsg.h:140
void mrmsg_set_text(mrmsg_t *msg, const char *text)
Set the text of a message object.
Definition: mrmsg.c:125
An object for handling key=value parameter lists.
Definition: mrparam.h:36
mrparam_t * m_param
Additional paramter for the message.
Definition: mrmsg.h:139
char * m_text
message text or NULL if unset
Definition: mrmsg.h:138
void mrmsg_unref(mrmsg_t *msg)
Free an mrmsg_t object created eg.
Definition: mrmsg.c:66
uint32_t m_id
Message ID.
Definition: mrmsg.h:52
int m_state
Message state.
Definition: mrmsg.h:128
void mrmsg_save_param_to_disk(mrmsg_t *msg)
can be used to add some additional, persistent information to a messages record.
Definition: mrmsg.c:590
void mrmsg_empty(mrmsg_t *msg)
Empty a message object.
Definition: mrmsg.c:87
time_t m_timestamp
Unix time the message was sended or received.
Definition: mrmsg.h:82
An object representing a single chat in memory.
Definition: mrchat.h:39