Commit 2568cfa5 2568cfa5cfc5d053cb99f3f366e0e42874d6dc9d by Jakob Kaivo

mail hacking

first pass at implementing file/folder command - you can now switch folders on the fly
tracked down bug in argcv.c that made mail shell/! function not work properly
removed unnecessary #if stuff from source.c
1 parent a7936f44
......@@ -49,7 +49,7 @@ argcv_get (const char *command, int *argc, char ***argv)
{
/* Reserve space for the null. */
(*argv)[j] = calloc ((i - start + 1), sizeof (char));
if ((*argv[j]) == NULL)
if ((*argv)[j] == NULL)
return 1;
strncpy ((*argv)[j], &command[start], i - start);
j++;
......@@ -94,7 +94,7 @@ argcv_string (int argc, char **argv, char **pstring)
for (len = i = 0; i < argc; i++)
{
len += strlen (argv[i] + 2);
len += strlen (argv[i]) + 2;
buffer = realloc (buffer, len);
if (buffer == NULL)
return 1;
......
......@@ -60,4 +60,4 @@ strtok_r (s, delim, save_ptr)
}
return token;
}
weak_alias (__strtok_r, strtok_r)
/* weak_alias (__strtok_r, strtok_r) */
......
......@@ -25,6 +25,34 @@
int
mail_file (int argc, char **argv)
{
printf ("Function not implemented in %s line %d\n", __FILE__, __LINE__);
if (argc == 1)
{
/* display current folder info */
}
else if (argc == 2)
{
/* switch folders */
/*
* special characters:
* % system mailbox
* %user system mailbox of user
* # the previous file
* & the current mbox
* +file the file named in the folder directory (set folder=foo)
*/
mailbox_t newbox;
if (mailbox_create (&newbox, argv[1]) != 0)
return 1;
if (mailbox_open (newbox, MU_STREAM_READ) != 0)
return 1;
mailbox_messages_count (newbox, &total);
mailbox_expunge (mbox);
mailbox_close (mbox);
mbox = newbox;
/* mailbox_destroy (&newbox); */
if ((util_find_env("header"))->set)
util_do_command ("from *");
return 0;
}
return 1;
}
......
......@@ -226,6 +226,16 @@ main (int argc, char **argv)
if ((mode = util_find_env ("mode")) == NULL || mode->set == 0)
exit (EXIT_FAILURE);
if (!(util_find_env("quit"))->set)
{
printf ("%s, Copyright (C) 2001 Free Software Foundation, Inc.\n"
"mail comes with ABSOLUTELY NO WARRANTY; for details type\n"
"'warranty'. This is free software, and you are welcome to\n"
"redistribute it under certain conditions; type 'copying'\n"
"for details.\n",
argp_program_version);
}
modelen = strlen (mode->value);
if (strlen ("exist") == modelen && !strcmp ("exist", mode->value))
return (total < 1) ? 1 : 0;
......
......@@ -44,7 +44,7 @@ mail_shell (int argc, char **argv)
int pid = fork ();
if (pid == 0)
{
const char **argvec;
char **argvec;
char *buf = NULL;
/* 1(shell) + 1 (-c) + 1(arg) + 1 (null) = 4 */
......@@ -57,14 +57,12 @@ mail_shell (int argc, char **argv)
argvec[2] = buf;
argvec[3] = NULL;
/* why does this complain if argvec[2] is in the path but not
fully qualified ? */
execvp (argvec[0], argvec);
free (buf); /* Being cute, nuke it when finish testing. */
free (argvec);
return 1;
}
else if (pid > 0)
if (pid > 0)
{
while (waitpid(pid, NULL, 0) == -1)
/* do nothing */;
......
......@@ -24,11 +24,6 @@
int
mail_source (int argc, char **argv)
{
#if 1
/* 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");
......@@ -38,7 +33,9 @@ mail_source (int argc, char **argv)
size_t s = 0;
while (getline (&buf, &s, rc) >= 0)
{
buf[strlen(buf) - 1] = '\0';
int len = strlen (buf);
if (buf[len-1] == '\n')
buf[len-1] = '\0';
util_do_command("%s", buf);
free (buf);
buf = NULL;
......@@ -48,6 +45,5 @@ mail_source (int argc, char **argv)
return 0;
}
}
#endif
return 1;
}
......