summaryrefslogtreecommitdiff
path: root/3rdParty/libquickmail/quickmail.h
blob: d241a23ac93c150648acfc761c3b62120338e803 (plain)
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/*
    This file is part of libquickmail.

    libquickmail 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 of the License, or
    (at your option) any later version.

    libquickmail 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 libquickmail.  If not, see <http://www.gnu.org/licenses/>.
*/

/*! \file      quickmail.h
 *  \brief     header file for libquickmail
 *  \author    Brecht Sanders
 *  \date      2012-2016
 *  \copyright GPL
 */

#ifndef __INCLUDED_QUICKMAIL_H
#define __INCLUDED_QUICKMAIL_H

#include <stdio.h>

/*! \cond PRIVATE */
#ifdef _WIN32
#if defined(BUILD_QUICKMAIL_DLL)
#define DLL_EXPORT_LIBQUICKMAIL __declspec(dllexport)
#elif !defined(STATIC) && !defined(BUILD_QUICKMAIL_STATIC)
#define DLL_EXPORT_LIBQUICKMAIL __declspec(dllimport)
#else
#define DLL_EXPORT_LIBQUICKMAIL
#endif
#else
#define DLL_EXPORT_LIBQUICKMAIL
#endif
/*! \endcond */

#ifdef __cplusplus
extern "C" {
#endif

/*! \brief quickmail object type */
typedef struct email_info_struct* quickmail;



/*! \brief type of pointer to function for opening attachment data
 * \param  filedata    custom data as passed to quickmail_add_body_custom/quickmail_add_attachment_custom
 * \return data structure to be used in calls to quickmail_attachment_read_fn and quickmail_attachment_close_fn functions
 * \sa     quickmail_add_body_custom()
 * \sa     quickmail_add_attachment_custom()
 */
typedef void* (*quickmail_attachment_open_fn)(void* filedata);

/*! \brief type of pointer to function for reading attachment data
 * \param  handle      data structure obtained via the corresponding quickmail_attachment_open_fn function
 * \param  buf         buffer for receiving data
 * \param  len         size in bytes of buffer for receiving data
 * \return number of bytes read (zero on end of file)
 * \sa     quickmail_add_body_custom()
 * \sa     quickmail_add_attachment_custom()
 */
typedef size_t (*quickmail_attachment_read_fn)(void* handle, void* buf, size_t len);

/*! \brief type of pointer to function for closing attachment data
 * \param  handle      data structure obtained via the corresponding quickmail_attachment_open_fn function
 * \sa     quickmail_add_body_custom()
 * \sa     quickmail_add_attachment_custom()
 */
typedef void (*quickmail_attachment_close_fn)(void* handle);

/*! \brief type of pointer to function for cleaning up custom data in quickmail_destroy
 * \param  filedata    custom data as passed to quickmail_add_body_custom/quickmail_add_attachment_custom
 * \sa     quickmail_add_body_custom()
 * \sa     quickmail_add_attachment_custom()
 */
typedef void (*quickmail_attachment_free_filedata_fn)(void* filedata);

/*! \brief type of pointer to function for cleaning up custom data in quickmail_destroy
 * \param  mailobj                        quickmail object
 * \param  filename                       attachment filename (same value as mimetype for mail body)
 * \param  mimetype                       MIME type
 * \param  attachment_data_open           function for opening attachment data
 * \param  attachment_data_read           function for reading attachment data
 * \param  attachment_data_close          function for closing attachment data (optional, free() will be used if NULL)
 * \param  callbackdata                   custom data passed to quickmail_list_attachments
 * \sa     quickmail_list_bodies()
 * \sa     quickmail_list_attachments()
 */
typedef void (*quickmail_list_attachment_callback_fn)(quickmail mailobj, const char* filename, const char* mimetype, quickmail_attachment_open_fn email_info_attachment_open, quickmail_attachment_read_fn email_info_attachment_read, quickmail_attachment_close_fn email_info_attachment_close, void* callbackdata);



/*! \brief get version quickmail library
 * \return library version
 */
DLL_EXPORT_LIBQUICKMAIL const char* quickmail_get_version ();

/*! \brief initialize quickmail library, call once at the beginning of the main thread of the application
 * \return zero on success
 */
DLL_EXPORT_LIBQUICKMAIL int quickmail_initialize ();

/*! \brief clean up quickmail library, call once at the end of the main thread of the application
 * \return zero on success
 */
DLL_EXPORT_LIBQUICKMAIL int quickmail_cleanup ();

/*! \brief create a new quickmail object
 * \param  from        sender e-mail address
 * \param  subject     e-mail subject
 * \return quickmail object or NULL on error
 */
DLL_EXPORT_LIBQUICKMAIL quickmail quickmail_create (const char* from, const char* subject);

/*! \brief clean up a quickmail object
 * \param  mailobj     quickmail object
 */
DLL_EXPORT_LIBQUICKMAIL void quickmail_destroy (quickmail mailobj);

/*! \brief set the sender (from) e-mail address of a quickmail object
 * \param  mailobj     quickmail object
 * \param  from        sender e-mail address
 */
DLL_EXPORT_LIBQUICKMAIL void quickmail_set_from (quickmail mailobj, const char* from);

/*! \brief get the sender (from) e-mail address of a quickmail object
 * \param  mailobj     quickmail object
 * \return sender e-mail address
 */
DLL_EXPORT_LIBQUICKMAIL const char* quickmail_get_from (quickmail mailobj);

/*! \brief add a recipient (to) e-mail address to a quickmail object
 * \param  mailobj     quickmail object
 * \param  e-mail      recipient e-mail address
 */
DLL_EXPORT_LIBQUICKMAIL void quickmail_add_to (quickmail mailobj, const char* email);

/*! \brief add a carbon copy recipient (cc) e-mail address to a quickmail object
 * \param  mailobj     quickmail object
 * \param  e-mail      recipient e-mail address
 */
DLL_EXPORT_LIBQUICKMAIL void quickmail_add_cc (quickmail mailobj, const char* email);

/*! \brief add a blind carbon copy recipient (bcc) e-mail address to a quickmail object
 * \param  mailobj     quickmail object
 * \param  e-mail      recipient e-mail address
 */
DLL_EXPORT_LIBQUICKMAIL void quickmail_add_bcc (quickmail mailobj, const char* email);

/*! \brief set the subject of a quickmail object
 * \param  mailobj     quickmail object
 * \param  subject     e-mail subject
 */
DLL_EXPORT_LIBQUICKMAIL void quickmail_set_subject (quickmail mailobj, const char* subject);

/*! \brief set the subject of a quickmail object
 * \param  mailobj     quickmail object
 * \return e-mail subject
 */
DLL_EXPORT_LIBQUICKMAIL const char* quickmail_get_subject (quickmail mailobj);

/*! \brief add an e-mail header to a quickmail object
 * \param  mailobj     quickmail object
 * \param  headerline  header line to add
 */
DLL_EXPORT_LIBQUICKMAIL void quickmail_add_header (quickmail mailobj, const char* headerline);

/*! \brief set the body of a quickmail object
 * \param  mailobj     quickmail object
 * \param  body        e-mail body
 */
DLL_EXPORT_LIBQUICKMAIL void quickmail_set_body (quickmail mailobj, const char* body);

/*! \brief set the body of a quickmail object
 * any existing bodies will be removed and a single plain text body will be added
 * \param  mailobj     quickmail object
 * \return e-mail body or NULL on error (caller must free result)
 */
DLL_EXPORT_LIBQUICKMAIL char* quickmail_get_body (quickmail mailobj);

/*! \brief add a body file to a quickmail object (deprecated)
 * \param  mailobj     quickmail object
 * \param  mimetype    MIME type (text/plain will be used if set to NULL)
 * \param  path        path of file with body data
 */
DLL_EXPORT_LIBQUICKMAIL void quickmail_add_body_file (quickmail mailobj, const char* mimetype, const char* path);

/*! \brief add a body from memory to a quickmail object
 * \param  mailobj     quickmail object
 * \param  mimetype    MIME type (text/plain will be used if set to NULL)
 * \param  data        body content
 * \param  datalen     size of data in bytes
 * \param  mustfree    non-zero if data must be freed by quickmail_destroy
 */
DLL_EXPORT_LIBQUICKMAIL void quickmail_add_body_memory (quickmail mailobj, const char* mimetype, char* data, size_t datalen, int mustfree);

/*! \brief add a body with custom read functions to a quickmail object
 * \param  mailobj                        quickmail object
 * \param  mimetype                       MIME type (text/plain will be used if set to NULL)
 * \param  data                           custom data passed to attachment_data_open and attachment_data_filedata_free functions
 * \param  attachment_data_open           function for opening attachment data
 * \param  attachment_data_read           function for reading attachment data
 * \param  attachment_data_close          function for closing attachment data (optional, free() will be used if NULL)
 * \param  attachment_data_filedata_free  function for cleaning up custom data in quickmail_destroy (optional, free() will be used if NULL)
 */
DLL_EXPORT_LIBQUICKMAIL void quickmail_add_body_custom (quickmail mailobj, const char* mimetype, char* data, quickmail_attachment_open_fn attachment_data_open, quickmail_attachment_read_fn attachment_data_read, quickmail_attachment_close_fn attachment_data_close, quickmail_attachment_free_filedata_fn attachment_data_filedata_free);

/*! \brief remove body from quickmail object
 * \param  mailobj     quickmail object
 * \param  mimetype    MIME type (text/plain will be used if set to NULL)
 * \return zero on success
 */
DLL_EXPORT_LIBQUICKMAIL int quickmail_remove_body (quickmail mailobj, const char* mimetype);

/*! \brief list bodies by calling a callback function for each body
 * \param  mailobj                        quickmail object
 * \param  callback                       function to call for each attachment
 * \param  callbackdata                   custom data to pass to the callback function
 * \sa     quickmail_list_attachment_callback_fn
 */
DLL_EXPORT_LIBQUICKMAIL void quickmail_list_bodies (quickmail mailobj, quickmail_list_attachment_callback_fn callback, void* callbackdata);

/*! \brief add a file attachment to a quickmail object
 * \param  mailobj     quickmail object
 * \param  path        path of file to attach
 * \param  mimetype    MIME type of file to attach (application/octet-stream will be used if set to NULL)
 */
DLL_EXPORT_LIBQUICKMAIL void quickmail_add_attachment_file (quickmail mailobj, const char* path, const char* mimetype);

/*! \brief add an attachment from memory to a quickmail object
 * \param  mailobj     quickmail object
 * \param  filename    name of file to attach (must not include full path)
 * \param  mimetype    MIME type of file to attach (set to NULL for default binary file)
 * \param  data        data content
 * \param  datalen     size of data in bytes
 * \param  mustfree    non-zero if data must be freed by quickmail_destroy
 */
DLL_EXPORT_LIBQUICKMAIL void quickmail_add_attachment_memory (quickmail mailobj, const char* filename, const char* mimetype, char* data, size_t datalen, int mustfree);

/*! \brief add an attachment with custom read functions to a quickmail object
 * \param  mailobj                        quickmail object
 * \param  filename                       name of file to attach (must not include full path)
 * \param  mimetype                       MIME type of file to attach (set to NULL for default binary file)
 * \param  data                           custom data passed to attachment_data_open and attachment_data_filedata_free functions
 * \param  attachment_data_open           function for opening attachment data
 * \param  attachment_data_read           function for reading attachment data
 * \param  attachment_data_close          function for closing attachment data (optional, free() will be used if NULL)
 * \param  attachment_data_filedata_free  function for cleaning up custom data in quickmail_destroy (optional, free() will be used if NULL)
 */
DLL_EXPORT_LIBQUICKMAIL void quickmail_add_attachment_custom (quickmail mailobj, const char* filename, const char* mimetype, char* data, quickmail_attachment_open_fn attachment_data_open, quickmail_attachment_read_fn attachment_data_read, quickmail_attachment_close_fn attachment_data_close, quickmail_attachment_free_filedata_fn attachment_data_filedata_free);

/*! \brief remove attachment from quickmail object
 * \param  mailobj     quickmail object
 * \param  filename    name of file to attach (must not include full path)
 * \return zero on success
 */
DLL_EXPORT_LIBQUICKMAIL int quickmail_remove_attachment (quickmail mailobj, const char* filename);

/*! \brief list attachments by calling a callback function for each attachment
 * \param  mailobj                        quickmail object
 * \param  callback                       function to call for each attachment
 * \param  callbackdata                   custom data to pass to the callback function
 * \sa     quickmail_list_attachment_callback_fn
 */
DLL_EXPORT_LIBQUICKMAIL void quickmail_list_attachments (quickmail mailobj, quickmail_list_attachment_callback_fn callback, void* callbackdata);

/*! \brief set the debug logging destination of a quickmail object
 * \param  mailobj     quickmail object
 * \param  filehandle  file handle of logging destination (or NULL for no logging)
 */
DLL_EXPORT_LIBQUICKMAIL void quickmail_set_debug_log (quickmail mailobj, FILE* filehandle);

/*! \brief save the generated e-mail to a file
 * \param  mailobj     quickmail object
 * \param  filehandle  file handle to write the e-mail contents to
 */
DLL_EXPORT_LIBQUICKMAIL void quickmail_fsave (quickmail mailobj, FILE* filehandle);

/*! \brief read data the next data from the e-mail contents (can be used as CURLOPT_READFUNCTION callback function)
 * \param  buffer      buffer to copy data to (bust be able to hold size * nmemb bytes)
 * \param  size        record size
 * \param  nmemb       number of records to copy to \p buffer
 * \param  mailobj     quickmail object
 * \return number of bytes copied to \p buffer or 0 if at end
 */
DLL_EXPORT_LIBQUICKMAIL size_t quickmail_get_data (void* buffer, size_t size, size_t nmemb, void* mailobj);

/*! \brief send the e-mail via SMTP
 * \param  mailobj     quickmail object
 * \param  smtpserver  IP address or hostname of SMTP server
 * \param  smtpport    SMTP port number (normally this is 25)
 * \param  username    username to use for authentication (or NULL if not needed)
 * \param  password    password to use for authentication (or NULL if not needed)
 * \return NULL on success or error message on error
 */
DLL_EXPORT_LIBQUICKMAIL const char* quickmail_send (quickmail mailobj, const char* smtpserver, unsigned int smtpport, const char* username, const char* password);

/*! \brief send the e-mail via SMTPS
 * \param  mailobj     quickmail object
 * \param  smtpserver  IP address or hostname of SMTPS server
 * \param  smtpport    SMTPS port number (normally this is 465)
 * \param  username    username to use for authentication (or NULL if not needed)
 * \param  password    password to use for authentication (or NULL if not needed)
 * \return NULL on success or error message on error
 */
DLL_EXPORT_LIBQUICKMAIL const char* quickmail_send_secure (quickmail mailobj, const char* smtpserver, unsigned int smtpport, const char* username, const char* password);


#ifdef __cplusplus
}
#endif

#endif //__INCLUDED_QUICKMAIL_H