Delta Chat Core C-API
mrmimeparser.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 /* Parse MIME body; this is the text part of an IMF, see https://tools.ietf.org/html/rfc5322
24 mrmimeparser_t has no deep dependencies to mrmailbox_t or to the database
25 (mrmailbox_t is used for logging only). */
26 
27 
28 #ifndef __MRMIMEPARSER_H__
29 #define __MRMIMEPARSER_H__
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 
35 #include "mrhash.h"
36 #include "mrparam.h"
37 
38 
39 typedef struct mrmimepart_t
40 {
42  int m_type; /*one of MR_MSG_* */
43  int m_is_meta; /*meta parts contain eg. profile or group images and are only present if there is at least one "normal" part*/
44  int m_int_mimetype;
45  char* m_msg;
46  char* m_msg_raw;
47  int m_bytes;
48  mrparam_t* m_param;
49 } mrmimepart_t;
50 
51 
52 typedef struct mrmimeparser_t
53 {
56  /* data, read-only, must not be free()'d (it is free()'d when the mrmimeparser_t object gets destructed) */
57  carray* m_parts; /* array of mrmimepart_t objects */
58  struct mailmime* m_mimeroot;
59 
60  mrhash_t m_header; /* memoryhole-compliant header */
61  struct mailimf_fields* m_header_root; /* must NOT be freed, do not use for query, merged into m_header, a pointer somewhere to the MIME data*/
62  struct mailimf_fields* m_header_protected; /* MUST be freed, do not use for query, merged into m_header */
63 
64  char* m_subject;
65  int m_is_send_by_messenger;
66  int m_decrypted_and_validated;
67  int m_decrypted_with_validation_errors;
68  int m_decrypting_failed; /* set, if there are multipart/encrypted parts left after decryption */
69  const char* m_blobdir;
70 
71  int m_is_forwarded;
72 
73  mrmailbox_t* m_mailbox;
74 
75  carray* m_reports; /* array of mailmime objects */
76 
77  int m_is_system_message;
78 
79 } mrmimeparser_t;
80 
81 
82 mrmimeparser_t* mrmimeparser_new (const char* blobdir, mrmailbox_t*);
83 void mrmimeparser_unref (mrmimeparser_t*);
84 void mrmimeparser_empty (mrmimeparser_t*);
85 
86 void mrmimeparser_parse (mrmimeparser_t*, const char* body_not_terminated, size_t body_bytes);
87 
88 
89 /* the following functions can be used only after a call to mrmimeparser_parse() */
90 struct mailimf_field* mrmimeparser_lookup_field (mrmimeparser_t*, const char* field_name);
91 struct mailimf_optional_field* mrmimeparser_lookup_optional_field (mrmimeparser_t*, const char* field_name);
92 struct mailimf_optional_field* mrmimeparser_lookup_optional_field2 (mrmimeparser_t*, const char* field_name, const char* or_field_name);
93 mrmimepart_t* mrmimeparser_get_last_nonmeta (mrmimeparser_t*);
94 #define mrmimeparser_has_nonmeta(a) (mrmimeparser_get_last_nonmeta((a))!=NULL)
95 int mrmimeparser_is_mailinglist_message (mrmimeparser_t*);
96 int mrmimeparser_sender_equals_recipient(mrmimeparser_t*);
97 
98 
99 
100 /* low-level-tools for working with mailmime structures directly */
101 #ifdef MR_USE_MIME_DEBUG
102 void mailmime_print (struct mailmime*);
103 #endif
104 struct mailmime_parameter* mailmime_find_ct_parameter (struct mailmime*, const char* name);
105 int mailmime_transfer_decode (struct mailmime*, const char** ret_decoded_data, size_t* ret_decoded_data_bytes, char** ret_to_mmap_string_unref);
106 struct mailimf_fields* mailmime_find_mailimf_fields (struct mailmime*); /*the result is a pointer to mime, must not be freed*/
107 char* mailimf_find_first_addr (const struct mailimf_mailbox_list*); /*the result must be freed*/
108 struct mailimf_field* mailimf_find_field (struct mailimf_fields*, int wanted_fld_type); /*the result is a pointer to mime, must not be freed*/
109 struct mailimf_optional_field* mailimf_find_optional_field (struct mailimf_fields*, const char* wanted_fld_name);
110 mrhash_t* mailimf_get_recipients (struct mailimf_fields*);
111 
112 
113 #ifdef __cplusplus
114 } /* /extern "C" */
115 #endif
116 #endif /* __MRMIMEPARSER_H__ */
117 
An object representing a single mailbox.