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 @@ ...@@ -24,18 +24,17 @@
24 int 24 int
25 mail_bang (int argc, char **argv) 25 mail_bang (int argc, char **argv)
26 { 26 {
27 int pid = fork (); 27 if (!fork ())
28 if (pid == 0)
29 { 28 {
30 free (argv[0]); 29 char *path = getenv ("SHELL");
31 argv[0] = strdup ("/bin/sh"); 30 if (path == NULL)
32 execv ("/bin/sh", argv); 31 path = strdup ("/bin/sh");
32 execv (path, &path);
33 return 1; 33 return 1;
34 } 34 }
35 else if (pid > 0) 35 else
36 { 36 {
37 while (waitpid(pid, NULL, 0) == -1) 37 wait(NULL);
38 /* do nothing */;
39 return 0; 38 return 0;
40 } 39 }
41 return 1; 40 return 1;
......
...@@ -25,6 +25,11 @@ ...@@ -25,6 +25,11 @@
25 int 25 int
26 mail_dp (int argc, char **argv) 26 mail_dp (int argc, char **argv)
27 { 27 {
28 printf ("Function not implemented in %s line %d\n", __FILE__, __LINE__); 28 if (argc > 1)
29 return 1; 29 util_msglist_command (mail_delete, argc, argv);
30 else
31 util_do_command ("delete");
32 util_do_command ("next");
33 util_do_command ("print");
34 return 0;
30 } 35 }
......
...@@ -33,8 +33,9 @@ mail_next (int argc, char **argv) ...@@ -33,8 +33,9 @@ mail_next (int argc, char **argv)
33 } 33 }
34 else if (argc == 2) 34 else if (argc == 2)
35 { 35 {
36 printf ("Function not implemented in %s line %d\n", __FILE__, __LINE__); 36 cursor = strtol (argv[1], NULL, 10);
37 return 1; 37 realcursor = cursor;
38 return 0;
38 } 39 }
39 return 1; 40 return 1;
40 } 41 }
......
...@@ -25,6 +25,17 @@ ...@@ -25,6 +25,17 @@
25 int 25 int
26 mail_previous (int argc, char **argv) 26 mail_previous (int argc, char **argv)
27 { 27 {
28 printf ("Function not implemented in %s line %d\n", __FILE__, __LINE__); 28 if (argc < 2)
29 {
30 cursor--;
31 realcursor--;
32 return 0;
33 }
34 else if ( argc == 2)
35 {
36 cursor = strtol (argv[1], NULL, 10);
37 realcursor = cursor;
38 return 0;
39 }
29 return 1; 40 return 1;
30 } 41 }
......
...@@ -24,6 +24,41 @@ ...@@ -24,6 +24,41 @@
24 int 24 int
25 mail_set (int argc, char **argv) 25 mail_set (int argc, char **argv)
26 { 26 {
27 printf ("Function not implemented in %s line %d\n", __FILE__, __LINE__); 27 if (argc < 2)
28 {
29 /* step through the environment */
30 }
31 else
32 {
33 int i = 0;
34 char *var = NULL, *value = NULL;
35 for (i = 1; i < argc; i++)
36 {
37 if (!strncmp ("no", argv[i], 2))
38 {
39 /* unset variable */
40 }
41 else if (strchr (argv[i], '=') != NULL)
42 {
43 int j = 0;
44 var = strdup (argv[i]);
45 for (j = 0; j < strlen (var); j++)
46 if (var[j] == '=')
47 {
48 var[j] = '\0';
49 break;
50 }
51 value = strdup (&var[j+1]);
52 /* set var = value */
53 free (var);
54 free (value);
55 }
56 else
57 {
58 /* set var = NULL */
59 }
60 }
61 return 0;
62 }
28 return 1; 63 return 1;
29 } 64 }
......
...@@ -26,18 +26,26 @@ mail_shell (int argc, char **argv) ...@@ -26,18 +26,26 @@ mail_shell (int argc, char **argv)
26 { 26 {
27 if (argc > 1) 27 if (argc > 1)
28 return 1; 28 return 1;
29 else if (!fork ())
30 {
31 char *path = getenv ("SHELL");
32 if (path == NULL)
33 path = strdup ("/bin/sh");
34 execv (path, &path);
35 return 1;
36 }
37 else 29 else
38 { 30 {
39 wait(NULL); 31 int pid = fork ();
40 return 0; 32 if (pid == 0)
33 {
34 free (argv[0]);
35 /*
36 argv[0] = getenv ("SHELL");
37 if (!argv[0])
38 */
39 argv[0] = strdup ("/bin/sh");
40 execv ("/bin/sh", argv);
41 return 1;
42 }
43 else if (pid > 0)
44 {
45 while (waitpid(pid, NULL, 0) == -1)
46 /* do nothing */;
47 return 0;
48 }
41 } 49 }
42 return 1; 50 return 1;
43 } 51 }
......
...@@ -24,6 +24,20 @@ ...@@ -24,6 +24,20 @@
24 int 24 int
25 mail_size (int argc, char **argv) 25 mail_size (int argc, char **argv)
26 { 26 {
27 printf ("Function not implemented in %s line %d\n", __FILE__, __LINE__); 27 if (argc > 1)
28 util_msglist_command (mail_size, argc, argv);
29 else
30 {
31 unsigned int s = 0;
32 message_t msg;
33 if (mailbox_get_message (mbox, cursor, &msg) != 0)
34 {
35 fprintf (stderr, "Could not read message %d\n", cursor);
36 return 1;
37 }
38 message_size (msg, &s);
39 printf ("%c%2d %d\n", cursor == realcursor ? '>' : ' ', cursor, s);
40 return 0;
41 }
28 return 1; 42 return 1;
29 } 43 }
......
...@@ -67,6 +67,8 @@ const struct mail_command_entry mail_command_table[] = { ...@@ -67,6 +67,8 @@ const struct mail_command_entry mail_command_table[] = {
67 { "T", "Type", mail_printall, "T[ype] [msglist]" }, 67 { "T", "Type", mail_printall, "T[ype] [msglist]" },
68 { "p", "print", mail_print, "p[rint] [msglist]" }, 68 { "p", "print", mail_print, "p[rint] [msglist]" },
69 { "t", "type", mail_print, "t[ype] [msglist]" }, 69 { "t", "type", mail_print, "t[ype] [msglist]" },
70 { "prev", "previous", mail_previous, "prev[ious] [message]" },
71 { "-", "-", mail_previous, "- [message]" },
70 { "q", "quit", mail_quit, "q[uit]" }, 72 { "q", "quit", mail_quit, "q[uit]" },
71 73
72 /* Hmm... will this work? */ 74 /* Hmm... will this work? */
......
...@@ -24,6 +24,20 @@ ...@@ -24,6 +24,20 @@
24 int 24 int
25 mail_unset (int argc, char **argv) 25 mail_unset (int argc, char **argv)
26 { 26 {
27 printf ("Function not implemented in %s line %d\n", __FILE__, __LINE__); 27 if (argc < 2)
28 return 1;
29 else
30 {
31 int status = 0, i = 1;
32 for (i=1; i < argc; i++)
33 {
34 char *buf = malloc ((6+strlen (argv[i])) * sizeof (char));
35 strcpy (buf, "set no");
36 strcat (buf, argv[i]);
37 if (!util_do_command (buf))
38 status = 1;
39 free (buf);
40 }
41 }
28 return 1; 42 return 1;
29 } 43 }
......
...@@ -85,7 +85,7 @@ util_expand_msglist (const int argc, char **argv, int **list) ...@@ -85,7 +85,7 @@ util_expand_msglist (const int argc, char **argv, int **list)
85 else if (!strcmp (argv[i], "^")) 85 else if (!strcmp (argv[i], "^"))
86 { 86 {
87 /* FIXME: first [un]deleted message */ 87 /* FIXME: first [un]deleted message */
88 current =util_ll_add (current, 1); 88 current = util_ll_add (current, 1);
89 } 89 }
90 else if (!strcmp (argv[i], "$")) 90 else if (!strcmp (argv[i], "$"))
91 { 91 {
...@@ -104,6 +104,27 @@ util_expand_msglist (const int argc, char **argv, int **list) ...@@ -104,6 +104,27 @@ util_expand_msglist (const int argc, char **argv, int **list)
104 { 104 {
105 /* FIXME: all messages with pattern following / in 105 /* FIXME: all messages with pattern following / in
106 the subject line, case insensitive */ 106 the subject line, case insensitive */
107 /* This currently appears to be quit b0rked */
108 message_t msg;
109 header_t hdr;
110 char subj[128];
111 int j = 1, k = 0, l2 = 0;
112 int len = strlen (&argv[i][1]);
113 for (j = 1; j <= total; j++)
114 {
115 mailbox_get_message (mbox, j, &msg);
116 message_get_header (msg, &hdr);
117 header_get_value (hdr, MU_HEADER_SUBJECT, subj, 128, NULL);
118 l2 = strlen (subj);
119 for (k = 0; i < strlen (subj); k++)
120 {
121 if (l2-k >= len && !strncasecmp (&argv[i][1], &subj[k], len))
122 {
123 current = util_ll_add (current, j);
124 k = 128;
125 }
126 }
127 }
107 } 128 }
108 else if (argv[i][0] == ':') 129 else if (argv[i][0] == ':')
109 { 130 {
......
...@@ -34,6 +34,6 @@ pop3_dele (const char *arg) ...@@ -34,6 +34,6 @@ pop3_dele (const char *arg)
34 if (/* FIXME: mailbox_delete (mbox, num) != */ 0) 34 if (/* FIXME: mailbox_delete (mbox, num) != */ 0)
35 return ERR_NO_MESG; 35 return ERR_NO_MESG;
36 36
37 fprintf (ofile, "+OK Message %d marked\r\n", num + 1); 37 fprintf (ofile, "+OK Message %d marked\r\n", num);
38 return OK; 38 return OK;
39 } 39 }
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
22 int 22 int
23 pop3_list (const char *arg) 23 pop3_list (const char *arg)
24 { 24 {
25 int mesg = 0, size = 0; 25 unsigned int mesg = 0, size = 0;
26 message_t msg; 26 message_t msg;
27 27
28 if (state != TRANSACTION) 28 if (state != TRANSACTION)
...@@ -35,24 +35,26 @@ pop3_list (const char *arg) ...@@ -35,24 +35,26 @@ pop3_list (const char *arg)
35 35
36 if (strlen (arg) == 0) 36 if (strlen (arg) == 0)
37 { 37 {
38 int total; 38 unsigned int total;
39 mailbox_messages_count (mbox, &total); 39 mailbox_messages_count (mbox, &total);
40 fprintf (ofile, "+OK\r\n"); 40 fprintf (ofile, "+OK\r\n");
41 for (mesg = 1; mesg <= total; mesg++) 41 for (mesg = 1; mesg <= total; mesg++)
42 { 42 {
43 mailbox_get_message (mbox, &msg, mesg); 43 mailbox_get_message (mbox, mesg, &msg);
44 /* if ! deleted */ 44 if ( /* deleted == 0 */ 1)
45 /* message_get_size (msg, &size); */ 45 {
46 fprintf (ofile, "%d %d\r\n", mesg, size); 46 message_size (msg, &size);
47 fprintf (ofile, "%d %d\r\n", mesg, size);
48 }
47 } 49 }
48 fprintf (ofile, ".\r\n"); 50 fprintf (ofile, ".\r\n");
49 } 51 }
50 else 52 else
51 { 53 {
52 mesg = atoi (arg); 54 mesg = atoi (arg);
53 if (mailbox_get_message (mbox, &msg, mesg) != 0) 55 if (mailbox_get_message (mbox, mesg, &msg) != 0)
54 return ERR_NO_MESG; 56 return ERR_NO_MESG;
55 /* message_get_size (msg, &size); */ 57 message_size (msg, &size);
56 fprintf (ofile, "+OK %d %d\r\n", mesg, size); 58 fprintf (ofile, "+OK %d %d\r\n", mesg, size);
57 } 59 }
58 60
......
...@@ -31,8 +31,7 @@ pop3_stat (const char *arg) ...@@ -31,8 +31,7 @@ pop3_stat (const char *arg)
31 if (state != TRANSACTION) 31 if (state != TRANSACTION)
32 return ERR_WRONG_STATE; 32 return ERR_WRONG_STATE;
33 33
34 /* FIXME: unimplemented! */ 34 mailbox_size (mbox, &size);
35 /* mailbox_size (mbox, &size); */
36 mailbox_messages_count (mbox, &mesgs); 35 mailbox_messages_count (mbox, &mesgs);
37 36
38 fprintf (ofile, "+OK %d %d\r\n", mesgs, (int)size); 37 fprintf (ofile, "+OK %d %d\r\n", mesgs, (int)size);
......