masqmail
changeset 298:6281ff92cb86
refactoring
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Thu, 09 Dec 2010 13:20:14 -0300 |
parents | b639e97feda3 |
children | ca2d11aec2a3 |
files | src/accept.c |
diffstat | 1 files changed, 37 insertions(+), 39 deletions(-) [+] |
line diff
1.1 --- a/src/accept.c Thu Dec 09 11:41:49 2010 -0300 1.2 +++ b/src/accept.c Thu Dec 09 13:20:14 2010 -0300 1.3 @@ -191,26 +191,23 @@ 1.4 1.5 /* create unique message id */ 1.6 msg->uid = g_malloc(14); 1.7 - 1.8 string_base62(msg->uid, rec_time, 6); 1.9 msg->uid[6] = '-'; 1.10 - string_base62(&(msg->uid[7]), getpid(), 3); 1.11 + string_base62(msg->uid + 7, getpid(), 3); 1.12 msg->uid[10] = '-'; 1.13 - string_base62(&(msg->uid[11]), msg->transfer_id, 2); 1.14 - msg->uid[13] = 0; 1.15 + string_base62(msg->uid + 11, msg->transfer_id, 2); 1.16 + msg->uid[13] = '\0'; 1.17 1.18 - /* if local, get password entry */ 1.19 - if (msg->received_host == NULL) { 1.20 + /* if local, get password entry and set return path if missing */ 1.21 + if (!msg->received_host) { 1.22 passwd = g_memdup(getpwuid(geteuid()), sizeof(struct passwd)); 1.23 msg->ident = g_strdup(passwd->pw_name); 1.24 - } 1.25 - 1.26 - /* set return path if local */ 1.27 - if (msg->return_path == NULL && msg->received_host == NULL) { 1.28 - gchar *path = g_strdup_printf("<%s@%s>", passwd->pw_name, conf.host_name); 1.29 - DEBUG(3) debugf("setting return_path for local accept: %s\n", path); 1.30 - msg->return_path = create_address(path, TRUE); 1.31 - g_free(path); 1.32 + if (!msg->return_path) { 1.33 + gchar *path = g_strdup_printf("<%s@%s>", passwd->pw_name, conf.host_name); 1.34 + DEBUG(3) debugf("setting return_path for local accept: %s\n", path); 1.35 + msg->return_path = create_address(path, TRUE); 1.36 + g_free(path); 1.37 + } 1.38 } 1.39 1.40 /* scan headers */ 1.41 @@ -224,7 +221,8 @@ 1.42 header *hdr; 1.43 1.44 for (hdr_node = g_list_first(msg->hdr_list); 1.45 - hdr_node != NULL; hdr_node = hdr_node_next) { 1.46 + hdr_node; 1.47 + hdr_node = hdr_node_next) { 1.48 hdr_node_next = g_list_next(hdr_node); 1.49 hdr = ((header *) (hdr_node->data)); 1.50 DEBUG(5) debugf("scanning headers: %s", hdr->header); 1.51 @@ -287,16 +285,20 @@ 1.52 } 1.53 } 1.54 1.55 - if (msg->return_path == NULL) { 1.56 - /* this can happen for pop3 accept only and if no Return-path: header was given */ 1.57 + if (!msg->return_path) { 1.58 + /* TODO: do we still need this as we don't fetch 1.59 + mail anymore? */ 1.60 + /* this can happen for pop3 accept only and if no 1.61 + Return-Path: header was given */ 1.62 GList *hdr_list; 1.63 header *hdr; 1.64 1.65 DEBUG(3) debugf("return_path == NULL\n"); 1.66 1.67 hdr_list = find_header(msg->hdr_list, HEAD_SENDER, NULL); 1.68 - if (!hdr_list) 1.69 + if (!hdr_list) { 1.70 hdr_list = find_header(msg->hdr_list, HEAD_FROM, NULL); 1.71 + } 1.72 if (hdr_list) { 1.73 gchar *addr; 1.74 hdr = (header *) (g_list_first(hdr_list)->data); 1.75 @@ -306,19 +308,19 @@ 1.76 addr = g_strdup(hdr->value); 1.77 g_strchomp(addr); 1.78 1.79 - if ((msg->return_path = create_address_qualified(addr, FALSE, msg->received_host)) != NULL) { 1.80 + msg->return_path = create_address_qualified(addr, FALSE, msg->received_host)); 1.81 + if (msg->return_path) { 1.82 DEBUG(3) debugf("setting return_path to %s\n", addr_string(msg->return_path)); 1.83 - msg->hdr_list = g_list_append(msg->hdr_list, create_header(HEAD_UNKNOWN, 1.84 - "X-Warning: return path set from %s address\n", 1.85 - hdr->id == HEAD_SENDER ? "Sender:" : "From:")); 1.86 + 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.87 } 1.88 g_free(addr); 1.89 } 1.90 - if (msg->return_path == NULL) { /* no Sender: or From: or create_address_qualified failed */ 1.91 + if (!msg->return_path) { 1.92 + /* no Sender: or From: or 1.93 + create_address_qualified failed */ 1.94 msg->return_path = create_address_qualified("postmaster", TRUE, conf.host_name); 1.95 DEBUG(3) debugf("setting return_path to %s\n", addr_string(msg->return_path)); 1.96 - msg->hdr_list = g_list_append(msg->hdr_list, create_header(HEAD_UNKNOWN, 1.97 - "X-Warning: real return path is unknown\n")); 1.98 + msg->hdr_list = g_list_append(msg->hdr_list, create_header(HEAD_UNKNOWN, "X-Warning: real return path is unknown\n")); 1.99 } 1.100 } 1.101 1.102 @@ -328,17 +330,13 @@ 1.103 return AERR_NORCPT; 1.104 } 1.105 1.106 - if (!(has_sender || has_from)) { 1.107 - DEBUG(3) debugf("adding 'From' header\n"); 1.108 - msg->hdr_list = g_list_append(msg->hdr_list, 1.109 - msg->full_sender_name 1.110 - ? 1.111 - create_header(HEAD_FROM, "From: \"%s\" <%s@%s>\n", msg->full_sender_name, 1.112 - msg->return_path->local_part, msg->return_path->domain) 1.113 - : 1.114 - create_header(HEAD_FROM, "From: <%s@%s>\n", 1.115 - msg->return_path->local_part, msg->return_path->domain) 1.116 - ); 1.117 + if (!has_sender && !has_from)) { 1.118 + DEBUG(3) debugf("adding 'From:' header\n"); 1.119 + if (msg->full_sender_name) { 1.120 + 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)); 1.121 + } else { 1.122 + 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)); 1.123 + } 1.124 } 1.125 if (!has_to_or_cc) { 1.126 DEBUG(3) debugf("no To: or Cc: header, hence adding `To: undisclosed recipients:;'\n"); 1.127 @@ -350,13 +348,13 @@ 1.128 } 1.129 if (!has_id) { 1.130 DEBUG(3) debugf("adding 'Message-ID:' header\n"); 1.131 - msg->hdr_list = g_list_append(msg->hdr_list, 1.132 - create_header(HEAD_MESSAGE_ID, "Message-ID: <%s@%s>\n", msg->uid, conf.host_name)); 1.133 + 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.134 } 1.135 } 1.136 1.137 /* Received header: */ 1.138 /* At this point because we have to know the rcpts for the 'for' part */ 1.139 + /* The `for' part will only be used if exactly one rcpt is present. */ 1.140 gchar *for_string = NULL; 1.141 header *hdr = NULL; 1.142 1.143 @@ -364,7 +362,7 @@ 1.144 1.145 if (g_list_length(msg->rcpt_list) == 1) { 1.146 address *addr = (address *) (g_list_first(msg->rcpt_list)->data); 1.147 - for_string = g_strdup_printf(" for %s", addr_string(addr)); 1.148 + for_string = g_strdup_printf("\n\tfor %s", addr_string(addr)); 1.149 } 1.150 1.151 if (!msg->received_host) {