| 1 |
/*! \file quickmail.h |
| 2 |
* \brief header file for libquickmail |
| 3 |
* \author Brecht Sanders |
| 4 |
* \date 2012-2013 |
| 5 |
* \copyright GPL |
| 6 |
*/ |
| 7 |
/* |
| 8 |
This file is part of libquickmail. |
| 9 |
|
| 10 |
libquickmail is free software: you can redistribute it and/or modify |
| 11 |
it under the terms of the GNU General Public License as published by |
| 12 |
the Free Software Foundation, either version 3 of the License, or |
| 13 |
(at your option) any later version. |
| 14 |
|
| 15 |
libquickmail is distributed in the hope that it will be useful, |
| 16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
GNU General Public License for more details. |
| 19 |
|
| 20 |
You should have received a copy of the GNU General Public License |
| 21 |
along with libquickmail. If not, see <http://www.gnu.org/licenses/>. |
| 22 |
*/ |
| 23 |
|
| 24 |
#ifndef __INCLUDED_QUICKMAIL_H |
| 25 |
#define __INCLUDED_QUICKMAIL_H |
| 26 |
|
| 27 |
#include <stdio.h> |
| 28 |
|
| 29 |
/*! \brief define for exporting/importing functions in/from shared library */ |
| 30 |
#ifdef _WIN32 |
| 31 |
#if defined(BUILD_QUICKMAIL_DLL) |
| 32 |
#define DLL_EXPORT_LIBQUICKMAIL __declspec(dllexport) |
| 33 |
#elif !defined(STATIC) && !defined(BUILD_QUICKMAIL_STATIC) |
| 34 |
#define DLL_EXPORT_LIBQUICKMAIL __declspec(dllimport) |
| 35 |
#else |
| 36 |
#define DLL_EXPORT_LIBQUICKMAIL |
| 37 |
#endif |
| 38 |
#else |
| 39 |
#define DLL_EXPORT_LIBQUICKMAIL |
| 40 |
#endif |
| 41 |
|
| 42 |
#ifdef __cplusplus |
| 43 |
extern "C" { |
| 44 |
#endif |
| 45 |
|
| 46 |
/*! \brief quickmail object type */ |
| 47 |
typedef struct email_info_struct* quickmail; |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
/*! \brief type of pointer to function for opening attachment data |
| 52 |
* \param filedata custom data as passed to quickmail_add_body_custom/quickmail_add_attachment_custom |
| 53 |
* \return data structure to be used in calls to quickmail_attachment_read_fn and quickmail_attachment_close_fn functions |
| 54 |
* \sa quickmail_add_body_custom() |
| 55 |
* \sa quickmail_add_attachment_custom() |
| 56 |
*/ |
| 57 |
typedef void* (*quickmail_attachment_open_fn)(void* filedata); |
| 58 |
|
| 59 |
/*! \brief type of pointer to function for reading attachment data |
| 60 |
* \param handle data structure obtained via the corresponding quickmail_attachment_open_fn function |
| 61 |
* \param buf buffer for receiving data |
| 62 |
* \param len size in bytes of buffer for receiving data |
| 63 |
* \return number of bytes read (zero on end of file) |
| 64 |
* \sa quickmail_add_body_custom() |
| 65 |
* \sa quickmail_add_attachment_custom() |
| 66 |
*/ |
| 67 |
typedef size_t (*quickmail_attachment_read_fn)(void* handle, void* buf, size_t len); |
| 68 |
|
| 69 |
/*! \brief type of pointer to function for closing attachment data |
| 70 |
* \param handle data structure obtained via the corresponding quickmail_attachment_open_fn function |
| 71 |
* \sa quickmail_add_body_custom() |
| 72 |
* \sa quickmail_add_attachment_custom() |
| 73 |
*/ |
| 74 |
typedef void (*quickmail_attachment_close_fn)(void* handle); |
| 75 |
|
| 76 |
/*! \brief type of pointer to function for cleaning up custom data in quickmail_destroy |
| 77 |
* \param filedata custom data as passed to quickmail_add_body_custom/quickmail_add_attachment_custom |
| 78 |
* \sa quickmail_add_body_custom() |
| 79 |
* \sa quickmail_add_attachment_custom() |
| 80 |
*/ |
| 81 |
typedef void (*quickmail_attachment_free_filedata_fn)(void* filedata); |
| 82 |
|
| 83 |
/*! \brief type of pointer to function for cleaning up custom data in quickmail_destroy |
| 84 |
* \param mailobj quickmail object |
| 85 |
* \param filename attachment filename (same value as mimetype for mail body) |
| 86 |
* \param mimetype MIME type |
| 87 |
* \param attachment_data_open function for opening attachment data |
| 88 |
* \param attachment_data_read function for reading attachment data |
| 89 |
* \param attachment_data_close function for closing attachment data (optional, free() will be used if NULL) |
| 90 |
* \param callbackdata custom data passed to quickmail_list_attachments |
| 91 |
* \sa quickmail_list_bodies() |
| 92 |
* \sa quickmail_list_attachments() |
| 93 |
*/ |
| 94 |
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); |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
/*! \brief get version quickmail library |
| 99 |
* \return library version |
| 100 |
*/ |
| 101 |
DLL_EXPORT_LIBQUICKMAIL const char* quickmail_get_version (); |
| 102 |
|
| 103 |
/*! \brief initialize quickmail library |
| 104 |
* \return zero on success |
| 105 |
*/ |
| 106 |
DLL_EXPORT_LIBQUICKMAIL int quickmail_initialize (); |
| 107 |
|
| 108 |
/*! \brief create a new quickmail object |
| 109 |
* \param from sender e-mail address |
| 110 |
* \param subject e-mail subject |
| 111 |
* \return quickmail object or NULL on error |
| 112 |
*/ |
| 113 |
DLL_EXPORT_LIBQUICKMAIL quickmail quickmail_create (const char* from, const char* subject); |
| 114 |
|
| 115 |
/*! \brief clean up a quickmail object |
| 116 |
* \param mailobj quickmail object |
| 117 |
*/ |
| 118 |
DLL_EXPORT_LIBQUICKMAIL void quickmail_destroy (quickmail mailobj); |
| 119 |
|
| 120 |
/*! \brief set the sender (from) e-mail address of a quickmail object |
| 121 |
* \param mailobj quickmail object |
| 122 |
* \param from sender e-mail address |
| 123 |
*/ |
| 124 |
DLL_EXPORT_LIBQUICKMAIL void quickmail_set_from (quickmail mailobj, const char* from); |
| 125 |
|
| 126 |
/*! \brief get the sender (from) e-mail address of a quickmail object |
| 127 |
* \param mailobj quickmail object |
| 128 |
* \return sender e-mail address |
| 129 |
*/ |
| 130 |
DLL_EXPORT_LIBQUICKMAIL const char* quickmail_get_from (quickmail mailobj); |
| 131 |
|
| 132 |
/*! \brief add a recipient (to) e-mail address to a quickmail object |
| 133 |
* \param mailobj quickmail object |
| 134 |
* \param e-mail recipient e-mail address |
| 135 |
*/ |
| 136 |
DLL_EXPORT_LIBQUICKMAIL void quickmail_add_to (quickmail mailobj, const char* email); |
| 137 |
|
| 138 |
/*! \brief add a carbon copy recipient (cc) e-mail address to a quickmail object |
| 139 |
* \param mailobj quickmail object |
| 140 |
* \param e-mail recipient e-mail address |
| 141 |
*/ |
| 142 |
DLL_EXPORT_LIBQUICKMAIL void quickmail_add_cc (quickmail mailobj, const char* email); |
| 143 |
|
| 144 |
/*! \brief add a blind carbon copy recipient (bcc) e-mail address to a quickmail object |
| 145 |
* \param mailobj quickmail object |
| 146 |
* \param e-mail recipient e-mail address |
| 147 |
*/ |
| 148 |
DLL_EXPORT_LIBQUICKMAIL void quickmail_add_bcc (quickmail mailobj, const char* email); |
| 149 |
|
| 150 |
/*! \brief set the subject of a quickmail object |
| 151 |
* \param mailobj quickmail object |
| 152 |
* \param subject e-mail subject |
| 153 |
*/ |
| 154 |
DLL_EXPORT_LIBQUICKMAIL void quickmail_set_subject (quickmail mailobj, const char* subject); |
| 155 |
|
| 156 |
/*! \brief set the subject of a quickmail object |
| 157 |
* \param mailobj quickmail object |
| 158 |
* \return e-mail subject |
| 159 |
*/ |
| 160 |
DLL_EXPORT_LIBQUICKMAIL const char* quickmail_get_subject (quickmail mailobj); |
| 161 |
|
| 162 |
/*! \brief add an e-mail header to a quickmail object |
| 163 |
* \param mailobj quickmail object |
| 164 |
* \param headerline header line to add |
| 165 |
*/ |
| 166 |
DLL_EXPORT_LIBQUICKMAIL void quickmail_add_header (quickmail mailobj, const char* headerline); |
| 167 |
|
| 168 |
/*! \brief set the body of a quickmail object |
| 169 |
* \param mailobj quickmail object |
| 170 |
* \param body e-mail body |
| 171 |
*/ |
| 172 |
DLL_EXPORT_LIBQUICKMAIL void quickmail_set_body (quickmail mailobj, const char* body); |
| 173 |
|
| 174 |
/*! \brief set the body of a quickmail object |
| 175 |
* any existing bodies will be removed and a single plain text body will be added |
| 176 |
* \param mailobj quickmail object |
| 177 |
* \return e-mail body or NULL on error (caller must free result) |
| 178 |
*/ |
| 179 |
DLL_EXPORT_LIBQUICKMAIL char* quickmail_get_body (quickmail mailobj); |
| 180 |
|
| 181 |
/*! \brief add a body file to a quickmail object (deprecated) |
| 182 |
* \param mailobj quickmail object |
| 183 |
* \param mimetype MIME type (text/plain will be used if set to NULL) |
| 184 |
* \param path path of file with body data |
| 185 |
*/ |
| 186 |
DLL_EXPORT_LIBQUICKMAIL void quickmail_add_body_file (quickmail mailobj, const char* mimetype, const char* path); |
| 187 |
|
| 188 |
/*! \brief add a body from memory to a quickmail object |
| 189 |
* \param mailobj quickmail object |
| 190 |
* \param mimetype MIME type (text/plain will be used if set to NULL) |
| 191 |
* \param data body content |
| 192 |
* \param datalen size of data in bytes |
| 193 |
* \param mustfree non-zero if data must be freed by quickmail_destroy |
| 194 |
*/ |
| 195 |
DLL_EXPORT_LIBQUICKMAIL void quickmail_add_body_memory (quickmail mailobj, const char* mimetype, char* data, size_t datalen, int mustfree); |
| 196 |
|
| 197 |
/*! \brief add a body with custom read functions to a quickmail object |
| 198 |
* \param mailobj quickmail object |
| 199 |
* \param mimetype MIME type (text/plain will be used if set to NULL) |
| 200 |
* \param data custom data passed to attachment_data_open and attachment_data_filedata_free functions |
| 201 |
* \param attachment_data_open function for opening attachment data |
| 202 |
* \param attachment_data_read function for reading attachment data |
| 203 |
* \param attachment_data_close function for closing attachment data (optional, free() will be used if NULL) |
| 204 |
* \param attachment_data_filedata_free function for cleaning up custom data in quickmail_destroy (optional, free() will be used if NULL) |
| 205 |
*/ |
| 206 |
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); |
| 207 |
|
| 208 |
/*! \brief remove body from quickmail object |
| 209 |
* \param mailobj quickmail object |
| 210 |
* \param mimetype MIME type (text/plain will be used if set to NULL) |
| 211 |
* \return zero on success |
| 212 |
*/ |
| 213 |
DLL_EXPORT_LIBQUICKMAIL int quickmail_remove_body (quickmail mailobj, const char* mimetype); |
| 214 |
|
| 215 |
/*! \brief list bodies by calling a callback function for each body |
| 216 |
* \param mailobj quickmail object |
| 217 |
* \param callback function to call for each attachment |
| 218 |
* \param callbackdata custom data to pass to the callback function |
| 219 |
* \sa quickmail_list_attachment_callback_fn |
| 220 |
*/ |
| 221 |
DLL_EXPORT_LIBQUICKMAIL void quickmail_list_bodies (quickmail mailobj, quickmail_list_attachment_callback_fn callback, void* callbackdata); |
| 222 |
|
| 223 |
/*! \brief add a file attachment to a quickmail object |
| 224 |
* \param mailobj quickmail object |
| 225 |
* \param path path of file to attach |
| 226 |
* \param mimetype MIME type of file to attach (application/octet-stream will be used if set to NULL) |
| 227 |
*/ |
| 228 |
DLL_EXPORT_LIBQUICKMAIL void quickmail_add_attachment_file (quickmail mailobj, const char* path, const char* mimetype); |
| 229 |
|
| 230 |
/*! \brief add an attachment from memory to a quickmail object |
| 231 |
* \param mailobj quickmail object |
| 232 |
* \param filename name of file to attach (must not include full path) |
| 233 |
* \param mimetype MIME type of file to attach (set to NULL for default binary file) |
| 234 |
* \param data data content |
| 235 |
* \param datalen size of data in bytes |
| 236 |
* \param mustfree non-zero if data must be freed by quickmail_destroy |
| 237 |
*/ |
| 238 |
DLL_EXPORT_LIBQUICKMAIL void quickmail_add_attachment_memory (quickmail mailobj, const char* filename, const char* mimetype, char* data, size_t datalen, int mustfree); |
| 239 |
|
| 240 |
/*! \brief add an attachment with custom read functions to a quickmail object |
| 241 |
* \param mailobj quickmail object |
| 242 |
* \param filename name of file to attach (must not include full path) |
| 243 |
* \param mimetype MIME type of file to attach (set to NULL for default binary file) |
| 244 |
* \param data custom data passed to attachment_data_open and attachment_data_filedata_free functions |
| 245 |
* \param attachment_data_open function for opening attachment data |
| 246 |
* \param attachment_data_read function for reading attachment data |
| 247 |
* \param attachment_data_close function for closing attachment data (optional, free() will be used if NULL) |
| 248 |
* \param attachment_data_filedata_free function for cleaning up custom data in quickmail_destroy (optional, free() will be used if NULL) |
| 249 |
*/ |
| 250 |
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); |
| 251 |
|
| 252 |
/*! \brief remove attachment from quickmail object |
| 253 |
* \param mailobj quickmail object |
| 254 |
* \param filename name of file to attach (must not include full path) |
| 255 |
* \return zero on success |
| 256 |
*/ |
| 257 |
DLL_EXPORT_LIBQUICKMAIL int quickmail_remove_attachment (quickmail mailobj, const char* filename); |
| 258 |
|
| 259 |
/*! \brief list attachments by calling a callback function for each attachment |
| 260 |
* \param mailobj quickmail object |
| 261 |
* \param callback function to call for each attachment |
| 262 |
* \param callbackdata custom data to pass to the callback function |
| 263 |
* \sa quickmail_list_attachment_callback_fn |
| 264 |
*/ |
| 265 |
DLL_EXPORT_LIBQUICKMAIL void quickmail_list_attachments (quickmail mailobj, quickmail_list_attachment_callback_fn callback, void* callbackdata); |
| 266 |
|
| 267 |
/*! \brief set the debug logging destination of a quickmail object |
| 268 |
* \param mailobj quickmail object |
| 269 |
* \param filehandle file handle of logging destination (or NULL for no logging) |
| 270 |
*/ |
| 271 |
DLL_EXPORT_LIBQUICKMAIL void quickmail_set_debug_log (quickmail mailobj, FILE* filehandle); |
| 272 |
|
| 273 |
/*! \brief save the generated e-mail to a file |
| 274 |
* \param mailobj quickmail object |
| 275 |
* \param filehandle file handle to write the e-mail contents to |
| 276 |
*/ |
| 277 |
DLL_EXPORT_LIBQUICKMAIL void quickmail_fsave (quickmail mailobj, FILE* filehandle); |
| 278 |
|
| 279 |
/*! \brief read data the next data from the e-mail contents (can be used as CURLOPT_READFUNCTION callback function) |
| 280 |
* \param buffer buffer to copy data to (bust be able to hold size * nmemb bytes) |
| 281 |
* \param size record size |
| 282 |
* \param nmemb number of records to copy to \p buffer |
| 283 |
* \param mailobj quickmail object |
| 284 |
* \return number of bytes copied to \p buffer or 0 if at end |
| 285 |
*/ |
| 286 |
DLL_EXPORT_LIBQUICKMAIL size_t quickmail_get_data (void* buffer, size_t size, size_t nmemb, void* mailobj); |
| 287 |
|
| 288 |
/*! \brief send the e-mail via SMTP |
| 289 |
* \param mailobj quickmail object |
| 290 |
* \param smtpserver IP address or hostname of SMTP server |
| 291 |
* \param smtpport SMTP port number (normally this is 25) |
| 292 |
* \param username username to use for authentication (or NULL if not needed) |
| 293 |
* \param password password to use for authentication (or NULL if not needed) |
| 294 |
* \return NULL on success or error message on error |
| 295 |
*/ |
| 296 |
DLL_EXPORT_LIBQUICKMAIL const char* quickmail_send (quickmail mailobj, const char* smtpserver, unsigned int smtpport, const char* username, const char* password); |
| 297 |
|
| 298 |
#ifdef __cplusplus |
| 299 |
} |
| 300 |
#endif |
| 301 |
|
| 302 |
#endif //__INCLUDED_QUICKMAIL_H |