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 };
68 
69 
70 dc_mimeparser_t* dc_mimeparser_new (const char* blobdir, dc_context_t*);
71 void dc_mimeparser_unref (dc_mimeparser_t*);
72 void dc_mimeparser_empty (dc_mimeparser_t*);
73 
74 void dc_mimeparser_parse (dc_mimeparser_t*, const char* body_not_terminated, size_t body_bytes);
75 
76 
77 /* the following functions can be used only after a call to dc_mimeparser_parse() */
78 struct mailimf_field* dc_mimeparser_lookup_field (dc_mimeparser_t*, const char* field_name);
79 struct mailimf_optional_field* dc_mimeparser_lookup_optional_field (dc_mimeparser_t*, const char* field_name);
80 dc_mimepart_t* dc_mimeparser_get_last_nonmeta (dc_mimeparser_t*);
81 #define dc_mimeparser_has_nonmeta(a) (dc_mimeparser_get_last_nonmeta((a))!=NULL)
82 int dc_mimeparser_is_mailinglist_message (dc_mimeparser_t*);
83 int dc_mimeparser_sender_equals_recipient(dc_mimeparser_t*);
84 
85 
86 
87 /* low-level-tools for working with mailmime structures directly */
88 #ifdef DC_USE_MIME_DEBUG
89 void mailmime_print (struct mailmime*);
90 #endif
91 struct mailmime_parameter* mailmime_find_ct_parameter (struct mailmime*, const char* name);
92 int mailmime_transfer_decode (struct mailmime*, const char** ret_decoded_data, size_t* ret_decoded_data_bytes, char** ret_to_mmap_string_unref);
93 struct mailimf_fields* mailmime_find_mailimf_fields (struct mailmime*); /*the result is a pointer to mime, must not be freed*/
94 char* mailimf_find_first_addr (const struct mailimf_mailbox_list*); /*the result must be freed*/
95 struct mailimf_field* mailimf_find_field (struct mailimf_fields*, int wanted_fld_type); /*the result is a pointer to mime, must not be freed*/
96 struct mailimf_optional_field* mailimf_find_optional_field (struct mailimf_fields*, const char* wanted_fld_name);
97 dc_hash_t* mailimf_get_recipients (struct mailimf_fields*);
98 
99 
100 #ifdef __cplusplus
101 } /* /extern "C" */
102 #endif
103 #endif /* __DC_MIMEPARSER_H__ */
104 
An object representing a single account.