Mercurial > noffle
diff src/protocol.c @ 150:1c7303c71f66 noffle
[svn] * src/protocol.c: Fix bug in Prt_getLn if we should read a line
starting with '\0' - according to the leafnode mailing list,
this has been seen in the wild.
* docs/inews.1,docs/noffle.1,docs/noffle.conf.5,
packages/redhat/noffle.spec,src/configfile.h,src/configfile.c,
src/noffle.c,src/post.h,src/post.c: Removed use of getopt_long,
and added inews mode - the Noffle executable behaves
as inews is invoked as inews. This includes adding From: and
Organization: headers if necessary - add configs to override
defaults for the From: domain and specify the organization.
For all my fellow trn-heads out there, and users of any other
ageing newsreader that expects inews. Updated RPM spec to create
inews link to noffle on install.
author | bears |
---|---|
date | Thu, 26 Oct 2000 22:21:13 +0100 |
parents | 8b9366fc1361 |
children | cb799054bd61 |
line wrap: on
line diff
--- a/src/protocol.c Thu Oct 26 22:13:28 2000 +0100 +++ b/src/protocol.c Thu Oct 26 22:21:13 2000 +0100 @@ -1,7 +1,7 @@ /* protocol.c - $Id: protocol.c 217 2000-09-23 10:40:35Z enz $ + $Id: protocol.c 227 2000-10-26 21:21:13Z bears $ */ #if HAVE_CONFIG_H @@ -11,6 +11,7 @@ #include <stdio.h> #include <ctype.h> #include <netdb.h> +#include <pwd.h> #include <signal.h> #include <sys/types.h> #include <sys/utsname.h> @@ -79,10 +80,10 @@ if ( ret == NULL ) return FALSE; len = strlen( line ); - if ( line[ len - 1 ] == '\n' ) + if ( len > 0 && line[ len - 1 ] == '\n' ) { line[ len - 1 ] = '\0'; - if ( line[ len - 2 ] == '\r' ) + if ( len > 1 && line[ len - 2 ] == '\r' ) line[ len - 2 ] = '\0'; } Log_dbg( "[R] %s", line ); @@ -344,6 +345,63 @@ Utl_catStr( pathHdr, "!not-for-mail" ); } +Bool +Prt_genFromHdr( Str fromHdr ) +{ + Str name, domain; + const char *nameval; + struct passwd *pwd; + + /* First get the domain to use. If config empty, use FQDN */ + Utl_cpyStr( domain, Cfg_fromDomain() ); + + if ( DynStr_len( domain ) == 0 ) + if ( ! getFQDN( domain ) ) + Utl_catStr( domain, "unknown" ); + + /* Now get pwd for the username */ + pwd = getpwuid( getuid() ); + if ( pwd == NULL ) + return FALSE; + + /* Now for their name - use env NAME if available */ + nameval = getenv( "NAME" ); + if ( nameval != NULL ) + Utl_cpyStr( name, nameval ); + else + { + char *p; + + /* + Extract from GECOS field. Following the lead of the INN inews, + ignore leading stuff like "23-" "stuff]-" or "stuff -" as well + as trailing whitespace, or anything that comes after + a comma or semicolon. + */ + nameval = pwd->pw_gecos; + p = strchr( nameval, '-' ); + if ( p != NULL && p > nameval && + ( p[-1] == ']' || p[-1] == ' ' || isdigit( p[ -1 ] ) ) ) + nameval = p; + p = strrchr( nameval, ',' ); + if ( p != NULL ) + *p = '\0'; + p = strchr( nameval, ';' ); + if ( p != NULL ) + *p = '\0'; + Utl_cpyStr( name, nameval ); + } + + /* OK, build From: contents */ + Utl_cpyStr( fromHdr, pwd->pw_name ); + Utl_catStr( fromHdr, "@" ); + Utl_catStr( fromHdr, domain ); + Utl_catStr( fromHdr, " (" ); + Utl_catStr( fromHdr, name ); + Utl_catStr( fromHdr, ")" ); + + return TRUE; +}