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 
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 
53 typedef struct mrmimeparser_t
54 {
57  /* data, read-only, must not be free()'d (it is free()'d when the MrMimeParser object gets destructed) */
58  carray* m_parts; /*array of mrmimepart_t objects*/
59  struct mailmime* m_mimeroot;
60  struct mailimf_fields* m_header; /* a pointer somewhere to the MIME data, must not be freed */
61  char* m_subject;
62  int m_is_send_by_messenger;
63  int m_decrypted_and_validated;
64  int m_decrypted_with_validation_errors;
65  int m_decrypting_failed; /* set, if there are multipart/encrypted parts left after decryption */
66  const char* m_blobdir;
67 
68  int m_is_forwarded;
69 
70  mrmailbox_t* m_mailbox;
71 
72  carray* m_reports; /* array of mailmime objects */
73 
74  int m_is_system_message;
75 
76 } mrmimeparser_t;
77 
78 
79 mrmimeparser_t* mrmimeparser_new (const char* blobdir, mrmailbox_t*);
80 void mrmimeparser_unref (mrmimeparser_t*);
81 void mrmimeparser_empty (mrmimeparser_t*);
82 
83 /* The data returned from Parse() must not be freed (it is free()'d when the MrMimeParser object gets destructed)
84 Unless memory-allocation-errors occur, Parse() returns at least one empty part.
85 (this is because we want to add even these message to our database to avoid reading them several times.
86 of course, these empty messages are not added to any chat) */
87 void mrmimeparser_parse (mrmimeparser_t*, const char* body_not_terminated, size_t body_bytes);
88 
89 /* mrmimeparser_get_last_nonmeta() gets the _last_ part _not_ flagged with m_is_meta. */
90 mrmimepart_t* mrmimeparser_get_last_nonmeta (mrmimeparser_t*);
91 #define mrmimeparser_has_nonmeta(a) (mrmimeparser_get_last_nonmeta((a))!=NULL)
92 
93 /* mrmimeparser_is_mailinglist_message() just checks if there is a `List-ID`-header. */
94 int mrmimeparser_is_mailinglist_message (mrmimeparser_t*);
95 
96 /* low-level-tools for working with mailmime structures directly */
97 char* mr_find_first_addr (const struct mailimf_mailbox_list*); /*the result must be freed*/
98 char* mr_normalize_addr (const char*); /*the result must be freed*/
99 struct mailimf_fields* mr_find_mailimf_fields(struct mailmime*); /*the result is a pointer to mime, must not be freed*/
100 struct mailimf_field* mr_find_mailimf_field (struct mailimf_fields*, int wanted_fld_type); /*the result is a pointer to mime, must not be freed*/
101 struct mailimf_optional_field* mr_find_mailimf_field2(struct mailimf_fields*, const char* wanted_fld_name);
102 struct mailmime_parameter* mr_find_ct_parameter (struct mailmime*, const char* name);
103 int mr_mime_transfer_decode(struct mailmime*, const char** ret_decoded_data, size_t* ret_decoded_data_bytes, char** ret_to_mmap_string_unref);
104 
105 
106 #ifdef MR_USE_MIME_DEBUG
107 void mr_print_mime(struct mailmime * mime);
108 #endif
109 
110 
111 #ifdef __cplusplus
112 } /* /extern "C" */
113 #endif
114 #endif /* __MRMIMEPARSER_H__ */
115 
An object representing a single mailbox.
Definition: mrmailbox.h:178
An object for handling key=value parameter lists.
Definition: mrparam.h:36