masqmail
diff src/parse.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 | f671821d8222 |
line diff
1.1 --- a/src/parse.c Mon Oct 27 16:21:27 2008 +0100 1.2 +++ b/src/parse.c Mon Oct 27 16:23:10 2008 +0100 1.3 @@ -33,320 +33,315 @@ 1.4 1.5 char *parse_error = NULL; 1.6 1.7 -static 1.8 -gchar *skip_comment(gchar *p) 1.9 +static gchar* 1.10 +skip_comment(gchar * p) 1.11 { 1.12 1.13 #ifdef PARSE_TEST 1.14 - g_print("skip_comment: %s\n", p); 1.15 + g_print("skip_comment: %s\n", p); 1.16 #endif 1.17 1.18 - p++; 1.19 - while(*p && *p != ')'){ 1.20 - p++; 1.21 - if(*p == '(') 1.22 - p = skip_comment(p); 1.23 - } 1.24 - p++; 1.25 + p++; 1.26 + while (*p && *p != ')') { 1.27 + p++; 1.28 + if (*p == '(') 1.29 + p = skip_comment(p); 1.30 + } 1.31 + p++; 1.32 1.33 - return p; 1.34 + return p; 1.35 } 1.36 1.37 -static 1.38 -gboolean read_word(gchar *p, gchar **b, gchar **e) 1.39 +static gboolean 1.40 +read_word(gchar * p, gchar ** b, gchar ** e) 1.41 { 1.42 #ifdef PARSE_TEST 1.43 - g_print("read_word: %s\n", p); 1.44 + g_print("read_word: %s\n", p); 1.45 #endif 1.46 - /* eat leading spaces */ 1.47 - while(*p && isspace(*p)) p++; 1.48 - 1.49 - *b = p; 1.50 - /* b = &p;*/ 1.51 - if(*p == '\"'){ 1.52 - /* quoted-string */ 1.53 - p++; 1.54 - while(*p && (*p != '\"')) p++; 1.55 - p++; 1.56 - }else{ 1.57 - /* atom */ 1.58 - while(*p && !strchr(specials, *p) && !iscntrl(*p) && !isspace(*p)) 1.59 - p++; 1.60 - } 1.61 - *e = p; 1.62 - return TRUE; 1.63 + /* eat leading spaces */ 1.64 + while (*p && isspace(*p)) 1.65 + p++; 1.66 + 1.67 + *b = p; 1.68 + /* b = &p; */ 1.69 + if (*p == '\"') { 1.70 + /* quoted-string */ 1.71 + p++; 1.72 + while (*p && (*p != '\"')) 1.73 + p++; 1.74 + p++; 1.75 + } else { 1.76 + /* atom */ 1.77 + while (*p && !strchr(specials, *p) && !iscntrl(*p) && !isspace(*p)) 1.78 + p++; 1.79 + } 1.80 + *e = p; 1.81 + return TRUE; 1.82 } 1.83 1.84 -static 1.85 -gboolean read_word_with_dots(gchar *p, gchar **b, gchar **e) 1.86 +static gboolean 1.87 +read_word_with_dots(gchar * p, gchar ** b, gchar ** e) 1.88 { 1.89 - gchar *b0 = p; 1.90 + gchar *b0 = p; 1.91 1.92 #ifdef PARSE_TEST 1.93 - g_print("read_word_with_dots: %s\n", p); 1.94 + g_print("read_word_with_dots: %s\n", p); 1.95 #endif 1.96 - while(TRUE){ 1.97 - if(!read_word(p, b, e)) 1.98 - return FALSE; 1.99 - p = *e; 1.100 - if(*p != '.') break; 1.101 - p++; 1.102 - } 1.103 - *b = b0; 1.104 - *e = p; 1.105 - return TRUE; 1.106 + while (TRUE) { 1.107 + if (!read_word(p, b, e)) 1.108 + return FALSE; 1.109 + p = *e; 1.110 + if (*p != '.') 1.111 + break; 1.112 + p++; 1.113 + } 1.114 + *b = b0; 1.115 + *e = p; 1.116 + return TRUE; 1.117 } 1.118 1.119 -static 1.120 -gboolean read_domain(gchar *p, gchar **b, gchar **e) 1.121 +static gboolean 1.122 +read_domain(gchar * p, gchar ** b, gchar ** e) 1.123 { 1.124 #ifdef PARSE_TEST 1.125 - g_print("read_domain: %s\n", p); 1.126 + g_print("read_domain: %s\n", p); 1.127 #endif 1.128 - *b = p; 1.129 - if(*p != '['){ 1.130 - while(isalnum(*p) || (*p == '-') || (*p == '.')) 1.131 - p++; 1.132 - }else{ 1.133 - p++; 1.134 - while(isalpha(*p) || (*p == '.')) 1.135 - p++; 1.136 - if(*p != ']'){ 1.137 - parse_error = 1.138 - g_strdup_printf("']' expected at end of literal address %s", *b); 1.139 - return FALSE; 1.140 - } 1.141 - p++; 1.142 - } 1.143 - *e = p; 1.144 - return TRUE; 1.145 + *b = p; 1.146 + if (*p != '[') { 1.147 + while (isalnum(*p) || (*p == '-') || (*p == '.')) 1.148 + p++; 1.149 + } else { 1.150 + p++; 1.151 + while (isalpha(*p) || (*p == '.')) 1.152 + p++; 1.153 + if (*p != ']') { 1.154 + parse_error = g_strdup_printf("']' expected at end of literal address %s", *b); 1.155 + return FALSE; 1.156 + } 1.157 + p++; 1.158 + } 1.159 + *e = p; 1.160 + return TRUE; 1.161 } 1.162 1.163 -gboolean parse_address_rfc822(gchar *string, 1.164 - gchar **local_begin, gchar **local_end, 1.165 - gchar **domain_begin, gchar **domain_end, 1.166 - gchar **address_end) 1.167 +gboolean 1.168 +parse_address_rfc822(gchar* string, gchar** local_begin, gchar** local_end, gchar** domain_begin, gchar** domain_end, gchar** address_end) 1.169 { 1.170 - gint angle_brackets = 0; 1.171 + gint angle_brackets = 0; 1.172 1.173 - gchar *p = string; 1.174 - gchar *b, *e; 1.175 + gchar *p = string; 1.176 + gchar *b, *e; 1.177 1.178 - *local_begin = *local_end = NULL; 1.179 - *domain_begin = *domain_end = NULL; 1.180 + *local_begin = *local_end = NULL; 1.181 + *domain_begin = *domain_end = NULL; 1.182 1.183 - /* might be some memory left from previous call: */ 1.184 - if(parse_error != NULL){ 1.185 - g_free(parse_error); 1.186 - parse_error = NULL; 1.187 - } 1.188 + /* might be some memory left from previous call: */ 1.189 + if (parse_error != NULL) { 1.190 + g_free(parse_error); 1.191 + parse_error = NULL; 1.192 + } 1.193 1.194 - /* leading spaces and angle brackets */ 1.195 - while(*p && (isspace(*p) || (*p == '<'))){ 1.196 - if(*p == '<') 1.197 - angle_brackets++; 1.198 - p++; 1.199 - } 1.200 - 1.201 - if(*p){ 1.202 - while(TRUE){ 1.203 - if(read_word_with_dots(p, &b, &e)){ 1.204 - p = e; 1.205 + /* leading spaces and angle brackets */ 1.206 + while (*p && (isspace(*p) || (*p == '<'))) { 1.207 + if (*p == '<') 1.208 + angle_brackets++; 1.209 + p++; 1.210 + } 1.211 + 1.212 + if (*p) { 1.213 + while (TRUE) { 1.214 + if (read_word_with_dots(p, &b, &e)) { 1.215 + p = e; 1.216 #ifdef PARSE_TEST 1.217 - g_print("after read_word_with_dots: %s\n", p); 1.218 + g_print("after read_word_with_dots: %s\n", p); 1.219 #endif 1.220 - /* eat white spaces and comments */ 1.221 - while((*p && (isspace(*p))) || (*p == '(')){ 1.222 - if(*p == '('){ 1.223 - if(!(p = skip_comment(p))){ 1.224 - parse_error = 1.225 - g_strdup("missing right bracket ')'"); 1.226 - return FALSE; 1.227 - } 1.228 - }else 1.229 - p++; 1.230 + /* eat white spaces and comments */ 1.231 + while ((*p && (isspace(*p))) || (*p == '(')) { 1.232 + if (*p == '(') { 1.233 + if (!(p = skip_comment(p))) { 1.234 + parse_error = g_strdup("missing right bracket ')'"); 1.235 + return FALSE; 1.236 + } 1.237 + } else 1.238 + p++; 1.239 + } 1.240 + /* we now have a non-space char that is not 1.241 + the beginning of a comment */ 1.242 + 1.243 + if (*p == '@') { 1.244 + /* the last word was the local_part 1.245 + of an addr-spec */ 1.246 + *local_begin = b; 1.247 + *local_end = e; 1.248 +#ifdef PARSE_TEST 1.249 + g_print("found local part: %s\n", *local_begin); 1.250 +#endif 1.251 + if (*p == '@') { 1.252 + p++; /* skip @ */ 1.253 + /* now the domain */ 1.254 + if (read_domain(p, &b, &e)) { 1.255 + p = e; 1.256 + *domain_begin = b; 1.257 + *domain_end = e; 1.258 + } else 1.259 + return FALSE; 1.260 + } else { 1.261 + /* unqualified? */ 1.262 + *domain_begin = *domain_end = NULL; 1.263 + } 1.264 + break; 1.265 + } else if (*p == '<') { 1.266 + /* addr-spec follows */ 1.267 + while (isspace(*p) || (*p == '<')) { 1.268 + if (*p == '<') 1.269 + angle_brackets++; 1.270 + p++; 1.271 + } 1.272 + if (read_word_with_dots(p, &b, &e)) { 1.273 + p = e; 1.274 + *local_begin = b; 1.275 + *local_end = e; 1.276 +#ifdef PARSE_TEST 1.277 + g_print("found local part: %s\n", *local_begin); 1.278 +#endif 1.279 + } else 1.280 + return FALSE; 1.281 + if (*p == '@') { 1.282 + p++; 1.283 + if (read_domain(p, &b, &e)) { 1.284 + p = e; 1.285 + *domain_begin = b; 1.286 + *domain_end = e; 1.287 + } else 1.288 + return FALSE; 1.289 + } else { 1.290 + /* may be unqualified address */ 1.291 + *domain_begin = *domain_end = NULL; 1.292 + } 1.293 + break; 1.294 + } else if (!*p || *p == '>') { 1.295 + *local_begin = b; 1.296 + *local_end = e; 1.297 +#ifdef PARSE_TEST 1.298 + g_print("found local part: %s\n", *local_begin); 1.299 +#endif 1.300 + *domain_begin = *domain_end = NULL; 1.301 + break; 1.302 + } else if (strchr(specials, *p) || iscntrl(*p) || isspace(*p)) { 1.303 + parse_error = g_strdup_printf("unexpected character: %c", *p); 1.304 + return FALSE; 1.305 + } 1.306 + } else 1.307 + return FALSE; 1.308 + } 1.309 + /* trailing spaces and angle brackets */ 1.310 +#ifdef PARSE_TEST 1.311 + g_print("down counting trailing '>'\n"); 1.312 +#endif 1.313 + while (*p && (isspace(*p) || (*p == '>'))) { 1.314 + if (*p == '>') 1.315 + angle_brackets--; 1.316 + p++; 1.317 + } 1.318 + 1.319 + *address_end = p; 1.320 + 1.321 + if (angle_brackets != 0) { 1.322 + if (angle_brackets > 0) 1.323 + parse_error = g_strdup("missing '>' at end of string"); 1.324 + else 1.325 + parse_error = g_strdup("superfluous '>' at end of string"); 1.326 + return FALSE; 1.327 + } else { 1.328 + /* we successfully parsed the address */ 1.329 + return TRUE; 1.330 + } 1.331 + /* we never get here */ 1.332 } 1.333 - /* we now have a non-space char that is not 1.334 - the beginning of a comment */ 1.335 - 1.336 - if(*p == '@'){ 1.337 - /* the last word was the local_part 1.338 - of an addr-spec */ 1.339 - *local_begin = b; 1.340 - *local_end = e; 1.341 -#ifdef PARSE_TEST 1.342 - g_print("found local part: %s\n", *local_begin); 1.343 -#endif 1.344 - if(*p == '@'){ 1.345 - p++; /* skip @ */ 1.346 - /* now the domain */ 1.347 - if(read_domain(p, &b, &e)){ 1.348 - p = e; 1.349 - *domain_begin = b; 1.350 - *domain_end = e; 1.351 - } 1.352 - else 1.353 - return FALSE; 1.354 - }else{ 1.355 - /* unqualified? */ 1.356 - *domain_begin = *domain_end = NULL; 1.357 - } 1.358 - break; 1.359 - }else if(*p == '<'){ 1.360 - /* addr-spec follows */ 1.361 - while(isspace(*p) || (*p == '<')){ 1.362 - if(*p == '<') 1.363 - angle_brackets++; 1.364 - p++; 1.365 - } 1.366 - if(read_word_with_dots(p, &b, &e)){ 1.367 - p = e; 1.368 - *local_begin = b; 1.369 - *local_end = e; 1.370 -#ifdef PARSE_TEST 1.371 - g_print("found local part: %s\n", *local_begin); 1.372 -#endif 1.373 - }else 1.374 - return FALSE; 1.375 - if(*p == '@'){ 1.376 - p++; 1.377 - if(read_domain(p, &b, &e)){ 1.378 - p = e; 1.379 - *domain_begin = b; 1.380 - *domain_end = e; 1.381 - }else 1.382 - return FALSE; 1.383 - }else{ 1.384 - /* may be unqualified address */ 1.385 - *domain_begin = *domain_end = NULL; 1.386 - } 1.387 - break; 1.388 - }else if(!*p || *p == '>'){ 1.389 - *local_begin = b; 1.390 - *local_end = e; 1.391 -#ifdef PARSE_TEST 1.392 - g_print("found local part: %s\n", *local_begin); 1.393 -#endif 1.394 - *domain_begin = *domain_end = NULL; 1.395 - break; 1.396 - }else if(strchr(specials, *p) || iscntrl(*p) || isspace(*p)){ 1.397 - parse_error = g_strdup_printf("unexpected character: %c", *p); 1.398 - return FALSE; 1.399 - } 1.400 - }else 1.401 return FALSE; 1.402 - } 1.403 - /* trailing spaces and angle brackets */ 1.404 -#ifdef PARSE_TEST 1.405 - g_print("down counting trailing '>'\n"); 1.406 -#endif 1.407 - while(*p && (isspace(*p) || (*p == '>'))){ 1.408 - if(*p == '>') 1.409 - angle_brackets--; 1.410 - p++; 1.411 - } 1.412 - 1.413 - *address_end = p; 1.414 - 1.415 - if(angle_brackets != 0){ 1.416 - if(angle_brackets > 0) 1.417 - parse_error = g_strdup("missing '>' at end of string"); 1.418 - else 1.419 - parse_error = g_strdup("superfluous '>' at end of string"); 1.420 - return FALSE; 1.421 - }else{ 1.422 - /* we successfully parsed the address */ 1.423 - return TRUE; 1.424 - } 1.425 - /* we never get here */ 1.426 - } 1.427 - return FALSE; 1.428 } 1.429 1.430 -gboolean parse_address_rfc821(gchar *string, 1.431 - gchar **local_begin, gchar **local_end, 1.432 - gchar **domain_begin, gchar **domain_end, 1.433 - gchar **address_end) 1.434 +gboolean 1.435 +parse_address_rfc821(gchar* string, gchar** local_begin, gchar** local_end, gchar** domain_begin, gchar** domain_end, gchar** address_end) 1.436 { 1.437 - gint angle_brackets = 0; 1.438 + gint angle_brackets = 0; 1.439 1.440 - gchar *p = string; 1.441 - gchar *b, *e; 1.442 + gchar *p = string; 1.443 + gchar *b, *e; 1.444 1.445 - *local_begin = *local_end = NULL; 1.446 - *domain_begin = *domain_end = NULL; 1.447 + *local_begin = *local_end = NULL; 1.448 + *domain_begin = *domain_end = NULL; 1.449 1.450 - /* might be some memory left from previous call: */ 1.451 - if(parse_error != NULL){ 1.452 - g_free(parse_error); 1.453 - parse_error = NULL; 1.454 - } 1.455 + /* might be some memory left from previous call: */ 1.456 + if (parse_error != NULL) { 1.457 + g_free(parse_error); 1.458 + parse_error = NULL; 1.459 + } 1.460 1.461 - /* leading spaces and angle brackets */ 1.462 - while(*p && (isspace(*p) || (*p == '<'))){ 1.463 - if(*p == '<') 1.464 - angle_brackets++; 1.465 - p++; 1.466 - } 1.467 - 1.468 - if(*p){ 1.469 - while(TRUE){ 1.470 - if(read_word_with_dots(p, &b, &e)){ 1.471 - p = e; 1.472 + /* leading spaces and angle brackets */ 1.473 + while (*p && (isspace(*p) || (*p == '<'))) { 1.474 + if (*p == '<') 1.475 + angle_brackets++; 1.476 + p++; 1.477 + } 1.478 + 1.479 + if (*p) { 1.480 + while (TRUE) { 1.481 + if (read_word_with_dots(p, &b, &e)) { 1.482 + p = e; 1.483 #ifdef PARSE_TEST 1.484 - g_print("after read_word_with_dots: %s\n", p); 1.485 + g_print("after read_word_with_dots: %s\n", p); 1.486 #endif 1.487 - *local_begin = b; 1.488 - *local_end = e; 1.489 + *local_begin = b; 1.490 + *local_end = e; 1.491 #ifdef PARSE_TEST 1.492 - g_print("found local part: %s\n", *local_begin); 1.493 - g_print("local_end = %s\n", *local_end); 1.494 + g_print("found local part: %s\n", *local_begin); 1.495 + g_print("local_end = %s\n", *local_end); 1.496 #endif 1.497 - if(!(*p) || isspace(*p) || (*p == '>')){ 1.498 - /* unqualified ?*/ 1.499 - domain_begin = domain_end = NULL; 1.500 - break; 1.501 - }else if(*p == '@'){ 1.502 - p++; 1.503 - if(read_domain(p, &b, &e)){ 1.504 - p = e; 1.505 - *domain_begin = b; 1.506 - *domain_end = e; 1.507 - } 1.508 - break; 1.509 - }else{ 1.510 - parse_error = 1.511 - g_strdup_printf("unexpected character after local part '%c'",*p); 1.512 - return FALSE; 1.513 + if (!(*p) || isspace(*p) || (*p == '>')) { 1.514 + /* unqualified ? */ 1.515 + domain_begin = domain_end = NULL; 1.516 + break; 1.517 + } else if (*p == '@') { 1.518 + p++; 1.519 + if (read_domain(p, &b, &e)) { 1.520 + p = e; 1.521 + *domain_begin = b; 1.522 + *domain_end = e; 1.523 + } 1.524 + break; 1.525 + } else { 1.526 + parse_error = g_strdup_printf ("unexpected character after local part '%c'", *p); 1.527 + return FALSE; 1.528 + } 1.529 + } else 1.530 + return FALSE; 1.531 + } 1.532 + 1.533 + /* trailing spaces and angle brackets */ 1.534 +#ifdef PARSE_TEST 1.535 + g_print("down counting trailing '>'\n"); 1.536 +#endif 1.537 + while (*p && (isspace(*p) || (*p == '>'))) { 1.538 + if (*p == '>') 1.539 + angle_brackets--; 1.540 + p++; 1.541 + } 1.542 + *address_end = p; 1.543 + 1.544 + if (angle_brackets != 0) { 1.545 + if (angle_brackets > 0) 1.546 + parse_error = g_strdup("missing '>' at end of string"); 1.547 + else 1.548 + parse_error = g_strdup("superfluous '>' at end of string"); 1.549 + return FALSE; 1.550 + } else { 1.551 + /* we successfully parsed the address */ 1.552 + return TRUE; 1.553 + } 1.554 + /* we never get here */ 1.555 } 1.556 - } else 1.557 - return FALSE; 1.558 - } 1.559 - 1.560 - /* trailing spaces and angle brackets */ 1.561 -#ifdef PARSE_TEST 1.562 - g_print("down counting trailing '>'\n"); 1.563 -#endif 1.564 - while(*p && (isspace(*p) || (*p == '>'))){ 1.565 - if(*p == '>') 1.566 - angle_brackets--; 1.567 - p++; 1.568 - } 1.569 - *address_end = p; 1.570 - 1.571 - if(angle_brackets != 0){ 1.572 - if(angle_brackets > 0) 1.573 - parse_error = g_strdup("missing '>' at end of string"); 1.574 - else 1.575 - parse_error = g_strdup("superfluous '>' at end of string"); 1.576 - return FALSE; 1.577 - }else{ 1.578 - /* we successfully parsed the address */ 1.579 - return TRUE; 1.580 - } 1.581 - /* we never get here */ 1.582 - } 1.583 - return FALSE; 1.584 + return FALSE; 1.585 } 1.586 1.587 /* 1.588 @@ -358,93 +353,98 @@ 1.589 parses both rfc 821 and rfc 822 addresses, depending on flag is_rfc821 1.590 */ 1.591 1.592 -address *_create_address(gchar *string, gchar **end, gboolean is_rfc821) 1.593 +address* 1.594 +_create_address(gchar * string, gchar ** end, gboolean is_rfc821) 1.595 { 1.596 - gchar *loc_beg, *loc_end; 1.597 - gchar *dom_beg, *dom_end; 1.598 - gchar *addr_end; 1.599 + gchar *loc_beg, *loc_end; 1.600 + gchar *dom_beg, *dom_end; 1.601 + gchar *addr_end; 1.602 1.603 - if (string && (string[0] == 0)) { 1.604 - address *addr = g_malloc(sizeof(address)); 1.605 - addr->address = g_strdup(""); 1.606 - addr->local_part = g_strdup(""); 1.607 - addr->domain = g_strdup(""); /* 'NULL' address (failure notice), 1.608 - "" makes sure it will not be qualified with a hostname */ 1.609 - return addr; 1.610 - } 1.611 + if (string && (string[0] == 0)) { 1.612 + address *addr = g_malloc(sizeof(address)); 1.613 + addr->address = g_strdup(""); 1.614 + addr->local_part = g_strdup(""); 1.615 + addr->domain = g_strdup(""); /* 'NULL' address (failure notice), "" makes sure it will not be qualified with a hostname */ 1.616 + return addr; 1.617 + } 1.618 1.619 - if(is_rfc821 ? 1.620 - parse_address_rfc821(string, 1.621 - &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end) : 1.622 - parse_address_rfc822(string, 1.623 - &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end)){ 1.624 - address *addr = g_malloc(sizeof(address)); 1.625 - gchar *p = addr_end; 1.626 - 1.627 + if (is_rfc821 1.628 + ? parse_address_rfc821(string, &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end) 1.629 + : parse_address_rfc822(string, &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end)) 1.630 + { 1.631 + address *addr = g_malloc(sizeof(address)); 1.632 + gchar *p = addr_end; 1.633 1.634 - memset(addr, 0, sizeof(address)); 1.635 1.636 - if(loc_beg[0] == '|'){ 1.637 - parse_error = g_strdup("no pipe allowed for RFC 822/821 address"); 1.638 - return NULL; 1.639 - } 1.640 + memset(addr, 0, sizeof(address)); 1.641 1.642 - while(*p && (*p != ',')) p++; 1.643 - addr->address = g_strndup(string, p - string); 1.644 + if (loc_beg[0] == '|') { 1.645 + parse_error = g_strdup("no pipe allowed for RFC 822/821 address"); 1.646 + return NULL; 1.647 + } 1.648 1.649 - addr->local_part = g_strndup(loc_beg, loc_end - loc_beg); 1.650 + while (*p && (*p != ',')) 1.651 + p++; 1.652 + addr->address = g_strndup(string, p - string); 1.653 + 1.654 + addr->local_part = g_strndup(loc_beg, loc_end - loc_beg); 1.655 1.656 #ifdef PARSE_TEST 1.657 - g_print("addr->local_part = %s\n", addr->local_part); 1.658 + g_print("addr->local_part = %s\n", addr->local_part); 1.659 #endif 1.660 1.661 - if(dom_beg != NULL){ 1.662 - addr->domain = g_strndup(dom_beg, dom_end - dom_beg); 1.663 - }else{ 1.664 - if(addr->local_part[0] == 0) 1.665 - addr->domain = g_strdup(""); /* 'NULL' address (failure notice), 1.666 - "" makes sure it will not be qualified with a hostname */ 1.667 - else 1.668 - addr->domain = NULL; 1.669 - } 1.670 + if (dom_beg != NULL) { 1.671 + addr->domain = g_strndup(dom_beg, dom_end - dom_beg); 1.672 + } else { 1.673 + if (addr->local_part[0] == 0) 1.674 + addr->domain = g_strdup(""); /* 'NULL' address (failure notice), "" makes sure it will not be qualified with a hostname */ 1.675 + else 1.676 + addr->domain = NULL; 1.677 + } 1.678 1.679 - if(end != NULL) 1.680 - *end = p; 1.681 + if (end != NULL) 1.682 + *end = p; 1.683 1.684 #ifndef PARSE_TEST 1.685 - addr_unmark_delivered(addr); 1.686 + addr_unmark_delivered(addr); 1.687 #endif 1.688 1.689 - return addr; 1.690 - } 1.691 - return NULL; 1.692 + return addr; 1.693 + } 1.694 + return NULL; 1.695 } 1.696 1.697 -address *create_address_rfc822(gchar *string, gchar **end){ 1.698 - return _create_address(string, end, FALSE); 1.699 +address* 1.700 +create_address_rfc822(gchar * string, gchar ** end) 1.701 +{ 1.702 + return _create_address(string, end, FALSE); 1.703 } 1.704 1.705 -address *create_address_rfc821(gchar *string, gchar **end){ 1.706 - return _create_address(string, end, TRUE); 1.707 +address* 1.708 +create_address_rfc821(gchar * string, gchar ** end) 1.709 +{ 1.710 + return _create_address(string, end, TRUE); 1.711 } 1.712 1.713 -GList *addr_list_append_rfc822(GList *addr_list, gchar *string, gchar *domain) 1.714 +GList* 1.715 +addr_list_append_rfc822(GList * addr_list, gchar * string, gchar * domain) 1.716 { 1.717 - gchar *p = string; 1.718 - gchar *end; 1.719 + gchar *p = string; 1.720 + gchar *end; 1.721 1.722 - while(*p){ 1.723 - address *addr = _create_address(p, &end, FALSE); 1.724 - if(addr){ 1.725 - if(domain) 1.726 - if(addr->domain == NULL) 1.727 - addr->domain = g_strdup(domain); 1.728 + while (*p) { 1.729 + address *addr = _create_address(p, &end, FALSE); 1.730 + if (addr) { 1.731 + if (domain) 1.732 + if (addr->domain == NULL) 1.733 + addr->domain = g_strdup(domain); 1.734 1.735 - addr_list = g_list_append(addr_list, addr); 1.736 - p = end; 1.737 - }else 1.738 - break; 1.739 - while(*p == ',' || isspace(*p)) p++; 1.740 - } 1.741 - return addr_list; 1.742 + addr_list = g_list_append(addr_list, addr); 1.743 + p = end; 1.744 + } else 1.745 + break; 1.746 + while (*p == ',' || isspace(*p)) 1.747 + p++; 1.748 + } 1.749 + return addr_list; 1.750 }