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