Mercurial > noffle
diff src/protocol.c @ 249:0340b9c17edc noffle
[svn] *** empty log message ***
author | mirkol |
---|---|
date | Tue, 14 May 2002 15:25:45 +0100 |
parents | 7a830ce3211e |
children | 93d5d8b098da |
line wrap: on
line diff
--- a/src/protocol.c Tue Mar 26 17:52:48 2002 +0000 +++ b/src/protocol.c Tue May 14 15:25:45 2002 +0100 @@ -1,7 +1,7 @@ /* protocol.c - $Id: protocol.c 379 2002-03-26 17:52:01Z mirkol $ + $Id: protocol.c 381 2002-05-14 14:25:45Z mirkol $ */ #if HAVE_CONFIG_H @@ -270,9 +270,12 @@ Str head, domain; int len, headLen; const char *p; + const char * specials = "\t\r\n ()@<>"; /* hmm, check "\\\'\"[]" as well? */ len = strlen( msgId ); - p = strstr( msgId, "@" ); + if ( len > 250 ) + return FALSE; /* see draft-ietf-usefor-article-06.txt, ch 5.3 */ + p = strchr( msgId, '@' ); if ( msgId[ 0 ] != '<' || msgId[ len - 1 ] != '>' || p == NULL ) return FALSE; strcpy( domain, p + 1 ); @@ -280,12 +283,20 @@ headLen = p - msgId - 1; Utl_cpyStrN( head, msgId + 1, headLen ); head[ headLen ] = '\0'; + for ( p = msgId ; *p != '\0' ; p++ ) + { + if ( ( (unsigned char ) *p ) >= 128 ) + return FALSE; /* pure 7bit ASCII */ + } + if ( strpbrk( head, specials ) ) + return FALSE; + if ( strpbrk( domain, specials ) ) + return FALSE; /* - To do: check for special characters in head and domain (non-printable - or '@', '<', '>'). Maybe compare domain with a config option + To do: Maybe compare domain with a config option and replace it by the config option, if not equal. */ - if ( strstr( domain, "." ) == NULL ) + if ( strchr( domain, '.' ) == NULL ) return FALSE; return TRUE; } @@ -295,12 +306,17 @@ { Str domain, date; time_t t; - static long count = 0; + static long count = 0; + const char *pattern; getDomain( domain, from ); time( &t ); strftime( date, MAXCHAR, "%Y%m%d%H%M%S", gmtime( &t ) ); - snprintf( msgId, MAXCHAR, "<%s.%X.%lx.%s@%s>", date, getpid(), count++ ,suffix, domain ); + if ( strchr( domain, '@' ) ) + pattern = "<%s.%X.%lx.%s%s>"; + else + pattern = "<%s.%X.%lx.%s@%s>"; + snprintf( msgId, MAXCHAR, pattern , date, getpid(), count++ ,suffix, domain ); ASSERT( Prt_isValidMsgId( msgId ) ); } @@ -359,12 +375,21 @@ } /* OK, build From: contents */ +/* deprecated. Utl_cpyStr( fromHdr, pwd->pw_name ); Utl_catStr( fromHdr, "@" ); Utl_catStr( fromHdr, domain ); Utl_catStr( fromHdr, " (" ); Utl_catStr( fromHdr, name ); Utl_catStr( fromHdr, ")" ); +*/ + Utl_cpyStr( fromHdr, "\"" ); + Utl_catStr( fromHdr, name ); + Utl_catStr( fromHdr, "\" <" ); + Utl_catStr( fromHdr, pwd->pw_name ); + Utl_catStr( fromHdr, "@" ); + Utl_catStr( fromHdr, domain ); + Utl_catStr( fromHdr, ">" ); return TRUE; }