Mercurial > masqmail
comparison src/accept.c @ 298:6281ff92cb86
refactoring
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Thu, 09 Dec 2010 13:20:14 -0300 |
parents | bb3005ce0837 |
children | ca2d11aec2a3 |
comparison
equal
deleted
inserted
replaced
297:b639e97feda3 | 298:6281ff92cb86 |
---|---|
189 | 189 |
190 DEBUG(5) debugf("accept_message_prepare()\n"); | 190 DEBUG(5) debugf("accept_message_prepare()\n"); |
191 | 191 |
192 /* create unique message id */ | 192 /* create unique message id */ |
193 msg->uid = g_malloc(14); | 193 msg->uid = g_malloc(14); |
194 | |
195 string_base62(msg->uid, rec_time, 6); | 194 string_base62(msg->uid, rec_time, 6); |
196 msg->uid[6] = '-'; | 195 msg->uid[6] = '-'; |
197 string_base62(&(msg->uid[7]), getpid(), 3); | 196 string_base62(msg->uid + 7, getpid(), 3); |
198 msg->uid[10] = '-'; | 197 msg->uid[10] = '-'; |
199 string_base62(&(msg->uid[11]), msg->transfer_id, 2); | 198 string_base62(msg->uid + 11, msg->transfer_id, 2); |
200 msg->uid[13] = 0; | 199 msg->uid[13] = '\0'; |
201 | 200 |
202 /* if local, get password entry */ | 201 /* if local, get password entry and set return path if missing */ |
203 if (msg->received_host == NULL) { | 202 if (!msg->received_host) { |
204 passwd = g_memdup(getpwuid(geteuid()), sizeof(struct passwd)); | 203 passwd = g_memdup(getpwuid(geteuid()), sizeof(struct passwd)); |
205 msg->ident = g_strdup(passwd->pw_name); | 204 msg->ident = g_strdup(passwd->pw_name); |
206 } | 205 if (!msg->return_path) { |
207 | 206 gchar *path = g_strdup_printf("<%s@%s>", passwd->pw_name, conf.host_name); |
208 /* set return path if local */ | 207 DEBUG(3) debugf("setting return_path for local accept: %s\n", path); |
209 if (msg->return_path == NULL && msg->received_host == NULL) { | 208 msg->return_path = create_address(path, TRUE); |
210 gchar *path = g_strdup_printf("<%s@%s>", passwd->pw_name, conf.host_name); | 209 g_free(path); |
211 DEBUG(3) debugf("setting return_path for local accept: %s\n", path); | 210 } |
212 msg->return_path = create_address(path, TRUE); | |
213 g_free(path); | |
214 } | 211 } |
215 | 212 |
216 /* scan headers */ | 213 /* scan headers */ |
217 { | 214 { |
218 gboolean has_id = FALSE; | 215 gboolean has_id = FALSE; |
222 gboolean has_to_or_cc = FALSE; | 219 gboolean has_to_or_cc = FALSE; |
223 GList *hdr_node, *hdr_node_next; | 220 GList *hdr_node, *hdr_node_next; |
224 header *hdr; | 221 header *hdr; |
225 | 222 |
226 for (hdr_node = g_list_first(msg->hdr_list); | 223 for (hdr_node = g_list_first(msg->hdr_list); |
227 hdr_node != NULL; hdr_node = hdr_node_next) { | 224 hdr_node; |
225 hdr_node = hdr_node_next) { | |
228 hdr_node_next = g_list_next(hdr_node); | 226 hdr_node_next = g_list_next(hdr_node); |
229 hdr = ((header *) (hdr_node->data)); | 227 hdr = ((header *) (hdr_node->data)); |
230 DEBUG(5) debugf("scanning headers: %s", hdr->header); | 228 DEBUG(5) debugf("scanning headers: %s", hdr->header); |
231 switch (hdr->id) { | 229 switch (hdr->id) { |
232 case HEAD_MESSAGE_ID: | 230 case HEAD_MESSAGE_ID: |
285 default: | 283 default: |
286 break; /* make compiler happy */ | 284 break; /* make compiler happy */ |
287 } | 285 } |
288 } | 286 } |
289 | 287 |
290 if (msg->return_path == NULL) { | 288 if (!msg->return_path) { |
291 /* this can happen for pop3 accept only and if no Return-path: header was given */ | 289 /* TODO: do we still need this as we don't fetch |
290 mail anymore? */ | |
291 /* this can happen for pop3 accept only and if no | |
292 Return-Path: header was given */ | |
292 GList *hdr_list; | 293 GList *hdr_list; |
293 header *hdr; | 294 header *hdr; |
294 | 295 |
295 DEBUG(3) debugf("return_path == NULL\n"); | 296 DEBUG(3) debugf("return_path == NULL\n"); |
296 | 297 |
297 hdr_list = find_header(msg->hdr_list, HEAD_SENDER, NULL); | 298 hdr_list = find_header(msg->hdr_list, HEAD_SENDER, NULL); |
298 if (!hdr_list) | 299 if (!hdr_list) { |
299 hdr_list = find_header(msg->hdr_list, HEAD_FROM, NULL); | 300 hdr_list = find_header(msg->hdr_list, HEAD_FROM, NULL); |
301 } | |
300 if (hdr_list) { | 302 if (hdr_list) { |
301 gchar *addr; | 303 gchar *addr; |
302 hdr = (header *) (g_list_first(hdr_list)->data); | 304 hdr = (header *) (g_list_first(hdr_list)->data); |
303 | 305 |
304 DEBUG(5) debugf("hdr->value = '%s'\n", hdr->value); | 306 DEBUG(5) debugf("hdr->value = '%s'\n", hdr->value); |
305 | 307 |
306 addr = g_strdup(hdr->value); | 308 addr = g_strdup(hdr->value); |
307 g_strchomp(addr); | 309 g_strchomp(addr); |
308 | 310 |
309 if ((msg->return_path = create_address_qualified(addr, FALSE, msg->received_host)) != NULL) { | 311 msg->return_path = create_address_qualified(addr, FALSE, msg->received_host)); |
312 if (msg->return_path) { | |
310 DEBUG(3) debugf("setting return_path to %s\n", addr_string(msg->return_path)); | 313 DEBUG(3) debugf("setting return_path to %s\n", addr_string(msg->return_path)); |
311 msg->hdr_list = g_list_append(msg->hdr_list, create_header(HEAD_UNKNOWN, | 314 msg->hdr_list = g_list_append( msg->hdr_list, create_header(HEAD_UNKNOWN, "X-Warning: return path set from %s address\n", hdr->id == HEAD_SENDER ? "Sender:" : "From:")); |
312 "X-Warning: return path set from %s address\n", | |
313 hdr->id == HEAD_SENDER ? "Sender:" : "From:")); | |
314 } | 315 } |
315 g_free(addr); | 316 g_free(addr); |
316 } | 317 } |
317 if (msg->return_path == NULL) { /* no Sender: or From: or create_address_qualified failed */ | 318 if (!msg->return_path) { |
319 /* no Sender: or From: or | |
320 create_address_qualified failed */ | |
318 msg->return_path = create_address_qualified("postmaster", TRUE, conf.host_name); | 321 msg->return_path = create_address_qualified("postmaster", TRUE, conf.host_name); |
319 DEBUG(3) debugf("setting return_path to %s\n", addr_string(msg->return_path)); | 322 DEBUG(3) debugf("setting return_path to %s\n", addr_string(msg->return_path)); |
320 msg->hdr_list = g_list_append(msg->hdr_list, create_header(HEAD_UNKNOWN, | 323 msg->hdr_list = g_list_append(msg->hdr_list, create_header(HEAD_UNKNOWN, "X-Warning: real return path is unknown\n")); |
321 "X-Warning: real return path is unknown\n")); | |
322 } | 324 } |
323 } | 325 } |
324 | 326 |
325 /* here we should have our recipients, fail if not: */ | 327 /* here we should have our recipients, fail if not: */ |
326 if (!msg->rcpt_list) { | 328 if (!msg->rcpt_list) { |
327 logwrite(LOG_WARNING, "no recipients found in message\n"); | 329 logwrite(LOG_WARNING, "no recipients found in message\n"); |
328 return AERR_NORCPT; | 330 return AERR_NORCPT; |
329 } | 331 } |
330 | 332 |
331 if (!(has_sender || has_from)) { | 333 if (!has_sender && !has_from)) { |
332 DEBUG(3) debugf("adding 'From' header\n"); | 334 DEBUG(3) debugf("adding 'From:' header\n"); |
333 msg->hdr_list = g_list_append(msg->hdr_list, | 335 if (msg->full_sender_name) { |
334 msg->full_sender_name | 336 msg->hdr_list = g_list_append(msg->hdr_list, create_header(HEAD_FROM, "From: \"%s\" <%s@%s>\n", msg->full_sender_name, msg->return_path->local_part, msg->return_path->domain)); |
335 ? | 337 } else { |
336 create_header(HEAD_FROM, "From: \"%s\" <%s@%s>\n", msg->full_sender_name, | 338 msg->hdr_list = g_list_append(msg->hdr_list, create_header(HEAD_FROM, "From: <%s@%s>\n", msg->return_path->local_part, msg->return_path->domain)); |
337 msg->return_path->local_part, msg->return_path->domain) | 339 } |
338 : | |
339 create_header(HEAD_FROM, "From: <%s@%s>\n", | |
340 msg->return_path->local_part, msg->return_path->domain) | |
341 ); | |
342 } | 340 } |
343 if (!has_to_or_cc) { | 341 if (!has_to_or_cc) { |
344 DEBUG(3) debugf("no To: or Cc: header, hence adding `To: undisclosed recipients:;'\n"); | 342 DEBUG(3) debugf("no To: or Cc: header, hence adding `To: undisclosed recipients:;'\n"); |
345 msg->hdr_list = g_list_append(msg->hdr_list, create_header(HEAD_TO, "To: undisclosed-recipients:;\n")); | 343 msg->hdr_list = g_list_append(msg->hdr_list, create_header(HEAD_TO, "To: undisclosed-recipients:;\n")); |
346 } | 344 } |
348 DEBUG(3) debugf("adding 'Date:' header\n"); | 346 DEBUG(3) debugf("adding 'Date:' header\n"); |
349 msg->hdr_list = g_list_append(msg->hdr_list, create_header(HEAD_DATE, "Date: %s\n", rec_timestamp())); | 347 msg->hdr_list = g_list_append(msg->hdr_list, create_header(HEAD_DATE, "Date: %s\n", rec_timestamp())); |
350 } | 348 } |
351 if (!has_id) { | 349 if (!has_id) { |
352 DEBUG(3) debugf("adding 'Message-ID:' header\n"); | 350 DEBUG(3) debugf("adding 'Message-ID:' header\n"); |
353 msg->hdr_list = g_list_append(msg->hdr_list, | 351 msg->hdr_list = g_list_append(msg->hdr_list, create_header(HEAD_MESSAGE_ID, "Message-ID: <%s@%s>\n", msg->uid, conf.host_name)); |
354 create_header(HEAD_MESSAGE_ID, "Message-ID: <%s@%s>\n", msg->uid, conf.host_name)); | |
355 } | 352 } |
356 } | 353 } |
357 | 354 |
358 /* Received header: */ | 355 /* Received header: */ |
359 /* At this point because we have to know the rcpts for the 'for' part */ | 356 /* At this point because we have to know the rcpts for the 'for' part */ |
357 /* The `for' part will only be used if exactly one rcpt is present. */ | |
360 gchar *for_string = NULL; | 358 gchar *for_string = NULL; |
361 header *hdr = NULL; | 359 header *hdr = NULL; |
362 | 360 |
363 DEBUG(3) debugf("adding 'Received:' header\n"); | 361 DEBUG(3) debugf("adding 'Received:' header\n"); |
364 | 362 |
365 if (g_list_length(msg->rcpt_list) == 1) { | 363 if (g_list_length(msg->rcpt_list) == 1) { |
366 address *addr = (address *) (g_list_first(msg->rcpt_list)->data); | 364 address *addr = (address *) (g_list_first(msg->rcpt_list)->data); |
367 for_string = g_strdup_printf(" for %s", addr_string(addr)); | 365 for_string = g_strdup_printf("\n\tfor %s", addr_string(addr)); |
368 } | 366 } |
369 | 367 |
370 if (!msg->received_host) { | 368 if (!msg->received_host) { |
371 /* received locally */ | 369 /* received locally */ |
372 hdr = create_header(HEAD_RECEIVED, | 370 hdr = create_header(HEAD_RECEIVED, |