Mercurial > noffle
annotate outgoing.c @ 26:526a4c34ee2e noffle
[svn] Applied patch from Jim Hague: support for local groups / new command
line options --create and --cancel.
author | enz |
---|---|
date | Sat, 29 Apr 2000 15:45:56 +0100 |
parents | 04124a4423d4 |
children |
rev | line source |
---|---|
0 | 1 /* |
2 outgoing.c | |
3 | |
26
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
4 $Id: outgoing.c 32 2000-04-29 14:45:56Z enz $ |
0 | 5 */ |
6 | |
7 #include "outgoing.h" | |
8 | |
9 #include <dirent.h> | |
10 #include <errno.h> | |
11 #include <fcntl.h> | |
12 #include <sys/types.h> | |
13 #include <sys/stat.h> | |
14 #include <time.h> | |
15 #include <unistd.h> | |
16 #include "config.h" | |
17 #include "log.h" | |
18 #include "util.h" | |
19 | |
20 struct Outgoing | |
21 { | |
22 DIR *dir; | |
23 Str serv; | |
24 } outgoing = { NULL, "" }; | |
25 | |
26 static void | |
27 fileOutgoing( Str file, const char *serv, const char *msgId ) | |
28 { | |
29 snprintf( file, MAXCHAR, "%s/outgoing/%s/%s", | |
30 Cfg_spoolDir(), serv, msgId ); | |
31 } | |
32 | |
33 static void | |
34 createDir( const char *serv ) | |
35 { | |
36 Str dir; | |
37 int r; | |
38 | |
39 snprintf( dir, MAXCHAR, "%s/outgoing/%s", Cfg_spoolDir(), serv ); | |
40 r = mkdir( dir, 0755 ); | |
41 if ( r != 0 ) | |
42 Log_dbg( "mkdir: %s", strerror( errno ) ); | |
43 } | |
44 | |
45 Bool | |
26
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
46 Out_add( const char *serv, const char *msgId, const DynStr *artTxt ) |
0 | 47 { |
48 Str file; | |
49 FILE *f; | |
50 | |
51 fileOutgoing( file, serv, msgId ); | |
52 if ( ! ( f = fopen( file, "w" ) ) ) | |
53 { | |
54 createDir( serv ); | |
55 if ( ! ( f = fopen( file, "w" ) ) ) | |
56 { | |
57 Log_err( "Cannot open %s", file ); | |
58 return FALSE; | |
59 } | |
60 } | |
61 fprintf( f, "%s", DynStr_str( artTxt ) ); | |
62 fclose( f ); | |
63 return TRUE; | |
64 } | |
65 | |
66 Bool | |
67 Out_first( const char *serv, Str msgId, DynStr *artTxt ) | |
68 { | |
69 Str file; | |
70 | |
71 snprintf( file, MAXCHAR, "%s/outgoing/%s", Cfg_spoolDir(), serv ); | |
72 if ( ! ( outgoing.dir = opendir( file ) ) ) | |
73 { | |
74 Log_dbg( "Cannot open %s", file ); | |
75 return FALSE; | |
76 } | |
77 Utl_cpyStr( outgoing.serv, serv ); | |
78 Out_next( NULL, NULL ); /* "." */ | |
79 Out_next( NULL, NULL ); /* ".." */ | |
80 return Out_next( msgId, artTxt ); | |
81 } | |
82 | |
83 Bool | |
84 Out_next( Str msgId, DynStr *artTxt ) | |
85 { | |
86 struct dirent *d; | |
87 FILE *f; | |
88 Str file, line; | |
89 | |
90 ASSERT( outgoing.dir ); | |
91 if ( ! ( d = readdir( outgoing.dir ) ) ) | |
92 { | |
93 closedir( outgoing.dir ); | |
94 outgoing.dir = NULL; | |
95 return FALSE; | |
96 } | |
97 if ( artTxt == NULL ) | |
98 return ( d->d_name != NULL ); | |
99 fileOutgoing( file, outgoing.serv, d->d_name ); | |
100 if ( ! ( f = fopen( file, "r" ) ) ) | |
101 { | |
102 Log_err( "Cannot open %s for read", file ); | |
103 return FALSE; | |
104 } | |
105 DynStr_clear( artTxt ); | |
106 while ( fgets( line, MAXCHAR, f ) ) | |
107 DynStr_app( artTxt, line ); | |
108 Utl_cpyStr( msgId, d->d_name ); | |
109 fclose( f ); | |
110 return TRUE; | |
111 } | |
112 | |
113 void | |
26
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
114 Out_remove( const char *serv, const char *msgId ) |
0 | 115 { |
116 Str file; | |
117 | |
118 fileOutgoing( file, serv, msgId ); | |
119 if ( unlink( file ) != 0 ) | |
120 Log_err( "Cannot remove %s", file ); | |
121 } | |
26
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
122 |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
123 Bool |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
124 Out_find( const char *msgId, Str server ) |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
125 { |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
126 Str servdir; |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
127 DIR *d; |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
128 struct dirent *entry; |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
129 Bool res; |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
130 |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
131 |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
132 snprintf( servdir, MAXCHAR, "%s/outgoing", Cfg_spoolDir() ); |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
133 if ( ! ( d = opendir( servdir ) ) ) |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
134 { |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
135 Log_dbg( "Cannot open %s", servdir ); |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
136 return FALSE; |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
137 } |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
138 |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
139 readdir( d ); /* '.' */ |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
140 readdir( d ); /* '..' */ |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
141 |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
142 res = FALSE; |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
143 while ( ! res && ( entry = readdir( d ) ) != NULL ) |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
144 { |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
145 Str file; |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
146 struct stat s; |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
147 |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
148 fileOutgoing( file, entry->d_name, msgId ); |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
149 if ( stat( file, &s ) == 0 ) |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
150 { |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
151 res = TRUE; |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
152 Utl_cpyStr( server, entry->d_name ); |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
153 } |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
154 } |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
155 |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
156 closedir( d ); |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
157 return res; |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
158 } |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
159 |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
160 |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
161 |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
162 |
526a4c34ee2e
[svn] Applied patch from Jim Hague: support for local groups / new command
enz
parents:
0
diff
changeset
|
163 |