Commit 5c470f14 5c470f1488e05c87bdaef2936eb74670d49ee5ab by Sergey Poznyakoff

Implemented Write. Fixed memory leaks.

1 parent 2400d34e
......@@ -45,26 +45,25 @@ mail_write (int argc, char **argv)
if (isupper (argv[0][0]))
sender = 1;
else if (argc >= 2)
filename = argv[--argc];
filename = strdup (argv[--argc]);
else
{
filename = strdup ("mbox");
}
num = util_expand_msglist (argc, argv, &msglist);
if (sender)
{
mailbox_get_message (mbox, num > 0 ? msglist[0] : cursor, 0);
/* get from */
/* filename = login name part */
filename = util_get_sender(msglist[0], 1);
if (!filename)
{
free (msglist);
return 1;
}
}
output = fopen (filename, "a");
if (num > 0)
{
for (i=0; i < num; i++)
for (i = 0; i < num; i++)
{
mailbox_get_message (mbox, msglist[i], &msg);
message_get_body (msg, &bod);
......@@ -79,22 +78,6 @@ mail_write (int argc, char **argv)
}
/* mark as saved */
}
}
else
{
mailbox_get_message (mbox, cursor, &msg);
message_get_body (msg, &bod);
body_get_stream (bod, &stream);
/* should there be a separator? */
while (stream_read(stream, buffer, sizeof (buffer) - 1, off, &n)
== 0 && n != 0)
{
buffer[n] = '\0';
fprintf (output, "%s", buffer);
off += n;
}
/* mark as save */
}
fclose (output);
free (msglist);
......