masqmail-0.2

annotate src/message.c @ 84:ffeff2c33799

is_ingroup(): check for the primary group of a user too also some refactoring
author meillo@marmaro.de
date Sat, 19 Jun 2010 18:08:55 +0200
parents 26e34ae9a3e3
children 7f1f364c2a29
rev   line source
meillo@0 1 /* MasqMail
meillo@0 2 Copyright (C) 1999-2001 Oliver Kurth
meillo@0 3
meillo@0 4 This program is free software; you can redistribute it and/or modify
meillo@0 5 it under the terms of the GNU General Public License as published by
meillo@0 6 the Free Software Foundation; either version 2 of the License, or
meillo@0 7 (at your option) any later version.
meillo@0 8
meillo@0 9 This program is distributed in the hope that it will be useful,
meillo@0 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
meillo@0 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
meillo@0 12 GNU General Public License for more details.
meillo@0 13
meillo@0 14 You should have received a copy of the GNU General Public License
meillo@0 15 along with this program; if not, write to the Free Software
meillo@0 16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
meillo@0 17 */
meillo@0 18
meillo@0 19 #include "masqmail.h"
meillo@0 20
meillo@10 21 message*
meillo@10 22 create_message()
meillo@0 23 {
meillo@10 24 message *msg = (message *) g_malloc(sizeof(message));
meillo@10 25 if (msg) {
meillo@10 26 memset(msg, 0, sizeof(message));
meillo@10 27 msg->data_size = -1;
meillo@10 28 }
meillo@10 29 return msg;
meillo@0 30 }
meillo@0 31
meillo@10 32 gint
meillo@10 33 msg_calc_size(message * msg, gboolean is_smtp)
meillo@0 34 {
meillo@10 35 GList *node;
meillo@10 36 gint l_cnt = 0, c_cnt = 0;
meillo@0 37
meillo@10 38 /* header size */
meillo@10 39 if (msg->hdr_list) {
meillo@10 40 for (node = g_list_first(msg->hdr_list); node; node = g_list_next(node)) {
meillo@10 41 if (node->data) {
meillo@10 42 header *hdr = (header *) (node->data);
meillo@10 43 if (hdr->header) {
meillo@10 44 char *p = hdr->header;
meillo@10 45 while (*p) {
meillo@10 46 if (*p++ == '\n')
meillo@10 47 l_cnt++;
meillo@10 48 c_cnt++;
meillo@10 49 }
meillo@10 50 }
meillo@10 51 }
meillo@10 52 }
meillo@0 53 }
meillo@0 54
meillo@10 55 /* empty line separating headers from data: */
meillo@10 56 c_cnt++;
meillo@10 57 l_cnt++;
meillo@0 58
meillo@10 59 /* data size */
meillo@10 60 if (msg->data_list) {
meillo@10 61 for (node = g_list_first(msg->data_list); node; node = g_list_next(node)) {
meillo@10 62 if (node->data) {
meillo@10 63 char *p = node->data;
meillo@10 64 while (*p) {
meillo@10 65 if (*p++ == '\n')
meillo@10 66 l_cnt++;
meillo@10 67 c_cnt++;
meillo@10 68 }
meillo@10 69 }
meillo@10 70 }
meillo@0 71 }
meillo@0 72
meillo@10 73 return is_smtp ? c_cnt + l_cnt : c_cnt;
meillo@0 74 }
meillo@0 75
meillo@10 76 void
meillo@10 77 msg_free_data(message * msg)
meillo@0 78 {
meillo@10 79 GList *node;
meillo@0 80
meillo@10 81 if (msg->data_list) {
meillo@10 82 for (node = g_list_first(msg->data_list); node; node = g_list_next(node)) {
meillo@10 83 if (node->data)
meillo@10 84 g_free(node->data);
meillo@10 85 }
meillo@10 86 g_list_free(msg->data_list);
meillo@10 87 msg->data_list = NULL;
meillo@10 88 }
meillo@0 89 }
meillo@0 90
meillo@10 91 void
meillo@10 92 destroy_message(message * msg)
meillo@0 93 {
meillo@10 94 GList *node;
meillo@0 95
meillo@81 96 if (!msg) {
meillo@81 97 return;
meillo@81 98 }
meillo@81 99
meillo@10 100 if (msg->uid)
meillo@10 101 g_free(msg->uid);
meillo@10 102 if (msg->ident)
meillo@10 103 g_free(msg->ident);
meillo@10 104 if (msg->return_path)
meillo@10 105 g_free(msg->return_path);
meillo@0 106
meillo@10 107 if (msg->rcpt_list) {
meillo@10 108 for (node = g_list_first(msg->rcpt_list); node; node = g_list_next(node)) {
meillo@10 109 if (node->data)
meillo@10 110 g_free(node->data);
meillo@10 111 }
meillo@10 112 g_list_free(msg->rcpt_list);
meillo@10 113 }
meillo@10 114 if (msg->hdr_list) {
meillo@10 115 for (node = g_list_first(msg->hdr_list); node; node = g_list_next(node)) {
meillo@10 116 if (node->data) {
meillo@10 117 header *hdr = (header *) (node->data);
meillo@10 118 if (hdr->header)
meillo@10 119 g_free(hdr->header);
meillo@10 120 g_free(node->data);
meillo@10 121 }
meillo@10 122 }
meillo@10 123 g_list_free(msg->hdr_list);
meillo@10 124 }
meillo@0 125
meillo@10 126 if (msg->full_sender_name)
meillo@10 127 g_free(msg->full_sender_name);
meillo@0 128
meillo@10 129 msg_free_data(msg);
meillo@0 130
meillo@10 131 g_free(msg);
meillo@0 132 }
meillo@0 133
meillo@10 134 void
meillo@10 135 destroy_msg_list(GList * msg_list)
meillo@0 136 {
meillo@10 137 GList *msg_node;
meillo@0 138
meillo@10 139 foreach(msg_list, msg_node) {
meillo@10 140 message *msg = (message *) (msg_node->data);
meillo@10 141 destroy_message(msg);
meillo@10 142 }
meillo@10 143 g_list_free(msg_list);
meillo@0 144 }
meillo@0 145
meillo@10 146 msg_out*
meillo@10 147 create_msg_out(message * msg)
meillo@0 148 {
meillo@10 149 msg_out *msgout = NULL;
meillo@0 150
meillo@10 151 msgout = g_malloc(sizeof(msg_out));
meillo@10 152 if (msgout) {
meillo@10 153 msgout->msg = msg;
meillo@10 154 msgout->return_path = NULL;
meillo@10 155 msgout->rcpt_list = NULL;
meillo@10 156
meillo@10 157 msgout->hdr_list = NULL;
meillo@10 158 msgout->xtra_hdr_list = NULL;
meillo@10 159 }
meillo@10 160 return msgout;
meillo@0 161 }
meillo@0 162
meillo@10 163 msg_out*
meillo@10 164 clone_msg_out(msg_out * msgout_orig)
meillo@0 165 {
meillo@10 166 if (msgout_orig) {
meillo@10 167 msg_out *msgout = create_msg_out(msgout_orig->msg);
meillo@10 168 if (msgout) {
meillo@10 169 msgout->msg = msgout_orig->msg;
meillo@10 170 if (msgout_orig->return_path)
meillo@10 171 msgout->return_path = copy_address(msgout_orig->return_path);
meillo@10 172 if (msgout_orig->hdr_list)
meillo@10 173 msgout->hdr_list = g_list_copy(msgout_orig->hdr_list);
meillo@10 174 /* FIXME: if this lives longer than the original
meillo@10 175 and we access one of the xtra hdrs, we will segfault
meillo@10 176 or cause some weird bugs: */
meillo@10 177 msgout->xtra_hdr_list = NULL;
meillo@10 178 if (msgout_orig->rcpt_list)
meillo@10 179 msgout->rcpt_list = g_list_copy(msgout_orig->rcpt_list);
meillo@10 180 }
meillo@10 181 return msgout;
meillo@10 182 }
meillo@10 183 return NULL;
meillo@0 184 }
meillo@0 185
meillo@10 186 GList*
meillo@10 187 create_msg_out_list(GList * msg_list)
meillo@0 188 {
meillo@10 189 GList *msgout_list = NULL;
meillo@10 190 GList *msg_node;
meillo@0 191
meillo@10 192 foreach(msg_list, msg_node) {
meillo@10 193 message *msg = (message *) (msg_node->data);
meillo@10 194 msgout_list = g_list_append(msgout_list, create_msg_out(msg));
meillo@10 195 }
meillo@10 196 return msgout_list;
meillo@0 197 }
meillo@0 198
meillo@10 199 void
meillo@10 200 destroy_msg_out(msg_out * msgout)
meillo@0 201 {
meillo@10 202 if (msgout) {
meillo@10 203 if (msgout->return_path)
meillo@10 204 destroy_address(msgout->return_path);
meillo@10 205 if (msgout->hdr_list)
meillo@10 206 g_list_free(msgout->hdr_list);
meillo@10 207 if (msgout->xtra_hdr_list) {
meillo@10 208 GList *hdr_node;
meillo@10 209 foreach(msgout->xtra_hdr_list, hdr_node) {
meillo@10 210 header *hdr = (header *) (hdr_node->data);
meillo@10 211 destroy_header(hdr);
meillo@10 212 }
meillo@10 213 g_list_free(msgout->xtra_hdr_list);
meillo@10 214 }
meillo@10 215 g_free(msgout);
meillo@10 216 }
meillo@0 217 }
meillo@0 218
meillo@10 219 void
meillo@10 220 destroy_msg_out_list(GList * msgout_list)
meillo@0 221 {
meillo@10 222 GList *msgout_node;
meillo@0 223
meillo@10 224 foreach(msgout_list, msgout_node) {
meillo@10 225 msg_out *msgout = (msg_out *) (msgout_node->data);
meillo@10 226 destroy_msg_out(msgout);
meillo@10 227 }
meillo@10 228 g_list_free(msgout_list);
meillo@0 229 }