Commit f9958ce0 f9958ce0ae94bb9ca285ea435c8eea0741da7443 by Jakob Kaivo

Clean up mail code

Beginning of mail source command implementation
Have mail source MAILRC file on startup
Fix bugs in mail pipe command
1 parent ec021eea
......@@ -199,6 +199,10 @@ main (int argc, char **argv)
/* argument parsing */
argp_parse (&argp, argc, argv, 0, 0, &args);
/* read .mailrc */
if ((util_find_env ("rc"))->set)
util_do_command ("source %s", getenv ("MAILRC"));
/* Initialize readline */
rl_readline_name = "mail";
rl_attempted_completion_function = (CPPFunction *)util_command_completion;
......@@ -231,7 +235,7 @@ main (int argc, char **argv)
return util_do_command ("from *");
else if (strlen ("send") == modelen && !strcmp ("send", mode->value))
{
/* set cmd to "mail [add1...]" */
/* FIXME: set cmd to "mail [add1...]" */
cmd = strdup ("mail");
return util_do_command (cmd);
}
......
......@@ -49,7 +49,6 @@ mail_pipe (int argc, char **argv)
{
if (mailbox_get_message (mbox, list[i], &msg) == 0)
{
fprintf (stderr, "message %d\n", list[i]);
message_get_stream (msg, &stream);
off = 0;
while (stream_read (stream, buffer, sizeof (buffer) - 1, off,
......@@ -57,10 +56,10 @@ mail_pipe (int argc, char **argv)
{
buffer[n] = '\0';
fprintf (pipe, "%s", buffer);
off =+ n;
off += n;
}
if ((util_find_env("page"))->set)
fprintf (pipe, "\f"); /* FIXME: is this formfeed ? */
if ((util_find_env("page"))->set && i < num - 1)
fprintf (pipe, "\f\n");
}
}
}
......
......@@ -67,7 +67,7 @@ mail_print (int argc, char **argv)
fprintf (out, "Subject: %s\n", buffer);
/* free (buf); */
}
fprintf (out, "\n");
message_get_body (mesg, &body);
body_get_stream (body, &stream);
}
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "mail.h"
/*
* P[rint] [msglist]
* T[ype] [msglist]
*/
int
mail_printall (int argc, char **argv)
{
if (argc > 1)
return util_msglist_command (mail_printall, argc, argv);
else
{
message_t msg;
stream_t is;
char buffer[BUFSIZ];
off_t off = 0;
size_t n = 0;
if (mailbox_get_message (mbox, cursor, &msg) != 0)
return 1;
message_get_stream (msg, &is);
while (stream_read (is, buffer, sizeof (buffer) - 1, off, &n) == 0
&& n != 0)
{
buffer[n] = '\0';
printf ("%s", buffer);
off += n;
}
return 0;
}
return 1;
}
......@@ -25,6 +25,8 @@
int
mail_quit (int argc, char **argv)
{
printf ("Function not implemented in %s line %d\n", __FILE__, __LINE__);
return 1;
mailbox_expunge (mbox);
mailbox_close (mbox);
mailbox_destroy (&mbox);
exit (0);
}
......
......@@ -24,6 +24,27 @@
int
mail_source (int argc, char **argv)
{
printf ("Function not implemented in %s line %d\n", __FILE__, __LINE__);
#if 0
/* On sparky's machine, there is an odd SEGV coming from a free() deep
withing fopen(). I don't get it */
if (argc == 2)
{
FILE *rc = fopen (argv[1], "r");
char *buf = NULL;
size_t s = 0;
while (getline (&buf, &s, rc) >= 0)
{
buf[strlen(buf) - 1] = '\0';
util_do_command("%s", buf);
free (buf);
buf = NULL;
s = 0;
}
fclose (rc);
return 0;
}
#endif
return 1;
}
......