Commit 150e71a6 150e71a689dab8ba9b7f9c0f85e659becba1a0a3 by Sergey Poznyakoff

(open_source): Removed in favor of mh_open_msg_file().

1 parent 35ae733d
...@@ -198,92 +198,6 @@ refile (mailbox_t mbox, message_t msg, size_t num, void *data) ...@@ -198,92 +198,6 @@ refile (mailbox_t mbox, message_t msg, size_t num, void *data)
198 } 198 }
199 } 199 }
200 200
201 mailbox_t
202 open_source (char *file_name)
203 {
204 struct stat st;
205 char *buffer;
206 int fd;
207 size_t len = 0;
208 mailbox_t tmp;
209 stream_t stream;
210 char *p;
211
212 if (stat (file_name, &st) < 0)
213 {
214 mh_error (_("can't stat file %s: %s"), file_name, strerror (errno));
215 return NULL;
216 }
217
218 buffer = xmalloc (st.st_size+1);
219 fd = open (file_name, O_RDONLY);
220 if (fd == -1)
221 {
222 mh_error (_("can't open file %s: %s"), file_name, strerror (errno));
223 return NULL;
224 }
225
226 if (read (fd, buffer, st.st_size) != st.st_size)
227 {
228 mh_error (_("error reading file %s: %s"), file_name, strerror (errno));
229 return NULL;
230 }
231
232 buffer[st.st_size] = 0;
233 close (fd);
234
235 if (mailbox_create (&tmp, "/dev/null")
236 || mailbox_open (tmp, MU_STREAM_READ) != 0)
237 {
238 mh_error (_("can't create temporary mailbox"));
239 return NULL;
240 }
241
242 if (memory_stream_create (&stream, 0, MU_STREAM_RDWR)
243 || stream_open (stream))
244 {
245 mailbox_close (tmp);
246 mh_error (_("can't create temporary stream"));
247 return NULL;
248 }
249
250 for (p = buffer; *p && isspace (*p); p++)
251 ;
252
253 if (strncmp (p, "From ", 5))
254 {
255 struct tm *tm;
256 time_t t;
257 char date[80];
258
259 time(&t);
260 tm = gmtime(&t);
261 strftime (date, sizeof (date),
262 "From GNU-MH-refile %a %b %e %H:%M:%S %Y%n",
263 tm);
264 stream_write (stream, date, strlen (date), 0, &len);
265 }
266
267 stream_write (stream, p, strlen (p), len, &len);
268 mailbox_set_stream (tmp, stream);
269 if (mailbox_messages_count (tmp, &len)
270 || len < 1)
271 {
272 mh_error (_("input file %s is not a valid message file"), file_name);
273 return NULL;
274 }
275 else if (len > 1)
276 {
277 mh_error (ngettext ("input file %s contains %lu message",
278 "input file %s contains %lu messages",
279 len),
280 (unsigned long) len);
281 return NULL;
282 }
283 free (buffer);
284 return tmp;
285 }
286
287 int 201 int
288 main (int argc, char **argv) 202 main (int argc, char **argv)
289 { 203 {
...@@ -305,7 +219,7 @@ main (int argc, char **argv) ...@@ -305,7 +219,7 @@ main (int argc, char **argv)
305 mh_error (_("both message set and source file given")); 219 mh_error (_("both message set and source file given"));
306 exit (1); 220 exit (1);
307 } 221 }
308 mbox = open_source (source_file); 222 mbox = mh_open_msg_file (source_file);
309 mh_msgset_parse (mbox, &msgset, 0, NULL, "first"); 223 mh_msgset_parse (mbox, &msgset, 0, NULL, "first");
310 } 224 }
311 else 225 else
......