masqmail
diff src/accept.c @ 10:26e34ae9a3e3
changed indention and line wrapping to a more consistent style
author | meillo@marmaro.de |
---|---|
date | Mon, 27 Oct 2008 16:23:10 +0100 |
parents | 08114f7dcc23 |
children | 49dab67fe461 |
line diff
1.1 --- a/src/accept.c Mon Oct 27 16:21:27 2008 +0100 1.2 +++ b/src/accept.c Mon Oct 27 16:23:10 2008 +0100 1.3 @@ -19,41 +19,40 @@ 1.4 #include "masqmail.h" 1.5 #include "readsock.h" 1.6 1.7 -gchar *prot_names[] = 1.8 -{ 1.9 - "local", 1.10 - "bsmtp", 1.11 - "smtp", 1.12 - "esmtp", 1.13 - "pop3", 1.14 - "apop", 1.15 - "(unknown)" /* should not happen, but better than crashing. */ 1.16 +gchar *prot_names[] = { 1.17 + "local", 1.18 + "bsmtp", 1.19 + "smtp", 1.20 + "esmtp", 1.21 + "pop3", 1.22 + "apop", 1.23 + "(unknown)" /* should not happen, but better than crashing. */ 1.24 }; 1.25 1.26 -static 1.27 -gchar *string_base62(gchar *res, guint value, gchar len) 1.28 +static gchar* 1.29 +string_base62(gchar * res, guint value, gchar len) 1.30 { 1.31 - static gchar base62_chars[] = 1.32 - "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 1.33 - gchar *p = res + len; 1.34 - *p = 0; 1.35 - while (p > res){ 1.36 - *(--p) = base62_chars[value % 62]; 1.37 - value /= 62; 1.38 - } 1.39 - return res; 1.40 + static gchar base62_chars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 1.41 + gchar *p = res + len; 1.42 + *p = 0; 1.43 + while (p > res) { 1.44 + *(--p) = base62_chars[value % 62]; 1.45 + value /= 62; 1.46 + } 1.47 + return res; 1.48 } 1.49 1.50 -static gint _g_list_addr_isequal(gconstpointer a, gconstpointer b) 1.51 +static gint 1.52 +_g_list_addr_isequal(gconstpointer a, gconstpointer b) 1.53 { 1.54 - address *addr1 = (address *)a; 1.55 - address *addr2 = (address *)b; 1.56 - int ret; 1.57 + address *addr1 = (address *) a; 1.58 + address *addr2 = (address *) b; 1.59 + int ret; 1.60 1.61 - if((ret = strcasecmp(addr1->domain, addr2->domain)) == 0) 1.62 - return strcmp(addr1->local_part, addr2->local_part); 1.63 - else 1.64 - return ret; 1.65 + if ((ret = strcasecmp(addr1->domain, addr2->domain)) == 0) 1.66 + return strcmp(addr1->local_part, addr2->local_part); 1.67 + else 1.68 + return ret; 1.69 } 1.70 1.71 /* accept message from anywhere. 1.72 @@ -64,415 +63,392 @@ 1.73 (from To/Cc/Bcc headers if ACC_RCPT_TO is set) rcpt_list. 1.74 */ 1.75 1.76 -accept_error accept_message_stream(FILE *in, message *msg, guint flags) 1.77 +accept_error 1.78 +accept_message_stream(FILE * in, message * msg, guint flags) 1.79 { 1.80 - gchar *line, *line1; 1.81 - int line_size = MAX_DATALINE; 1.82 - gboolean in_headers = TRUE; 1.83 - header *hdr = NULL; 1.84 - gint line_cnt = 0, data_size = 0; 1.85 + gchar *line, *line1; 1.86 + int line_size = MAX_DATALINE; 1.87 + gboolean in_headers = TRUE; 1.88 + header *hdr = NULL; 1.89 + gint line_cnt = 0, data_size = 0; 1.90 1.91 - line = g_malloc(line_size); 1.92 - line[0] = 0; 1.93 + line = g_malloc(line_size); 1.94 + line[0] = 0; 1.95 1.96 - while(TRUE){ 1.97 - int len = read_sockline1(in, &line, &line_size, 5*60, READSOCKL_CVT_CRLF); 1.98 + while (TRUE) { 1.99 + int len = read_sockline1(in, &line, &line_size, 5 * 60, READSOCKL_CVT_CRLF); 1.100 1.101 - line1 = line; 1.102 + line1 = line; 1.103 1.104 - if((line[0] == '.') && (!(flags & ACC_NODOT_TERM))){ 1.105 - if(line[1] == '\n'){ 1.106 - g_free(line); 1.107 - break; 1.108 - } 1.109 - line1++; 1.110 - } 1.111 - 1.112 - if(len <= 0){ 1.113 - if((len == -1) && ((flags & ACC_NODOT_TERM) || (flags & ACC_NODOT_RELAX))){ 1.114 - /* we got an EOF, and the last line was not terminated by a CR */ 1.115 - gint len1 = strlen(line1); 1.116 - if(len1 > 0){ /* == 0 is 'normal' (EOF after a CR) */ 1.117 - if(line1[len1-1] != '\n'){ /* some mail clients allow unterminated lines */ 1.118 - line1[len1] = '\n'; 1.119 - line1[len1+1] = 0; 1.120 - msg->data_list = g_list_prepend(msg->data_list, g_strdup(line1)); 1.121 - data_size += strlen(line1); 1.122 - line_cnt++; 1.123 - } 1.124 + if ((line[0] == '.') && (!(flags & ACC_NODOT_TERM))) { 1.125 + if (line[1] == '\n') { 1.126 + g_free(line); 1.127 + break; 1.128 + } 1.129 + line1++; 1.130 + } 1.131 + 1.132 + if (len <= 0) { 1.133 + if ((len == -1) && ((flags & ACC_NODOT_TERM) || (flags & ACC_NODOT_RELAX))) { 1.134 + /* we got an EOF, and the last line was not terminated by a CR */ 1.135 + gint len1 = strlen(line1); 1.136 + if (len1 > 0) { /* == 0 is 'normal' (EOF after a CR) */ 1.137 + if (line1[len1 - 1] != '\n') { /* some mail clients allow unterminated lines */ 1.138 + line1[len1] = '\n'; 1.139 + line1[len1 + 1] = 0; 1.140 + msg->data_list = g_list_prepend(msg->data_list, g_strdup(line1)); 1.141 + data_size += strlen(line1); 1.142 + line_cnt++; 1.143 + } 1.144 + } 1.145 + break; 1.146 + } else { 1.147 + g_free(line); 1.148 + if (len == -1) { 1.149 + return AERR_EOF; 1.150 + } else if (len == -2) { 1.151 + /* should not happen any more */ 1.152 + return AERR_OVERFLOW; 1.153 + } else if (len == -3) { 1.154 + return AERR_TIMEOUT; 1.155 + } else { 1.156 + /* does not happen */ 1.157 + DEBUG(5) debugf("read_sockline returned %d\n", len); 1.158 + return AERR_UNKNOWN; 1.159 + } 1.160 + } 1.161 + } else { 1.162 + if (in_headers) { 1.163 + 1.164 + /* some pop servers send the 'From ' line, skip it: */ 1.165 + if (msg->hdr_list == NULL) 1.166 + if (strncmp(line1, "From ", 5) == 0) 1.167 + continue; 1.168 + 1.169 + if (line1[0] == ' ' || line1[0] == '\t') { 1.170 + /* continuation of 'folded' header: */ 1.171 + if (hdr) { 1.172 + hdr->header = 1.173 + g_strconcat(hdr->header, line1, NULL); 1.174 + } 1.175 + 1.176 + } else if (line1[0] == '\n') { 1.177 + /* an empty line marks end of headers */ 1.178 + in_headers = FALSE; 1.179 + } else { 1.180 + /* in all other cases we expect another header */ 1.181 + if ((hdr = get_header(line1))) 1.182 + msg->hdr_list = g_list_append(msg->hdr_list, hdr); 1.183 + else { 1.184 + /* if get_header() returns NULL, no header was recognized, 1.185 + so this seems to be the first data line of a broken mailer 1.186 + which does not send an empty line after the headers */ 1.187 + in_headers = FALSE; 1.188 + msg->data_list = g_list_prepend(msg->data_list, g_strdup(line1)); 1.189 + } 1.190 + } 1.191 + } else { 1.192 + msg->data_list = g_list_prepend(msg->data_list, g_strdup(line1)); 1.193 + data_size += strlen(line1); 1.194 + line_cnt++; 1.195 + } 1.196 + } 1.197 } 1.198 - break; 1.199 - }else{ 1.200 - g_free(line); 1.201 - if(len == -1){ 1.202 - return AERR_EOF; 1.203 - }else if(len == -2){ 1.204 - /* should not happen any more */ 1.205 - return AERR_OVERFLOW; 1.206 - }else if(len == -3){ 1.207 - return AERR_TIMEOUT; 1.208 - }else{ 1.209 - /* does not happen */ 1.210 - DEBUG(5) debugf("read_sockline returned %d\n", len); 1.211 - return AERR_UNKNOWN; 1.212 - } 1.213 - } 1.214 - } 1.215 - else{ 1.216 - if(in_headers){ 1.217 1.218 - /* some pop servers send the 'From ' line, skip it: */ 1.219 - if(msg->hdr_list == NULL) 1.220 - if(strncmp(line1, "From ", 5) == 0) 1.221 - continue; 1.222 + if (msg->data_list != NULL) 1.223 + msg->data_list = g_list_reverse(msg->data_list); 1.224 + else 1.225 + /* make sure data list is not NULL: */ 1.226 + msg->data_list = g_list_append(NULL, g_strdup("")); 1.227 1.228 - if(line1[0] == ' ' || line1[0] == '\t'){ 1.229 - /* continuation of 'folded' header: */ 1.230 - if(hdr){ 1.231 - hdr->header = g_strconcat(hdr->header, line1, NULL); 1.232 - } 1.233 + DEBUG(4) debugf("received %d lines of data (%d bytes)\n", line_cnt, data_size); 1.234 + /* we get here after we succesfully received the mail data */ 1.235 1.236 - }else if(line1[0] == '\n'){ 1.237 - /* an empty line marks end of headers */ 1.238 - in_headers = FALSE; 1.239 - }else{ 1.240 - /* in all other cases we expect another header */ 1.241 - if((hdr = get_header(line1))) 1.242 - msg->hdr_list = g_list_append(msg->hdr_list, hdr); 1.243 - else{ 1.244 - /* if get_header() returns NULL, no header was recognized, 1.245 - so this seems to be the first data line of a broken mailer 1.246 - which does not send an empty line after the headers */ 1.247 - in_headers = FALSE; 1.248 - msg->data_list = g_list_prepend(msg->data_list, g_strdup(line1)); 1.249 - } 1.250 - } 1.251 - }else{ 1.252 - msg->data_list = g_list_prepend(msg->data_list, g_strdup(line1)); 1.253 - data_size += strlen(line1); 1.254 - line_cnt++; 1.255 - } 1.256 - } 1.257 - } 1.258 + msg->data_size = data_size; 1.259 + msg->received_time = time(NULL); 1.260 1.261 - if(msg->data_list != NULL) 1.262 - msg->data_list = g_list_reverse(msg->data_list); 1.263 - else 1.264 - /* make sure data list is not NULL: */ 1.265 - msg->data_list = g_list_append(NULL, g_strdup("")); 1.266 - 1.267 - DEBUG(4) debugf("received %d lines of data (%d bytes)\n", 1.268 - line_cnt, data_size); 1.269 - /* we get here after we succesfully 1.270 - received the mail data */ 1.271 - 1.272 - msg->data_size = data_size; 1.273 - msg->received_time = time(NULL); 1.274 - 1.275 - return AERR_OK; 1.276 + return AERR_OK; 1.277 } 1.278 1.279 -accept_error accept_message_prepare(message *msg, guint flags) 1.280 +accept_error 1.281 +accept_message_prepare(message * msg, guint flags) 1.282 { 1.283 - struct passwd *passwd = NULL; 1.284 - GList *non_rcpt_list = NULL; 1.285 - time_t rec_time = time(NULL); 1.286 + struct passwd *passwd = NULL; 1.287 + GList *non_rcpt_list = NULL; 1.288 + time_t rec_time = time(NULL); 1.289 1.290 - DEBUG(5) debugf("accept_message_prepare()\n"); 1.291 + DEBUG(5) debugf("accept_message_prepare()\n"); 1.292 1.293 - /* create unique message id */ 1.294 - msg->uid = g_malloc(14); 1.295 + /* create unique message id */ 1.296 + msg->uid = g_malloc(14); 1.297 1.298 - string_base62(msg->uid, rec_time, 6); 1.299 - msg->uid[6] = '-'; 1.300 - string_base62(&(msg->uid[7]), getpid(), 3); 1.301 - msg->uid[10] = '-'; 1.302 - string_base62(&(msg->uid[11]), msg->transfer_id, 2); 1.303 - msg->uid[13] = 0; 1.304 + string_base62(msg->uid, rec_time, 6); 1.305 + msg->uid[6] = '-'; 1.306 + string_base62(&(msg->uid[7]), getpid(), 3); 1.307 + msg->uid[10] = '-'; 1.308 + string_base62(&(msg->uid[11]), msg->transfer_id, 2); 1.309 + msg->uid[13] = 0; 1.310 1.311 - /* if local, get password entry */ 1.312 - if(msg->received_host == NULL){ 1.313 - passwd = g_memdup(getpwuid(geteuid()), sizeof(struct passwd)); 1.314 - msg->ident = g_strdup(passwd->pw_name); 1.315 - } 1.316 + /* if local, get password entry */ 1.317 + if (msg->received_host == NULL) { 1.318 + passwd = g_memdup(getpwuid(geteuid()), sizeof(struct passwd)); 1.319 + msg->ident = g_strdup(passwd->pw_name); 1.320 + } 1.321 1.322 - /* set return path if local */ 1.323 - if(msg->return_path == NULL){ 1.324 + /* set return path if local */ 1.325 + if (msg->return_path == NULL) { 1.326 1.327 - if(msg->received_host == NULL){ 1.328 - gchar *path = g_strdup_printf("<%s@%s>", 1.329 - passwd->pw_name, conf.host_name); 1.330 - DEBUG(3) debugf("setting return_path for local accept: %s\n", path); 1.331 - msg->return_path = create_address(path, TRUE); 1.332 - g_free(path); 1.333 - } 1.334 - } 1.335 + if (msg->received_host == NULL) { 1.336 + gchar *path = g_strdup_printf("<%s@%s>", passwd->pw_name, conf.host_name); 1.337 + DEBUG(3) debugf("setting return_path for local accept: %s\n", path); 1.338 + msg->return_path = create_address(path, TRUE); 1.339 + g_free(path); 1.340 + } 1.341 + } 1.342 1.343 - /* -t option */ 1.344 - if(flags & ACC_DEL_RCPTS){ 1.345 - non_rcpt_list = msg->rcpt_list; 1.346 - msg->rcpt_list = NULL; 1.347 - } 1.348 + /* -t option */ 1.349 + if (flags & ACC_DEL_RCPTS) { 1.350 + non_rcpt_list = msg->rcpt_list; 1.351 + msg->rcpt_list = NULL; 1.352 + } 1.353 1.354 - /* scan headers */ 1.355 - { 1.356 - gboolean has_id = FALSE; 1.357 - gboolean has_date = FALSE; 1.358 - gboolean has_sender = FALSE; 1.359 - gboolean has_from = FALSE; 1.360 - gboolean has_rcpt = FALSE; 1.361 - gboolean has_to_or_cc = FALSE; 1.362 - GList *hdr_node, *hdr_node_next; 1.363 - header *hdr; 1.364 + /* scan headers */ 1.365 + { 1.366 + gboolean has_id = FALSE; 1.367 + gboolean has_date = FALSE; 1.368 + gboolean has_sender = FALSE; 1.369 + gboolean has_from = FALSE; 1.370 + gboolean has_rcpt = FALSE; 1.371 + gboolean has_to_or_cc = FALSE; 1.372 + GList *hdr_node, *hdr_node_next; 1.373 + header *hdr; 1.374 1.375 - for(hdr_node = g_list_first(msg->hdr_list); 1.376 - hdr_node != NULL; 1.377 - hdr_node = hdr_node_next){ 1.378 - hdr_node_next = g_list_next(hdr_node); 1.379 - hdr = ((header *)(hdr_node->data)); 1.380 - DEBUG(5) debugf("scanning headers: %s", hdr->header); 1.381 - switch(hdr->id){ 1.382 - case HEAD_MESSAGE_ID: 1.383 - has_id = TRUE; break; 1.384 - case HEAD_DATE: 1.385 - has_date = TRUE; break; 1.386 - case HEAD_FROM: 1.387 - has_from = TRUE; 1.388 - break; 1.389 - case HEAD_SENDER: 1.390 - has_sender = TRUE; 1.391 - break; 1.392 - case HEAD_TO: 1.393 - case HEAD_CC: 1.394 - case HEAD_BCC: 1.395 - has_rcpt = TRUE; 1.396 - if(flags & ACC_RCPT_FROM_HEAD){ 1.397 - DEBUG(5) debugf("hdr->value = %s\n", hdr->value); 1.398 - if(hdr->value){ 1.399 - msg->rcpt_list = 1.400 - addr_list_append_rfc822(msg->rcpt_list, hdr->value, conf.host_name); 1.401 - } 1.402 + for (hdr_node = g_list_first(msg->hdr_list); 1.403 + hdr_node != NULL; hdr_node = hdr_node_next) { 1.404 + hdr_node_next = g_list_next(hdr_node); 1.405 + hdr = ((header *) (hdr_node->data)); 1.406 + DEBUG(5) debugf("scanning headers: %s", hdr->header); 1.407 + switch (hdr->id) { 1.408 + case HEAD_MESSAGE_ID: 1.409 + has_id = TRUE; 1.410 + break; 1.411 + case HEAD_DATE: 1.412 + has_date = TRUE; 1.413 + break; 1.414 + case HEAD_FROM: 1.415 + has_from = TRUE; 1.416 + break; 1.417 + case HEAD_SENDER: 1.418 + has_sender = TRUE; 1.419 + break; 1.420 + case HEAD_TO: 1.421 + case HEAD_CC: 1.422 + case HEAD_BCC: 1.423 + has_rcpt = TRUE; 1.424 + if (flags & ACC_RCPT_FROM_HEAD) { 1.425 + DEBUG(5) debugf("hdr->value = %s\n", hdr->value); 1.426 + if (hdr->value) { 1.427 + msg->rcpt_list = addr_list_append_rfc822(msg->rcpt_list, hdr->value, conf.host_name); 1.428 + } 1.429 + } 1.430 + if ((flags & ACC_DEL_BCC) && (hdr->id == HEAD_BCC)) { 1.431 + DEBUG(3) debugf("removing 'Bcc' header\n"); 1.432 + msg->hdr_list = g_list_remove_link(msg->hdr_list, hdr_node); 1.433 + g_list_free_1(hdr_node); 1.434 + destroy_header(hdr); 1.435 + } else 1.436 + has_to_or_cc = TRUE; 1.437 + break; 1.438 + case HEAD_ENVELOPE_TO: 1.439 + if (flags & ACC_SAVE_ENVELOPE_TO) { 1.440 + DEBUG(3) debugf("creating 'X-Orig-Envelope-To' header\n"); 1.441 + msg->hdr_list = g_list_prepend(msg->hdr_list, create_header(HEAD_UNKNOWN, "X-Orig-Envelope-to: %s", hdr->value)); 1.442 + } 1.443 + DEBUG(3) debugf("removing 'Envelope-To' header\n"); 1.444 + msg->hdr_list = g_list_remove_link(msg->hdr_list, hdr_node); 1.445 + g_list_free_1(hdr_node); 1.446 + destroy_header(hdr); 1.447 + break; 1.448 + case HEAD_RETURN_PATH: 1.449 + if (flags & ACC_MAIL_FROM_HEAD) { 1.450 + /* usually POP3 accept */ 1.451 + msg->return_path = create_address_qualified(hdr->value, TRUE, msg->received_host); 1.452 + DEBUG(3) debugf("setting return_path to %s\n", addr_string(msg->return_path)); 1.453 + } 1.454 + DEBUG(3) debugf("removing 'Return-Path' header\n"); 1.455 + msg->hdr_list = g_list_remove_link(msg->hdr_list, hdr_node); 1.456 + g_list_free_1(hdr_node); 1.457 + destroy_header(hdr); 1.458 + break; 1.459 + default: 1.460 + break; /* make compiler happy */ 1.461 + } 1.462 + } 1.463 + 1.464 + if (msg->return_path == NULL) { 1.465 + /* this can happen for pop3 accept only and if no Return-path: header was given */ 1.466 + GList *hdr_list; 1.467 + header *hdr; 1.468 + 1.469 + DEBUG(3) debugf("return_path == NULL\n"); 1.470 + 1.471 + hdr_list = find_header(msg->hdr_list, HEAD_SENDER, NULL); 1.472 + if (!hdr_list) 1.473 + hdr_list = find_header(msg->hdr_list, HEAD_FROM, NULL); 1.474 + if (hdr_list) { 1.475 + gchar *addr; 1.476 + hdr = (header *) (g_list_first(hdr_list)->data); 1.477 + 1.478 + DEBUG(5) debugf("hdr->value = '%s'\n", hdr->value); 1.479 + 1.480 + addr = g_strdup(hdr->value); 1.481 + g_strchomp(addr); 1.482 + 1.483 + if ((msg->return_path = create_address_qualified(addr, FALSE, msg->received_host)) != NULL) { 1.484 + DEBUG(3) debugf("setting return_path to %s\n", addr_string(msg->return_path)); 1.485 + 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:")); 1.486 + } 1.487 + g_free(addr); 1.488 + } 1.489 + if (msg->return_path == NULL) { /* no Sender: or From: or create_address_qualified failed */ 1.490 + msg->return_path = create_address_qualified("postmaster", TRUE, conf.host_name); 1.491 + DEBUG(3) debugf("setting return_path to %s\n", addr_string(msg->return_path)); 1.492 + msg->hdr_list = g_list_append(msg->hdr_list, create_header(HEAD_UNKNOWN, "X-Warning: real return path is unkown\n")); 1.493 + } 1.494 + } 1.495 + 1.496 + if (flags & ACC_DEL_RCPTS) { 1.497 + GList *rcpt_node; 1.498 + foreach(non_rcpt_list, rcpt_node) { 1.499 + address *rcpt = (address *) (rcpt_node->data); 1.500 + GList *node; 1.501 + if ((node = g_list_find_custom(msg->rcpt_list, rcpt, _g_list_addr_isequal))) { 1.502 + DEBUG(3) debugf("removing rcpt address %s\n", addr_string(node->data)); 1.503 + msg->rcpt_list = g_list_remove_link(msg->rcpt_list, node); 1.504 + destroy_address((address *) (node->data)); 1.505 + g_list_free_1(node); 1.506 + } 1.507 + } 1.508 + } 1.509 + 1.510 + /* here we should have our recipients, fail if not: */ 1.511 + if (msg->rcpt_list == NULL) { 1.512 + logwrite(LOG_WARNING, "no recipients found in message\n"); 1.513 + return AERR_NORCPT; 1.514 + } 1.515 + 1.516 + if (!(has_sender || has_from)) { 1.517 + DEBUG(3) debugf("adding 'From' header\n"); 1.518 + msg->hdr_list = g_list_append(msg->hdr_list, 1.519 + msg->full_sender_name 1.520 + ? 1.521 + create_header(HEAD_FROM, 1.522 + "From: \"%s\" <%s@%s>\n", 1.523 + msg->full_sender_name, 1.524 + msg->return_path->local_part, 1.525 + msg->return_path-> 1.526 + domain) 1.527 + : 1.528 + create_header(HEAD_FROM, "From: <%s@%s>\n", 1.529 + msg->return_path->local_part, 1.530 + msg->return_path->domain) 1.531 + ); 1.532 + } 1.533 + if ((flags & ACC_HEAD_FROM_RCPT) && !has_rcpt) { 1.534 + GList *node; 1.535 + DEBUG(3) debugf("adding 'To' header(s)\n"); 1.536 + for (node = g_list_first(msg->rcpt_list); node; node = g_list_next(node)) { 1.537 + msg->hdr_list = g_list_append(msg->hdr_list, create_header(HEAD_TO, "To: %s\n", addr_string(msg-> return_path))); 1.538 + } 1.539 + } 1.540 + if ((flags & ACC_DEL_BCC) && !has_to_or_cc) { 1.541 + /* Bcc headers have been removed, and there are no remaining rcpt headers */ 1.542 + DEBUG(3) debugf("adding empty 'Bcc:' header\n"); 1.543 + msg->hdr_list = g_list_append(msg->hdr_list, create_header(HEAD_BCC, "Bcc:\n")); 1.544 + } 1.545 + if (!has_date) { 1.546 + DEBUG(3) debugf("adding 'Date:' header\n"); 1.547 + msg->hdr_list = g_list_append(msg->hdr_list, create_header(HEAD_DATE, "Date: %s\n", rec_timestamp())); 1.548 + } 1.549 + if (!has_id) { 1.550 + DEBUG(3) debugf("adding 'Message-ID:' header\n"); 1.551 + msg->hdr_list = g_list_append(msg->hdr_list, create_header(HEAD_MESSAGE_ID, "Message-ID: <%s@%s>\n", msg->uid, conf.host_name)); 1.552 + } 1.553 } 1.554 - if((flags & ACC_DEL_BCC) && (hdr->id == HEAD_BCC)){ 1.555 - DEBUG(3) debugf("removing 'Bcc' header\n"); 1.556 - msg->hdr_list = g_list_remove_link(msg->hdr_list, hdr_node); 1.557 - g_list_free_1(hdr_node); 1.558 - destroy_header(hdr); 1.559 - }else 1.560 - has_to_or_cc = TRUE; 1.561 - break; 1.562 - case HEAD_ENVELOPE_TO: 1.563 - if(flags & ACC_SAVE_ENVELOPE_TO){ 1.564 - DEBUG(3) debugf("creating 'X-Orig-Envelope-To' header\n"); 1.565 - msg->hdr_list = 1.566 - g_list_prepend(msg->hdr_list, 1.567 - create_header(HEAD_UNKNOWN, 1.568 - "X-Orig-Envelope-to: %s", hdr->value)); 1.569 + 1.570 + /* Received header: */ 1.571 + /* At this point because we have to know the rcpts for the 'for' part */ 1.572 + if (!(flags & ACC_NO_RECVD_HDR)) { 1.573 + gchar *for_string = NULL; 1.574 + header *hdr = NULL; 1.575 + 1.576 + DEBUG(3) debugf("adding 'Received:' header\n"); 1.577 + 1.578 + if (g_list_length(msg->rcpt_list) == 1) { 1.579 + address *addr = (address *) (g_list_first(msg->rcpt_list)->data); 1.580 + for_string = g_strdup_printf(" for %s", addr_string(addr)); 1.581 + } 1.582 + 1.583 + if (msg->received_host == NULL) { 1.584 + hdr = create_header(HEAD_RECEIVED, 1.585 + "Received: from %s by %s" 1.586 + " with %s (%s %s) id %s%s;" 1.587 + " %s\n", 1.588 + passwd->pw_name, conf.host_name, 1.589 + prot_names[msg->received_prot], 1.590 + PACKAGE, VERSION, 1.591 + msg->uid, for_string ? for_string : "", 1.592 + rec_timestamp()); 1.593 + } else { 1.594 +#ifdef ENABLE_IDENT 1.595 + DEBUG(5) debugf("adding 'Received:' header (5)\n"); 1.596 + hdr = create_header(HEAD_RECEIVED, 1.597 + "Received: from %s (ident=%s) by %s" 1.598 + " with %s (%s %s) id %s%s;" 1.599 + " %s\n", 1.600 + msg->received_host, 1.601 + msg->ident ? msg->ident : "unknown", 1.602 + conf.host_name, 1.603 + prot_names[msg->received_prot], 1.604 + PACKAGE, VERSION, 1.605 + msg->uid, for_string ? for_string : "", 1.606 + rec_timestamp()); 1.607 +#else 1.608 + hdr = create_header(HEAD_RECEIVED, 1.609 + "Received: from %s by %s" 1.610 + " with %s (%s %s) id %s%s;" 1.611 + " %s\n", 1.612 + msg->received_host, 1.613 + conf.host_name, 1.614 + prot_names[msg->received_prot], 1.615 + PACKAGE, VERSION, 1.616 + msg->uid, for_string ? for_string : "", 1.617 + rec_timestamp()); 1.618 +#endif 1.619 + } 1.620 + header_fold(hdr); 1.621 + msg->hdr_list = g_list_prepend(msg->hdr_list, hdr); 1.622 + 1.623 + if (for_string) 1.624 + g_free(for_string); 1.625 } 1.626 - DEBUG(3) debugf("removing 'Envelope-To' header\n"); 1.627 - msg->hdr_list = g_list_remove_link(msg->hdr_list, hdr_node); 1.628 - g_list_free_1(hdr_node); 1.629 - destroy_header(hdr); 1.630 - break; 1.631 - case HEAD_RETURN_PATH: 1.632 - if(flags & ACC_MAIL_FROM_HEAD){ 1.633 - /* usually POP3 accept */ 1.634 - msg->return_path = create_address_qualified(hdr->value, TRUE, msg->received_host); 1.635 - DEBUG(3) debugf("setting return_path to %s\n", 1.636 - addr_string(msg->return_path)); 1.637 - } 1.638 - DEBUG(3) debugf("removing 'Return-Path' header\n"); 1.639 - msg->hdr_list = g_list_remove_link(msg->hdr_list, hdr_node); 1.640 - g_list_free_1(hdr_node); 1.641 - destroy_header(hdr); 1.642 - break; 1.643 - default: 1.644 - break; /* make compiler happy */ 1.645 - } 1.646 - } 1.647 1.648 - if(msg->return_path == NULL){ 1.649 - /* this can happen for pop3 accept only 1.650 - and if no Return-path: header was given */ 1.651 - GList *hdr_list; 1.652 - header *hdr; 1.653 - 1.654 - DEBUG(3) debugf("return_path == NULL\n"); 1.655 - 1.656 - hdr_list = find_header(msg->hdr_list, HEAD_SENDER, NULL); 1.657 - if(!hdr_list) hdr_list = find_header(msg->hdr_list, HEAD_FROM, NULL); 1.658 - if(hdr_list){ 1.659 - gchar *addr; 1.660 - hdr = (header *)(g_list_first(hdr_list)->data); 1.661 - 1.662 - DEBUG(5) debugf("hdr->value = '%s'\n", hdr->value); 1.663 - 1.664 - addr = g_strdup(hdr->value); 1.665 - g_strchomp(addr); 1.666 - 1.667 - if((msg->return_path = 1.668 - create_address_qualified(addr, FALSE, msg->received_host)) 1.669 - != NULL){ 1.670 - DEBUG(3) debugf("setting return_path to %s\n", addr_string(msg->return_path)); 1.671 - msg->hdr_list = 1.672 - g_list_append(msg->hdr_list, 1.673 - create_header(HEAD_UNKNOWN, 1.674 - "X-Warning: return path set from %s address\n", 1.675 - hdr->id == HEAD_SENDER ? "Sender:" : "From:")); 1.676 - } 1.677 - g_free(addr); 1.678 - } 1.679 - if(msg->return_path == NULL){ /* no Sender: or From: or create_address_qualified failed */ 1.680 - msg->return_path = create_address_qualified("postmaster", TRUE, conf.host_name); 1.681 - DEBUG(3) debugf("setting return_path to %s\n", addr_string(msg->return_path)); 1.682 - msg->hdr_list = 1.683 - g_list_append(msg->hdr_list, 1.684 - create_header(HEAD_UNKNOWN, 1.685 - "X-Warning: real return path is unkown\n")); 1.686 - } 1.687 - } 1.688 - 1.689 - if(flags & ACC_DEL_RCPTS){ 1.690 - GList *rcpt_node; 1.691 - foreach(non_rcpt_list, rcpt_node){ 1.692 - address *rcpt = (address *)(rcpt_node->data); 1.693 - GList *node; 1.694 - if((node = g_list_find_custom(msg->rcpt_list, rcpt, 1.695 - _g_list_addr_isequal))){ 1.696 - DEBUG(3) debugf("removing rcpt address %s\n", addr_string(node->data)); 1.697 - 1.698 - msg->rcpt_list = g_list_remove_link(msg->rcpt_list, node); 1.699 - destroy_address((address *)(node->data)); 1.700 - g_list_free_1(node); 1.701 - } 1.702 - } 1.703 - } 1.704 - 1.705 - /* here we should have our recipients, fail if not: */ 1.706 - if(msg->rcpt_list == NULL){ 1.707 - logwrite(LOG_WARNING, "no recipients found in message\n"); 1.708 - return AERR_NORCPT; 1.709 - } 1.710 - 1.711 - if(!(has_sender || has_from)){ 1.712 - DEBUG(3) debugf("adding 'From' header\n"); 1.713 - msg->hdr_list = 1.714 - g_list_append(msg->hdr_list, 1.715 - msg->full_sender_name ? 1.716 - create_header(HEAD_FROM, "From: \"%s\" <%s@%s>\n", 1.717 - msg->full_sender_name, 1.718 - msg->return_path->local_part, 1.719 - msg->return_path->domain) : 1.720 - create_header(HEAD_FROM, "From: <%s@%s>\n", 1.721 - msg->return_path->local_part, 1.722 - msg->return_path->domain) 1.723 - ); 1.724 - } 1.725 - if((flags & ACC_HEAD_FROM_RCPT) && !has_rcpt){ 1.726 - GList *node; 1.727 - DEBUG(3) debugf("adding 'To' header(s)\n"); 1.728 - for(node = g_list_first(msg->rcpt_list); 1.729 - node; 1.730 - node = g_list_next(node)){ 1.731 - msg->hdr_list = 1.732 - g_list_append(msg->hdr_list, 1.733 - create_header(HEAD_TO, "To: %s\n", addr_string(msg->return_path))); 1.734 - } 1.735 - } 1.736 - if((flags & ACC_DEL_BCC) && !has_to_or_cc){ 1.737 - /* Bcc headers have been removed, and there are no remaining rcpt headers */ 1.738 - DEBUG(3) debugf("adding empty 'Bcc:' header\n"); 1.739 - msg->hdr_list = 1.740 - g_list_append(msg->hdr_list, create_header(HEAD_BCC, "Bcc:\n")); 1.741 - } 1.742 - if(!has_date){ 1.743 - DEBUG(3) debugf("adding 'Date:' header\n"); 1.744 - msg->hdr_list = 1.745 - g_list_append(msg->hdr_list, 1.746 - create_header(HEAD_DATE, "Date: %s\n", rec_timestamp())); 1.747 - } 1.748 - if(!has_id){ 1.749 - DEBUG(3) debugf("adding 'Message-ID:' header\n"); 1.750 - msg->hdr_list = 1.751 - g_list_append(msg->hdr_list, 1.752 - create_header(HEAD_MESSAGE_ID, 1.753 - "Message-ID: <%s@%s>\n", 1.754 - msg->uid, conf.host_name)); 1.755 - } 1.756 - } 1.757 - 1.758 - /* Received header: */ 1.759 - /* At this point because we have to know the rcpts for the 'for' part */ 1.760 - if(!(flags & ACC_NO_RECVD_HDR)){ 1.761 - gchar *for_string = NULL; 1.762 - header *hdr = NULL; 1.763 - 1.764 - DEBUG(3) debugf("adding 'Received:' header\n"); 1.765 - 1.766 - if(g_list_length(msg->rcpt_list) == 1){ 1.767 - address *addr = (address *)(g_list_first(msg->rcpt_list)->data); 1.768 - for_string = g_strdup_printf(" for %s", addr_string(addr)); 1.769 - } 1.770 - 1.771 - if(msg->received_host == NULL){ 1.772 - hdr = create_header(HEAD_RECEIVED, 1.773 - "Received: from %s by %s" 1.774 - " with %s (%s %s) id %s%s;" 1.775 - " %s\n", 1.776 - passwd->pw_name, conf.host_name, 1.777 - prot_names[msg->received_prot], 1.778 - PACKAGE, VERSION, 1.779 - msg->uid, for_string ? for_string : "", 1.780 - rec_timestamp()); 1.781 - }else{ 1.782 -#ifdef ENABLE_IDENT 1.783 - DEBUG(5) debugf("adding 'Received:' header (5)\n"); 1.784 - hdr = create_header(HEAD_RECEIVED, 1.785 - "Received: from %s (ident=%s) by %s" 1.786 - " with %s (%s %s) id %s%s;" 1.787 - " %s\n", 1.788 - msg->received_host, 1.789 - msg->ident ? msg->ident : "unknown", 1.790 - conf.host_name, 1.791 - prot_names[msg->received_prot], 1.792 - PACKAGE, VERSION, 1.793 - msg->uid, for_string ? for_string : "", 1.794 - rec_timestamp()); 1.795 -#else 1.796 - hdr = create_header(HEAD_RECEIVED, 1.797 - "Received: from %s by %s" 1.798 - " with %s (%s %s) id %s%s;" 1.799 - " %s\n", 1.800 - msg->received_host, 1.801 - conf.host_name, 1.802 - prot_names[msg->received_prot], 1.803 - PACKAGE, VERSION, 1.804 - msg->uid, for_string ? for_string : "", 1.805 - rec_timestamp()); 1.806 -#endif 1.807 - } 1.808 - header_fold(hdr); 1.809 - msg->hdr_list = g_list_prepend(msg->hdr_list, hdr); 1.810 - 1.811 - if(for_string) g_free(for_string); 1.812 - } 1.813 - 1.814 - /* write message to spool: */ 1.815 - /* accept is no longer responsible for this 1.816 - if(!spool_write(msg, TRUE)) 1.817 - return AERR_NOSPOOL; 1.818 - */ 1.819 - return AERR_OK; 1.820 + /* write message to spool: */ 1.821 + /* accept is no longer responsible for this 1.822 + if(!spool_write(msg, TRUE)) 1.823 + return AERR_NOSPOOL; 1.824 + */ 1.825 + return AERR_OK; 1.826 } 1.827 1.828 -accept_error accept_message(FILE *in, message *msg, guint flags) 1.829 +accept_error 1.830 +accept_message(FILE * in, message * msg, guint flags) 1.831 { 1.832 - accept_error err; 1.833 + accept_error err; 1.834 1.835 - err = accept_message_stream(in, msg, flags); 1.836 - if(err == AERR_OK) 1.837 - err = accept_message_prepare(msg, flags); 1.838 + err = accept_message_stream(in, msg, flags); 1.839 + if (err == AERR_OK) 1.840 + err = accept_message_prepare(msg, flags); 1.841 1.842 - return err; 1.843 + return err; 1.844 } 1.845 -