1 /* 2 Copyright (C) 2004 Aaron Stone aaron at serendipity dot cx 3 4 This program is free software; you can redistribute it and/or 5 modify it under the terms of the GNU General Public License 6 as published by the Free Software Foundation; either 7 version 2 of the License, or (at your option) any later 8 version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 */ 19 20 #ifndef DM_DSN_H 21 #define DM_DSN_H 22 23 #include "dbmail.h" 24 25 typedef enum { 26 DSN_CLASS_NONE = 0, 27 DSN_CLASS_OK = 2, 28 DSN_CLASS_TEMP = 4, 29 DSN_CLASS_FAIL = 5, 30 DSN_CLASS_QUOTA, 31 } dsn_class_t; 32 33 typedef struct { 34 dsn_class_t class; 35 int subject; 36 int detail; 37 } delivery_status_t; 38 39 typedef struct { 40 uint64_t useridnr; /* Specific user id recipient (from outside). */ 41 char *address; /* Envelope recipient (from outside). */ 42 char *mailbox; /* Default mailbox to use for userid deliveries (from outside). */ 43 mailbox_source source; /* Who specified the mailbox (e.g. trusted or untrusted source)? */ 44 GList *userids; /* List of uint64_t* -- internal useridnr's to deliver to (internal). */ 45 GList *forwards; /* List of char* -- external addresses to forward to (internal). */ 46 delivery_status_t dsn; /* Return status of this "delivery basket" (to outside). */ 47 } Delivery_T; 48 49 /** 50 * \brief Turn a numerical delivery status 51 * structure into a series of English explanations. 52 * \param dsn delivery_status_t containing status codes. 53 * \param class filled with a pointer to a Class explanation 54 * \param subject filled with a pointer to a Subject explanation 55 * \param detail filled with a pointer to a Detail explanation 56 * \return 57 * - 0 on success 58 * - -1 on failure 59 */ 60 int dsn_tostring(delivery_status_t dsn, const char ** const class, 61 const char ** const subject, const char ** const detail); 62 63 /** 64 * \brief Sets values on the dsn delivery_status_t 65 * inside of a delivery Delivery_T. 66 * \param delivery is a pointer to a Delivery_T struct. 67 * \param class is the class (use values from dsn_class_t). 68 * \param subject is the subject. 69 * \param detail is the detail. 70 */ 71 void set_dsn(delivery_status_t *dsn, 72 int class, int subject, int detail); 73 74 /** 75 * \brief Initialize a dsnuser structure and its lists. 76 * \param dsnuser Pointer to a dsnuser structure in need of initialization. 77 * \return 78 * - 0 on success 79 * - -1 on failure 80 */ 81 int dsnuser_init(Delivery_T * dsnuser); 82 83 void dsnuser_free(Delivery_T * dsnuser); 84 void dsnuser_free_list(List_T deliveries); 85 86 /** 87 * \brief Loop through the list of delivery addresses 88 * and resolve them into lists of final delivery useridnr's, 89 * and external forwarding addresses. Each dsnuser is flagged 90 * with DSN codes so that successes and failures can be properly 91 * indicated at the top of the delivery call chain, such as in 92 * dbmail-deliver and dbmail-lmtpd. 93 * \param deliveries Pointer to a list of dsnuser structs. 94 * \return 95 * - 0 on success 96 * - -1 on failure 97 */ 98 int dsnuser_resolve_list(List_T deliveries); 99 100 /** 101 * \brief The dsnuser structure should have either a useridnr or 102 * an address/alias set. It will be resolved to deliveries and 103 * flagged with a DSN code so that success or failure can be 104 * properly indicated at the top of the delivery call chain, 105 * such as in dbmail-deliver and dbmail-lmtpd. 106 * \param deliveries Pointer to a Delivery_T. 107 * \return 108 * - 0 on success 109 * - -1 on failure 110 */ 111 int dsnuser_resolve(Delivery_T *dsnuser); 112 113 /** 114 * \brief Loop through the list of delivery addresses 115 * and find out what the single worst case scenario was 116 * for situations where we are limited to returning a single 117 * status code yet might have had a whole lot of deliveries. 118 * \param deliveries Pointer to a list of dsnuser structs. 119 * \return 120 * - see dsn_class_t for details. 121 */ 122 dsn_class_t dsnuser_worstcase_list(List_T deliveries); 123 124 /** 125 * \brief Given true/false values for each of the three 126 * delivery classes, find out what the single worst case scenario was 127 * for situations where we are limited to returning a single 128 * status code yet might have had a whole lot of deliveries. 129 * \param ok 0 if nothing was DSN_CLASS_OK, 1 if there was. 130 * \param temp 0 if nothing was DSN_CLASS_TEMP, 1 if there was. 131 * \param fail 0 if nothing was DSN_CLASS_FAIL, 1 if there was. 132 * \param fail_quota 0 if nothing was DSN_CLASS_QUOTA, 1 if there was. 133 * \return 134 * - see dsn_class_t for details. 135 */ 136 dsn_class_t dsnuser_worstcase_int(int ok, int temp, int fail, int fail_quota); 137 138 #endif /* DSN_H */ 139