summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2019-01-23 06:48:03 +0200
committerSergey Poznyakoff <gray@gnu.org>2019-01-23 07:03:12 +0200
commit6ea2ea5259553f5d8437e7fd8c7d4c15e7facfb0 (patch)
tree9bc9a6c52f4f4929d83c6ff17ddb77ce9a3b8607
parentab197daa87423ba95205800ff53247777411aebc (diff)
downloadmailutils-6ea2ea5259553f5d8437e7fd8c7d4c15e7facfb0.tar.gz
mailutils-6ea2ea5259553f5d8437e7fd8c7d4c15e7facfb0.tar.bz2
mail: new notation @, for the mailbox given with the -f option
* doc/texinfo/programs/mail.texi: Document the @ notation. * NEWS: Likewise. * mail/copy.c (mail_copy0): Rewrite. Use mailbox URLs instead of filenames. * mail/file.c (mail_expand_name): Return integer code. On success, convert the expanded name to URL and return it in the memory location supplied by the second argument. Use new shorthand notation @, for the name of the file given with the -f option. All uses changed. * mail/mail.c (secondary_url): New global. (main): Save the URL of the file given with the -f option in secondary_url. Use it, instead of the file variable, to decide what kind of summary message to display for empty mailbox (see commit 99b6b6f02c3cf94ebe1daf7233a702c743d6a2b5). * mail/mail.h (secondary_url): New global. (mail_expand_name): Change prototype. * mail/mailline.c: Minor changes. * libmailutils/wicket/noauth.c (noauth_ticket_get_cred): Return MU_ERR_AUTH_NO_CRED.
-rw-r--r--NEWS7
-rw-r--r--doc/texinfo/programs/mail.texi5
-rw-r--r--libmailutils/wicket/noauth.c2
-rw-r--r--mail/copy.c98
-rw-r--r--mail/file.c73
-rw-r--r--mail/mail.c133
-rw-r--r--mail/mail.h3
-rw-r--r--mail/mailline.c20
8 files changed, 186 insertions, 155 deletions
diff --git a/NEWS b/NEWS
index a333d734f..206e05323 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-GNU mailutils NEWS -- history of user-visible changes. 2019-01-22
+GNU mailutils NEWS -- history of user-visible changes. 2019-01-23
Copyright (C) 2002-2019 Free Software Foundation, Inc.
See the end of file for copying conditions.
@@ -8,6 +8,11 @@ Version 3.5.90 (git)
* Fixes in the 'mail' utility
+** New mailbox notation @
+
+@ can be used with any command requring a mailbox name to refer to the
+file given with the -f option.
+
** showenvelope
With the showenvelope variable set, mail incorrectly displayed
diff --git a/doc/texinfo/programs/mail.texi b/doc/texinfo/programs/mail.texi
index 52b91835f..6a10435ab 100644
--- a/doc/texinfo/programs/mail.texi
+++ b/doc/texinfo/programs/mail.texi
@@ -566,7 +566,10 @@ The system mailbox for @var{user}.
The previous file.
@item &
-The current mbox.
+The current @samp{mbox}.
+
+@item @@
+Secondary mailbox, given using the @option{-f} command line option.
@item +@var{file}
The named @var{file} in the folder directory. @xref{folder variable}.
diff --git a/libmailutils/wicket/noauth.c b/libmailutils/wicket/noauth.c
index 2a4da1080..90f72a70b 100644
--- a/libmailutils/wicket/noauth.c
+++ b/libmailutils/wicket/noauth.c
@@ -27,7 +27,7 @@ static int
noauth_ticket_get_cred (mu_ticket_t ticket, mu_url_t url, const char *challenge,
char **pplain, mu_secret_t *psec)
{
- return MU_ERR_AUTH_FAILURE;
+ return MU_ERR_AUTH_NO_CRED;
}
int
diff --git a/mail/copy.c b/mail/copy.c
index 15deebe6f..967a0db1a 100644
--- a/mail/copy.c
+++ b/mail/copy.c
@@ -30,7 +30,7 @@ struct append_stat
};
static int
-append_to_mailbox (char const *filename, msgset_t *msglist, int mark,
+append_to_mailbox (mu_url_t url, msgset_t *msglist, int mark,
struct append_stat *totals)
{
int status;
@@ -38,18 +38,21 @@ append_to_mailbox (char const *filename, msgset_t *msglist, int mark,
msgset_t *mp;
size_t size;
mu_message_t msg;
-
- if ((status = mu_mailbox_create (&mbx, filename)) != 0)
+ mu_url_t url_copy;
+
+ mu_url_dup (url, &url_copy);
+ if ((status = mu_mailbox_create_from_url (&mbx, url_copy)) != 0)
{
- mu_error (_("Cannot create mailbox %s: %s"), filename,
- mu_strerror (status));
+ mu_url_destroy (&url_copy);
+ mu_error (_("Cannot create mailbox %s: %s"), mu_url_to_string (url),
+ mu_strerror (status));
return 1;
}
mu_mailbox_attach_ticket (mbx);
- if ((status = mu_mailbox_open (mbx, MU_STREAM_WRITE | MU_STREAM_CREAT)) != 0)
+ if ((status = mu_mailbox_open (mbx, MU_STREAM_CREAT | MU_STREAM_APPEND)) != 0)
{
- mu_error (_("Cannot open mailbox %s: %s"), filename,
- mu_strerror (status));
+ mu_error (_("Cannot open mailbox %s: %s"), mu_url_to_string (url),
+ mu_strerror (status));
mu_mailbox_destroy (&mbx);
return 1;
}
@@ -58,7 +61,7 @@ append_to_mailbox (char const *filename, msgset_t *msglist, int mark,
{
status = util_get_message (mbox, mp->msg_part[0], &msg);
if (status)
- break;
+ break;
status = mu_mailbox_append_message (mbx, msg);
if (status)
@@ -66,20 +69,20 @@ append_to_mailbox (char const *filename, msgset_t *msglist, int mark,
mu_error (_("Cannot append message: %s"), mu_strerror (status));
break;
}
-
+
mu_message_size (msg, &size);
totals->size += size;
mu_message_lines (msg, &size);
totals->lines += size;
if (mark)
- {
+ {
mu_attribute_t attr;
mu_message_get_attribute (msg, &attr);
mu_attribute_set_userflag (attr, MAIL_ATTRIBUTE_SAVED);
}
}
-
+
mu_mailbox_close (mbx);
mu_mailbox_destroy (&mbx);
return 0;
@@ -105,7 +108,7 @@ append_to_file (char const *filename, msgset_t *msglist, int mark,
filename, mu_strerror (status));
return 1;
}
-
+
status = mu_locker_create (&locker, filename,
MU_LOCKER_KERNEL|MU_LOCKER_RETRY);
if (status)
@@ -126,16 +129,16 @@ append_to_file (char const *filename, msgset_t *msglist, int mark,
mu_stream_unref (ostr);
return 1;
}
-
+
for (mp = msglist; mp; mp = mp->next)
{
mu_envelope_t env;
const char *s, *d;
int n;
-
+
status = util_get_message (mbox, mp->msg_part[0], &msg);
if (status)
- break;
+ break;
status = mu_message_get_envelope (msg, &env);
if (status)
@@ -150,24 +153,24 @@ append_to_file (char const *filename, msgset_t *msglist, int mark,
mu_error (_("Cannot get envelope sender: %s"), mu_strerror (status));
break;
}
-
+
status = mu_envelope_sget_date (env, &d);
if (status)
{
mu_error (_("Cannot get envelope date: %s"), mu_strerror (status));
break;
}
-
+
status = mu_stream_printf (ostr, "From %s %s\n%n", s, d, &n);
if (status)
{
mu_error (_("Write error: %s"), mu_strerror (status));
break;
}
-
+
totals->lines++;
totals->size += n;
-
+
status = mu_message_get_streamref (msg, &mstr);
if (status)
{
@@ -181,17 +184,17 @@ append_to_file (char const *filename, msgset_t *msglist, int mark,
mu_error (_("Cannot append message: %s"), mu_strerror (status));
break;
}
-
+
mu_stream_unref (mstr);
mu_stream_write (ostr, "\n", 1, NULL);
-
+
totals->size += size + 1;
mu_message_lines (msg, &lines);
totals->lines += lines + 1;
if (mark)
- {
+ {
mu_attribute_t attr;
mu_message_get_attribute (msg, &attr);
mu_attribute_set_userflag (attr, MAIL_ATTRIBUTE_SAVED);
@@ -203,7 +206,7 @@ append_to_file (char const *filename, msgset_t *msglist, int mark,
mu_locker_unlock (locker);
mu_locker_destroy (&locker);
-
+
return 0;
}
@@ -215,45 +218,36 @@ append_to_file (char const *filename, msgset_t *msglist, int mark,
int
mail_copy0 (int argc, char **argv, int mark)
{
- char *filename = NULL;
+ mu_url_t url;
msgset_t *msglist = NULL;
- int sender = 0;
struct append_stat totals = { 0, 0 };
- int status;
+ int rc;
+ char *filename;
if (mu_isupper (argv[0][0]))
- sender = 1;
- else if (argc >= 2)
- filename = mail_expand_name (argv[--argc]);
- else
- filename = mu_strdup ("mbox");
-
- if (msgset_parse (argc, argv, MSG_NODELETED|MSG_SILENT, &msglist))
{
- if (filename)
- free (filename);
- return 1;
+ if (msgset_parse (argc, argv, MSG_NODELETED, &msglist))
+ return 1;
+ filename = util_outfolder_name (util_get_sender (msglist->msg_part[0], 1));
}
-
- if (sender)
- filename = util_outfolder_name (util_get_sender (msglist->msg_part[0], 1));
-
- if (!filename)
+ else
{
- msgset_free (msglist);
- return 1;
+ filename = argc >= 2 ? argv[--argc] : getenv ("MBOX");
+ if (msgset_parse (argc, argv, MSG_NODELETED, &msglist))
+ return 1;
}
- if (mu_is_proto (filename))
- status = append_to_mailbox (filename, msglist, mark, &totals);
+ if (mail_expand_name (filename, &url))
+ return 1;
+ filename = mu_url_to_string (url);
+ if (mu_url_is_scheme (url, "file") || mu_url_is_scheme (url, "mbox"))
+ rc = append_to_file (filename, msglist, mark, &totals);
else
- status = append_to_file (filename, msglist, mark, &totals);
-
- if (status == 0)
+ rc = append_to_mailbox (url, msglist, mark, &totals);
+ if (rc == 0)
mu_printf ("\"%s\" %3lu/%-5lu\n", filename,
- (unsigned long) totals.lines, (unsigned long) totals.size);
-
- free (filename);
+ (unsigned long) totals.lines, (unsigned long) totals.size);
+ mu_url_destroy (&url);
msgset_free (msglist);
return 0;
}
diff --git a/mail/file.c b/mail/file.c
index bc94f130e..98efaca92 100644
--- a/mail/file.c
+++ b/mail/file.c
@@ -16,7 +16,7 @@
#include "mail.h"
-static char *prev_name;
+static mu_url_t prev_url;
/* Expand mail special characters:
* # the previous file
@@ -24,22 +24,37 @@ static char *prev_name;
* +file the file named in the folder directory (set folder=foo)
* % system mailbox
* %user system mailbox of the user
+ * @ file given by the -f option
*/
-char *
-mail_expand_name (const char *name)
+int
+mail_expand_name (const char *name, mu_url_t *purl)
{
- int status = 0;
+ int rc;
char *exp = NULL;
if (strcmp (name, "#") == 0)
{
- if (!prev_name)
+ if (!prev_url)
{
mu_error (_("No previous file"));
- return NULL;
+ return -1;
}
else
- return mu_strdup (prev_name);
+ {
+ rc = mu_url_dup (prev_url, purl);
+ if (rc)
+ mu_diag_funcall (MU_DIAG_ERROR, "mu_url_dup", exp, rc);
+ return rc;
+ }
+ }
+
+ if (secondary_url && strcmp (name, "@") == 0)
+ {
+ rc = mu_url_dup (secondary_url, purl);
+ if (rc)
+ mu_diag_funcall (MU_DIAG_ERROR, "mu_url_dup",
+ mu_url_to_string (secondary_url), rc);
+ return rc;
}
if (strcmp (name, "&") == 0)
@@ -48,17 +63,22 @@ mail_expand_name (const char *name)
if (!name)
{
mu_error (_("MBOX environment variable not set"));
- return NULL;
+ return MU_ERR_FAILURE;
}
/* else fall through */
}
- status = mu_mailbox_expand_name (name, &exp);
+ rc = mu_mailbox_expand_name (name, &exp);
+
+ if (rc)
+ mu_error (_("Failed to expand %s: %s"), name, mu_strerror (rc));
- if (status)
- mu_error (_("Failed to expand %s: %s"), name, mu_strerror (status));
+ rc = mu_url_create (purl, exp);
+ if (rc)
+ mu_diag_funcall (MU_DIAG_ERROR, "mu_url_create", exp, rc);
+ free (exp);
- return (char*) exp;
+ return rc;
}
/*
@@ -76,50 +96,47 @@ mail_file (int argc, char **argv)
else if (argc == 2)
{
/* switch folders */
- char *pname;
- mu_url_t url;
+ mu_url_t url, tmp_url;
mu_mailbox_t newbox = NULL;
- char *name = mail_expand_name (argv[1]);
int status;
- if (!name)
+ if (mail_expand_name (argv[1], &url))
return 1;
- status = mu_mailbox_create (&newbox, name);
+ status = mu_mailbox_create_from_url (&newbox, url);
if (status)
{
- mu_error(_("Cannot create mailbox %s: %s"), name,
+ mu_error(_("Cannot create mailbox %s: %s"),
+ mu_url_to_string (url),
mu_strerror (status));
- free (name);
+ mu_url_destroy (&url);
return 1;
}
mu_mailbox_attach_ticket (newbox);
if ((status = mu_mailbox_open (newbox, MU_STREAM_RDWR)) != 0)
{
+ mu_error(_("Cannot open mailbox %s: %s"),
+ mu_url_to_string (url), mu_strerror (status));
mu_mailbox_destroy (&newbox);
- mu_error(_("Cannot open mailbox %s: %s"), name, mu_strerror (status));
- free (name);
return 1;
}
- free (name); /* won't need it any more */
page_invalidate (1); /* Invalidate current page map */
mu_mailbox_get_url (mbox, &url);
- pname = mu_strdup (mu_url_to_string (url));
+ mu_url_dup (url, &tmp_url);
+
if (mail_mbox_close ())
{
- if (pname)
- free (pname);
+ mu_url_destroy (&tmp_url);
mu_mailbox_close (newbox);
mu_mailbox_destroy (&newbox);
return 1;
}
- if (prev_name)
- free (prev_name);
- prev_name = pname;
+ mu_url_destroy (&prev_url);
+ prev_url = tmp_url;
mbox = newbox;
mu_mailbox_messages_count (mbox, &total);
diff --git a/mail/mail.c b/mail/mail.c
index f5d1689ca..b9142ea24 100644
--- a/mail/mail.c
+++ b/mail/mail.c
@@ -21,9 +21,9 @@
/* Global variables and constants*/
mu_mailbox_t mbox; /* Mailbox being operated upon */
size_t total; /* Total number of messages in the mailbox */
-int interactive; /* Is the session interactive */
+int interactive; /* Is the session interactive */
int read_recipients; /* Read recipients from the message (mail -t) */
-
+mu_url_t secondary_url; /* URL of the mailbox given with the -f option */
static mu_list_t command_list;/* List of commands to be executed after parsing
command line */
const char *program_version = "mail (" PACKAGE_STRING ")";
@@ -52,7 +52,7 @@ static void
cli_file_option (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
if (arg)
- file = mu_strdup (arg);
+ file = mu_strdup (arg);
hint |= HINT_FILE_OPTION;
}
@@ -65,41 +65,41 @@ cli_command_option (struct mu_parseopt *po, struct mu_option *opt,
case 'e':
util_cache_command (&command_list, "setq mode=exist");
break;
-
+
case 'p':
util_cache_command (&command_list, "setq mode=print");
break;
-
+
case 'r':
util_cache_command (&command_list, "set return-address=%s", arg);
break;
-
+
case 'q':
util_cache_command (&command_list, "set quit");
break;
-
+
case 't':
read_recipients = 1;
util_cache_command (&command_list, "set editheaders");
util_cache_command (&command_list, "setq mode=send");
break;
-
+
case 'H':
util_cache_command (&command_list, "setq mode=headers");
break;
-
+
case 'i':
util_cache_command (&command_list, "set ignore");
break;
-
+
case 'n':
util_do_command ("set norc");
break;
-
+
case 'N':
util_cache_command (&command_list, "set noheader");
break;
-
+
case 'E':
util_cache_command (&command_list, "%s", arg);
break;
@@ -112,12 +112,12 @@ cli_command_option (struct mu_parseopt *po, struct mu_option *opt,
mu_parseopt_error (po, _("--%s: option should have been recognized"),
opt->opt_long);
exit (po->po_exit_error);
-
+
default:
mu_parseopt_error (po, _("-%c: option should have been recognized"),
opt->opt_short);
exit (po->po_exit_error);
- }
+ }
}
static void
@@ -139,7 +139,7 @@ static void
cli_attach (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
int fd = -1;
-
+
hint |= HINT_SEND_MODE;
if (strcmp (arg, "-") == 0)
{
@@ -160,7 +160,7 @@ static void
cli_attach_fd (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
{
int rc, fd;
-
+
hint |= HINT_SEND_MODE;
rc = mu_str_to_c (arg, mu_c_int, &fd, NULL);
if (rc)
@@ -168,10 +168,10 @@ cli_attach_fd (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
mu_parseopt_error (po, _("%s: bad descriptor"), arg);
exit (po->po_exit_error);
}
-
+
send_attach_file (fd, NULL, content_filename, content_name,
default_content_type, default_encoding);
-
+
free (content_name);
content_name = NULL;
free (content_filename);
@@ -189,52 +189,52 @@ static struct mu_option mail_options[] = {
{ "exist", 'e', NULL, MU_OPTION_DEFAULT,
N_("return true if mail exists"),
mu_c_string, NULL, cli_command_option },
-
+
{ "byname", 'F', NULL, MU_OPTION_DEFAULT,
N_("save messages according to sender"),
mu_c_string, NULL, cli_command_option },
-
+
{ "headers", 'H', NULL, MU_OPTION_DEFAULT,
N_("write a header summary and exit"),
mu_c_string, NULL, cli_command_option },
-
+
{ "ignore", 'i', NULL, MU_OPTION_DEFAULT,
N_("ignore interrupts"),
mu_c_string, NULL, cli_command_option },
-
+
{ "norc", 'n', NULL, MU_OPTION_DEFAULT,
N_("do not read the system mailrc file"),
mu_c_string, NULL, cli_command_option },
-
+
{ "nosum", 'N', NULL, MU_OPTION_DEFAULT,
N_("do not display initial header summary"),
mu_c_string, NULL, cli_command_option },
-
+
{ "print", 'p', NULL, MU_OPTION_DEFAULT,
N_("print all mail to standard output"),
- mu_c_string, NULL, cli_command_option },
+ mu_c_string, NULL, cli_command_option },
{ "read", 0, NULL, MU_OPTION_ALIAS },
-
+
{ "return-address", 'r', N_("ADDRESS"), MU_OPTION_DEFAULT,
N_("use address as the return address when sending mail"),
mu_c_string, NULL, cli_command_option },
-
+
{ "quit", 'q', NULL, MU_OPTION_DEFAULT,
N_("cause interrupts to terminate program"),
mu_c_string, NULL, cli_command_option },
-
+
{ "subject", 's', N_("SUBJ"), MU_OPTION_DEFAULT,
N_("send a message with the given SUBJECT"),
mu_c_string, NULL, cli_subject },
-
+
{ "to", 't', NULL, MU_OPTION_DEFAULT,
N_("read recipients from the message header"),
mu_c_string, NULL, cli_command_option },
-
+
{ "user", 'u', N_("USER"), MU_OPTION_DEFAULT,
N_("operate on USER's mailbox"),
mu_c_string, &user },
-
+
{ "append", 'a', N_("HEADER: VALUE"), MU_OPTION_DEFAULT,
N_("append given header to the message being sent"),
mu_c_string, NULL, cli_append },
@@ -242,30 +242,30 @@ static struct mu_option mail_options[] = {
{ "alternative", 0, NULL, MU_OPTION_DEFAULT,
N_("force multipart/alternative content type"),
mu_c_bool, &multipart_alternative },
-
+
{ "skip-empty-attachments", 0, NULL, MU_OPTION_DEFAULT,
N_("skip attachments with empty body"),
mu_c_bool, &skip_empty_attachments },
-
+
{ "exec" , 'E', N_("COMMAND"), MU_OPTION_DEFAULT,
N_("execute COMMAND"),
mu_c_string, NULL, cli_command_option },
-
+
{ "encoding", 0, N_("NAME"), MU_OPTION_DEFAULT,
N_("set encoding for subsequent --attach options"),
mu_c_string, &default_encoding },
-
+
{ "content-type", 0, N_("TYPE"), MU_OPTION_DEFAULT,
N_("set content type for subsequent --attach options"),
mu_c_string, &default_content_type },
-
+
{ "content-name", 0, N_("NAME"), MU_OPTION_DEFAULT,
N_("set the Content-Type name parameter for the next --attach option"),
mu_c_string, &content_name },
{ "content-filename", 0, N_("NAME"), MU_OPTION_DEFAULT,
N_("set the Content-Disposition filename parameter for the next --attach option"),
mu_c_string, &content_filename },
-
+
{ "attach", 'A', N_("FILE"), MU_OPTION_DEFAULT,
N_("attach FILE"),
mu_c_string, NULL, cli_attach },
@@ -306,9 +306,9 @@ static char *mail_capa[] = {
"debug",
"mailbox",
"locking",
- NULL
+ NULL
};
-
+
static char *
mail_cmdline (void *closure, int cont MU_ARG_UNUSED)
{
@@ -325,7 +325,7 @@ mail_cmdline (void *closure, int cont MU_ARG_UNUSED)
}
rc = ml_readline (prompt);
-
+
if (ml_got_interrupt ())
{
mu_error (_("Interrupt"));
@@ -392,7 +392,7 @@ static char *default_setup[] = {
"set fromfield",
"set headline=\"%>%a%4m %18f %16d %3L/%-5o %s\"",
"unset folder",
-
+
/* Start in mail reading mode */
"setq mode=read",
"set noquit",
@@ -404,7 +404,7 @@ static char *default_setup[] = {
"set nullbody", /* Null message body is traditionally allowed */
"set nullbodymsg=\"" N_("Null message body; hope that's ok") "\"",
-
+
/* These settings are not yet used */
"set noonehop",
"set nosendwait",
@@ -423,18 +423,18 @@ main (int argc, char **argv)
{
char *mode = NULL, *prompt = NULL, *p;
int i, rc;
-
+
mu_stdstream_setup (MU_STDSTREAM_RESET_NONE);
set_cursor (1);
/* Native Language Support */
MU_APP_INIT_NLS ();
-
+
/* Register the desired formats. */
mu_register_all_formats ();
- mu_auth_register_module (&mu_auth_tls_module);
-
+ mu_auth_register_module (&mu_auth_tls_module);
+
interactive = isatty (fileno (stdin));
#ifdef HAVE_SIGACTION
{
@@ -471,13 +471,13 @@ main (int argc, char **argv)
util_do_command ("set screen=%s", p);
else
util_do_command ("set screen=%d", util_getlines ());
-
+
p = getenv ("COLUMNS");
if (p && p[strspn (p, "0123456789")] == 0)
util_do_command ("set columns=%s", p);
else
util_do_command ("set columns=%d", util_getcols ());
-
+
/* Set the default mailer to sendmail. */
mailvar_set ("sendmail",
mu_strdup ("sendmail:" PATH_SENDMAIL), mailvar_type_string,
@@ -490,13 +490,13 @@ main (int argc, char **argv)
mime_option = 1;
if (mime_option)
util_cache_command (&command_list, "set mime");
-
+
if (read_recipients)
{
argv += argc;
argc = 0;
}
-
+
if ((hint & (HINT_SEND_MODE|HINT_FILE_OPTION)) ==
(HINT_SEND_MODE|HINT_FILE_OPTION))
{
@@ -532,7 +532,7 @@ main (int argc, char **argv)
else if (user)
mu_asprintf (&file, "%%%s", user);
-
+
/* read system-wide mail.rc and user's .mailrc */
if (mailvar_is_true ("rc"))
util_do_command ("source %s", SITE_MAIL_RC);
@@ -582,7 +582,7 @@ main (int argc, char **argv)
return mailvar_is_true ("mailx") ? 0 : rc;
}
/* Or acting as a normal reader */
- else
+ else
{
if ((rc = mu_mailbox_create_default (&mbox, file)) != 0)
{
@@ -597,12 +597,22 @@ main (int argc, char **argv)
if (file)
{
+ /* Save URL of the file for further use */
+ mu_url_t url;
+
+ if (mu_mailbox_get_url (mbox, &url) == 0)
+ {
+ rc = mu_url_dup (url, &secondary_url);
+ if (rc)
+ {
+ mu_diag_funcall (MU_DIAG_ERROR, "mu_url_dup", NULL, rc);
+ exit (EXIT_FAILURE);
+ }
+ }
/* Destroy the content of file prior to freeing it: it can contain
password, although such usage is discouraged */
memset (file, 0, strlen (file));
free (file);
- /* Note: the *value* of this variable will be used later to determine
- what kind of message to display if the mailbox is empty */
}
if ((rc = mu_mailbox_open (mbox, MU_STREAM_RDWR|MU_STREAM_CREAT)) != 0)
@@ -643,16 +653,16 @@ main (int argc, char **argv)
return 1;
}
}
-
+
if (total == 0
&& (strcmp (mode, "read") || !mailvar_is_true ("emptystart")))
- {
- if (file) /* See the comment above */
+ {
+ if (secondary_url)
mail_summary (0, NULL);
else
mu_printf (_("No mail for %s\n"), user ? user : mail_whoami ());
- return 1;
- }
+ return 1;
+ }
/* initial commands */
if (mailvar_is_true ("header"))
@@ -715,7 +725,7 @@ mail_warranty (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
{
mu_printf (
_("GNU Mailutils -- a suite of utilities for electronic mail\n"
- "Copyright (C) 1999-2011 Free Software Foundation, Inc.\n\n"));
+ "Copyright (C) 1999-2019 Free Software Foundation, Inc.\n\n"));
mu_printf (
_(" GNU Mailutils is free software; you can redistribute it and/or modify\n"
" it under the terms of the GNU General Public License as published by\n"
@@ -728,11 +738,10 @@ mail_warranty (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
" GNU General Public License for more details.\n"
"\n"
" You should have received a copy of the GNU General Public License along\n"
- " with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.\n"
+ " with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>.\n"
"\n"
"\n"
));
return 0;
}
-
diff --git a/mail/mail.h b/mail/mail.h
index a6cc3139d..ec48f9e32 100644
--- a/mail/mail.h
+++ b/mail/mail.h
@@ -172,6 +172,7 @@ typedef int (*msg_handler_t) (msgset_t *mp, mu_message_t mesg, void *data);
extern mu_mailbox_t mbox;
extern size_t total;
extern int interactive;
+extern mu_url_t secondary_url;
extern const char *program_version;
extern char *default_encoding;
extern char *default_content_type;
@@ -259,7 +260,7 @@ char *mail_whoami (void);
int mail_header_is_visible (const char *str);
int mail_header_is_unfoldable (const char *str);
int mail_mbox_close (void);
-char *mail_expand_name (const char *name);
+int mail_expand_name (const char *name, mu_url_t *purl);
void send_append_header (char const *text);
void send_append_header2 (char const *name, char const *value, int mode);
diff --git a/mail/mailline.c b/mail/mailline.c
index 92513eff4..06cb1dea8 100644
--- a/mail/mailline.c
+++ b/mail/mailline.c
@@ -563,13 +563,6 @@ filegen_init (struct filegen *fg,
int rc;
int free_folder;
- rc = mu_mailbox_get_folder (mbox, &folder);
- if (rc)
- {
- mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_get_folder", NULL, rc);
- return -1;
- }
-
rc = mu_url_create (&url, folder_path);
if (rc)
{
@@ -577,9 +570,18 @@ filegen_init (struct filegen *fg,
return -1;
}
- if (folder_match_url (folder, url))
- free_folder = 0;
+ rc = mu_mailbox_get_folder (mbox, &folder);
+ if (rc == 0)
+ {
+ if (folder_match_url (folder, url))
+ free_folder = 0;
+ else
+ folder = NULL;
+ }
else
+ folder = NULL;
+
+ if (!folder)
{
if (new_folder (&folder, url, type))
return -1;

Return to:

Send suggestions and report system problems to the System administrator.