Mercurial > masqmail
comparison src/accept.c @ 270:0c44b239c7fe
refactoring in the small
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Fri, 03 Dec 2010 13:02:45 -0300 |
parents | fd1d77e5a5da |
children | 1405012509e3 |
comparison
equal
deleted
inserted
replaced
269:fd1d77e5a5da | 270:0c44b239c7fe |
---|---|
46 { | 46 { |
47 address *addr1 = (address *) a; | 47 address *addr1 = (address *) a; |
48 address *addr2 = (address *) b; | 48 address *addr2 = (address *) b; |
49 int ret; | 49 int ret; |
50 | 50 |
51 if ((ret = strcasecmp(addr1->domain, addr2->domain)) == 0) | 51 if ((ret = strcasecmp(addr1->domain, addr2->domain)) == 0) { |
52 return strcmp(addr1->local_part, addr2->local_part); | 52 return strcmp(addr1->local_part, addr2->local_part); |
53 else | 53 } |
54 return ret; | 54 return ret; |
55 } | 55 } |
56 | 56 |
57 /* accept message from anywhere. | 57 /* accept message from anywhere. |
58 A locally originating message is indicated by msg->recieved_host == NULL | 58 A locally originating message is indicated by msg->recieved_host == NULL |
59 | 59 |
86 break; | 86 break; |
87 } | 87 } |
88 line1++; | 88 line1++; |
89 } | 89 } |
90 | 90 |
91 if (len <= 0) { | 91 if ((len == -1) && (flags & (ACC_DOT_IGNORE | ACC_NODOT_RELAX))) { |
92 if ((len == -1) && (flags & (ACC_DOT_IGNORE | ACC_NODOT_RELAX))) { | 92 /* we got an EOF, and the last line was not terminated by a CR */ |
93 /* we got an EOF, and the last line was not terminated by a CR */ | 93 gint len1 = strlen(line1); |
94 gint len1 = strlen(line1); | 94 if (len1 > 0) { /* == 0 is 'normal' (EOF after a CR) */ |
95 if (len1 > 0) { /* == 0 is 'normal' (EOF after a CR) */ | 95 if (line1[len1 - 1] != '\n') { /* some mail clients allow unterminated lines */ |
96 if (line1[len1 - 1] != '\n') { /* some mail clients allow unterminated lines */ | 96 line1[len1] = '\n'; |
97 line1[len1] = '\n'; | 97 line1[len1 + 1] = '\0'; |
98 line1[len1 + 1] = '\0'; | 98 msg->data_list = g_list_prepend(msg->data_list, g_strdup(line1)); |
99 msg->data_list = g_list_prepend(msg->data_list, g_strdup(line1)); | 99 data_size += strlen(line1); |
100 data_size += strlen(line1); | 100 line_cnt++; |
101 line_cnt++; | 101 } |
102 } | 102 } |
103 } | 103 break; |
104 break; | 104 |
105 } else if (len == -1) { | |
106 g_free(line); | |
107 return AERR_EOF; | |
108 | |
109 } else if (len == -2) { | |
110 /* should not happen any more */ | |
111 g_free(line); | |
112 return AERR_OVERFLOW; | |
113 | |
114 } else if (len == -3) { | |
115 g_free(line); | |
116 return AERR_TIMEOUT; | |
117 | |
118 } else if (len <= 0) { | |
119 /* does not happen */ | |
120 g_free(line); | |
121 DEBUG(5) debugf("read_sockline returned %d\n", len); | |
122 return AERR_UNKNOWN; | |
123 | |
124 } | |
125 | |
126 if (in_headers) { | |
127 | |
128 /* some pop servers send the 'From ' line, skip it: */ | |
129 if (!msg->hdr_list && strncmp(line1, "From ", 5) == 0) { | |
130 continue; | |
131 } | |
132 | |
133 if (line1[0] == ' ' || line1[0] == '\t') { | |
134 /* continuation of 'folded' header: */ | |
135 if (hdr) { | |
136 hdr->header = g_strconcat(hdr->header, line1, NULL); | |
137 } | |
138 | |
139 } else if (line1[0] == '\n') { | |
140 /* an empty line marks end of headers */ | |
141 in_headers = FALSE; | |
105 } else { | 142 } else { |
106 g_free(line); | 143 /* in all other cases we expect another header */ |
107 if (len == -1) { | 144 if ((hdr = get_header(line1))) { |
108 return AERR_EOF; | 145 msg->hdr_list = g_list_append(msg->hdr_list, hdr); |
109 } else if (len == -2) { | |
110 /* should not happen any more */ | |
111 return AERR_OVERFLOW; | |
112 } else if (len == -3) { | |
113 return AERR_TIMEOUT; | |
114 } else { | 146 } else { |
115 /* does not happen */ | 147 /* if get_header() returns NULL, no header was recognized, |
116 DEBUG(5) debugf("read_sockline returned %d\n", len); | 148 so this seems to be the first data line of a broken mailer |
117 return AERR_UNKNOWN; | 149 which does not send an empty line after the headers */ |
150 in_headers = FALSE; | |
151 msg->data_list = g_list_prepend(msg->data_list, g_strdup(line1)); | |
118 } | 152 } |
119 } | 153 } |
120 } else { | 154 } else { |
121 if (in_headers) { | 155 /* message body */ |
122 | 156 msg->data_list = g_list_prepend(msg->data_list, g_strdup(line1)); |
123 /* some pop servers send the 'From ' line, skip it: */ | 157 data_size += strlen(line1); |
124 if (msg->hdr_list == NULL) | 158 line_cnt++; |
125 if (strncmp(line1, "From ", 5) == 0) | 159 } |
126 continue; | 160 |
127 | |
128 if (line1[0] == ' ' || line1[0] == '\t') { | |
129 /* continuation of 'folded' header: */ | |
130 if (hdr) { | |
131 hdr->header = g_strconcat(hdr->header, line1, NULL); | |
132 } | |
133 | |
134 } else if (line1[0] == '\n') { | |
135 /* an empty line marks end of headers */ | |
136 in_headers = FALSE; | |
137 } else { | |
138 /* in all other cases we expect another header */ | |
139 if ((hdr = get_header(line1))) | |
140 msg->hdr_list = g_list_append(msg->hdr_list, hdr); | |
141 else { | |
142 /* if get_header() returns NULL, no header was recognized, | |
143 so this seems to be the first data line of a broken mailer | |
144 which does not send an empty line after the headers */ | |
145 in_headers = FALSE; | |
146 msg->data_list = g_list_prepend(msg->data_list, g_strdup(line1)); | |
147 } | |
148 } | |
149 } else { | |
150 msg->data_list = g_list_prepend(msg->data_list, g_strdup(line1)); | |
151 data_size += strlen(line1); | |
152 line_cnt++; | |
153 } | |
154 } | |
155 if (conf.max_msg_size && (data_size > conf.max_msg_size)) { | 161 if (conf.max_msg_size && (data_size > conf.max_msg_size)) { |
156 DEBUG(4) debugf("accept_message_stream(): " | 162 DEBUG(4) debugf("accept_message_stream(): " |
157 "received %d bytes (conf.max_msg_size=%d)\n", | 163 "received %d bytes (conf.max_msg_size=%d)\n", |
158 data_size, conf.max_msg_size); | 164 data_size, conf.max_msg_size); |
159 return AERR_SIZE; | 165 return AERR_SIZE; |
160 } | 166 } |
161 | 167 |
162 } | 168 } |
163 | 169 |
164 if (msg->data_list != NULL) | 170 DEBUG(4) debugf("received %d lines of data (%d bytes)\n", line_cnt, data_size); |
165 msg->data_list = g_list_reverse(msg->data_list); | 171 |
166 else | 172 if (!msg->data_list) { |
167 /* make sure data list is not NULL: */ | 173 /* make sure data list is not NULL: */ |
168 msg->data_list = g_list_append(NULL, g_strdup("")); | 174 msg->data_list = g_list_append(NULL, g_strdup("")); |
169 | 175 } |
170 DEBUG(4) debugf("received %d lines of data (%d bytes)\n", line_cnt, data_size); | 176 msg->data_list = g_list_reverse(msg->data_list); |
177 | |
171 /* we get here after we succesfully received the mail data */ | 178 /* we get here after we succesfully received the mail data */ |
172 | 179 |
173 msg->data_size = data_size; | 180 msg->data_size = data_size; |
174 msg->received_time = time(NULL); | 181 msg->received_time = time(NULL); |
175 | 182 |
419 accept_message(FILE * in, message * msg, guint flags) | 426 accept_message(FILE * in, message * msg, guint flags) |
420 { | 427 { |
421 accept_error err; | 428 accept_error err; |
422 | 429 |
423 err = accept_message_stream(in, msg, flags); | 430 err = accept_message_stream(in, msg, flags); |
424 if (err == AERR_OK) | 431 if (err == AERR_OK) { |
425 err = accept_message_prepare(msg, flags); | 432 err = accept_message_prepare(msg, flags); |
433 } | |
426 | 434 |
427 return err; | 435 return err; |
428 } | 436 } |