Commit 7096a7d8 7096a7d8ca6bcafc23e037b24bd9bc7a4554ecaf by Jakob Kaivo

Implement mailx pipe command, alphabetize command table, merge relist and reply

1 parent 5f620059
...@@ -8,6 +8,6 @@ mail_LDADD = ../mailbox/libmailbox.la ../lib/libmailutils.a -lreadline ...@@ -8,6 +8,6 @@ mail_LDADD = ../mailbox/libmailbox.la ../lib/libmailutils.a -lreadline
8 mail_SOURCES = alias.c alt.c bang.c cd.c copy.c delete.c discard.c dp.c \ 8 mail_SOURCES = alias.c alt.c bang.c cd.c copy.c delete.c discard.c dp.c \
9 echo.c edit.c eq.c exit.c file.c folders.c followup.c from.c hash.c \ 9 echo.c edit.c eq.c exit.c file.c folders.c followup.c from.c hash.c \
10 headers.c help.c hold.c if.c list.c mail.c mail.h mbox.c next.c pipe.c \ 10 headers.c help.c hold.c if.c list.c mail.c mail.h mbox.c next.c pipe.c \
11 previous.c print.c quit.c relist.c reply.c retain.c save.c \ 11 previous.c print.c quit.c reply.c retain.c save.c \
12 send.c set.c shell.c size.c source.c top.c touch.c unalias.c \ 12 send.c set.c shell.c size.c source.c top.c touch.c unalias.c \
13 undelete.c unset.c util.c visual.c write.c z.c table.c 13 undelete.c unset.c util.c visual.c write.c z.c table.c
......
...@@ -25,9 +25,7 @@ int ...@@ -25,9 +25,7 @@ int
25 mail_delete (int argc, char **argv) 25 mail_delete (int argc, char **argv)
26 { 26 {
27 if (argc > 1) 27 if (argc > 1)
28 { 28 return util_msglist_command (mail_delete, argc, argv);
29 return util_msglist_command (mail_delete, argc, argv);
30 }
31 else if (/* mailbox_delete (mbox, list[cursor]) == */ 0) 29 else if (/* mailbox_delete (mbox, list[cursor]) == */ 0)
32 return 0; 30 return 0;
33 return 1; 31 return 1;
......
...@@ -127,6 +127,8 @@ main (int argc, char **argv) ...@@ -127,6 +127,8 @@ main (int argc, char **argv)
127 cursor = 1; 127 cursor = 1;
128 realcursor = cursor; 128 realcursor = cursor;
129 129
130 signal (SIGPIPE, SIG_IGN);
131
130 /* set defaults for execution */ 132 /* set defaults for execution */
131 util_do_command ("set noallnet"); 133 util_do_command ("set noallnet");
132 util_do_command ("set noappend"); 134 util_do_command ("set noappend");
...@@ -154,7 +156,7 @@ main (int argc, char **argv) ...@@ -154,7 +156,7 @@ main (int argc, char **argv)
154 util_do_command ("set noonehop"); 156 util_do_command ("set noonehop");
155 util_do_command ("set nooutfolder"); 157 util_do_command ("set nooutfolder");
156 util_do_command ("set nopage"); 158 util_do_command ("set nopage");
157 util_do_command ("set prompt=? "); /* FIXME: "set prompt=\"? \"" */ 159 util_do_command ("set prompt=?"); /* FIXME: "set prompt=\"? \"" */
158 util_do_command ("set noquiet"); 160 util_do_command ("set noquiet");
159 util_do_command ("set norecord"); 161 util_do_command ("set norecord");
160 util_do_command ("set save"); 162 util_do_command ("set save");
...@@ -216,7 +218,8 @@ main (int argc, char **argv) ...@@ -216,7 +218,8 @@ main (int argc, char **argv)
216 } 218 }
217 219
218 /* initial commands */ 220 /* initial commands */
219 util_do_command ("from *"); 221 if ((util_find_env("header"))->set)
222 util_do_command ("from *");
220 223
221 prompt = util_find_env ("prompt"); 224 prompt = util_find_env ("prompt");
222 225
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
30 #include <sys/wait.h> 30 #include <sys/wait.h>
31 #include <sys/types.h> 31 #include <sys/types.h>
32 #include <stdarg.h> 32 #include <stdarg.h>
33 #include <signal.h>
33 34
34 #include <argp.h> 35 #include <argp.h>
35 36
......
...@@ -25,6 +25,58 @@ ...@@ -25,6 +25,58 @@
25 int 25 int
26 mail_pipe (int argc, char **argv) 26 mail_pipe (int argc, char **argv)
27 { 27 {
28 printf ("Function not implemented in %s line %d\n", __FILE__, __LINE__); 28 message_t msg;
29 return 1; 29 stream_t stream;
30 char *cmd;
31 FILE *pipe;
32 int *list, num = 0;
33 char buffer[BUFSIZ];
34 off_t off = 0;
35 size_t n = 0;
36
37 if (argc > 1)
38 cmd = argv[--argc];
39 else if ((util_find_env ("cmd"))->set)
40 cmd = (util_find_env ("cmd"))->value;
41 else
42 return 1;
43
44 pipe = popen (cmd, "w");
45 if ((num = util_expand_msglist (argc, argv, &list)) > 0)
46 {
47 int i = 0;
48 for (i = 0; i < num; i++)
49 {
50 if (mailbox_get_message (mbox, list[i], &msg) == 0)
51 {
52 printf ("message %d\n", list[i]);
53 message_get_stream (msg, &stream);
54 off = 0;
55 while (stream_read (stream, buffer, sizeof (buffer) - 1, off,
56 &n) == 0 && n != 0)
57 {
58 buffer[n] = '\0';
59 fprintf (pipe, "%s", buffer);
60 off =+ n;
61 }
62 if ((util_find_env("page"))->set)
63 fprintf (pipe, "\f");
64 }
65 }
66 }
67 else if (mailbox_get_message (mbox, cursor, &msg) == 0)
68 {
69 message_get_stream (msg, &stream);
70 while (stream_read (stream, buffer, sizeof (buffer) - 1, off, &n) == 0
71 && n != 0)
72 {
73 buffer[n] = '\0';
74 fprintf (pipe, "%s", buffer);
75 off += n;
76 }
77 }
78
79 free (list);
80 pclose (pipe);
81 return 0;
30 } 82 }
......
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include "mail.h"
19
20 /*
21 * R[eply] [msglist]
22 * R[espond] [msglist]
23 */
24
25 int
26 mail_relist (int argc, char **argv)
27 {
28 printf ("Function not implemented in %s line %d\n", __FILE__, __LINE__);
29 return 1;
30 }
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
20 /* 20 /*
21 * r[eply] [message] 21 * r[eply] [message]
22 * r[espond] [message] 22 * r[espond] [message]
23 * R[eply] [msglist]
24 * R[espond] [msglist]
23 */ 25 */
24 26
25 int 27 int
......
...@@ -20,85 +20,78 @@ ...@@ -20,85 +20,78 @@
20 const struct mail_command_entry mail_command_table[] = { 20 const struct mail_command_entry mail_command_table[] = {
21 { "a", "alias", mail_alias, 21 { "a", "alias", mail_alias,
22 "a[lias] [alias [address...]]" }, 22 "a[lias] [alias [address...]]" },
23 { "g", "group", mail_alias,
24 "g[roup] [alias [address...]]" },
25 { "alt", "alternates", mail_alt, "alt[ernates] name..." }, 23 { "alt", "alternates", mail_alt, "alt[ernates] name..." },
24 { "C", "Copy", mail_copy, "C[opy] [msglist]" },
26 { "cd", "cd", mail_cd, "cd [directory]" }, 25 { "cd", "cd", mail_cd, "cd [directory]" },
27 { "ch", "chdir", mail_cd, "ch[dir] directory" }, 26 { "ch", "chdir", mail_cd, "ch[dir] directory" },
28 { "c", "copy", mail_copy, 27 { "c", "copy", mail_copy,
29 "c[opy] [file]\nc[opy] [msglist] file" }, 28 "c[opy] [file]\nc[opy] [msglist] file" },
30 { "C", "Copy", mail_copy, "C[opy] [msglist]" },
31 { "d", "delete", mail_delete, "d[elete] [msglist]" }, 29 { "d", "delete", mail_delete, "d[elete] [msglist]" },
32 { "di", "discard", mail_discard, 30 { "di", "discard", mail_discard,
33 "di[scard] [header-field...]" }, 31 "di[scard] [header-field...]" },
34 { "ig", "ignore", mail_discard, "ig[nore] [header-field...]" },
35 { "dp", "dp", mail_dp, "dp [msglist]" }, 32 { "dp", "dp", mail_dp, "dp [msglist]" },
36 { "dt", "dt", mail_dp, "dt [msglist]" }, 33 { "dt", "dt", mail_dp, "dt [msglist]" },
37 { "ec", "echo", mail_echo, "ec[ho] string ..." }, 34 { "ec", "echo", mail_echo, "ec[ho] string ..." },
38 { "e", "edit", mail_edit, "e[dit] [msglist]" }, 35 { "e", "edit", mail_edit, "e[dit] [msglist]" },
36 { "el", "else", mail_if, "el[se]" }, /* FIXME */
37 { "en", "endif", mail_if, "en[dif]" }, /* FIXME */
39 { "ex", "exit", mail_exit, "ex[it]" }, 38 { "ex", "exit", mail_exit, "ex[it]" },
40 { "x", "xit", mail_exit, "x[it]" }, 39 { "F", "Followup", mail_followup, "F[ollowup] [msglist]" },
41 { "fi", "file", mail_file, "fi[le] [file]" }, 40 { "fi", "file", mail_file, "fi[le] [file]" },
42 { "fold", "folder", mail_file, "fold[er] [file]" }, 41 { "fold", "folder", mail_file, "fold[er] [file]" },
43 { "folders", "folders", mail_folders, "folders" }, 42 { "folders", "folders", mail_folders, "folders" },
44 { "fo", "followup", mail_followup, "fo[llowup] [message]" }, 43 { "fo", "followup", mail_followup, "fo[llowup] [message]" },
45 { "F", "Followup", mail_followup, "F[ollowup] [msglist]" },
46 { "f", "from", mail_from, "f[rom] [msglist]" }, 44 { "f", "from", mail_from, "f[rom] [msglist]" },
45 { "g", "group", mail_alias,
46 "g[roup] [alias [address...]]" },
47 { "h", "headers", mail_headers, "h[eaders] [message]" }, 47 { "h", "headers", mail_headers, "h[eaders] [message]" },
48 { "hel", "help", mail_help, "hel[p] [command]" }, 48 { "hel", "help", mail_help, "hel[p] [command]" },
49 { "?", "?", mail_help, "? [command]" },
50 { "ho", "hold", mail_hold, "ho[ld] [msglist]" }, 49 { "ho", "hold", mail_hold, "ho[ld] [msglist]" },
51 { "pre", "preserve", mail_hold, "pre[server] [msglist]" }, 50 { "i", "if", mail_if, "i[f] s|r" }, /* FIXME */
52 51 { "ig", "ignore", mail_discard, "ig[nore] [header-field...]" },
53 /* Should if be handled in the main loop rather than a function? */
54 { "i", "if", mail_if, "i[f] s|r" },
55 { "el", "else", mail_if, "el[se]" },
56 { "en", "endif", mail_if, "en[dif]" },
57
58 { "l", "list", mail_list, "l[ist]" }, 52 { "l", "list", mail_list, "l[ist]" },
59 { "*", "*", mail_list, "*" },
60 { "m", "mail", mail_send, "m[ail] [address...]" }, 53 { "m", "mail", mail_send, "m[ail] [address...]" },
61 { "mb", "mbox", mail_mbox, "mb[ox] [msglist]" }, 54 { "mb", "mbox", mail_mbox, "mb[ox] [msglist]" },
62 { "n", "next", mail_next, "n[ext] [message]" }, 55 { "n", "next", mail_next, "n[ext] [message]" },
63 { "+", "+", mail_next, "+ [message]" },
64 { "pi", "pipe", mail_pipe, "pi[pe] [[msglist] command]" },
65 { "|", "|", mail_pipe, "| [[msglist] command]" },
66 { "P", "Print", mail_print, "P[rint] [msglist]" }, 56 { "P", "Print", mail_print, "P[rint] [msglist]" },
67 { "T", "Type", mail_print, "T[ype] [msglist]" }, 57 { "pi", "pipe", mail_pipe, "pi[pe] [[msglist] command]" },
68 { "p", "print", mail_print, "p[rint] [msglist]" }, 58 { "pre", "preserve", mail_hold, "pre[server] [msglist]" },
69 { "t", "type", mail_print, "t[ype] [msglist]" },
70 { "prev", "previous", mail_previous, "prev[ious] [message]" }, 59 { "prev", "previous", mail_previous, "prev[ious] [message]" },
71 { "-", "-", mail_previous, "- [message]" }, 60 { "p", "print", mail_print, "p[rint] [msglist]" },
72 { "q", "quit", mail_quit, "q[uit]" }, 61 { "q", "quit", mail_quit, "q[uit]" },
73 62 { "R", "Reply", mail_reply, "R[eply] [msglist]" },
74 /* Hmm... will this work? */ 63 { "R", "Respond", mail_reply, "R[espond] [msglist]" },
75 /* { "", "", mail_quit, "<EOF>" }, */
76
77 { "R", "Reply", mail_relist, "R[eply] [msglist]" },
78 { "R", "Respond", mail_relist, "R[espond] [msglist]" },
79 { "r", "reply", mail_reply, "r[eply] [message]" }, 64 { "r", "reply", mail_reply, "r[eply] [message]" },
80 { "r", "respond", mail_reply, "r[espond] [message]" }, 65 { "r", "respond", mail_reply, "r[espond] [message]" },
81 { "ret", "retain", mail_retain, "ret[ain] [header-field]" }, 66 { "ret", "retain", mail_retain, "ret[ain] [header-field]" },
67 { "S", "Save", mail_save, "S[ave] [msglist]" },
82 { "s", "save", mail_save, 68 { "s", "save", mail_save,
83 "s[ave] [file]\ns[ave] [msglist] file" }, 69 "s[ave] [file]\ns[ave] [msglist] file" },
84 { "S", "Save", mail_save, "S[ave] [msglist]" },
85 { "se", "set", mail_set, 70 { "se", "set", mail_set,
86 "se[t] [name[=[string]]...] [name=number...] [noname...]" }, 71 "se[t] [name[=[string]]...] [name=number...] [noname...]" },
87 { "sh", "shell", mail_shell, "sh[ell]" }, 72 { "sh", "shell", mail_shell, "sh[ell]" },
88 { "si", "size", mail_size, "si[ze] [msglist]" }, 73 { "si", "size", mail_size, "si[ze] [msglist]" },
89 { "so", "source", mail_source, "so[urce] file" }, 74 { "so", "source", mail_source, "so[urce] file" },
75 { "T", "Type", mail_print, "T[ype] [msglist]" },
90 { "to", "top", mail_top, "to[p] [msglist]" }, 76 { "to", "top", mail_top, "to[p] [msglist]" },
91 { "tou", "touch", mail_touch, "tou[ch] [msglist]" }, 77 { "tou", "touch", mail_touch, "tou[ch] [msglist]" },
78 { "t", "type", mail_print, "t[ype] [msglist]" },
92 { "una", "unalias", mail_unalias, "una[lias] [alias]..." }, 79 { "una", "unalias", mail_unalias, "una[lias] [alias]..." },
93 { "u", "undelete", mail_undelete, "u[ndelete] [msglist]" }, 80 { "u", "undelete", mail_undelete, "u[ndelete] [msglist]" },
94 { "uns", "unset", mail_unset, "uns[et] name..." }, 81 { "uns", "unset", mail_unset, "uns[et] name..." },
95 { "v", "visual", mail_visual, "v[isual] [msglist]" }, 82 { "v", "visual", mail_visual, "v[isual] [msglist]" },
83 { "W", "Write", mail_write, "W[rite] [msglist]" },
96 { "w", "write", mail_write, 84 { "w", "write", mail_write,
97 "w[rite] [file]\nw[rite] [msglist] file" }, 85 "w[rite] [file]\nw[rite] [msglist] file" },
98 { "W", "Write", mail_write, "W[rite] [msglist]" }, 86 { "x", "xit", mail_exit, "x[it]" },
99 { "z", "", mail_z, "z[+|-]" }, 87 { "z", "", mail_z, "z[+|-]" },
88 { "?", "?", mail_help, "? [command]" },
100 { "!", "", mail_bang, "!command" }, 89 { "!", "", mail_bang, "!command" },
101 { "=", "=", mail_eq, "=" }, 90 { "=", "=", mail_eq, "=" },
102 { "#", "#", NULL, "# comment" }, 91 { "#", "#", NULL, "# comment" },
92 { "*", "*", mail_list, "*" },
93 { "+", "+", mail_next, "+ [message]" },
94 { "|", "|", mail_pipe, "| [[msglist] command]" },
95 { "-", "-", mail_previous, "- [message]" },
103 { 0, 0, 0, 0,} 96 { 0, 0, 0, 0,}
104 }; 97 };
......