Commit 46aac409 46aac40933f291a7e1fb910e3c2521470ab34457 by Sergey Poznyakoff

use util_fullpath().

1 parent f642d023
...@@ -23,10 +23,6 @@ ...@@ -23,10 +23,6 @@
23 * W[rite] [msglist] -- GNU extension 23 * W[rite] [msglist] -- GNU extension
24 */ 24 */
25 25
26 /*
27 * NOTE: outfolder variable
28 */
29
30 int 26 int
31 mail_write (int argc, char **argv) 27 mail_write (int argc, char **argv)
32 { 28 {
...@@ -41,11 +37,14 @@ mail_write (int argc, char **argv) ...@@ -41,11 +37,14 @@ mail_write (int argc, char **argv)
41 int *msglist = NULL; 37 int *msglist = NULL;
42 int num = 0, i = 0; 38 int num = 0, i = 0;
43 int sender = 0; 39 int sender = 0;
40 size_t total_size, total_lines, size;
44 41
45 if (isupper (argv[0][0])) 42 if (isupper (argv[0][0]))
46 sender = 1; 43 sender = 1;
47 else if (argc >= 2) 44 else if (argc >= 2)
48 filename = strdup (argv[--argc]); 45 filename = util_fullpath (argv[--argc]);
46 /* FIXME: Should we use util_outfolder_name() and honour
47 outfolder variable? */
49 else 48 else
50 filename = strdup ("mbox"); 49 filename = strdup ("mbox");
51 50
...@@ -62,23 +61,46 @@ mail_write (int argc, char **argv) ...@@ -62,23 +61,46 @@ mail_write (int argc, char **argv)
62 } 61 }
63 62
64 output = fopen (filename, "a"); 63 output = fopen (filename, "a");
64 if (!output)
65 {
66 fprintf (ofile, "can't open %s: %s\n", filename, strerror (errno));
67 free (filename);
68 fclose (output);
69 free (msglist);
70 return 1;
71 }
65 72
66 for (i = 0; i < num; i++) 73 for (i = 0; i < num; i++)
67 { 74 {
75 attribute_t attr;
76
68 mailbox_get_message (mbox, msglist[i], &msg); 77 mailbox_get_message (mbox, msglist[i], &msg);
69 message_get_body (msg, &bod); 78 message_get_body (msg, &bod);
79
80 body_size (bod, &size);
81 total_size += size;
82 body_lines (bod, &size);
83 total_lines += size;
84
70 body_get_stream (bod, &stream); 85 body_get_stream (bod, &stream);
71 /* should there be a separator? */ 86 /* should there be a separator? */
72 while (stream_read(stream, buffer, sizeof (buffer) - 1, off, &n) 87 while (stream_read(stream, buffer, sizeof (buffer) - 1, off, &n) == 0
73 == 0 && n != 0) 88 && n != 0)
74 { 89 {
75 buffer[n] = '\0'; 90 buffer[n] = '\0';
76 fprintf (output, "%s", buffer); 91 fprintf (output, "%s", buffer);
77 off += n; 92 off += n;
78 } 93 }
79 /* mark as saved */ 94
95 /* mark as saved. */
96
97 message_get_attribute (msg, &attr);
98 attribute_set_userflag (attr, MAIL_ATTRIBUTE_SAVED);
80 } 99 }
81 100
101 fprintf (ofile, "\"%s\" %3ld/%-5ld\n", filename, total_lines, total_size);
102
103 free (filename);
82 fclose (output); 104 fclose (output);
83 free (msglist); 105 free (msglist);
84 return 0; 106 return 0;
......