Commit 33e314b0 33e314b0bd324b91353b7f5c93309a5264d5245c by Jakob Kaivo

Implement dp, next, previous, size, and unset in mail

tweak bang, set, shell in mail
fixup list and stat in pop3d
minor dele tweaking in pop3d
1 parent b7c6e7ca
......@@ -24,18 +24,17 @@
int
mail_bang (int argc, char **argv)
{
int pid = fork ();
if (pid == 0)
if (!fork ())
{
free (argv[0]);
argv[0] = strdup ("/bin/sh");
execv ("/bin/sh", argv);
char *path = getenv ("SHELL");
if (path == NULL)
path = strdup ("/bin/sh");
execv (path, &path);
return 1;
}
else if (pid > 0)
else
{
while (waitpid(pid, NULL, 0) == -1)
/* do nothing */;
wait(NULL);
return 0;
}
return 1;
......
......@@ -25,6 +25,11 @@
int
mail_dp (int argc, char **argv)
{
printf ("Function not implemented in %s line %d\n", __FILE__, __LINE__);
return 1;
if (argc > 1)
util_msglist_command (mail_delete, argc, argv);
else
util_do_command ("delete");
util_do_command ("next");
util_do_command ("print");
return 0;
}
......
......@@ -33,8 +33,9 @@ mail_next (int argc, char **argv)
}
else if (argc == 2)
{
printf ("Function not implemented in %s line %d\n", __FILE__, __LINE__);
return 1;
cursor = strtol (argv[1], NULL, 10);
realcursor = cursor;
return 0;
}
return 1;
}
......
......@@ -25,6 +25,17 @@
int
mail_previous (int argc, char **argv)
{
printf ("Function not implemented in %s line %d\n", __FILE__, __LINE__);
if (argc < 2)
{
cursor--;
realcursor--;
return 0;
}
else if ( argc == 2)
{
cursor = strtol (argv[1], NULL, 10);
realcursor = cursor;
return 0;
}
return 1;
}
......
......@@ -24,6 +24,41 @@
int
mail_set (int argc, char **argv)
{
printf ("Function not implemented in %s line %d\n", __FILE__, __LINE__);
if (argc < 2)
{
/* step through the environment */
}
else
{
int i = 0;
char *var = NULL, *value = NULL;
for (i = 1; i < argc; i++)
{
if (!strncmp ("no", argv[i], 2))
{
/* unset variable */
}
else if (strchr (argv[i], '=') != NULL)
{
int j = 0;
var = strdup (argv[i]);
for (j = 0; j < strlen (var); j++)
if (var[j] == '=')
{
var[j] = '\0';
break;
}
value = strdup (&var[j+1]);
/* set var = value */
free (var);
free (value);
}
else
{
/* set var = NULL */
}
}
return 0;
}
return 1;
}
......
......@@ -26,18 +26,26 @@ mail_shell (int argc, char **argv)
{
if (argc > 1)
return 1;
else if (!fork ())
{
char *path = getenv ("SHELL");
if (path == NULL)
path = strdup ("/bin/sh");
execv (path, &path);
return 1;
}
else
{
wait(NULL);
return 0;
int pid = fork ();
if (pid == 0)
{
free (argv[0]);
/*
argv[0] = getenv ("SHELL");
if (!argv[0])
*/
argv[0] = strdup ("/bin/sh");
execv ("/bin/sh", argv);
return 1;
}
else if (pid > 0)
{
while (waitpid(pid, NULL, 0) == -1)
/* do nothing */;
return 0;
}
}
return 1;
}
......
......@@ -24,6 +24,20 @@
int
mail_size (int argc, char **argv)
{
printf ("Function not implemented in %s line %d\n", __FILE__, __LINE__);
if (argc > 1)
util_msglist_command (mail_size, argc, argv);
else
{
unsigned int s = 0;
message_t msg;
if (mailbox_get_message (mbox, cursor, &msg) != 0)
{
fprintf (stderr, "Could not read message %d\n", cursor);
return 1;
}
message_size (msg, &s);
printf ("%c%2d %d\n", cursor == realcursor ? '>' : ' ', cursor, s);
return 0;
}
return 1;
}
......
......@@ -67,6 +67,8 @@ const struct mail_command_entry mail_command_table[] = {
{ "T", "Type", mail_printall, "T[ype] [msglist]" },
{ "p", "print", mail_print, "p[rint] [msglist]" },
{ "t", "type", mail_print, "t[ype] [msglist]" },
{ "prev", "previous", mail_previous, "prev[ious] [message]" },
{ "-", "-", mail_previous, "- [message]" },
{ "q", "quit", mail_quit, "q[uit]" },
/* Hmm... will this work? */
......
......@@ -24,6 +24,20 @@
int
mail_unset (int argc, char **argv)
{
printf ("Function not implemented in %s line %d\n", __FILE__, __LINE__);
if (argc < 2)
return 1;
else
{
int status = 0, i = 1;
for (i=1; i < argc; i++)
{
char *buf = malloc ((6+strlen (argv[i])) * sizeof (char));
strcpy (buf, "set no");
strcat (buf, argv[i]);
if (!util_do_command (buf))
status = 1;
free (buf);
}
}
return 1;
}
......
......@@ -85,7 +85,7 @@ util_expand_msglist (const int argc, char **argv, int **list)
else if (!strcmp (argv[i], "^"))
{
/* FIXME: first [un]deleted message */
current =util_ll_add (current, 1);
current = util_ll_add (current, 1);
}
else if (!strcmp (argv[i], "$"))
{
......@@ -104,6 +104,27 @@ util_expand_msglist (const int argc, char **argv, int **list)
{
/* FIXME: all messages with pattern following / in
the subject line, case insensitive */
/* This currently appears to be quit b0rked */
message_t msg;
header_t hdr;
char subj[128];
int j = 1, k = 0, l2 = 0;
int len = strlen (&argv[i][1]);
for (j = 1; j <= total; j++)
{
mailbox_get_message (mbox, j, &msg);
message_get_header (msg, &hdr);
header_get_value (hdr, MU_HEADER_SUBJECT, subj, 128, NULL);
l2 = strlen (subj);
for (k = 0; i < strlen (subj); k++)
{
if (l2-k >= len && !strncasecmp (&argv[i][1], &subj[k], len))
{
current = util_ll_add (current, j);
k = 128;
}
}
}
}
else if (argv[i][0] == ':')
{
......
......@@ -34,6 +34,6 @@ pop3_dele (const char *arg)
if (/* FIXME: mailbox_delete (mbox, num) != */ 0)
return ERR_NO_MESG;
fprintf (ofile, "+OK Message %d marked\r\n", num + 1);
fprintf (ofile, "+OK Message %d marked\r\n", num);
return OK;
}
......
......@@ -22,7 +22,7 @@
int
pop3_list (const char *arg)
{
int mesg = 0, size = 0;
unsigned int mesg = 0, size = 0;
message_t msg;
if (state != TRANSACTION)
......@@ -35,24 +35,26 @@ pop3_list (const char *arg)
if (strlen (arg) == 0)
{
int total;
unsigned int total;
mailbox_messages_count (mbox, &total);
fprintf (ofile, "+OK\r\n");
for (mesg = 1; mesg <= total; mesg++)
{
mailbox_get_message (mbox, &msg, mesg);
/* if ! deleted */
/* message_get_size (msg, &size); */
fprintf (ofile, "%d %d\r\n", mesg, size);
mailbox_get_message (mbox, mesg, &msg);
if ( /* deleted == 0 */ 1)
{
message_size (msg, &size);
fprintf (ofile, "%d %d\r\n", mesg, size);
}
}
fprintf (ofile, ".\r\n");
}
else
{
mesg = atoi (arg);
if (mailbox_get_message (mbox, &msg, mesg) != 0)
if (mailbox_get_message (mbox, mesg, &msg) != 0)
return ERR_NO_MESG;
/* message_get_size (msg, &size); */
message_size (msg, &size);
fprintf (ofile, "+OK %d %d\r\n", mesg, size);
}
......
......@@ -31,8 +31,7 @@ pop3_stat (const char *arg)
if (state != TRANSACTION)
return ERR_WRONG_STATE;
/* FIXME: unimplemented! */
/* mailbox_size (mbox, &size); */
mailbox_size (mbox, &size);
mailbox_messages_count (mbox, &mesgs);
fprintf (ofile, "+OK %d %d\r\n", mesgs, (int)size);
......