Commit 9c99e86c 9c99e86cf1f9de1553f15cf3fdfe6401f4e4bfbd by Sergey Poznyakoff

Run "summary" after opening new mailbox.

Issue diagnostics if mailbox cannot be opened.
Display mailbox summary when called without arguments.
1 parent 9c4f7f6f
Showing 1 changed file with 33 additions and 13 deletions
......@@ -17,6 +17,8 @@
#include "mail.h"
static char *prev_name;
/*
* fi[le] [file]
* fold[er] [file]
......@@ -27,25 +29,23 @@ mail_file (int argc, char **argv)
{
if (argc == 1)
{
url_t url;
mailbox_get_url (mbox, &url);
fprintf (ofile, "%s\n", url_to_string (url));
/*FIXME: display current folder info */
mail_summary (0, NULL);
}
else if (argc == 2)
{
char *pname;
url_t url;
/* switch folders */
/*
* special characters:
* % system mailbox
* %user system mailbox of user
* %user system mailbox of the user
* # the previous file
* & the current mbox
* +file the file named in the folder directory (set folder=foo)
*/
mailbox_t newbox;
mailbox_t newbox = NULL;
struct mail_env_entry *env;
char *name;
......@@ -62,8 +62,13 @@ mail_file (int argc, char **argv)
break;
case '#':
util_error("# notation not supported");
if (!prev_name)
{
util_error("No previous file");
return 1;
}
name = prev_name;
break;
case '&':
name = getenv ("MBOX");
......@@ -81,23 +86,38 @@ mail_file (int argc, char **argv)
name = argv[1];
}
if (mailbox_create_default (&newbox, name) != 0)
return 1;
if (mailbox_open (newbox, MU_STREAM_READ) != 0)
return 1;
if (mailbox_create_default (&newbox, name) != 0
|| mailbox_open (newbox, MU_STREAM_READ) != 0)
{
mailbox_destroy (&newbox);
util_error("can't open mailbox %s: %s",
name ? name : "%", strerror(errno));
return 1;
}
mailbox_get_url (mbox, &url);
pname = strdup (url_to_string (url));
if (mail_mbox_close ())
{
if (pname)
free (pname);
mailbox_close (newbox);
mailbox_destroy (&newbox);
return 1;
}
if (prev_name)
free (prev_name);
prev_name = pname;
mbox = newbox;
mailbox_messages_count (mbox, &total);
cursor = realcursor = 1;
if ((util_find_env("header"))->set)
{
util_do_command ("summary");
util_do_command ("z.");
}
return 0;
}
else
......