qmail-smtpd.c
int addrparse(char *arg)
{
  unsigned int i;
  char ch;
  char terminator;
  struct ip_address ip;
  int flagesc;
  int flagquoted;
 
  terminator = '>';
  i = str_chr(arg,'<');
  if (arg[i])
    arg += i + 1;
  else { /* partner should go read rfc 821 */
    terminator = ' ';
    arg += str_chr(arg,':');
    if (*arg == ':') ++arg;
    if (*arg == '\0') return 0;
    while (*arg == ' ') ++arg;
  }

  /* strip source route */
  if (*arg == '@') while (*arg) if (*arg++ == ':') break;

  if (!stralloc_copys(&addr,"")) die_nomem();
  flagesc = 0;
  flagquoted = 0;
  for (i = 0;(ch = arg[i]);++i) { /* copy arg to addr, stripping quotes */
    if (flagesc) {
      if (!stralloc_append(&addr,&ch)) die_nomem();
      flagesc = 0;
    }
    else {
      if (!flagquoted && (ch == terminator)) break;
      switch(ch) {
        case '\\': flagesc = 1; break;
        case '"': flagquoted = !flagquoted; break;
        default: if (!stralloc_append(&addr,&ch)) die_nomem();
      }
    }
  }
  /* could check for termination failure here, but why bother? */
  if (!stralloc_append(&addr,"")) die_nomem();

  if (liphostok) {
    i = byte_rchr(addr.s,addr.len,'@');
    if (i < addr.len) /* if not, partner should go read rfc 821 */
      if (addr.s[i + 1] == '[')
        if (!addr.s[i + 1 + ip_scanbracket(addr.s + i + 1,&ip)])
          if (ipme_is(&ip)) {
            addr.len = i + 1;
            if (!stralloc_cat(&addr,&liphost)) die_nomem();
            if (!stralloc_0(&addr)) die_nomem();
          }
  }

  if (addr.len > 900) return 0;
  return 1;
}
/* will be 0-terminated, if addrparse returns 1 */
will be 0-terminated, if addrparse returns 1
will be 0 - terminated if addrparse returns 1
int addrparse(char *arg)
{
  unsigned int i;
  char ch;
  char terminator;
  struct ip_address ip;
  int flagesc;
  int flagquoted;
  terminator = '>';
  i = str_chr(arg,'<');
  if (arg[i])
    arg += i + 1;
  else { 
    terminator = ' ';
    arg += str_chr(arg,':');
    if (*arg == ':') ++arg;
    if (*arg == '\0') return 0;
    while (*arg == ' ') ++arg;
  }
  if (*arg == '@') while (*arg) if (*arg++ == ':') break;
  if (!stralloc_copys(&addr,"")) die_nomem();
  flagesc = 0;
  flagquoted = 0;
  for (i = 0;(ch = arg[i]);++i) { 
    if (flagesc) {
      if (!stralloc_append(&addr,&ch)) die_nomem();
      flagesc = 0;
    }
    else {
      if (!flagquoted && (ch == terminator)) break;
      switch(ch) {
        case '\\': flagesc = 1; break;
        case '"': flagquoted = !flagquoted; break;
        default: if (!stralloc_append(&addr,&ch)) die_nomem();
      }
    }
  }
  if (!stralloc_append(&addr,"")) die_nomem();
  if (liphostok) {
    i = byte_rchr(addr.s,addr.len,'@');
    if (i < addr.len) 
      if (addr.s[i + 1] == '[')
        if (!addr.s[i + 1 + ip_scanbracket(addr.s + i + 1,&ip)])
          if (ipme_is(&ip)) {
            addr.len = i + 1;
            if (!stralloc_cat(&addr,&liphost)) die_nomem();
            if (!stralloc_0(&addr)) die_nomem();
          }
  }
  if (addr.len > 900) return 0;
  return 1;
}
int addrparse ( char * arg ) { unsigned int i ; char ch ; char terminator ; struct ip_address ip ; int flagesc ; int flagquoted ; terminator = ' ' ; i = str_chr ( arg , ' ' ) ; if ( arg [ i ] ) arg += i + 1 ; else { terminator = ' ' ; arg += str_chr ( arg , ' ' ) ; if ( * arg == ' ' ) ++ arg ; if ( * arg == ' \0 ' ) return 0 ; while ( * arg == ' ' ) ++ arg ; } if ( * arg == ' ' ) while ( * arg ) if ( * arg ++ == ' ' ) break ; if ( ! stralloc_copys ( & addr , " " ) ) die_nomem ( ) ; flagesc = 0 ; flagquoted = 0 ; for ( i = 0 ; ( ch = arg [ i ] ) ; ++ i ) { if ( flagesc ) { if ( ! stralloc_append ( & addr , & ch ) ) die_nomem ( ) ; flagesc = 0 ; } else { if ( ! flagquoted && ( ch == terminator ) ) break ; switch ( ch ) { case ' \\ ' : flagesc = 1 ; break ; case ' ' : flagquoted = ! flagquoted ; break ; default : if ( ! stralloc_append ( & addr , & ch ) ) die_nomem ( ) ; } } } if ( ! stralloc_append ( & addr , " " ) ) die_nomem ( ) ; if ( liphostok ) { i = byte_rchr ( addr . s , addr . len , ' ' ) ; if ( i < addr . len ) if ( addr . s [ i + 1 ] == ' ' ) if ( ! addr . s [ i + 1 + ip_scanbracket ( addr . s + i + 1 , & ip ) ] ) if ( ipme_is ( & ip ) ) { addr . len = i + 1 ; if ( ! stralloc_cat ( & addr , & liphost ) ) die_nomem ( ) ; if ( ! stralloc_0 ( & addr ) ) die_nomem ( ) ; } } if ( addr . len > 900 ) return 0 ; return 1 ; }
will be 0-terminated, if addrparse returns 1
will be 0 - terminated if addrparse returns 1
/* partner should go read rfc 821 */ /* strip source route */ /* copy arg to addr, stripping quotes */ /* could check for termination failure here, but why bother? */ /* if not, partner should go read rfc 821 */