summaryrefslogtreecommitdiff
path: root/mail/write.c
diff options
context:
space:
mode:
Diffstat (limited to 'mail/write.c')
-rw-r--r--mail/write.c88
1 files changed, 42 insertions, 46 deletions
diff --git a/mail/write.c b/mail/write.c
index 3989b5c59..ce43692c2 100644
--- a/mail/write.c
+++ b/mail/write.c
@@ -1,5 +1,5 @@
/* GNU Mailutils -- a suite of utilities for electronic mail
- Copyright (C) 1999-2019 Free Software Foundation, Inc.
+ Copyright (C) 1999-2024 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -28,43 +28,46 @@ mail_write (int argc, char **argv)
int rc;
mu_stream_t output;
char *filename = NULL;
+ char *namebuf = NULL;
msgset_t *msglist = NULL, *mp;
- int sender = 0;
- size_t total_size = 0, total_lines = 0, size;
+ size_t total_size = 0, total_lines = 0;
if (mu_isupper (argv[0][0]))
- sender = 1;
- else if (argc >= 2)
- filename = util_outfolder_name (argv[--argc]);
- else
{
- size_t n = get_cursor ();
- char *p = NULL;
- if (n == 0)
- {
- mu_error (_("No applicable message"));
- return 1;
- }
- mu_asprintf (&p, "%lu", (unsigned long) n);
- filename = util_outfolder_name (p);
- free (p);
+ if (msgset_parse (argc, argv, MSG_NODELETED|MSG_SILENT|MSG_ALLOWPART,
+ &msglist))
+ return 1;
+ filename = namebuf = util_get_sender (msgset_msgno (msglist), 1);
}
-
- if (msgset_parse (argc, argv, MSG_NODELETED|MSG_SILENT, &msglist))
- {
- if (filename)
- free (filename);
- return 1;
- }
-
- if (sender)
+ else
{
- filename = util_outfolder_name (util_get_sender(msglist->msg_part[0], 1));
- if (!filename)
+ if (argc >= 2)
{
- msgset_free (msglist);
- return 1;
+ filename = argv[--argc];
}
+ else
+ {
+ size_t n = get_cursor ();
+ if (n == 0)
+ {
+ mu_error (_("No applicable message"));
+ return 1;
+ }
+ mu_asprintf (&namebuf, "%lu", (unsigned long) n);
+ filename = namebuf;
+ }
+ if (msgset_parse (argc, argv, MSG_NODELETED|MSG_SILENT|MSG_ALLOWPART,
+ &msglist))
+ return 1;
+ }
+
+ rc = mu_mailbox_expand_name (filename, &filename);
+ free (namebuf);
+ if (rc)
+ {
+ mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_expand_name", NULL, rc);
+ msgset_free (msglist);
+ return 1;
}
rc = mu_file_stream_create (&output, filename,
@@ -80,34 +83,27 @@ mail_write (int argc, char **argv)
for (mp = msglist; mp; mp = mp->next)
{
mu_message_t msg;
- mu_body_t body;
- mu_stream_t stream;
mu_attribute_t attr;
-
- if (util_get_message (mbox, mp->msg_part[0], &msg))
+ size_t stat[2];
+
+ if (util_get_message_part (mbox, mp, &msg))
continue;
- mu_message_get_body (msg, &body);
-
- mu_body_get_streamref (body, &stream);
- rc = mu_stream_copy (output, stream, 0, NULL);
- mu_stream_destroy (&stream);
-
+ rc = print_message_body (msg, output, stat);
if (rc == 0)
{
- mu_body_size (body, &size);
- total_size += size;
- mu_body_lines (body, &size);
- total_lines += size;
+ total_size += stat[0];
+ total_lines += stat[1];
/* mark as saved. */
-
+ if (msgset_length (mp) > 1)
+ util_get_message (mbox, msgset_msgno (mp), &msg);
mu_message_get_attribute (msg, &attr);
mu_attribute_set_userflag (attr, MAIL_ATTRIBUTE_SAVED);
}
else
mu_error (_("cannot save %lu: %s"),
- (unsigned long) mp->msg_part[0], mu_strerror (rc));
+ (unsigned long) msgset_msgno (mp), mu_strerror (rc));
}
mu_stream_close (output);

Return to:

Send suggestions and report system problems to the System administrator.