summaryrefslogtreecommitdiff
path: root/guimb
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2001-08-04 14:33:37 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2001-08-04 14:33:37 +0000
commit1aa9ef0957ab1eb11d2574e49767c8846fa7406c (patch)
treefd5ee87c701afb4b7653e53fd1357e3fcd8f9b4b /guimb
parentb8615cc059da9e790d4da94470fb084f245e0483 (diff)
downloadmailutils-1aa9ef0957ab1eb11d2574e49767c8846fa7406c.tar.gz
mailutils-1aa9ef0957ab1eb11d2574e49767c8846fa7406c.tar.bz2
Fixed handling of default mailbox in the absence of other mailbox arguments.
Diffstat (limited to 'guimb')
-rw-r--r--guimb/collect.c54
-rw-r--r--guimb/main.c42
2 files changed, 60 insertions, 36 deletions
diff --git a/guimb/collect.c b/guimb/collect.c
index d52202aa3..c0cab0bb8 100644
--- a/guimb/collect.c
+++ b/guimb/collect.c
@@ -28,7 +28,24 @@ char *temp_filename;
FILE *temp_file;
mailbox_t mbox;
-/* Open temporary file for collecting incoming message */
+void
+collect_open_default ()
+{
+ size_t nmesg;
+
+ if (mailbox_create (&mbox, default_mailbox) != 0
+ || mailbox_open (mbox, MU_STREAM_RDWR) != 0)
+ {
+ util_error ("can't open default mailbox %s: %s",
+ default_mailbox, strerror (errno));
+ exit (1);
+ }
+
+ /* Suck in the messages */
+ mailbox_messages_count (mbox, &nmesg);
+}
+
+/* Open temporary file for collecting incoming messages */
void
collect_open_mailbox_file ()
{
@@ -84,6 +101,9 @@ collect_create_mailbox ()
size_t count;
size_t nmesg;
+ if (!temp_file)
+ return;
+
fclose (temp_file);
if (mailbox_create (&mbox, temp_filename) != 0
@@ -111,33 +131,34 @@ collect_output ()
size_t i, count = 0;
mailbox_t outbox = NULL;
int saved_umask;
-
- if (!output_mailbox)
+
+ if (!temp_filename)
+ {
+ mailbox_expunge (mbox);
+ return 0;
+ }
+
+ if (!default_mailbox)
{
if (!user_name)
return 0;
- asprintf (&output_mailbox, "%s/%s", _PATH_MAILDIR, user_name);
- if (!output_mailbox)
+ asprintf (&default_mailbox, "%s/%s", _PATH_MAILDIR, user_name);
+ if (!default_mailbox)
{
fprintf (stderr, "guimb: not enough memory\n");
return 1;
}
}
- if (store_mailbox)
- unlink (output_mailbox);
-
if (user_name)
- {
- saved_umask = umask (077);
- }
+ saved_umask = umask (077);
- if (mailbox_create_default (&outbox, output_mailbox) != 0
+ if (mailbox_create_default (&outbox, default_mailbox) != 0
|| mailbox_open (outbox, MU_STREAM_RDWR|MU_STREAM_CREAT) != 0)
{
mailbox_destroy (&outbox);
fprintf (stderr, "guimb: can't open output mailbox %s: %s\n",
- output_mailbox, strerror (errno));
+ default_mailbox, strerror (errno));
return 1;
}
@@ -171,6 +192,9 @@ collect_drop_mailbox ()
{
mailbox_close (mbox);
mailbox_destroy (&mbox);
- unlink (temp_filename);
- free (temp_filename);
+ if (temp_filename)
+ {
+ unlink (temp_filename);
+ free (temp_filename);
+ }
}
diff --git a/guimb/main.c b/guimb/main.c
index 60e70f8ef..1ccaef8e0 100644
--- a/guimb/main.c
+++ b/guimb/main.c
@@ -35,8 +35,7 @@ char *program_file;
char *program_expr;
int debug_guile;
char *user_name;
-char *output_mailbox;
-int store_mailbox;
+char *default_mailbox;
static void usage (void);
static int g_size;
@@ -87,8 +86,7 @@ main (int argc, char *argv[])
usage ();
exit (0);
case 'm':
- output_mailbox = optarg;
- store_mailbox = 1;
+ default_mailbox = optarg;
break;
case 'u':
user_name = optarg;
@@ -133,23 +131,26 @@ main (int argc, char *argv[])
list_append (lst, smtp_record);
}
- collect_open_mailbox_file ();
- if (store_mailbox && !argv[optind])
+ if (default_mailbox && !argv[optind])
{
- append_arg (output_mailbox);
- collect_append_file (output_mailbox);
+ append_arg (default_mailbox);
+ collect_open_default ();
}
-
- if (argv[optind])
+ else
{
- for (; argv[optind]; optind++)
+ collect_open_mailbox_file ();
+
+ if (argv[optind])
{
- append_arg (argv[optind]);
- collect_append_file (argv[optind]);
+ for (; argv[optind]; optind++)
+ {
+ append_arg (argv[optind]);
+ collect_append_file (argv[optind]);
+ }
}
+ else
+ collect_append_file ("-");
}
- else if (!store_mailbox)
- collect_append_file ("-");
append_arg (NULL);
g_argc--;
@@ -175,12 +176,11 @@ static char usage_str[] =
"Any arguments between -{ and -} are passed to the Scheme program verbatim.\n"
"When both --file and --expression are specified, file is evaluated first.\n"
"If no mailboxes are specified, the standard input is read.\n\n"
- "The semantics of the default mailbox differs depending on whether\n"
- "more mailbox arguments are specified in the command line. If they\n"
- "are, any messages that are not deleted after executing the script\n"
- "are appended to the default mailbox. Otherwise its contents is read,\n"
- "processed and *replaced* by messages that remain undeleted after\n"
- "executing the script.\n";
+ "The semantics of the default mailbox depends on whether more mailbox\n"
+ "arguments are specified in the command line. If they are, any messages\n"
+ "that are not deleted after executing the script are appended to the default\n"
+ "mailbox. Otherwise its contents is read, processed and *replaced* by\n"
+ "messages that remain undeleted after executing the script.\n";
void
usage ()

Return to:

Send suggestions and report system problems to the System administrator.