comparison src/fetch.c @ 79:28aeb0b93509 noffle

[svn] Extracted function in Fetch_postArts for returning failed postings to sender
author enz
date Sun, 14 May 2000 08:12:23 +0100
parents adf0af5152f7
children 38b0a1532a37
comparison
equal deleted inserted replaced
78:8f99308edea0 79:28aeb0b93509
1 /* 1 /*
2 fetch.c 2 fetch.c
3 3
4 $Id: fetch.c 67 2000-05-12 17:19:38Z enz $ 4 $Id: fetch.c 85 2000-05-14 07:12:23Z enz $
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
176 while ( ( p = Utl_getLn( msgId, p ) ) ) 176 while ( ( p = Utl_getLn( msgId, p ) ) )
177 Req_remove( fetch.serv, msgId ); 177 Req_remove( fetch.serv, msgId );
178 del_DynStr( list ); 178 del_DynStr( list );
179 } 179 }
180 180
181 void 181 static void
182 Fetch_postArts( void ) 182 returnArticleToSender( const char *sender, const char *reason,
183 { 183 const char *article )
184 DynStr *s; 184 {
185 Str msgId, cmd, errStr, sender;
186 int ret; 185 int ret;
187 const char *txt; 186 Str cmd;
188 FILE *f; 187 FILE *f;
189 sig_t lastHandler; 188 sig_t lastHandler;
189
190 Log_err( "Return article to '%s' by mail", sender );
191 snprintf( cmd, MAXCHAR, "mail -s '[ NOFFLE: Posting failed ]' '%s'",
192 sender );
193 lastHandler = signal( SIGPIPE, SIG_IGN );
194 f = popen( cmd, "w" );
195 if ( f == NULL )
196 Log_err( "Invocation of '%s' failed (%s)", cmd, strerror( errno ) );
197 else
198 {
199 fprintf( f,
200 "\t[ NOFFLE: POSTING OF ARTICLE FAILED ]\n"
201 "\n"
202 "\t[ The posting of your article failed. ]\n"
203 "\t[ Reason of failure at remote server: ]\n"
204 "\n"
205 "\t[ %s ]\n"
206 "\n"
207 "\t[ Full article text has been appended. ]\n"
208 "\n"
209 "%s"
210 ".\n",
211 reason, article );
212 ret = pclose( f );
213 if ( ret != EXIT_SUCCESS )
214 Log_err( "'%s' exit value %d", cmd, ret );
215 signal( SIGPIPE, lastHandler );
216 }
217 }
218
219 void
220 Fetch_postArts( void )
221 {
222 DynStr *s;
223 Str msgId, errStr, sender;
224 const char *txt;
190 225
191 s = new_DynStr( 10000 ); 226 s = new_DynStr( 10000 );
192 if ( Out_first( fetch.serv, msgId, s ) ) 227 if ( Out_first( fetch.serv, msgId, s ) )
193 { 228 {
194 Log_inf( "Posting articles" ); 229 Log_inf( "Posting articles" );
205 sender ) /* see server.c */ 240 sender ) /* see server.c */
206 && ! Prt_searchHeader( txt, "FROM", sender ) ) 241 && ! Prt_searchHeader( txt, "FROM", sender ) )
207 Log_err( "Article %s has no From/Sender/X-Sender field", 242 Log_err( "Article %s has no From/Sender/X-Sender field",
208 msgId ); 243 msgId );
209 else 244 else
210 { 245 returnArticleToSender( sender, errStr, txt );
211 Log_ntc( "Return article to '%s' by mail", sender );
212 snprintf( cmd, MAXCHAR,
213 "mail -s '[ NOFFLE: Posting failed ]' '%s'",
214 sender );
215 lastHandler = signal( SIGPIPE, SIG_IGN );
216 f = popen( cmd, "w" );
217 if ( f == NULL )
218 Log_err( "Invocation of '%s' failed (%s)", cmd,
219 strerror( errno ) );
220 else
221 {
222 fprintf( f,
223 "\t[ NOFFLE: POSTING OF ARTICLE FAILED ]\n"
224 "\n"
225 "\t[ The posting of your article failed. ]\n"
226 "\t[ Reason of failure at remote server: ]\n"
227 "\n"
228 "\t[ %s ]\n"
229 "\n"
230 "\t[ Full article text has been appended. ]\n"
231 "\n"
232 "%s"
233 ".\n",
234 errStr, txt );
235 ret = pclose( f );
236 if ( ret != EXIT_SUCCESS )
237 Log_err( "'%s' exit value %d", cmd, ret );
238 signal( SIGPIPE, lastHandler );
239 }
240 }
241 } 246 }
242 } 247 }
243 while ( Out_next( msgId, s ) ); 248 while ( Out_next( msgId, s ) );
244 } 249 }
245 del_DynStr( s ); 250 del_DynStr( s );