Commit 2b656925 2b656925f6cdddbf0a9c901bd525a3d2965bc723 by Sergey Poznyakoff

Use msgset_parse instead of util_expand_msglist().

1 parent 3d8deee3
...@@ -34,8 +34,7 @@ mail_copy0 (int argc, char **argv, int mark) ...@@ -34,8 +34,7 @@ mail_copy0 (int argc, char **argv, int mark)
34 message_t msg; 34 message_t msg;
35 mailbox_t mbx; 35 mailbox_t mbx;
36 char *filename = NULL; 36 char *filename = NULL;
37 int *msglist = NULL; 37 msgset_t *msglist = NULL, *mp;
38 int num = 0, i = 0;
39 int sender = 0; 38 int sender = 0;
40 size_t total_size = 0, total_lines = 0, size; 39 size_t total_size = 0, total_lines = 0, size;
41 40
...@@ -46,13 +45,19 @@ mail_copy0 (int argc, char **argv, int mark) ...@@ -46,13 +45,19 @@ mail_copy0 (int argc, char **argv, int mark)
46 else 45 else
47 filename = strdup("mbox"); 46 filename = strdup("mbox");
48 47
49 num = util_expand_msglist (argc, argv, &msglist); 48 if (msgset_parse (argc, argv, &msglist))
49 {
50 if (filename)
51 free (filename);
52 return 1;
53 }
54
50 if (sender) 55 if (sender)
51 { 56 {
52 filename = util_get_sender(msglist[0], 1); 57 filename = util_get_sender(msglist->msg_part[0], 1);
53 if (!filename) 58 if (!filename)
54 { 59 {
55 free (msglist); 60 msgset_free (msglist);
56 return 1; 61 return 1;
57 } 62 }
58 } 63 }
...@@ -62,13 +67,13 @@ mail_copy0 (int argc, char **argv, int mark) ...@@ -62,13 +67,13 @@ mail_copy0 (int argc, char **argv, int mark)
62 { 67 {
63 util_error ("can't create mailbox %s", filename); 68 util_error ("can't create mailbox %s", filename);
64 free (filename); 69 free (filename);
65 free (msglist); 70 msgset_free (msglist);
66 return 1; 71 return 1;
67 } 72 }
68 73
69 for (i = 0; i < num; i++) 74 for (mp = msglist; mp; mp = mp->next)
70 { 75 {
71 mailbox_get_message (mbox, msglist[i], &msg); 76 mailbox_get_message (mbox, mp->msg_part[0], &msg);
72 mailbox_append_message (mbx, msg); 77 mailbox_append_message (mbx, msg);
73 78
74 message_size (msg, &size); 79 message_size (msg, &size);
...@@ -90,7 +95,7 @@ mail_copy0 (int argc, char **argv, int mark) ...@@ -90,7 +95,7 @@ mail_copy0 (int argc, char **argv, int mark)
90 mailbox_destroy (&mbx); 95 mailbox_destroy (&mbx);
91 96
92 free (filename); 97 free (filename);
93 free (msglist); 98 msgset_free (msglist);
94 return 0; 99 return 0;
95 } 100 }
96 101
......
...@@ -28,18 +28,20 @@ mail_followup (int argc, char **argv) ...@@ -28,18 +28,20 @@ mail_followup (int argc, char **argv)
28 message_t msg; 28 message_t msg;
29 header_t hdr; 29 header_t hdr;
30 char *str; 30 char *str;
31 int i, num, *msglist; 31 int i;
32 msgset_t *msglist, *mp;
32 struct send_environ env; 33 struct send_environ env;
33 int status; 34 int status;
34 35
35 env.to = env.cc = env.bcc = env.subj = NULL; 36 env.to = env.cc = env.bcc = env.subj = NULL;
36 env.outfiles = NULL; env.nfiles = 0; 37 env.outfiles = NULL; env.nfiles = 0;
37 num = util_expand_msglist (argc, argv, &msglist); 38 if (msgset_parse (argc, argv, &msglist))
39 return 1;
38 40
39 if (mailbox_get_message(mbox, cursor, &msg)) 41 if (mailbox_get_message(mbox, cursor, &msg))
40 { 42 {
41 util_error("%d: can't get message", cursor); 43 util_error("%d: can't get message", cursor);
42 free(msglist); 44 msgset_free (msglist);
43 return 1; 45 return 1;
44 } 46 }
45 47
...@@ -55,13 +57,13 @@ mail_followup (int argc, char **argv) ...@@ -55,13 +57,13 @@ mail_followup (int argc, char **argv)
55 57
56 /* Add authors of the subsequent messages to the to list 58 /* Add authors of the subsequent messages to the to list
57 (or should it be cc?)*/ 59 (or should it be cc?)*/
58 for (i = 1; i < num; i++) 60 for (mp = msglist; mp; mp = mp->next)
59 { 61 {
60 util_strcat(&env.to, ","); 62 util_strcat(&env.to, ",");
61 util_strcat(&env.to, util_get_sender(msglist[i], 0)); 63 util_strcat(&env.to, util_get_sender(mp->msg_part[0], 0));
62 } 64 }
63 65
64 free(msglist); 66 msgset_free(msglist);
65 67
66 fprintf(ofile, "To: %s\n", env.to); 68 fprintf(ofile, "To: %s\n", env.to);
67 fprintf(ofile, "Subject: %s\n\n", env.subj); 69 fprintf(ofile, "Subject: %s\n\n", env.subj);
......
...@@ -29,9 +29,17 @@ ...@@ -29,9 +29,17 @@
29 int 29 int
30 mail_headers (int argc, char **argv) 30 mail_headers (int argc, char **argv)
31 { 31 {
32 int low = 1, high = total, *list = NULL; 32 int low = 1, high = total;
33 msgset_t *list = NULL, *mp;
33 int lines = util_screen_lines (); 34 int lines = util_screen_lines ();
34 int num = util_expand_msglist (argc, argv, &list); 35 int num;
36
37 if (msgset_parse (argc, argv, &list))
38 return 1;
39
40 num = 0;
41 for (mp = list; mp; mp = mp->next)
42 num++;
35 43
36 lines = (lines / num) - 2; 44 lines = (lines / num) - 2;
37 if (lines < 0) 45 if (lines < 0)
...@@ -39,7 +47,7 @@ mail_headers (int argc, char **argv) ...@@ -39,7 +47,7 @@ mail_headers (int argc, char **argv)
39 47
40 if (lines < total) 48 if (lines < total)
41 { 49 {
42 low = list[0] - (lines / 2); 50 low = list->msg_part[0] - (lines / 2);
43 if (low < 1) 51 if (low < 1)
44 low = 1; 52 low = 1;
45 high = low + lines; 53 high = low + lines;
...@@ -52,6 +60,6 @@ mail_headers (int argc, char **argv) ...@@ -52,6 +60,6 @@ mail_headers (int argc, char **argv)
52 60
53 util_do_command ("from %d-%d", low, high); 61 util_do_command ("from %d-%d", low, high);
54 62
55 free (list); 63 msgset_free (list);
56 return 0; 64 return 0;
57 } 65 }
......
...@@ -33,11 +33,11 @@ mail_next (int argc, char **argv) ...@@ -33,11 +33,11 @@ mail_next (int argc, char **argv)
33 } 33 }
34 else 34 else
35 { 35 {
36 int *list = NULL; 36 msgset_t *list = NULL;
37 util_expand_msglist (argc, argv, &list); 37 msgset_parse (argc, argv, &list);
38 cursor = list[0]; 38 cursor = list->msg_part[0];
39 realcursor = cursor; 39 realcursor = cursor;
40 free (list); 40 msgset_free (list);
41 return 0; 41 return 0;
42 } 42 }
43 return 1; 43 return 1;
......
...@@ -29,11 +29,10 @@ mail_pipe (int argc, char **argv) ...@@ -29,11 +29,10 @@ mail_pipe (int argc, char **argv)
29 stream_t stream; 29 stream_t stream;
30 char *cmd; 30 char *cmd;
31 FILE *pipe; 31 FILE *pipe;
32 int *list, num = 0; 32 msgset_t *list, *mp;
33 char buffer[512]; 33 char buffer[512];
34 off_t off = 0; 34 off_t off = 0;
35 size_t n = 0; 35 size_t n = 0;
36 int i;
37 36
38 if (argc > 1) 37 if (argc > 1)
39 cmd = argv[--argc]; 38 cmd = argv[--argc];
...@@ -42,12 +41,14 @@ mail_pipe (int argc, char **argv) ...@@ -42,12 +41,14 @@ mail_pipe (int argc, char **argv)
42 else 41 else
43 return 1; 42 return 1;
44 43
44 if (msgset_parse (argc, argv, &list))
45 return 1;
46
45 pipe = popen (cmd, "w"); 47 pipe = popen (cmd, "w");
46 num = util_expand_msglist (argc, argv, &list);
47 48
48 for (i = 0; i < num; i++) 49 for (mp = list; mp; mp = mp->next)
49 { 50 {
50 if (mailbox_get_message (mbox, list[i], &msg) == 0) 51 if (mailbox_get_message (mbox, mp->msg_part[0], &msg) == 0)
51 { 52 {
52 message_get_stream (msg, &stream); 53 message_get_stream (msg, &stream);
53 off = 0; 54 off = 0;
...@@ -58,12 +59,12 @@ mail_pipe (int argc, char **argv) ...@@ -58,12 +59,12 @@ mail_pipe (int argc, char **argv)
58 fprintf (pipe, "%s", buffer); 59 fprintf (pipe, "%s", buffer);
59 off += n; 60 off += n;
60 } 61 }
61 if ((util_find_env("page"))->set && i < num - 1) 62 if ((util_find_env("page"))->set && mp->next)
62 fprintf (pipe, "\f\n"); 63 fprintf (pipe, "\f\n");
63 } 64 }
64 } 65 }
65 66
66 free (list); 67 msgset_free (list);
67 pclose (pipe); 68 pclose (pipe);
68 return 0; 69 return 0;
69 } 70 }
......
...@@ -33,11 +33,12 @@ mail_previous (int argc, char **argv) ...@@ -33,11 +33,12 @@ mail_previous (int argc, char **argv)
33 } 33 }
34 else 34 else
35 { 35 {
36 int *list = NULL; 36 msgset_t *list = NULL;
37 util_expand_msglist (argc, argv, &list); 37 if (msgset_parse (argc, argv, &list))
38 cursor = list[0]; 38 return 1;
39 cursor = list->msg_part[0];
39 realcursor = cursor; 40 realcursor = cursor;
40 free (list); 41 msgset_free (list);
41 return 0; 42 return 0;
42 } 43 }
43 return 1; 44 return 1;
......
...@@ -34,8 +34,7 @@ mail_write (int argc, char **argv) ...@@ -34,8 +34,7 @@ mail_write (int argc, char **argv)
34 char buffer[512]; 34 char buffer[512];
35 off_t off = 0; 35 off_t off = 0;
36 size_t n = 0; 36 size_t n = 0;
37 int *msglist = NULL; 37 msgset_t *msglist = NULL, *mp;
38 int num = 0, i = 0;
39 int sender = 0; 38 int sender = 0;
40 size_t total_size = 0, total_lines = 0, size; 39 size_t total_size = 0, total_lines = 0, size;
41 40
...@@ -48,14 +47,19 @@ mail_write (int argc, char **argv) ...@@ -48,14 +47,19 @@ mail_write (int argc, char **argv)
48 else 47 else
49 filename = strdup ("mbox"); 48 filename = strdup ("mbox");
50 49
51 num = util_expand_msglist (argc, argv, &msglist); 50 if (msgset_parse (argc, argv, &msglist))
51 {
52 if (filename)
53 free (filename);
54 return 1;
55 }
52 56
53 if (sender) 57 if (sender)
54 { 58 {
55 filename = util_get_sender(msglist[0], 1); 59 filename = util_get_sender(msglist->msg_part[0], 1);
56 if (!filename) 60 if (!filename)
57 { 61 {
58 free (msglist); 62 msgset_free (msglist);
59 return 1; 63 return 1;
60 } 64 }
61 } 65 }
...@@ -66,15 +70,15 @@ mail_write (int argc, char **argv) ...@@ -66,15 +70,15 @@ mail_write (int argc, char **argv)
66 util_error("can't open %s: %s", filename, strerror (errno)); 70 util_error("can't open %s: %s", filename, strerror (errno));
67 free (filename); 71 free (filename);
68 fclose (output); 72 fclose (output);
69 free (msglist); 73 msgset_free (msglist);
70 return 1; 74 return 1;
71 } 75 }
72 76
73 for (i = 0; i < num; i++) 77 for (mp = msglist; mp; mp = mp->next)
74 { 78 {
75 attribute_t attr; 79 attribute_t attr;
76 80
77 mailbox_get_message (mbox, msglist[i], &msg); 81 mailbox_get_message (mbox, mp->msg_part[0], &msg);
78 message_get_body (msg, &bod); 82 message_get_body (msg, &bod);
79 83
80 body_size (bod, &size); 84 body_size (bod, &size);
...@@ -102,6 +106,6 @@ mail_write (int argc, char **argv) ...@@ -102,6 +106,6 @@ mail_write (int argc, char **argv)
102 106
103 free (filename); 107 free (filename);
104 fclose (output); 108 fclose (output);
105 free (msglist); 109 msgset_free (msglist);
106 return 0; 110 return 0;
107 } 111 }
......