masqmail-0.2

annotate src/message.c @ 41:5432f13c7e58

updated ChangeLog and NEWS
author meillo@marmaro.de
date Mon, 10 May 2010 12:26:54 +0200
parents 08114f7dcc23
children 71ce3a1568e9
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@10 96 if (msg->uid)
meillo@10 97 g_free(msg->uid);
meillo@10 98 if (msg->ident)
meillo@10 99 g_free(msg->ident);
meillo@10 100 if (msg->return_path)
meillo@10 101 g_free(msg->return_path);
meillo@0 102
meillo@10 103 if (msg->rcpt_list) {
meillo@10 104 for (node = g_list_first(msg->rcpt_list); node; node = g_list_next(node)) {
meillo@10 105 if (node->data)
meillo@10 106 g_free(node->data);
meillo@10 107 }
meillo@10 108 g_list_free(msg->rcpt_list);
meillo@10 109 }
meillo@10 110 if (msg->hdr_list) {
meillo@10 111 for (node = g_list_first(msg->hdr_list); node; node = g_list_next(node)) {
meillo@10 112 if (node->data) {
meillo@10 113 header *hdr = (header *) (node->data);
meillo@10 114 if (hdr->header)
meillo@10 115 g_free(hdr->header);
meillo@10 116 g_free(node->data);
meillo@10 117 }
meillo@10 118 }
meillo@10 119 g_list_free(msg->hdr_list);
meillo@10 120 }
meillo@0 121
meillo@10 122 if (msg->full_sender_name)
meillo@10 123 g_free(msg->full_sender_name);
meillo@0 124
meillo@10 125 msg_free_data(msg);
meillo@0 126
meillo@10 127 g_free(msg);
meillo@0 128 }
meillo@0 129
meillo@10 130 void
meillo@10 131 destroy_msg_list(GList * msg_list)
meillo@0 132 {
meillo@10 133 GList *msg_node;
meillo@0 134
meillo@10 135 foreach(msg_list, msg_node) {
meillo@10 136 message *msg = (message *) (msg_node->data);
meillo@10 137 destroy_message(msg);
meillo@10 138 }
meillo@10 139 g_list_free(msg_list);
meillo@0 140 }
meillo@0 141
meillo@10 142 msg_out*
meillo@10 143 create_msg_out(message * msg)
meillo@0 144 {
meillo@10 145 msg_out *msgout = NULL;
meillo@0 146
meillo@10 147 msgout = g_malloc(sizeof(msg_out));
meillo@10 148 if (msgout) {
meillo@10 149 msgout->msg = msg;
meillo@10 150 msgout->return_path = NULL;
meillo@10 151 msgout->rcpt_list = NULL;
meillo@10 152
meillo@10 153 msgout->hdr_list = NULL;
meillo@10 154 msgout->xtra_hdr_list = NULL;
meillo@10 155 }
meillo@10 156 return msgout;
meillo@0 157 }
meillo@0 158
meillo@10 159 msg_out*
meillo@10 160 clone_msg_out(msg_out * msgout_orig)
meillo@0 161 {
meillo@10 162 if (msgout_orig) {
meillo@10 163 msg_out *msgout = create_msg_out(msgout_orig->msg);
meillo@10 164 if (msgout) {
meillo@10 165 msgout->msg = msgout_orig->msg;
meillo@10 166 if (msgout_orig->return_path)
meillo@10 167 msgout->return_path = copy_address(msgout_orig->return_path);
meillo@10 168 if (msgout_orig->hdr_list)
meillo@10 169 msgout->hdr_list = g_list_copy(msgout_orig->hdr_list);
meillo@10 170 /* FIXME: if this lives longer than the original
meillo@10 171 and we access one of the xtra hdrs, we will segfault
meillo@10 172 or cause some weird bugs: */
meillo@10 173 msgout->xtra_hdr_list = NULL;
meillo@10 174 if (msgout_orig->rcpt_list)
meillo@10 175 msgout->rcpt_list = g_list_copy(msgout_orig->rcpt_list);
meillo@10 176 }
meillo@10 177 return msgout;
meillo@10 178 }
meillo@10 179 return NULL;
meillo@0 180 }
meillo@0 181
meillo@10 182 GList*
meillo@10 183 create_msg_out_list(GList * msg_list)
meillo@0 184 {
meillo@10 185 GList *msgout_list = NULL;
meillo@10 186 GList *msg_node;
meillo@0 187
meillo@10 188 foreach(msg_list, msg_node) {
meillo@10 189 message *msg = (message *) (msg_node->data);
meillo@10 190 msgout_list = g_list_append(msgout_list, create_msg_out(msg));
meillo@10 191 }
meillo@10 192 return msgout_list;
meillo@0 193 }
meillo@0 194
meillo@10 195 void
meillo@10 196 destroy_msg_out(msg_out * msgout)
meillo@0 197 {
meillo@10 198 if (msgout) {
meillo@10 199 if (msgout->return_path)
meillo@10 200 destroy_address(msgout->return_path);
meillo@10 201 if (msgout->hdr_list)
meillo@10 202 g_list_free(msgout->hdr_list);
meillo@10 203 if (msgout->xtra_hdr_list) {
meillo@10 204 GList *hdr_node;
meillo@10 205 foreach(msgout->xtra_hdr_list, hdr_node) {
meillo@10 206 header *hdr = (header *) (hdr_node->data);
meillo@10 207 destroy_header(hdr);
meillo@10 208 }
meillo@10 209 g_list_free(msgout->xtra_hdr_list);
meillo@10 210 }
meillo@10 211 g_free(msgout);
meillo@10 212 }
meillo@0 213 }
meillo@0 214
meillo@10 215 void
meillo@10 216 destroy_msg_out_list(GList * msgout_list)
meillo@0 217 {
meillo@10 218 GList *msgout_node;
meillo@0 219
meillo@10 220 foreach(msgout_list, msgout_node) {
meillo@10 221 msg_out *msgout = (msg_out *) (msgout_node->data);
meillo@10 222 destroy_msg_out(msgout);
meillo@10 223 }
meillo@10 224 g_list_free(msgout_list);
meillo@0 225 }