annotate outgoing.c @ 0:04124a4423d4 noffle

[svn] Initial revision
author enz
date Tue, 04 Jan 2000 11:35:42 +0000
parents
children 526a4c34ee2e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
1 /*
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
2 outgoing.c
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
3
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
4 $Id: outgoing.c 3 2000-01-04 11:35:42Z enz $
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
5 */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
6
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
7 #include "outgoing.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
8
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
9 #include <dirent.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
10 #include <errno.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
11 #include <fcntl.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
12 #include <sys/types.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
13 #include <sys/stat.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
14 #include <time.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
15 #include <unistd.h>
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
16 #include "config.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
17 #include "log.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
18 #include "util.h"
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
19
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
20 struct Outgoing
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
21 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
22 DIR *dir;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
23 Str serv;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
24 } outgoing = { NULL, "" };
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
25
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
26 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
27 fileOutgoing( Str file, const char *serv, const char *msgId )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
28 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
29 snprintf( file, MAXCHAR, "%s/outgoing/%s/%s",
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
30 Cfg_spoolDir(), serv, msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
31 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
32
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
33 static void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
34 createDir( const char *serv )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
35 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
36 Str dir;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
37 int r;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
38
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
39 snprintf( dir, MAXCHAR, "%s/outgoing/%s", Cfg_spoolDir(), serv );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
40 r = mkdir( dir, 0755 );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
41 if ( r != 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
42 Log_dbg( "mkdir: %s", strerror( errno ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
43 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
44
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
45 Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
46 Out_add( const char *serv, const Str msgId, const DynStr *artTxt )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
47 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
48 Str file;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
49 FILE *f;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
50
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
51 fileOutgoing( file, serv, msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
52 if ( ! ( f = fopen( file, "w" ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
53 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
54 createDir( serv );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
55 if ( ! ( f = fopen( file, "w" ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
56 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
57 Log_err( "Cannot open %s", file );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
58 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
59 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
60 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
61 fprintf( f, "%s", DynStr_str( artTxt ) );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
62 fclose( f );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
63 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
64 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
65
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
66 Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
67 Out_first( const char *serv, Str msgId, DynStr *artTxt )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
68 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
69 Str file;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
70
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
71 snprintf( file, MAXCHAR, "%s/outgoing/%s", Cfg_spoolDir(), serv );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
72 if ( ! ( outgoing.dir = opendir( file ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
73 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
74 Log_dbg( "Cannot open %s", file );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
75 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
76 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
77 Utl_cpyStr( outgoing.serv, serv );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
78 Out_next( NULL, NULL ); /* "." */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
79 Out_next( NULL, NULL ); /* ".." */
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
80 return Out_next( msgId, artTxt );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
81 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
82
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
83 Bool
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
84 Out_next( Str msgId, DynStr *artTxt )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
85 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
86 struct dirent *d;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
87 FILE *f;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
88 Str file, line;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
89
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
90 ASSERT( outgoing.dir );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
91 if ( ! ( d = readdir( outgoing.dir ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
92 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
93 closedir( outgoing.dir );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
94 outgoing.dir = NULL;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
95 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
96 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
97 if ( artTxt == NULL )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
98 return ( d->d_name != NULL );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
99 fileOutgoing( file, outgoing.serv, d->d_name );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
100 if ( ! ( f = fopen( file, "r" ) ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
101 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
102 Log_err( "Cannot open %s for read", file );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
103 return FALSE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
104 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
105 DynStr_clear( artTxt );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
106 while ( fgets( line, MAXCHAR, f ) )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
107 DynStr_app( artTxt, line );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
108 Utl_cpyStr( msgId, d->d_name );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
109 fclose( f );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
110 return TRUE;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
111 }
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
112
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
113 void
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
114 Out_remove( const char *serv, Str msgId )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
115 {
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
116 Str file;
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
117
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
118 fileOutgoing( file, serv, msgId );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
119 if ( unlink( file ) != 0 )
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
120 Log_err( "Cannot remove %s", file );
04124a4423d4 [svn] Initial revision
enz
parents:
diff changeset
121 }