masqmail

view src/message.c @ 56:f6a6f55b7b9e

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