Delta Chat Core C-API
dc_mimeparser.h
1 /* Parse MIME body; this is the text part of an IMF, see https://tools.ietf.org/html/rfc5322
2 dc_mimeparser_t has no deep dependencies to dc_context_t or to the database
3 (dc_context_t is used for logging only). */
4 
5 
6 #ifndef __DC_MIMEPARSER_H__
7 #define __DC_MIMEPARSER_H__
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 
13 #include "dc_hash.h"
14 #include "dc_param.h"
15 
16 
17 typedef struct _dc_mimepart dc_mimepart_t;
18 typedef struct _dc_mimeparser dc_mimeparser_t;
19 
20 
21 struct _dc_mimepart
22 {
24  int type; /*one of DC_MSG_* */
25  int is_meta; /*meta parts contain eg. profile or group images and are only present if there is at least one "normal" part*/
26  int int_mimetype;
27  char* msg;
28  char* msg_raw;
29  int bytes;
30  dc_param_t* param;
31 
32 };
33 
34 
38 struct _dc_mimeparser
39 {
42  /* data, read-only, must not be free()'d (it is free()'d when the dc_mimeparser_t object gets destructed) */
43  carray* parts; /* array of dc_mimepart_t objects */
44  struct mailmime* mimeroot;
45 
46  dc_hash_t header; /* memoryhole-compliant header */
47  struct mailimf_fields* header_root; /* must NOT be freed, do not use for query, merged into header, a pointer somewhere to the MIME data*/
48  struct mailimf_fields* header_protected; /* MUST be freed, do not use for query, merged into header */
49 
50  char* subject;
51  int is_send_by_messenger;
52 
53  int decrypting_failed; /* set, if there are multipart/encrypted parts left after decryption */
54 
55  struct _dc_e2ee_helper* e2ee_helper;
56 
57  const char* blobdir;
58 
59  int is_forwarded;
60 
61  dc_context_t* context;
62 
63  carray* reports; /* array of mailmime objects */
64 
65  int is_system_message;
66 
67  struct _dc_kml* location_kml;
68  struct _dc_kml* message_kml;
69 };
70 
71 
72 dc_mimeparser_t* dc_mimeparser_new (const char* blobdir, dc_context_t*);
73 void dc_mimeparser_unref (dc_mimeparser_t*);
74 void dc_mimeparser_empty (dc_mimeparser_t*);
75 
76 void dc_mimeparser_parse (dc_mimeparser_t*, const char* body_not_terminated, size_t body_bytes);
77 
78 
79 /* the following functions can be used only after a call to dc_mimeparser_parse() */
80 struct mailimf_field* dc_mimeparser_lookup_field (dc_mimeparser_t*, const char* field_name);
81 struct mailimf_optional_field* dc_mimeparser_lookup_optional_field (dc_mimeparser_t*, const char* field_name);
82 dc_mimepart_t* dc_mimeparser_get_last_nonmeta (dc_mimeparser_t*);
83 #define dc_mimeparser_has_nonmeta(a) (dc_mimeparser_get_last_nonmeta((a))!=NULL)
84 int dc_mimeparser_is_mailinglist_message (dc_mimeparser_t*);
85 int dc_mimeparser_sender_equals_recipient(dc_mimeparser_t*);
86 void dc_mimeparser_repl_msg_by_error (dc_mimeparser_t*, const char* error_msg);
87 
88 
89 /* low-level-tools for working with mailmime structures directly */
90 #ifdef DC_USE_MIME_DEBUG
91 void mailmime_print (struct mailmime*);
92 #endif
93 struct mailmime_parameter* mailmime_find_ct_parameter (struct mailmime*, const char* name);
94 int mailmime_transfer_decode (struct mailmime*, const char** ret_decoded_data, size_t* ret_decoded_data_bytes, char** ret_to_mmap_string_unref);
95 struct mailimf_fields* mailmime_find_mailimf_fields (struct mailmime*); /*the result is a pointer to mime, must not be freed*/
96 char* mailimf_find_first_addr (const struct mailimf_mailbox_list*); /*the result must be freed*/
97 struct mailimf_field* mailimf_find_field (struct mailimf_fields*, int wanted_fld_type); /*the result is a pointer to mime, must not be freed*/
98 struct mailimf_optional_field* mailimf_find_optional_field (struct mailimf_fields*, const char* wanted_fld_name);
99 dc_hash_t* mailimf_get_recipients (struct mailimf_fields*);
100 
101 
102 #ifdef __cplusplus
103 } /* /extern "C" */
104 #endif
105 #endif /* __DC_MIMEPARSER_H__ */
106 
dc_context_t