diff src/post.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 55ba957023f9
children ca9769519c96
line wrap: on
line diff
--- a/src/post.c	Thu Oct 26 22:13:28 2000 +0100
+++ b/src/post.c	Thu Oct 26 22:21:13 2000 +0100
@@ -1,14 +1,18 @@
 /*
   post.c
 
-  $Id: post.c 202 2000-08-23 09:52:25Z enz $
+  $Id: post.c 227 2000-10-26 21:21:13Z bears $
 */
 
 #if HAVE_CONFIG_H
 #include <config.h>
 #endif
 
+#include <errno.h>
+#include <pwd.h>
 #include <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
 #include "post.h"
 #include <string.h>
 #include "common.h"
@@ -25,6 +29,9 @@
 #include "util.h"
 #include "portable.h"
 
+#define	BEGIN_SIG	"-- "
+#define	SIG_FILE	"/.signature"
+
 struct OverInfo
 {
     Str subject;
@@ -43,10 +50,11 @@
     ItemList *control;	   /* Control message? NULL if not */
     Bool approved;	   /* Has Approved: header? */
     Bool posted;	   /* Has it been put in the article database? */
+    int flags;             /* Posting flags */
     struct OverInfo over;
 };
 
-static struct Article article = { NULL, NULL, NULL, FALSE, FALSE,
+static struct Article article = { NULL, NULL, NULL, FALSE, FALSE, 0,
 				  { "", "", "", "", "", 0, 0 } };
 
 /* Add the article to a group. */
@@ -163,14 +171,15 @@
 {
     DynStr * s;
     Str line, field, value;
-    Bool replyToFound, pathFound;
+    Bool replyToFound, pathFound, orgFound;
     time_t t;
+    int sigLines;
 
     s = new_DynStr( 10000 );
     article.text = s;
 
     memset( &article.over, 0, sizeof( article.over ) );
-    replyToFound = pathFound = FALSE;
+    replyToFound = pathFound = orgFound = FALSE;
     
     /* Grab header lines first, getting overview info as we go. */
     while ( ( p = Utl_getHeaderLn( line, p ) ) != NULL
@@ -222,6 +231,11 @@
 	    pathFound = TRUE;
 	    DynStr_appLn( s, line );
 	}
+	else if ( strcmp ( field, "organization" ) == 0 )
+	{
+	    orgFound = TRUE;
+	    DynStr_appLn( s, line );
+	}
 	else if ( strcmp ( field, "x-sender" ) == 0 )
 	{
 	    DynStr_app( s, "X-NOFFLE-X-Sender: " );
@@ -236,8 +250,22 @@
     /* Now sort header-related issues */
     if ( article.over.from[ 0 ] == '\0' )
     {
-	Log_err( "Posted message has no From field" );
-	return FALSE;
+	if ( article.flags & POST_ADD_FROM )
+	{
+	    Log_dbg( "Adding From field to posted message." );
+	    DynStr_app( s, "From: " );
+	    if ( ! Prt_genFromHdr( article.over.from ) )
+	    {
+		Log_err( "Can't generate From field" );
+		return FALSE;
+	    }
+	    DynStr_appLn( s, article.over.from );
+	}
+	else
+	{
+	    Log_err( "Posted message has no From field" );
+	    return FALSE;
+	}
     }
     if ( article.over.subject[ 0 ] == '\0' )
     {
@@ -295,6 +323,20 @@
 	DynStr_appLn( s, article.over.from );
     }
 
+    /* Ensure Organization header if required */
+    if ( ( ! orgFound ) && ( article.flags & POST_ADD_ORG ) )
+    {
+	Str org;
+
+	Utl_cpyStr( org, Cfg_organization() );
+	if ( org[ 0 ] != '\0' )
+	{
+	    Log_dbg( "Adding Organization field to posted message." );
+	    DynStr_app( s, "Organization: " );
+ 	    DynStr_appLn( s, org );
+	}
+    }
+
     /* OK, header ready to roll. Something to accompany it? */
     if ( p == NULL || p[ 0 ] == '\0' )
     {
@@ -305,9 +347,68 @@
     /* Add the empty line separating header and body */
     DynStr_appLn( s, "" );
 
-    /* Now pop on the rest of the body and count the lines & bytes */
+    /* Now pop on the rest of the body */
     DynStr_app( s, p );
-    for ( p++, article.over.lines = 0; *p != '\0'; p++ )
+
+    /* Add a signature if requested to do so and if one found. */
+    sigLines = 0;
+    if ( article.flags & POST_ADD_SIG )
+    {
+	Str sigfile;
+	struct passwd *pwd;
+	FILE *f;
+
+	/* Generate sig file path */
+	pwd = getpwuid( getuid() );
+	Utl_cpyStr( sigfile, pwd->pw_dir );
+	Utl_catStr( sigfile, SIG_FILE );
+
+	f = fopen( sigfile, "r" );
+	if ( f == NULL )
+	{
+	    /* If err is ENOENT, file doesn't exist. This is OK. */
+	    if ( errno != ENOENT )
+	    {
+		Log_err( "Can't access .signature file (%s), "
+			 "article not posted.",
+			 strerror( errno ) );
+		return FALSE;
+	    }
+	}
+	else
+	{
+	    /* OK, try to add it. */
+	    Str sline;
+	    
+	    Log_dbg( "Adding .signature to posted message." );
+
+	    DynStr_appLn( s, BEGIN_SIG );
+	    sigLines++;
+	    while ( Prt_getLn( sline, f, 0 ) )
+	    {
+		DynStr_appLn( s, sline );
+		sigLines++;
+	    }
+
+	    if ( ferror( f ) )
+	    {
+		Log_err( "Error reading .signature file (%s), "
+			 "article not posted.",
+			 strerror( errno ) );
+		fclose( f );
+		return FALSE;
+	    }
+
+	    fclose( f );
+	}
+    }
+
+    /*
+     * Count the lines & bytes. This counts the original number of
+     * lines in the supplied body, so add in the number of signature
+     * lines added, including the separator.
+     */
+    for ( p++, article.over.lines = sigLines; *p != '\0'; p++ )
 	if ( *p == '\n' )
 	    article.over.lines++;
     article.over.bytes = DynStr_len( s );
@@ -428,7 +529,7 @@
 
 /* Register an article for posting. */
 Bool
-Post_open( const char * text )
+Post_open( const char * text, unsigned flags )
 {
     if ( article.text != NULL )
     {
@@ -436,6 +537,8 @@
 	return FALSE;
     }
 
+    article.flags = flags;
+    
     if ( ! getArticleText( text ) )
 	return FALSE;
 
@@ -453,6 +556,12 @@
 Bool
 Post_post( void )
 {
+    if ( article.flags & POST_DEBUG )
+    {
+	fputs( DynStr_str( article.text ), stdout );
+	return TRUE;
+    }
+
     if ( ! checkPostableNewsgroup() )
 	return FALSE;