summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2001-07-19 14:52:46 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2001-07-19 14:52:46 +0000
commit0211af8b96efd3050d8fcce51e44f8fd02f05612 (patch)
tree2e1ac3186caf6db7f196a814e5bf93d2f7ea71c5
parent6567d383b2fbc7c333d59f7878432ecb7912b83f (diff)
downloadmailutils-0211af8b96efd3050d8fcce51e44f8fd02f05612.tar.gz
mailutils-0211af8b96efd3050d8fcce51e44f8fd02f05612.tar.bz2
Collect input.
-rw-r--r--guimb/collect.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/guimb/collect.c b/guimb/collect.c
new file mode 100644
index 000000000..5f8a6b453
--- /dev/null
+++ b/guimb/collect.c
@@ -0,0 +1,111 @@
+/* GNU mailutils - a suite of utilities for electronic mail
+ Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "guimb.h"
+
+char *temp_filename;
+FILE *temp_file;
+mailbox_t mbox;
+size_t nmesg;
+size_t current_mesg_no;
+message_t current_message;
+
+/* Open temporary file for collecting incoming message */
+void
+collect_open_mailbox_file ()
+{
+ int fd;
+
+ /* Create input mailbox */
+ fd = util_tempfile (&temp_filename);
+ if (fd == -1)
+ exit (1);
+
+ temp_file = fdopen (fd, "w");
+ if (!temp_file)
+ {
+ util_error ("fdopen: %s", strerror (errno));
+ close (fd);
+ exit (1);
+ }
+}
+
+/* Append contents of file `name' to the temporary file */
+int
+collect_append_file (char *name)
+{
+ char *buf = NULL;
+ size_t n = 0;
+ FILE *fp;
+
+ if (strcmp (name, "-") == 0)
+ fp = stdin;
+ else
+ {
+ fp = fopen (name, "r");
+ if (!fp)
+ {
+ util_error ("can't open input file %s: %s", name, strerror (errno));
+ return -1;
+ }
+ }
+
+ /* Copy the contents of the file */
+ while (getline (&buf, &n, fp) > 0)
+ fprintf (temp_file, "%s", buf);
+
+ free (buf);
+ fclose (fp);
+ return 0;
+}
+
+/* Close the temporary, and reopen it as a mailbox. */
+void
+collect_create_mailbox ()
+{
+ size_t count;
+
+ fclose (temp_file);
+
+ if (mailbox_create (&mbox, temp_filename) != 0
+ || mailbox_open (mbox, MU_STREAM_READ) != 0)
+ {
+ util_error ("can't create temp mailbox %s: %s",
+ temp_filename, strerror (errno));
+ unlink (temp_filename);
+ exit (1);
+ }
+
+ /* Suck in the messages */
+ mailbox_messages_count (mbox, &nmesg);
+
+ if (nmesg == 0)
+ {
+ util_error ("input format not recognized");
+ exit (1);
+ }
+}
+
+/* Close the temporary mailbox and unlink the file associated with it */
+void
+collect_drop_mailbox ()
+{
+ mailbox_close (mbox);
+ mailbox_destroy (&mbox);
+ unlink (temp_filename);
+ free (temp_filename);
+}

Return to:

Send suggestions and report system problems to the System administrator.