masqmail-0.2

diff src/pop3_in.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/pop3_in.c	Mon Oct 27 16:21:27 2008 +0100
     1.2 +++ b/src/pop3_in.c	Mon Oct 27 16:23:10 2008 +0100
     1.3 @@ -4,7 +4,7 @@
     1.4   * it under the terms of the GNU General Public License as published by
     1.5   * the Free Software Foundation; either version 2 of the License, or
     1.6   * (at your option) any later version.
     1.7 - * 
     1.8 + *
     1.9   * This program is distributed in the hope that it will be useful,
    1.10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.12 @@ -36,785 +36,774 @@
    1.13  /* experimental feature */
    1.14  #define DO_WRITE_UIDL_EARLY 1
    1.15  
    1.16 -static
    1.17 -gchar *MD5String (char *string)
    1.18 +static gchar*
    1.19 +MD5String(char *string)
    1.20  {
    1.21 -  MD5_CTX context;
    1.22 -  unsigned char digest[16];
    1.23 -  char str_digest[33];
    1.24 -  int i;
    1.25 +	MD5_CTX context;
    1.26 +	unsigned char digest[16];
    1.27 +	char str_digest[33];
    1.28 +	int i;
    1.29  
    1.30  #ifdef USE_LIB_CRYPTO
    1.31 -  MD5(string, strlen(string), digest);
    1.32 +	MD5(string, strlen(string), digest);
    1.33  #else
    1.34 -  MD5Init(&context);
    1.35 -  MD5Update(&context, string, strlen(string));
    1.36 -  MD5Final(digest, &context);
    1.37 +	MD5Init(&context);
    1.38 +	MD5Update(&context, string, strlen(string));
    1.39 +	MD5Final(digest, &context);
    1.40  #endif
    1.41 -  for (i = 0;  i < 16;  i++) 
    1.42 -    sprintf(str_digest+2*i, "%02x", digest[i]);
    1.43 +	for (i = 0; i < 16; i++)
    1.44 +		sprintf(str_digest + 2 * i, "%02x", digest[i]);
    1.45  
    1.46 -  return g_strdup(str_digest);
    1.47 +	return g_strdup(str_digest);
    1.48  }
    1.49  
    1.50 -static
    1.51 -pop3_base *create_pop3base(gint sock, guint flags)
    1.52 +static pop3_base*
    1.53 +create_pop3base(gint sock, guint flags)
    1.54  {
    1.55 -  gint dup_sock;
    1.56 +	gint dup_sock;
    1.57  
    1.58 -  pop3_base *popb = (pop3_base *)g_malloc(sizeof(pop3_base));
    1.59 -  if(popb){
    1.60 -    memset(popb, 0, sizeof(pop3_base));
    1.61 +	pop3_base *popb = (pop3_base *) g_malloc(sizeof(pop3_base));
    1.62 +	if (popb) {
    1.63 +		memset(popb, 0, sizeof(pop3_base));
    1.64  
    1.65 -    popb->error = pop3_ok;
    1.66 +		popb->error = pop3_ok;
    1.67  
    1.68 -    popb->buffer = (gchar *)g_malloc(POP3_BUF_LEN);
    1.69 +		popb->buffer = (gchar *) g_malloc(POP3_BUF_LEN);
    1.70  
    1.71 -    dup_sock = dup(sock);
    1.72 -    popb->out = fdopen(sock, "w");
    1.73 -    popb->in = fdopen(dup_sock, "r");
    1.74 -    
    1.75 -    popb->flags = flags;
    1.76 -  }
    1.77 -  return popb;
    1.78 +		dup_sock = dup(sock);
    1.79 +		popb->out = fdopen(sock, "w");
    1.80 +		popb->in = fdopen(dup_sock, "r");
    1.81 +
    1.82 +		popb->flags = flags;
    1.83 +	}
    1.84 +	return popb;
    1.85  }
    1.86  
    1.87 -static
    1.88 -void pop3_printf(FILE *out, gchar *fmt, ...)
    1.89 +static void
    1.90 +pop3_printf(FILE * out, gchar * fmt, ...)
    1.91  {
    1.92 -  va_list args;
    1.93 -  va_start(args, fmt);
    1.94 +	va_list args;
    1.95 +	va_start(args, fmt);
    1.96  
    1.97 -  DEBUG(4){
    1.98 -    gchar buf[256];
    1.99 -    va_list args_copy;
   1.100 +	DEBUG(4) {
   1.101 +		gchar buf[256];
   1.102 +		va_list args_copy;
   1.103  
   1.104 -    va_copy(args_copy, args);
   1.105 -    vsnprintf(buf, 255, fmt, args_copy);
   1.106 -    va_end(args_copy);
   1.107 +		va_copy(args_copy, args);
   1.108 +		vsnprintf(buf, 255, fmt, args_copy);
   1.109 +		va_end(args_copy);
   1.110  
   1.111 -    debugf(">>>%s", buf);
   1.112 -  }
   1.113 +		debugf(">>>%s", buf);
   1.114 +	}
   1.115  
   1.116 -  vfprintf(out, fmt, args);  fflush(out);
   1.117 +	vfprintf(out, fmt, args);
   1.118 +	fflush(out);
   1.119  
   1.120 -  va_end(args);
   1.121 +	va_end(args);
   1.122  }
   1.123  
   1.124 -static
   1.125 -gboolean find_uid(pop3_base *popb, gchar *str)
   1.126 +static gboolean
   1.127 +find_uid(pop3_base * popb, gchar * str)
   1.128  {
   1.129 -  GList *node, *node_next;
   1.130 +	GList *node, *node_next;
   1.131  
   1.132 -  for(node = popb->list_uid_old; node; node=node_next){
   1.133 -    gchar *uid = (gchar *)(node->data);
   1.134 -    node_next = node->next;
   1.135 -    if(strcmp(uid, str) == 0){
   1.136 +	for (node = popb->list_uid_old; node; node = node_next) {
   1.137 +		gchar *uid = (gchar *) (node->data);
   1.138 +		node_next = node->next;
   1.139 +		if (strcmp(uid, str) == 0) {
   1.140  #if 1
   1.141 -      popb->list_uid_old = g_list_remove_link(popb->list_uid_old, node);
   1.142 -      g_list_free_1(node);
   1.143 -      g_free(uid);
   1.144 +			popb->list_uid_old = g_list_remove_link(popb->list_uid_old, node);
   1.145 +			g_list_free_1(node);
   1.146 +			g_free(uid);
   1.147  #endif
   1.148 -      return TRUE;
   1.149 -    }
   1.150 -  }
   1.151 -  return FALSE;
   1.152 +			return TRUE;
   1.153 +		}
   1.154 +	}
   1.155 +	return FALSE;
   1.156  }
   1.157  
   1.158 -static
   1.159 -gboolean write_uidl(pop3_base *popb, gchar *user)
   1.160 +static gboolean
   1.161 +write_uidl(pop3_base * popb, gchar * user)
   1.162  {
   1.163 -  gboolean ok = FALSE;
   1.164 -  GList *node;
   1.165 -  gchar *filename = g_strdup_printf("%s/popuidl/%s@%s",
   1.166 -				    conf.spool_dir,
   1.167 -				    user, popb->remote_host);
   1.168 -  gchar *tmpname = g_strdup_printf("%s.tmp", filename);
   1.169 -  FILE *fptr = fopen(tmpname, "wt");
   1.170 +	gboolean ok = FALSE;
   1.171 +	GList *node;
   1.172 +	gchar *filename = g_strdup_printf("%s/popuidl/%s@%s", conf.spool_dir, user, popb->remote_host);
   1.173 +	gchar *tmpname = g_strdup_printf("%s.tmp", filename);
   1.174 +	FILE *fptr = fopen(tmpname, "wt");
   1.175  
   1.176 -  if(fptr){
   1.177 -    foreach(popb->drop_list, node){
   1.178 -      msg_info *info = (msg_info *)(node->data);
   1.179 -      if(info->is_fetched || info->is_in_uidl)
   1.180 -	fprintf(fptr, "%s\n", info->uid);
   1.181 -    }
   1.182 -    fclose(fptr);
   1.183 -    ok = (rename(tmpname, filename) != -1);
   1.184 -  }
   1.185 -  
   1.186 -  g_free(tmpname);
   1.187 -  g_free(filename);
   1.188 -  return ok;
   1.189 +	if (fptr) {
   1.190 +		foreach(popb->drop_list, node) {
   1.191 +			msg_info *info = (msg_info *) (node->data);
   1.192 +			if (info->is_fetched || info->is_in_uidl)
   1.193 +				fprintf(fptr, "%s\n", info->uid);
   1.194 +		}
   1.195 +		fclose(fptr);
   1.196 +		ok = (rename(tmpname, filename) != -1);
   1.197 +	}
   1.198 +
   1.199 +	g_free(tmpname);
   1.200 +	g_free(filename);
   1.201 +	return ok;
   1.202  }
   1.203  
   1.204 -static
   1.205 -gboolean read_uidl_fname(pop3_base *popb, gchar *filename)
   1.206 +static gboolean
   1.207 +read_uidl_fname(pop3_base * popb, gchar * filename)
   1.208  {
   1.209 -  gboolean ok = FALSE;
   1.210 -  FILE *fptr = fopen(filename, "rt");
   1.211 -  gchar buf[256];
   1.212 +	gboolean ok = FALSE;
   1.213 +	FILE *fptr = fopen(filename, "rt");
   1.214 +	gchar buf[256];
   1.215  
   1.216 -  if(fptr){
   1.217 -    popb->list_uid_old = NULL;
   1.218 -    while(fgets(buf, 255, fptr)){
   1.219 -      if(buf[strlen(buf)-1] == '\n'){
   1.220 -	g_strchomp(buf);
   1.221 -	popb->list_uid_old =
   1.222 -	  g_list_append(popb->list_uid_old, g_strdup(buf));
   1.223 -      }else{
   1.224 -	logwrite(LOG_ALERT, "broken uid: %s\n", buf);
   1.225 -	break;
   1.226 -      }
   1.227 -    }
   1.228 -    fclose(fptr);
   1.229 -    ok = TRUE;
   1.230 -  }else
   1.231 -    logwrite(LOG_ALERT, "opening of %s failed: %s", filename, strerror(errno));
   1.232 -  return ok;
   1.233 +	if (fptr) {
   1.234 +		popb->list_uid_old = NULL;
   1.235 +		while (fgets(buf, 255, fptr)) {
   1.236 +			if (buf[strlen(buf) - 1] == '\n') {
   1.237 +				g_strchomp(buf);
   1.238 +				popb->list_uid_old = g_list_append(popb->list_uid_old, g_strdup(buf));
   1.239 +			} else {
   1.240 +				logwrite(LOG_ALERT, "broken uid: %s\n", buf);
   1.241 +				break;
   1.242 +			}
   1.243 +		}
   1.244 +		fclose(fptr);
   1.245 +		ok = TRUE;
   1.246 +	} else
   1.247 +		logwrite(LOG_ALERT, "opening of %s failed: %s", filename, strerror(errno));
   1.248 +	return ok;
   1.249  }
   1.250  
   1.251 -static
   1.252 -gboolean read_uidl(pop3_base *popb, gchar *user)
   1.253 +static gboolean
   1.254 +read_uidl(pop3_base * popb, gchar * user)
   1.255  {
   1.256 -  gboolean ok = FALSE;
   1.257 -  struct stat statbuf;
   1.258 -  gchar *filename = g_strdup_printf("%s/popuidl/%s@%s",
   1.259 -				    conf.spool_dir,
   1.260 -				    user, popb->remote_host);
   1.261 +	gboolean ok = FALSE;
   1.262 +	struct stat statbuf;
   1.263 +	gchar *filename = g_strdup_printf("%s/popuidl/%s@%s", conf.spool_dir, user, popb->remote_host);
   1.264  
   1.265 -  if(stat(filename, &statbuf) == 0){
   1.266 -    ok = read_uidl_fname(popb, filename);
   1.267 -    if(ok){
   1.268 -      GList *drop_node;
   1.269 -      foreach(popb->drop_list, drop_node){
   1.270 -	msg_info *info = (msg_info *)(drop_node->data);
   1.271 -	if(find_uid(popb, info->uid)){
   1.272 -	  DEBUG(5) debugf("msg with uid '%s' already known\n", info->uid);
   1.273 -	  info->is_in_uidl = TRUE;
   1.274 -	  popb->uidl_known_cnt++;
   1.275 -	}else
   1.276 -	  DEBUG(5) debugf("msg with uid '%s' not known\n", info->uid);
   1.277 -      }
   1.278 -    }
   1.279 -  }else{
   1.280 -    logwrite(LOG_DEBUG, "no uidl file '%s' found\n", filename);
   1.281 -    ok = TRUE;
   1.282 -  }
   1.283 +	if (stat(filename, &statbuf) == 0) {
   1.284 +		ok = read_uidl_fname(popb, filename);
   1.285 +		if (ok) {
   1.286 +			GList *drop_node;
   1.287 +			foreach(popb->drop_list, drop_node) {
   1.288 +				msg_info *info = (msg_info *) (drop_node->data);
   1.289 +				if (find_uid(popb, info->uid)) {
   1.290 +					DEBUG(5) debugf("msg with uid '%s' already known\n", info->uid);
   1.291 +					info->is_in_uidl = TRUE;
   1.292 +					popb->uidl_known_cnt++;
   1.293 +				} else
   1.294 +					DEBUG(5) debugf("msg with uid '%s' not known\n", info->uid);
   1.295 +			}
   1.296 +		}
   1.297 +	} else {
   1.298 +		logwrite(LOG_DEBUG, "no uidl file '%s' found\n", filename);
   1.299 +		ok = TRUE;
   1.300 +	}
   1.301  
   1.302 -  g_free(filename);
   1.303 -  return ok; /* return code is irrelevant, do not check... */
   1.304 +	g_free(filename);
   1.305 +	return ok;  /* return code is irrelevant, do not check... */
   1.306  }
   1.307  
   1.308 -static
   1.309 -gboolean read_response(pop3_base *popb, int timeout)
   1.310 +static gboolean
   1.311 +read_response(pop3_base * popb, int timeout)
   1.312  {
   1.313 -  gint len;
   1.314 +	gint len;
   1.315  
   1.316 -  len = read_sockline(popb->in, popb->buffer, POP3_BUF_LEN, timeout, READSOCKL_CHUG);
   1.317 +	len = read_sockline(popb->in, popb->buffer, POP3_BUF_LEN, timeout, READSOCKL_CHUG);
   1.318  
   1.319 -  if(len == -3){
   1.320 -    popb->error = pop3_timeout;
   1.321 -    return FALSE;
   1.322 -  }
   1.323 -  else if(len == -2){
   1.324 -    popb->error = pop3_syntax;
   1.325 -    return FALSE;
   1.326 -  }
   1.327 -  else if(len == -1){
   1.328 -    popb->error = pop3_eof;
   1.329 -    return FALSE;
   1.330 -  }
   1.331 -  
   1.332 -  return TRUE;
   1.333 +	if (len == -3) {
   1.334 +		popb->error = pop3_timeout;
   1.335 +		return FALSE;
   1.336 +	} else if (len == -2) {
   1.337 +		popb->error = pop3_syntax;
   1.338 +		return FALSE;
   1.339 +	} else if (len == -1) {
   1.340 +		popb->error = pop3_eof;
   1.341 +		return FALSE;
   1.342 +	}
   1.343 +
   1.344 +	return TRUE;
   1.345  }
   1.346  
   1.347 -static
   1.348 -gboolean check_response(pop3_base *popb)
   1.349 +static gboolean
   1.350 +check_response(pop3_base * popb)
   1.351  {
   1.352 -  char c = popb->buffer[0];
   1.353 +	char c = popb->buffer[0];
   1.354  
   1.355 -  if(c == '+'){
   1.356 -    popb->error = pop3_ok;
   1.357 -    return TRUE;
   1.358 -  }else if(c == '-')
   1.359 -    popb->error = pop3_fail;
   1.360 -  else
   1.361 -    popb->error = pop3_syntax;
   1.362 -  return FALSE;
   1.363 +	if (c == '+') {
   1.364 +		popb->error = pop3_ok;
   1.365 +		return TRUE;
   1.366 +	} else if (c == '-')
   1.367 +		popb->error = pop3_fail;
   1.368 +	else
   1.369 +		popb->error = pop3_syntax;
   1.370 +	return FALSE;
   1.371  }
   1.372  
   1.373 -static
   1.374 -gboolean strtoi(gchar *p, gchar **pend, gint *val)
   1.375 +static gboolean
   1.376 +strtoi(gchar * p, gchar ** pend, gint * val)
   1.377  {
   1.378 -  gchar buf[12];
   1.379 -  gint i = 0;
   1.380 +	gchar buf[12];
   1.381 +	gint i = 0;
   1.382  
   1.383 -  while(*p && isspace(*p)) p++;
   1.384 -  if(*p){
   1.385 -    while((i < 11) && isdigit(*p))
   1.386 -      buf[i++] = *(p++);
   1.387 -    buf[i] = 0;
   1.388 -    *val = atoi(buf);
   1.389 -    *pend = p;
   1.390 -    return TRUE;
   1.391 -  }
   1.392 -  return FALSE;
   1.393 +	while (*p && isspace(*p))
   1.394 +		p++;
   1.395 +	if (*p) {
   1.396 +		while ((i < 11) && isdigit(*p))
   1.397 +			buf[i++] = *(p++);
   1.398 +		buf[i] = 0;
   1.399 +		*val = atoi(buf);
   1.400 +		*pend = p;
   1.401 +		return TRUE;
   1.402 +	}
   1.403 +	return FALSE;
   1.404  }
   1.405  
   1.406 -static
   1.407 -gboolean check_response_int_int(pop3_base *popb, gint *arg0, gint *arg1)
   1.408 +static gboolean
   1.409 +check_response_int_int(pop3_base * popb, gint * arg0, gint * arg1)
   1.410  {
   1.411 -  if(check_response(popb)){
   1.412 -    gchar *p = &(popb->buffer[3]);
   1.413 -    gchar *pe;
   1.414 +	if (check_response(popb)) {
   1.415 +		gchar *p = &(popb->buffer[3]);
   1.416 +		gchar *pe;
   1.417  
   1.418 -    if(strtoi(p, &pe, arg0)){
   1.419 -      DEBUG(5) debugf("arg0 = %d\n", *arg0);
   1.420 -      p = pe;
   1.421 -      if(strtoi(p, &pe, arg1))
   1.422 -	DEBUG(5) debugf("arg1 = %d\n", *arg1);
   1.423 -	return TRUE;
   1.424 -    }
   1.425 -    popb->error = pop3_syntax;
   1.426 -  }
   1.427 -  return FALSE;
   1.428 +		if (strtoi(p, &pe, arg0)) {
   1.429 +			DEBUG(5) debugf("arg0 = %d\n", *arg0);
   1.430 +			p = pe;
   1.431 +			if (strtoi(p, &pe, arg1))
   1.432 +				DEBUG(5) debugf("arg1 = %d\n", *arg1);
   1.433 +			return TRUE;
   1.434 +		}
   1.435 +		popb->error = pop3_syntax;
   1.436 +	}
   1.437 +	return FALSE;
   1.438  }
   1.439  
   1.440 -static
   1.441 -gboolean get_drop_listing(pop3_base *popb)
   1.442 +static gboolean
   1.443 +get_drop_listing(pop3_base * popb)
   1.444  {
   1.445 -  gchar buf[64];
   1.446 +	gchar buf[64];
   1.447  
   1.448 -  DEBUG(5) debugf("get_drop_listing() entered\n");
   1.449 +	DEBUG(5) debugf("get_drop_listing() entered\n");
   1.450  
   1.451 -  while(1){
   1.452 -    gint len = read_sockline(popb->in, buf, 64, POP3_CMD_TIMEOUT, READSOCKL_CHUG);
   1.453 -    if(len > 0){
   1.454 -      if(buf[0] == '.')
   1.455 -	return TRUE;
   1.456 -      else{
   1.457 -	gint number, msg_size;
   1.458 -	gchar *p = buf, *pe;
   1.459 -	if(strtoi(p, &pe, &number)){
   1.460 -	  p = pe;
   1.461 -	  if(strtoi(p, &pe, &msg_size)){
   1.462 -	    msg_info *info = g_malloc(sizeof(msg_info));
   1.463 -	    info->number = number;
   1.464 -	    info->size = msg_size;
   1.465 +	while (1) {
   1.466 +		gint len = read_sockline(popb->in, buf, 64, POP3_CMD_TIMEOUT, READSOCKL_CHUG);
   1.467 +		if (len > 0) {
   1.468 +			if (buf[0] == '.')
   1.469 +				return TRUE;
   1.470 +			else {
   1.471 +				gint number, msg_size;
   1.472 +				gchar *p = buf, *pe;
   1.473 +				if (strtoi(p, &pe, &number)) {
   1.474 +					p = pe;
   1.475 +					if (strtoi(p, &pe, &msg_size)) {
   1.476 +						msg_info *info = g_malloc(sizeof(msg_info));
   1.477 +						info->number = number;
   1.478 +						info->size = msg_size;
   1.479  
   1.480 -	    DEBUG(5) debugf("get_drop_listing(), number = %d, msg_size = %d\n", number, msg_size);
   1.481 +						DEBUG(5) debugf ("get_drop_listing(), number = %d, msg_size = %d\n", number, msg_size);
   1.482  
   1.483 -	    info->uid = NULL;
   1.484 -	    info->is_fetched = FALSE;
   1.485 -	    info->is_in_uidl = FALSE;
   1.486 -	    popb->drop_list = g_list_append(popb->drop_list, info);
   1.487 -	  }else{
   1.488 -	    popb->error = pop3_syntax;
   1.489 -	    break;
   1.490 -	  }
   1.491 -	}else{
   1.492 -	  popb->error = pop3_syntax;
   1.493 -	  break;
   1.494 +						info->uid = NULL;
   1.495 +						info->is_fetched = FALSE;
   1.496 +						info->is_in_uidl = FALSE;
   1.497 +						popb->drop_list = g_list_append(popb->drop_list, info);
   1.498 +					} else {
   1.499 +						popb->error = pop3_syntax;
   1.500 +						break;
   1.501 +					}
   1.502 +				} else {
   1.503 +					popb->error = pop3_syntax;
   1.504 +					break;
   1.505 +				}
   1.506 +			}
   1.507 +		} else {
   1.508 +			popb->error = (len == -1) ? pop3_eof : pop3_timeout;
   1.509 +			return FALSE;
   1.510 +		}
   1.511  	}
   1.512 -      }
   1.513 -    }else{
   1.514 -      popb->error = (len == -1) ? pop3_eof : pop3_timeout;
   1.515 -      return FALSE;
   1.516 -    }
   1.517 -  }
   1.518 -  return FALSE;
   1.519 +	return FALSE;
   1.520  }
   1.521  
   1.522 -static
   1.523 -gboolean get_uid_listing(pop3_base *popb)
   1.524 +static gboolean
   1.525 +get_uid_listing(pop3_base * popb)
   1.526  {
   1.527 -  gchar buf[64];
   1.528 +	gchar buf[64];
   1.529  
   1.530 -  while(1){
   1.531 -    gint len = read_sockline(popb->in, buf, 64, POP3_CMD_TIMEOUT, READSOCKL_CHUG);
   1.532 -    if(len > 0){
   1.533 -      if(buf[0] == '.')
   1.534 -	return TRUE;
   1.535 -      else{
   1.536 -	gint number;
   1.537 -	gchar *p = buf, *pe;
   1.538 -	if(strtoi(p, &pe, &number)){
   1.539 -	  msg_info *info = NULL;
   1.540 -	  GList *drop_node;
   1.541 +	while (1) {
   1.542 +		gint len = read_sockline(popb->in, buf, 64, POP3_CMD_TIMEOUT, READSOCKL_CHUG);
   1.543 +		if (len > 0) {
   1.544 +			if (buf[0] == '.')
   1.545 +				return TRUE;
   1.546 +			else {
   1.547 +				gint number;
   1.548 +				gchar *p = buf, *pe;
   1.549 +				if (strtoi(p, &pe, &number)) {
   1.550 +					msg_info *info = NULL;
   1.551 +					GList *drop_node;
   1.552  
   1.553 -	  p = pe;
   1.554 -	  while(*p && isspace(*p)) p++;
   1.555 +					p = pe;
   1.556 +					while (*p && isspace(*p))
   1.557 +						p++;
   1.558  
   1.559 -	  foreach(popb->drop_list, drop_node){
   1.560 -	    msg_info *curr_info = (msg_info *)(drop_node->data);
   1.561 -	    if(curr_info->number == number){
   1.562 -	      info = curr_info;
   1.563 -	      break;
   1.564 -	    }
   1.565 -	  }
   1.566 -	  if(info){
   1.567 -	    info->uid = g_strdup(p);
   1.568 -	    g_strchomp(info->uid);
   1.569 -	  }
   1.570 +					foreach(popb->drop_list, drop_node) {
   1.571 +						msg_info *curr_info = (msg_info *) (drop_node->data);
   1.572 +						if (curr_info->number == number) {
   1.573 +							info = curr_info;
   1.574 +							break;
   1.575 +						}
   1.576 +					}
   1.577 +					if (info) {
   1.578 +						info->uid = g_strdup(p);
   1.579 +						g_strchomp(info->uid);
   1.580 +					}
   1.581  
   1.582 -	}else{
   1.583 -	  popb->error = pop3_syntax;
   1.584 -	  break;
   1.585 +				} else {
   1.586 +					popb->error = pop3_syntax;
   1.587 +					break;
   1.588 +				}
   1.589 +			}
   1.590 +		}
   1.591  	}
   1.592 -      }
   1.593 -    }
   1.594 -  }
   1.595 -  return FALSE;
   1.596 +	return FALSE;
   1.597  }
   1.598  
   1.599 -static
   1.600 -gboolean check_init_response(pop3_base *popb)
   1.601 +static gboolean
   1.602 +check_init_response(pop3_base * popb)
   1.603  {
   1.604 -  if(check_response(popb)){
   1.605 -    gchar buf[256];
   1.606 -    gchar *p = popb->buffer;
   1.607 -    gint i = 0;
   1.608 -    if(*p){
   1.609 -      while(*p && (*p != '<')) p++;
   1.610 -      while(*p && (*p != '>') && (i < 254))
   1.611 -	buf[i++] = *(p++);
   1.612 -      buf[i++] = '>';
   1.613 -      buf[i] = 0;
   1.614 +	if (check_response(popb)) {
   1.615 +		gchar buf[256];
   1.616 +		gchar *p = popb->buffer;
   1.617 +		gint i = 0;
   1.618 +		if (*p) {
   1.619 +			while (*p && (*p != '<'))
   1.620 +				p++;
   1.621 +			while (*p && (*p != '>') && (i < 254))
   1.622 +				buf[i++] = *(p++);
   1.623 +			buf[i++] = '>';
   1.624 +			buf[i] = 0;
   1.625  
   1.626 -      popb->timestamp = g_strdup(buf);
   1.627 +			popb->timestamp = g_strdup(buf);
   1.628  
   1.629 -      return TRUE;
   1.630 -    }
   1.631 -  }
   1.632 -  return FALSE;
   1.633 +			return TRUE;
   1.634 +		}
   1.635 +	}
   1.636 +	return FALSE;
   1.637  }
   1.638  
   1.639 -void pop3_in_close(pop3_base *popb)
   1.640 +void
   1.641 +pop3_in_close(pop3_base * popb)
   1.642  {
   1.643 -  GList *node;
   1.644 +	GList *node;
   1.645  
   1.646 -  fclose(popb->in);
   1.647 -  fclose(popb->out);
   1.648 +	fclose(popb->in);
   1.649 +	fclose(popb->out);
   1.650  
   1.651 -  close(popb->sock);
   1.652 +	close(popb->sock);
   1.653  
   1.654 -  foreach(popb->list_uid_old, node){
   1.655 -    gchar *uid = (gchar *)(node->data);
   1.656 -    g_free(uid);
   1.657 -  }
   1.658 -  g_list_free(popb->list_uid_old);
   1.659 +	foreach(popb->list_uid_old, node) {
   1.660 +		gchar *uid = (gchar *) (node->data);
   1.661 +		g_free(uid);
   1.662 +	}
   1.663 +	g_list_free(popb->list_uid_old);
   1.664  
   1.665 -  foreach(popb->drop_list, node){
   1.666 -    msg_info *info = (msg_info *)(node->data);
   1.667 -    if(info->uid) g_free(info->uid);
   1.668 -    g_free(info);
   1.669 -  }
   1.670 -  g_list_free(popb->drop_list);
   1.671 +	foreach(popb->drop_list, node) {
   1.672 +		msg_info *info = (msg_info *) (node->data);
   1.673 +		if (info->uid)
   1.674 +			g_free(info->uid);
   1.675 +		g_free(info);
   1.676 +	}
   1.677 +	g_list_free(popb->drop_list);
   1.678  
   1.679 -  if(popb->buffer) g_free(popb->buffer);
   1.680 -  if(popb->timestamp) g_free(popb->timestamp);
   1.681 +	if (popb->buffer)
   1.682 +		g_free(popb->buffer);
   1.683 +	if (popb->timestamp)
   1.684 +		g_free(popb->timestamp);
   1.685  }
   1.686  
   1.687 -pop3_base *pop3_in_open(gchar *host, gint port, GList *resolve_list, guint flags)
   1.688 +pop3_base*
   1.689 +pop3_in_open(gchar * host, gint port, GList * resolve_list, guint flags)
   1.690  {
   1.691 -  pop3_base *popb;
   1.692 -  gint sock;
   1.693 -  mxip_addr *addr;
   1.694 +	pop3_base *popb;
   1.695 +	gint sock;
   1.696 +	mxip_addr *addr;
   1.697  
   1.698 -  DEBUG(5) debugf("pop3_in_open entered, host = %s\n", host);
   1.699 +	DEBUG(5) debugf("pop3_in_open entered, host = %s\n", host);
   1.700  
   1.701 -  if((addr = connect_resolvelist(&sock, host, port, resolve_list))){
   1.702 -    /* create structure to hold status data: */
   1.703 -    popb = create_pop3base(sock, flags);
   1.704 -    popb->remote_host = addr->name;
   1.705 +	if ((addr = connect_resolvelist(&sock, host, port, resolve_list))) {
   1.706 +		/* create structure to hold status data: */
   1.707 +		popb = create_pop3base(sock, flags);
   1.708 +		popb->remote_host = addr->name;
   1.709  
   1.710 -    DEBUG(5){
   1.711 -      struct sockaddr_in name;
   1.712 -      int len;
   1.713 -      getsockname(sock, (struct sockaddr *)(&name), &len);
   1.714 -      debugf("socket: name.sin_addr = %s\n", inet_ntoa(name.sin_addr));
   1.715 -    }
   1.716 -    return popb;
   1.717 -  }
   1.718 -  return NULL;
   1.719 +		DEBUG(5) {
   1.720 +			struct sockaddr_in name;
   1.721 +			int len;
   1.722 +			getsockname(sock, (struct sockaddr *) (&name), &len);
   1.723 +			debugf("socket: name.sin_addr = %s\n", inet_ntoa(name.sin_addr));
   1.724 +		}
   1.725 +		return popb;
   1.726 +	}
   1.727 +	return NULL;
   1.728  }
   1.729  
   1.730 -pop3_base *pop3_in_open_child(gchar *cmd, guint flags)
   1.731 +pop3_base*
   1.732 +pop3_in_open_child(gchar * cmd, guint flags)
   1.733  {
   1.734 -  pop3_base *popb;
   1.735 -  gint sock;
   1.736 +	pop3_base *popb;
   1.737 +	gint sock;
   1.738  
   1.739 -  DEBUG(5) debugf("pop3_in_open_child entered, cmd = %s\n", cmd);
   1.740 +	DEBUG(5) debugf("pop3_in_open_child entered, cmd = %s\n", cmd);
   1.741  
   1.742 -  sock = child(cmd);
   1.743 +	sock = child(cmd);
   1.744  
   1.745 -  if(sock > 0){
   1.746 +	if (sock > 0) {
   1.747  
   1.748 -    popb = create_pop3base(sock, flags);
   1.749 -    popb->remote_host = NULL;
   1.750 +		popb = create_pop3base(sock, flags);
   1.751 +		popb->remote_host = NULL;
   1.752  
   1.753 -    return popb;
   1.754 -  }
   1.755 -  logwrite(LOG_ALERT, "child failed (sock = %d): %s\n", sock, strerror(errno));
   1.756 +		return popb;
   1.757 +	}
   1.758 +	logwrite(LOG_ALERT, "child failed (sock = %d): %s\n", sock, strerror(errno));
   1.759  
   1.760 -  return NULL;
   1.761 +	return NULL;
   1.762  }
   1.763  
   1.764 -gboolean pop3_in_init(pop3_base *popb)
   1.765 +gboolean
   1.766 +pop3_in_init(pop3_base * popb)
   1.767  {
   1.768 -  gboolean ok;
   1.769 +	gboolean ok;
   1.770  
   1.771 -  if((ok = read_response(popb, POP3_INITIAL_TIMEOUT))){
   1.772 -    ok = check_init_response(popb);
   1.773 -  }
   1.774 -  if(!ok)
   1.775 -    /*    pop3_in_log_failure(popb, NULL);*/
   1.776 -    logwrite(LOG_ALERT, "pop3 failed\n");
   1.777 -  return ok;
   1.778 +	if ((ok = read_response(popb, POP3_INITIAL_TIMEOUT))) {
   1.779 +		ok = check_init_response(popb);
   1.780 +	}
   1.781 +	if (!ok)
   1.782 +		/* pop3_in_log_failure(popb, NULL); */
   1.783 +		logwrite(LOG_ALERT, "pop3 failed\n");
   1.784 +	return ok;
   1.785  }
   1.786  
   1.787 -gboolean pop3_in_login(pop3_base *popb, gchar *user, gchar *pass)
   1.788 +gboolean
   1.789 +pop3_in_login(pop3_base * popb, gchar * user, gchar * pass)
   1.790  {
   1.791 -  if(popb->flags & POP3_FLAG_APOP){
   1.792 +	if (popb->flags & POP3_FLAG_APOP) {
   1.793  
   1.794 -    gchar *string = g_strdup_printf("%s%s", popb->timestamp, pass);
   1.795 -    gchar *digest = MD5String(string);
   1.796 -    pop3_printf(popb->out, "APOP %s %s\r\n", user, digest);
   1.797 -    g_free(string);
   1.798 -    g_free(digest);
   1.799 -    if(read_response(popb, POP3_CMD_TIMEOUT)){
   1.800 -      if(check_response(popb))
   1.801 -	return TRUE;
   1.802 -      else
   1.803 -	popb->error = pop3_login_failure;
   1.804 -    }
   1.805 +		gchar *string = g_strdup_printf("%s%s", popb->timestamp, pass);
   1.806 +		gchar *digest = MD5String(string);
   1.807 +		pop3_printf(popb->out, "APOP %s %s\r\n", user, digest);
   1.808 +		g_free(string);
   1.809 +		g_free(digest);
   1.810 +		if (read_response(popb, POP3_CMD_TIMEOUT)) {
   1.811 +			if (check_response(popb))
   1.812 +				return TRUE;
   1.813 +			else
   1.814 +				popb->error = pop3_login_failure;
   1.815 +		}
   1.816  
   1.817 -  }else{
   1.818 +	} else {
   1.819  
   1.820 -    pop3_printf(popb->out, "USER %s\r\n", user);
   1.821 -    if(read_response(popb, POP3_CMD_TIMEOUT)){
   1.822 -      if(check_response(popb)){
   1.823 -	pop3_printf(popb->out, "PASS %s\r\n", pass);
   1.824 -	if(read_response(popb, POP3_CMD_TIMEOUT)){
   1.825 -	  if(check_response(popb))
   1.826 -	    return TRUE;
   1.827 -	  else
   1.828 -	    popb->error = pop3_login_failure;
   1.829 +		pop3_printf(popb->out, "USER %s\r\n", user);
   1.830 +		if (read_response(popb, POP3_CMD_TIMEOUT)) {
   1.831 +			if (check_response(popb)) {
   1.832 +				pop3_printf(popb->out, "PASS %s\r\n", pass);
   1.833 +				if (read_response(popb, POP3_CMD_TIMEOUT)) {
   1.834 +					if (check_response(popb))
   1.835 +						return TRUE;
   1.836 +					else
   1.837 +						popb->error = pop3_login_failure;
   1.838 +				}
   1.839 +			} else {
   1.840 +				popb->error = pop3_login_failure;
   1.841 +			}
   1.842 +		}
   1.843  	}
   1.844 -      }else{
   1.845 -	popb->error = pop3_login_failure;
   1.846 -      }
   1.847 -    }
   1.848 -  }
   1.849 -  return FALSE;
   1.850 +	return FALSE;
   1.851  }
   1.852  
   1.853 -gboolean pop3_in_stat(pop3_base *popb)
   1.854 +gboolean
   1.855 +pop3_in_stat(pop3_base * popb)
   1.856  {
   1.857 -  pop3_printf(popb->out, "STAT\r\n");
   1.858 -  if(read_response(popb, POP3_CMD_TIMEOUT)){
   1.859 -    gint msg_cnt, mbox_size;
   1.860 -    if(check_response_int_int(popb, &msg_cnt, &mbox_size)){
   1.861 -      popb->msg_cnt = msg_cnt;
   1.862 -      popb->mbox_size = mbox_size;
   1.863 +	pop3_printf(popb->out, "STAT\r\n");
   1.864 +	if (read_response(popb, POP3_CMD_TIMEOUT)) {
   1.865 +		gint msg_cnt, mbox_size;
   1.866 +		if (check_response_int_int(popb, &msg_cnt, &mbox_size)) {
   1.867 +			popb->msg_cnt = msg_cnt;
   1.868 +			popb->mbox_size = mbox_size;
   1.869  
   1.870 -      return TRUE;
   1.871 -    }
   1.872 -  }
   1.873 -  return FALSE;
   1.874 +			return TRUE;
   1.875 +		}
   1.876 +	}
   1.877 +	return FALSE;
   1.878  }
   1.879  
   1.880 -gboolean pop3_in_list(pop3_base *popb)
   1.881 +gboolean
   1.882 +pop3_in_list(pop3_base * popb)
   1.883  {
   1.884 -  pop3_printf(popb->out, "LIST\r\n");
   1.885 -  if(read_response(popb, POP3_CMD_TIMEOUT)){
   1.886 -    if(get_drop_listing(popb)){
   1.887 -      return TRUE;
   1.888 -    }
   1.889 -  }
   1.890 -  return FALSE;
   1.891 +	pop3_printf(popb->out, "LIST\r\n");
   1.892 +	if (read_response(popb, POP3_CMD_TIMEOUT)) {
   1.893 +		if (get_drop_listing(popb)) {
   1.894 +			return TRUE;
   1.895 +		}
   1.896 +	}
   1.897 +	return FALSE;
   1.898  }
   1.899  
   1.900 -gboolean pop3_in_dele(pop3_base *popb, gint number)
   1.901 +gboolean
   1.902 +pop3_in_dele(pop3_base * popb, gint number)
   1.903  {
   1.904 -  pop3_printf(popb->out, "DELE %d\r\n", number);
   1.905 -  if(read_response(popb, POP3_CMD_TIMEOUT)){
   1.906 -    return TRUE;
   1.907 -  }
   1.908 -  return FALSE;
   1.909 +	pop3_printf(popb->out, "DELE %d\r\n", number);
   1.910 +	if (read_response(popb, POP3_CMD_TIMEOUT)) {
   1.911 +		return TRUE;
   1.912 +	}
   1.913 +	return FALSE;
   1.914  }
   1.915  
   1.916 -message *pop3_in_retr(pop3_base *popb, gint number, address *rcpt)
   1.917 +message*
   1.918 +pop3_in_retr(pop3_base * popb, gint number, address * rcpt)
   1.919  {
   1.920 -  accept_error err;
   1.921 +	accept_error err;
   1.922  
   1.923 -  pop3_printf(popb->out, "RETR %d\r\n", number);
   1.924 -  if(read_response(popb, POP3_CMD_TIMEOUT)){
   1.925 -    message *msg = create_message();
   1.926 -    msg->received_host = popb->remote_host;
   1.927 -    msg->received_prot = (popb->flags & POP3_FLAG_APOP) ? PROT_APOP : PROT_POP3;
   1.928 -    msg->transfer_id = (popb->next_id)++;
   1.929 -    msg->rcpt_list = g_list_append(NULL, copy_address(rcpt));
   1.930 +	pop3_printf(popb->out, "RETR %d\r\n", number);
   1.931 +	if (read_response(popb, POP3_CMD_TIMEOUT)) {
   1.932 +		message *msg = create_message();
   1.933 +		msg->received_host = popb->remote_host;
   1.934 +		msg->received_prot = (popb->flags & POP3_FLAG_APOP) ? PROT_APOP : PROT_POP3;
   1.935 +		msg->transfer_id = (popb->next_id)++;
   1.936 +		msg->rcpt_list = g_list_append(NULL, copy_address(rcpt));
   1.937  
   1.938 -    if((err = accept_message(popb->in, msg,
   1.939 -			     ACC_MAIL_FROM_HEAD|(conf.do_save_envelope_to ? ACC_SAVE_ENVELOPE_TO : 0)))
   1.940 -       == AERR_OK)
   1.941 -      return msg;
   1.942 +		if ((err = accept_message(popb->in, msg, ACC_MAIL_FROM_HEAD
   1.943 +		    | (conf.do_save_envelope_to ? ACC_SAVE_ENVELOPE_TO : 0)))
   1.944 +		    == AERR_OK)
   1.945 +			return msg;
   1.946  
   1.947 -    destroy_message(msg);
   1.948 -  }
   1.949 -  return NULL;
   1.950 -}  
   1.951 -
   1.952 -gboolean pop3_in_uidl(pop3_base *popb)
   1.953 -{
   1.954 -  pop3_printf(popb->out, "UIDL\r\n");
   1.955 -  if(read_response(popb, POP3_CMD_TIMEOUT)){
   1.956 -    if(get_uid_listing(popb)){
   1.957 -      return TRUE;
   1.958 -    }
   1.959 -  }
   1.960 -  return FALSE;
   1.961 +		destroy_message(msg);
   1.962 +	}
   1.963 +	return NULL;
   1.964  }
   1.965  
   1.966 -gboolean pop3_in_quit(pop3_base *popb)
   1.967 +gboolean
   1.968 +pop3_in_uidl(pop3_base * popb)
   1.969  {
   1.970 -  pop3_printf(popb->out, "QUIT\r\n");
   1.971 -  
   1.972 -  DEBUG(4) debugf("QUIT\n");
   1.973 +	pop3_printf(popb->out, "UIDL\r\n");
   1.974 +	if (read_response(popb, POP3_CMD_TIMEOUT)) {
   1.975 +		if (get_uid_listing(popb)) {
   1.976 +			return TRUE;
   1.977 +		}
   1.978 +	}
   1.979 +	return FALSE;
   1.980 +}
   1.981  
   1.982 -  signal(SIGALRM, SIG_DFL);
   1.983 +gboolean
   1.984 +pop3_in_quit(pop3_base * popb)
   1.985 +{
   1.986 +	pop3_printf(popb->out, "QUIT\r\n");
   1.987  
   1.988 -  return TRUE;
   1.989 +	DEBUG(4) debugf("QUIT\n");
   1.990 +
   1.991 +	signal(SIGALRM, SIG_DFL);
   1.992 +
   1.993 +	return TRUE;
   1.994  }
   1.995  
   1.996  /* Send a DELE command for each message in (the old) uid listing.
   1.997     This is to prevent mail from to be kept on server, if a previous
   1.998     transaction was interupted. */
   1.999 -gboolean pop3_in_uidl_dele(pop3_base *popb)
  1.1000 +gboolean
  1.1001 +pop3_in_uidl_dele(pop3_base * popb)
  1.1002  {
  1.1003 -  GList *drop_node;
  1.1004 +	GList *drop_node;
  1.1005  
  1.1006 -  foreach(popb->drop_list, drop_node){
  1.1007 -    msg_info *info = (msg_info *)(drop_node->data);
  1.1008 -    /*    if(find_uid(popb, info->uid)){*/
  1.1009 -    if(info->is_in_uidl){
  1.1010 -      if(!pop3_in_dele(popb, info->number))
  1.1011 -	return FALSE;
  1.1012 -      /* TODO: it probably makes sense to also
  1.1013 -	 delete this uid from the listing */
  1.1014 -    }
  1.1015 -  }
  1.1016 -  return TRUE;
  1.1017 +	foreach(popb->drop_list, drop_node) {
  1.1018 +		msg_info *info = (msg_info *) (drop_node->data);
  1.1019 +		/* if(find_uid(popb, info->uid)){ */
  1.1020 +		if (info->is_in_uidl) {
  1.1021 +			if (!pop3_in_dele(popb, info->number))
  1.1022 +				return FALSE;
  1.1023 +			/* TODO: it probably makes sense to also delete this uid from the listing */
  1.1024 +		}
  1.1025 +	}
  1.1026 +	return TRUE;
  1.1027  }
  1.1028  
  1.1029 -gboolean pop3_get(pop3_base *popb,
  1.1030 -		  gchar *user, gchar *pass, address *rcpt, address *return_path,
  1.1031 -		  gint max_count, gint max_size, gboolean max_size_delete)
  1.1032 +gboolean
  1.1033 +pop3_get(pop3_base * popb, gchar * user, gchar * pass, address * rcpt, address * return_path, gint max_count, gint max_size, gboolean max_size_delete)
  1.1034  {
  1.1035 -  gboolean ok = FALSE;
  1.1036 -  gint num_children = 0;
  1.1037 -  
  1.1038 -  DEBUG(5) debugf("rcpt = %s@%s\n", rcpt->local_part, rcpt->domain);
  1.1039 +	gboolean ok = FALSE;
  1.1040 +	gint num_children = 0;
  1.1041  
  1.1042 -  signal(SIGCHLD, SIG_DFL);
  1.1043 +	DEBUG(5) debugf("rcpt = %s@%s\n", rcpt->local_part, rcpt->domain);
  1.1044  
  1.1045 -  if(pop3_in_init(popb)){
  1.1046 -    if(pop3_in_login(popb, user, pass)){
  1.1047 -      if(pop3_in_stat(popb)){
  1.1048 -	if(popb->msg_cnt > 0){
  1.1049 +	signal(SIGCHLD, SIG_DFL);
  1.1050  
  1.1051 -	  logwrite(LOG_NOTICE|LOG_VERBOSE, "%d message(s) for user %s at %s\n",
  1.1052 -		   popb->msg_cnt, user, popb->remote_host);
  1.1053 +	if (pop3_in_init(popb)) {
  1.1054 +		if (pop3_in_login(popb, user, pass)) {
  1.1055 +			if (pop3_in_stat(popb)) {
  1.1056 +				if (popb->msg_cnt > 0) {
  1.1057  
  1.1058 -	  if(pop3_in_list(popb)){
  1.1059 -	    gboolean do_get = !(popb->flags & POP3_FLAG_UIDL);
  1.1060 -	    if(!do_get) do_get = pop3_in_uidl(popb);
  1.1061 -	    if(do_get){
  1.1062 -	      gint count = 0;
  1.1063 -	      GList *drop_node;
  1.1064 +					logwrite(LOG_NOTICE | LOG_VERBOSE, "%d message(s) for user %s at %s\n", popb->msg_cnt, user, popb->remote_host);
  1.1065  
  1.1066 -	      if(popb->flags & POP3_FLAG_UIDL){
  1.1067 -		read_uidl(popb, user);
  1.1068 -		logwrite(LOG_VERBOSE|LOG_NOTICE, "%d message(s) already in uidl.\n",
  1.1069 -			 popb->uidl_known_cnt);
  1.1070 -	      }
  1.1071 -	      if((popb->flags & POP3_FLAG_UIDL) && (popb->flags & POP3_FLAG_UIDL_DELE))
  1.1072 -		pop3_in_uidl_dele(popb);
  1.1073 +					if (pop3_in_list(popb)) {
  1.1074 +						gboolean do_get = !(popb->flags & POP3_FLAG_UIDL);
  1.1075 +						if (!do_get)
  1.1076 +							do_get = pop3_in_uidl(popb);
  1.1077 +						if (do_get) {
  1.1078 +							gint count = 0;
  1.1079 +							GList *drop_node;
  1.1080  
  1.1081 -	      foreach(popb->drop_list, drop_node){
  1.1082 +							if (popb->flags & POP3_FLAG_UIDL) {
  1.1083 +								read_uidl(popb, user);
  1.1084 +								logwrite(LOG_VERBOSE | LOG_NOTICE, "%d message(s) already in uidl.\n", popb->uidl_known_cnt);
  1.1085 +							}
  1.1086 +							if ((popb->flags & POP3_FLAG_UIDL) && (popb->flags & POP3_FLAG_UIDL_DELE))
  1.1087 +								pop3_in_uidl_dele(popb);
  1.1088  
  1.1089 -		msg_info *info = (msg_info *)(drop_node->data);
  1.1090 -		gboolean do_get_this = !(popb->flags & POP3_FLAG_UIDL);
  1.1091 -		/*		if(!do_get_this) do_get_this = !find_uid(popb, info->uid);*/
  1.1092 -		if(!do_get_this) do_get_this = !(info->is_in_uidl);
  1.1093 -		if(do_get_this){
  1.1094 +							foreach(popb->drop_list, drop_node) {
  1.1095  
  1.1096 -		  if((info->size < max_size) || (max_size == 0)){
  1.1097 -		    message *msg;
  1.1098 +								msg_info *info = (msg_info *) (drop_node->data);
  1.1099 +								gboolean do_get_this = !(popb->flags & POP3_FLAG_UIDL);
  1.1100 +								/* if(!do_get_this) do_get_this = !find_uid(popb, info->uid); */
  1.1101 +								if (!do_get_this)
  1.1102 +									do_get_this = !(info->is_in_uidl);
  1.1103 +								if (do_get_this) {
  1.1104  
  1.1105 -		    logwrite(LOG_VERBOSE|LOG_NOTICE, "receiving message %d\n", info->number);
  1.1106 -		    msg = pop3_in_retr(popb, info->number, rcpt);
  1.1107 +									if ((info->size < max_size) || (max_size == 0)) {
  1.1108 +										message *msg;
  1.1109  
  1.1110 -		    if(msg){
  1.1111 -		      if(return_path)
  1.1112 -			msg->return_path = copy_address(return_path);
  1.1113 -		      if(spool_write(msg, TRUE)){
  1.1114 -			pid_t pid;
  1.1115 -			logwrite(LOG_NOTICE, "%s <= %s host=%s with %s\n",
  1.1116 -				 msg->uid,
  1.1117 -				 addr_string(msg->return_path),
  1.1118 -				 popb->remote_host,
  1.1119 -				 (popb->flags & POP3_FLAG_APOP) ?
  1.1120 -				 prot_names[PROT_APOP] : prot_names[PROT_POP3]
  1.1121 -				 );
  1.1122 -			info->is_fetched = TRUE;
  1.1123 -			count++;
  1.1124 +										logwrite(LOG_VERBOSE | LOG_NOTICE, "receiving message %d\n", info->number);
  1.1125 +										msg = pop3_in_retr(popb, info->number, rcpt);
  1.1126 +
  1.1127 +										if (msg) {
  1.1128 +											if (return_path)
  1.1129 +												msg->return_path = copy_address(return_path);
  1.1130 +											if (spool_write(msg, TRUE)) {
  1.1131 +												pid_t pid;
  1.1132 +												logwrite(LOG_NOTICE, "%s <= %s host=%s with %s\n", msg->uid,
  1.1133 +												         addr_string(msg->return_path), popb->remote_host,
  1.1134 +												         (popb->flags & POP3_FLAG_APOP) ? prot_names [PROT_APOP] : prot_names [PROT_POP3]);
  1.1135 +												info->is_fetched = TRUE;
  1.1136 +												count++;
  1.1137  #if DO_WRITE_UIDL_EARLY
  1.1138 -			if(popb->flags & POP3_FLAG_UIDL) write_uidl(popb, user);
  1.1139 +												if (popb->flags & POP3_FLAG_UIDL)
  1.1140 +													write_uidl(popb, user);
  1.1141  #endif
  1.1142 -			if(!conf.do_queue){
  1.1143 +												if (!conf.do_queue) {
  1.1144  
  1.1145 -			  /* wait for child processes. If there are too many,
  1.1146 -			     we wait blocking, before we fork another one */
  1.1147 -			  while(num_children > 0){
  1.1148 -			    int status, options = WNOHANG;
  1.1149 -			    pid_t pid;
  1.1150 +													/* wait for child processes. If there are too many, we wait blocking, before we fork another one */
  1.1151 +													while (num_children > 0) {
  1.1152 +														int status, options = WNOHANG;
  1.1153 +														pid_t pid;
  1.1154  
  1.1155 -			    if(num_children >= POP3_MAX_CHILDREN){
  1.1156 -			      logwrite(LOG_NOTICE, "too many children - waiting\n");
  1.1157 -			      options = 0;
  1.1158 -			    }
  1.1159 -			    if((pid = waitpid(0, &status, options)) > 0){
  1.1160 -			      num_children--;
  1.1161 -			      if(WEXITSTATUS(status) != EXIT_SUCCESS)
  1.1162 -				logwrite(LOG_WARNING,
  1.1163 -					 "delivery process with pid %d returned %d\n",
  1.1164 -					 pid, WEXITSTATUS(status));
  1.1165 -			      if(WIFSIGNALED(status))
  1.1166 -				logwrite(LOG_WARNING,
  1.1167 -					 "delivery process with pid %d got signal: %d\n",
  1.1168 -					 pid, WTERMSIG(status));
  1.1169 -			    }else if(pid < 0){
  1.1170 -			      logwrite(LOG_WARNING, "wait got error: %s\n", strerror(errno));
  1.1171 -			    }
  1.1172 -			  }
  1.1173 +														if (num_children >= POP3_MAX_CHILDREN) {
  1.1174 +															logwrite(LOG_NOTICE, "too many children - waiting\n");
  1.1175 +															options = 0;
  1.1176 +														}
  1.1177 +														if ((pid = waitpid(0, &status, options)) > 0) {
  1.1178 +															num_children--;
  1.1179 +															if (WEXITSTATUS(status) != EXIT_SUCCESS)
  1.1180 +																logwrite(LOG_WARNING, "delivery process with pid %d returned %d\n", pid, WEXITSTATUS (status));
  1.1181 +															if (WIFSIGNALED(status))
  1.1182 +																logwrite(LOG_WARNING, "delivery process with pid %d got signal: %d\n", pid, WTERMSIG (status));
  1.1183 +														} else if (pid < 0) {
  1.1184 +															logwrite(LOG_WARNING, "wait got error: %s\n", strerror(errno));
  1.1185 +														}
  1.1186 +													}
  1.1187  
  1.1188 -			  if((pid = fork()) == 0){
  1.1189 -			    deliver(msg);
  1.1190 -			    _exit(EXIT_SUCCESS);
  1.1191 -			  }else if(pid < 0){
  1.1192 -			    logwrite(LOG_ALERT|LOG_VERBOSE,
  1.1193 -				     "could not fork for delivery, id = %s: %s\n",
  1.1194 -				     msg->uid, strerror(errno));
  1.1195 -			  }else
  1.1196 -			    num_children++;
  1.1197 -			}else{
  1.1198 -			  DEBUG(1) debugf("queuing forced by configuration or option.\n");
  1.1199 -			}
  1.1200 -			if(popb->flags & POP3_FLAG_DELETE)
  1.1201 -			  pop3_in_dele(popb, info->number);
  1.1202 +													if ((pid = fork()) == 0) {
  1.1203 +														deliver(msg);
  1.1204 +														_exit(EXIT_SUCCESS);
  1.1205 +													} else if (pid < 0) {
  1.1206 +														logwrite(LOG_ALERT | LOG_VERBOSE, "could not fork for delivery, id = %s: %s\n", msg->uid, strerror(errno));
  1.1207 +													} else
  1.1208 +														num_children++;
  1.1209 +												} else {
  1.1210 +													DEBUG(1) debugf("queuing forced by configuration or option.\n");
  1.1211 +												}
  1.1212 +												if (popb->flags & POP3_FLAG_DELETE)
  1.1213 +													pop3_in_dele(popb, info->number);
  1.1214  
  1.1215 -			destroy_message(msg);
  1.1216 -		      }/* if(spool_write(msg, TRUE)) */
  1.1217 -		    }else{
  1.1218 -		      logwrite(LOG_ALERT,
  1.1219 -			       "retrieving of message %d failed: %d\n",
  1.1220 -			       info->number, popb->error);
  1.1221 -		    }
  1.1222 -		  }/* if((info->size > max_size) ... */
  1.1223 -		  else{
  1.1224 -		    logwrite(LOG_NOTICE|LOG_VERBOSE, "size of message #%d (%d) > max_size (%d)\n",
  1.1225 -			     info->number, info->size, max_size);
  1.1226 -		    if(max_size_delete)
  1.1227 -			if(popb->flags & POP3_FLAG_DELETE)
  1.1228 -			  pop3_in_dele(popb, info->number);
  1.1229 -		  }
  1.1230 -		}/* if(do_get_this) ... */
  1.1231 -		else{
  1.1232 -		  if(popb->flags & POP3_FLAG_UIDL){
  1.1233 -		    info->is_fetched = TRUE; /* obsolete? */
  1.1234 -		    logwrite(LOG_VERBOSE, "message %d already known\n",
  1.1235 -			     info->number);
  1.1236 -		    DEBUG(1) debugf("message %d (uid = %s) not fetched\n",
  1.1237 -				    info->number, info->uid);
  1.1238 +												destroy_message(msg);
  1.1239 +											}	/* if(spool_write(msg, TRUE)) */
  1.1240 +										} else {
  1.1241 +											logwrite(LOG_ALERT, "retrieving of message %d failed: %d\n", info->number, popb->error);
  1.1242 +										}
  1.1243 +									} /* if((info->size > max_size) ... */
  1.1244 +									else {
  1.1245 +										logwrite(LOG_NOTICE | LOG_VERBOSE, "size of message #%d (%d) > max_size (%d)\n", info->number, info->size, max_size);
  1.1246 +										if (max_size_delete)
  1.1247 +											if (popb->flags & POP3_FLAG_DELETE)
  1.1248 +												pop3_in_dele(popb, info->number);
  1.1249 +									}
  1.1250 +								} /* if(do_get_this) ... */
  1.1251 +								else {
  1.1252 +									if (popb->flags & POP3_FLAG_UIDL) {
  1.1253 +										info->is_fetched = TRUE;  /* obsolete? */
  1.1254 +										logwrite(LOG_VERBOSE, "message %d already known\n", info->number);
  1.1255 +										DEBUG(1) debugf("message %d (uid = %s) not fetched\n", info->number, info->uid);
  1.1256  #if 0
  1.1257  #if DO_WRITE_UIDL_EARLY
  1.1258 -		    write_uidl(popb, user); /* obsolete? */
  1.1259 +										write_uidl(popb, user);  /* obsolete? */
  1.1260  #endif
  1.1261  #endif
  1.1262 -		  }
  1.1263 -		}
  1.1264 -		if((max_count != 0) && (count >= max_count))
  1.1265 -		  break;
  1.1266 -	      }/* foreach() */
  1.1267 +									}
  1.1268 +								}
  1.1269 +								if ((max_count != 0) && (count >= max_count))
  1.1270 +									break;
  1.1271 +							}	/* foreach() */
  1.1272  #if DO_WRITE_UIDL_EARLY
  1.1273  #else
  1.1274 -	      if(popb->flags & POP3_FLAG_UIDL) write_uidl(popb, user);
  1.1275 +							if (popb->flags & POP3_FLAG_UIDL)
  1.1276 +								write_uidl(popb, user);
  1.1277  #endif
  1.1278 -	    }/* if(pop3_in_uidl(popb) ... */
  1.1279 -	  }/* if(pop3_in_list(popb)) */
  1.1280 -	}/* if(popb->msg_cnt > 0) */
  1.1281 -	else{
  1.1282 -	  logwrite(LOG_NOTICE|LOG_VERBOSE,
  1.1283 -		   "no messages for user %s at %s\n", user, popb->remote_host);
  1.1284 +						}  /* if(pop3_in_uidl(popb) ... */
  1.1285 +					}  /* if(pop3_in_list(popb)) */
  1.1286 +				}  /* if(popb->msg_cnt > 0) */
  1.1287 +				else {
  1.1288 +					logwrite(LOG_NOTICE | LOG_VERBOSE, "no messages for user %s at %s\n", user, popb->remote_host);
  1.1289 +				}
  1.1290 +				ok = TRUE;
  1.1291 +			}
  1.1292 +			pop3_in_quit(popb);
  1.1293 +		} else {
  1.1294 +			logwrite(LOG_ALERT | LOG_VERBOSE, "pop3 login failed for user %s, host = %s\n", user, popb->remote_host);
  1.1295 +		}
  1.1296  	}
  1.1297 -	ok = TRUE;
  1.1298 -      }
  1.1299 -      pop3_in_quit(popb);
  1.1300 -    }else{
  1.1301 -      logwrite(LOG_ALERT|LOG_VERBOSE,
  1.1302 -	       "pop3 login failed for user %s, host = %s\n", user, popb->remote_host);
  1.1303 -    }
  1.1304 -  }
  1.1305 -  if(!ok){
  1.1306 -    logwrite(LOG_ALERT|LOG_VERBOSE, "pop3 failed, error = %d\n", popb->error);
  1.1307 -  }
  1.1308 +	if (!ok) {
  1.1309 +		logwrite(LOG_ALERT | LOG_VERBOSE, "pop3 failed, error = %d\n", popb->error);
  1.1310 +	}
  1.1311  
  1.1312 -  while(num_children > 0){
  1.1313 -    int status;
  1.1314 -    pid_t pid;
  1.1315 -    if((pid = wait(&status)) > 0){
  1.1316 -      num_children--;
  1.1317 -      if(WEXITSTATUS(status) != EXIT_SUCCESS)
  1.1318 -	logwrite(LOG_WARNING,
  1.1319 -		 "delivery process with pid %d returned %d\n",
  1.1320 -		 pid, WEXITSTATUS(status));
  1.1321 -      if(WIFSIGNALED(status))
  1.1322 -	logwrite(LOG_WARNING,
  1.1323 -		 "delivery process with pid %d got signal: %d\n",
  1.1324 -		 pid, WTERMSIG(status));
  1.1325 -    }else{
  1.1326 -      logwrite(LOG_WARNING, "wait got error: %s\n", strerror(errno));
  1.1327 -    }
  1.1328 -  }
  1.1329 +	while (num_children > 0) {
  1.1330 +		int status;
  1.1331 +		pid_t pid;
  1.1332 +		if ((pid = wait(&status)) > 0) {
  1.1333 +			num_children--;
  1.1334 +			if (WEXITSTATUS(status) != EXIT_SUCCESS)
  1.1335 +				logwrite(LOG_WARNING, "delivery process with pid %d returned %d\n", pid, WEXITSTATUS(status));
  1.1336 +			if (WIFSIGNALED(status))
  1.1337 +				logwrite(LOG_WARNING, "delivery process with pid %d got signal: %d\n", pid, WTERMSIG(status));
  1.1338 +		} else {
  1.1339 +			logwrite(LOG_WARNING, "wait got error: %s\n", strerror(errno));
  1.1340 +		}
  1.1341 +	}
  1.1342  
  1.1343 -  return ok;
  1.1344 +	return ok;
  1.1345  }
  1.1346  
  1.1347  /* function just to log into a pop server,
  1.1348     for pop_before_smtp (or is it smtp_after_pop?)
  1.1349  */
  1.1350  
  1.1351 -gboolean pop3_login(gchar *host, gint port, GList *resolve_list,
  1.1352 -		    gchar *user, gchar *pass, guint flags)
  1.1353 +gboolean
  1.1354 +pop3_login(gchar * host, gint port, GList * resolve_list, gchar * user, gchar * pass, guint flags)
  1.1355  {
  1.1356 -  gboolean ok = FALSE;
  1.1357 -  pop3_base *popb;
  1.1358 +	gboolean ok = FALSE;
  1.1359 +	pop3_base *popb;
  1.1360  
  1.1361 -  signal(SIGCHLD, SIG_IGN);
  1.1362 +	signal(SIGCHLD, SIG_IGN);
  1.1363  
  1.1364 -  if((popb = pop3_in_open(host, port, resolve_list, flags))){
  1.1365 -    if(pop3_in_init(popb)){
  1.1366 -      if(pop3_in_login(popb, user, pass))
  1.1367 -	ok = TRUE;
  1.1368 -      else
  1.1369 -	logwrite(LOG_ALERT|LOG_VERBOSE,
  1.1370 -		 "pop3 login failed for user %s, host = %s\n", user, host);
  1.1371 -    }
  1.1372 -    pop3_in_close(popb);
  1.1373 -  }
  1.1374 -  return ok;
  1.1375 +	if ((popb = pop3_in_open(host, port, resolve_list, flags))) {
  1.1376 +		if (pop3_in_init(popb)) {
  1.1377 +			if (pop3_in_login(popb, user, pass))
  1.1378 +				ok = TRUE;
  1.1379 +			else
  1.1380 +				logwrite(LOG_ALERT | LOG_VERBOSE, "pop3 login failed for user %s, host = %s\n", user, host);
  1.1381 +		}
  1.1382 +		pop3_in_close(popb);
  1.1383 +	}
  1.1384 +	return ok;
  1.1385  }
  1.1386  
  1.1387  #endif