comparison 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
comparison
equal deleted inserted replaced
248:cd022deb8390 249:0340b9c17edc
1 /* 1 /*
2 protocol.c 2 protocol.c
3 3
4 $Id: protocol.c 379 2002-03-26 17:52:01Z mirkol $ 4 $Id: protocol.c 381 2002-05-14 14:25:45Z mirkol $
5 */ 5 */
6 6
7 #if HAVE_CONFIG_H 7 #if HAVE_CONFIG_H
8 #include <config.h> 8 #include <config.h>
9 #endif 9 #endif
268 Prt_isValidMsgId( const char *msgId ) 268 Prt_isValidMsgId( const char *msgId )
269 { 269 {
270 Str head, domain; 270 Str head, domain;
271 int len, headLen; 271 int len, headLen;
272 const char *p; 272 const char *p;
273 const char * specials = "\t\r\n ()@<>"; /* hmm, check "\\\'\"[]" as well? */
273 274
274 len = strlen( msgId ); 275 len = strlen( msgId );
275 p = strstr( msgId, "@" ); 276 if ( len > 250 )
277 return FALSE; /* see draft-ietf-usefor-article-06.txt, ch 5.3 */
278 p = strchr( msgId, '@' );
276 if ( msgId[ 0 ] != '<' || msgId[ len - 1 ] != '>' || p == NULL ) 279 if ( msgId[ 0 ] != '<' || msgId[ len - 1 ] != '>' || p == NULL )
277 return FALSE; 280 return FALSE;
278 strcpy( domain, p + 1 ); 281 strcpy( domain, p + 1 );
279 domain[ strlen( domain ) - 1 ] = '\0'; 282 domain[ strlen( domain ) - 1 ] = '\0';
280 headLen = p - msgId - 1; 283 headLen = p - msgId - 1;
281 Utl_cpyStrN( head, msgId + 1, headLen ); 284 Utl_cpyStrN( head, msgId + 1, headLen );
282 head[ headLen ] = '\0'; 285 head[ headLen ] = '\0';
286 for ( p = msgId ; *p != '\0' ; p++ )
287 {
288 if ( ( (unsigned char ) *p ) >= 128 )
289 return FALSE; /* pure 7bit ASCII */
290 }
291 if ( strpbrk( head, specials ) )
292 return FALSE;
293 if ( strpbrk( domain, specials ) )
294 return FALSE;
283 /* 295 /*
284 To do: check for special characters in head and domain (non-printable 296 To do: Maybe compare domain with a config option
285 or '@', '<', '>'). Maybe compare domain with a config option
286 and replace it by the config option, if not equal. 297 and replace it by the config option, if not equal.
287 */ 298 */
288 if ( strstr( domain, "." ) == NULL ) 299 if ( strchr( domain, '.' ) == NULL )
289 return FALSE; 300 return FALSE;
290 return TRUE; 301 return TRUE;
291 } 302 }
292 303
293 void 304 void
294 Prt_genMsgId( Str msgId, const char *from, const char *suffix ) 305 Prt_genMsgId( Str msgId, const char *from, const char *suffix )
295 { 306 {
296 Str domain, date; 307 Str domain, date;
297 time_t t; 308 time_t t;
298 static long count = 0; 309 static long count = 0;
310 const char *pattern;
299 311
300 getDomain( domain, from ); 312 getDomain( domain, from );
301 time( &t ); 313 time( &t );
302 strftime( date, MAXCHAR, "%Y%m%d%H%M%S", gmtime( &t ) ); 314 strftime( date, MAXCHAR, "%Y%m%d%H%M%S", gmtime( &t ) );
303 snprintf( msgId, MAXCHAR, "<%s.%X.%lx.%s@%s>", date, getpid(), count++ ,suffix, domain ); 315 if ( strchr( domain, '@' ) )
316 pattern = "<%s.%X.%lx.%s%s>";
317 else
318 pattern = "<%s.%X.%lx.%s@%s>";
319 snprintf( msgId, MAXCHAR, pattern , date, getpid(), count++ ,suffix, domain );
304 ASSERT( Prt_isValidMsgId( msgId ) ); 320 ASSERT( Prt_isValidMsgId( msgId ) );
305 } 321 }
306 322
307 void 323 void
308 Prt_genPathHdr( Str pathHdr, const char *from ) 324 Prt_genPathHdr( Str pathHdr, const char *from )
357 *p = '\0'; 373 *p = '\0';
358 Utl_cpyStr( name, nameval ); 374 Utl_cpyStr( name, nameval );
359 } 375 }
360 376
361 /* OK, build From: contents */ 377 /* OK, build From: contents */
378 /* deprecated.
362 Utl_cpyStr( fromHdr, pwd->pw_name ); 379 Utl_cpyStr( fromHdr, pwd->pw_name );
363 Utl_catStr( fromHdr, "@" ); 380 Utl_catStr( fromHdr, "@" );
364 Utl_catStr( fromHdr, domain ); 381 Utl_catStr( fromHdr, domain );
365 Utl_catStr( fromHdr, " (" ); 382 Utl_catStr( fromHdr, " (" );
366 Utl_catStr( fromHdr, name ); 383 Utl_catStr( fromHdr, name );
367 Utl_catStr( fromHdr, ")" ); 384 Utl_catStr( fromHdr, ")" );
368 385 */
369 return TRUE; 386 Utl_cpyStr( fromHdr, "\"" );
370 } 387 Utl_catStr( fromHdr, name );
371 388 Utl_catStr( fromHdr, "\" <" );
372 389 Utl_catStr( fromHdr, pwd->pw_name );
373 390 Utl_catStr( fromHdr, "@" );
391 Utl_catStr( fromHdr, domain );
392 Utl_catStr( fromHdr, ">" );
393
394 return TRUE;
395 }
396
397
398