/
mu-msg-part.h
254 lines (210 loc) · 7.15 KB
/
mu-msg-part.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
/*
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
** Free Software Foundation; either version 3, or (at your option) any
** later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software Foundation,
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
*/
#ifndef __MU_MSG_PART_H__
#define __MU_MSG_PART_H__
#include <glib.h>
#include <unistd.h> /* for ssize_t */
G_BEGIN_DECLS
enum _MuMsgPartType {
MU_MSG_PART_TYPE_NONE = 0,
/* MIME part without children */
MU_MSG_PART_TYPE_LEAF = 1 << 1,
/* an RFC822 message part? */
MU_MSG_PART_TYPE_MESSAGE = 1 << 2,
/* disposition inline? */
MU_MSG_PART_TYPE_INLINE = 1 << 3,
/* disposition attachment? */
MU_MSG_PART_TYPE_ATTACHMENT = 1 << 4,
/* a signed part? */
MU_MSG_PART_TYPE_SIGNED = 1 << 5,
/* an encrypted part? */
MU_MSG_PART_TYPE_ENCRYPTED = 1 << 6,
/* a decrypted part? */
MU_MSG_PART_TYPE_DECRYPTED = 1 << 7,
/* a text/plain part? */
MU_MSG_PART_TYPE_TEXT_PLAIN = 1 << 8,
/* a text/html part? */
MU_MSG_PART_TYPE_TEXT_HTML = 1 << 9
};
typedef enum _MuMsgPartType MuMsgPartType;
/* the signature status */
enum _MuMsgPartSigStatus {
MU_MSG_PART_SIG_STATUS_UNSIGNED = 0,
MU_MSG_PART_SIG_STATUS_GOOD,
MU_MSG_PART_SIG_STATUS_BAD,
MU_MSG_PART_SIG_STATUS_ERROR,
MU_MSG_PART_SIG_STATUS_FAIL
};
typedef enum _MuMsgPartSigStatus MuMsgPartSigStatus;
struct _MuMsgPartSigStatusReport {
MuMsgPartSigStatus verdict;
const char *report;
};
typedef struct _MuMsgPartSigStatusReport MuMsgPartSigStatusReport;
/**
* destroy a MuMsgPartSignatureStatusReport object
*
* @param report a MuMsgPartSignatureStatusReport object
*/
void mu_msg_part_sig_status_report_destroy (MuMsgPartSigStatusReport *report);
struct _MuMsgPart {
/* index of this message part */
unsigned index;
/* cid */
/* const char *content_id; */
/* content-type: type/subtype, ie. text/plain */
const char *type;
const char *subtype;
/* size of the part; or < 0 if unknown */
ssize_t size;
gpointer data; /* opaque data */
MuMsgPartType part_type;
MuMsgPartSigStatusReport *sig_status_report;
};
typedef struct _MuMsgPart MuMsgPart;
/**
* get some appropriate file name for the mime-part
*
* @param mpart a MuMsgPart
* @param construct_if_needed if there is no
* real filename, construct one.
*
* @return the file name (free with g_free)
*/
char *mu_msg_part_get_filename (MuMsgPart *mpart, gboolean construct_if_needed)
G_GNUC_WARN_UNUSED_RESULT;
/**
* get the text in the MuMsgPart (ie. in its GMimePart)
*
* @param msg a MuMsg
* @param part a MuMsgPart
* @param opts MuMsgOptions
*
* @return utf8 string for this MIME part, to be freed by caller
*/
char* mu_msg_part_get_text (MuMsg *msg, MuMsgPart *part, MuMsgOptions opts)
G_GNUC_WARN_UNUSED_RESULT;
/**
* does this msg part look like an attachment?
*
* @param part a message part
*
* @return TRUE if it looks like an attachment, FALSE otherwise
*/
gboolean mu_msg_part_maybe_attachment (MuMsgPart *part);
/**
* save a specific attachment to some targetdir
*
* @param msg a valid MuMsg instance
* @param opts mu-message options (OVERWRITE/USE_EXISTING)
* @gchar filepath the filepath to save
* @param partidx index of the attachment you want to save
* @param err receives error information (when function returns NULL)
*
* @return full path to the message part saved or NULL in case or
* error; free with g_free
*/
gboolean mu_msg_part_save (MuMsg *msg, MuMsgOptions opts,
const char *filepath, guint partidx,
GError **err);
/**
* save a message part to a temporary file and return the full path to
* this file
*
* @param msg a MuMsg message
* @param opts mu-message options (OVERWRITE/USE_EXISTING)
* @param partidx index of the part to save
* @param err receives error information if any
*
* @return the full path to the temp file, or NULL in case of error
*/
gchar* mu_msg_part_save_temp (MuMsg *msg, MuMsgOptions opts,
guint partidx, GError **err)
G_GNUC_WARN_UNUSED_RESULT;
/**
* get a filename for the saving the message part; try the filename
* specified for the message part if any, otherwise determine a unique
* name based on the partidx and the message path
*
* @param msg a msg
* @param opts mu-message options
* @param targetdir where to store the part
* @param partidx the part for which to determine a filename
* @param err receives error information (when function returns NULL)
*
* @return a filepath (g_free when done with it) or NULL in case of error
*/
gchar* mu_msg_part_get_path (MuMsg *msg, MuMsgOptions opts,
const char* targetdir,
guint partidx, GError **err)
G_GNUC_WARN_UNUSED_RESULT;
/**
* get a full path name for a file for saving the message part INDEX;
* this path is unique (1:1) for this particular message and part for
* this user. Thus, it can be used as a cache.
*
* Will create the directory if needed.
*
* @param msg a msg
* @param opts mu-message options
* @param partidx the part for which to determine a filename
* @param err receives error information (when function returns NULL)
*
* @return a filepath (g_free when done with it) or NULL in case of error
*/
gchar* mu_msg_part_get_cache_path (MuMsg *msg, MuMsgOptions opts,
guint partidx, GError **err)
G_GNUC_WARN_UNUSED_RESULT;
/**
* get the part index for the message part with a certain content-id
*
* @param msg a message
* @param content_id a content-id to search
*
* @return the part index number of the found part, or -1 if it was not found
*/
int mu_msg_find_index_for_cid (MuMsg *msg, MuMsgOptions opts, const char* content_id);
/**
* retrieve a list of indices for mime-parts with filenames matching a regex
*
* @param msg a message
* @param opts
* @param a regular expression to match the filename with
*
* @return a list with indices for the files matching the pattern; the
* indices are the GPOINTER_TO_UINT(lst->data) of the list. They must
* be freed with g_slist_free
*/
GSList* mu_msg_find_files (MuMsg *msg, MuMsgOptions opts, const GRegex *pattern);
typedef void (*MuMsgPartForeachFunc) (MuMsg *msg, MuMsgPart*, gpointer);
/**
* call a function for each of the mime part in a message
*
* @param msg a valid MuMsg* instance
* @param func a callback function to call for each contact; when
* the callback does not return TRUE, it won't be called again
* @param user_data a user-provide pointer that will be passed to the callback
* @param options, bit-wise OR'ed
*
*/
gboolean mu_msg_part_foreach (MuMsg *msg, MuMsgOptions opts,
MuMsgPartForeachFunc func, gpointer user_data);
G_END_DECLS
#endif /*__MU_MSG_PART_H__*/