Changed initialization of format_str. Removed scan_folder: use current_folder
instead. Implemented -form and -header options. Use \f to clear screen if stdout is not a tty.
Showing
1 changed file
with
35 additions
and
46 deletions
... | @@ -21,6 +21,9 @@ | ... | @@ -21,6 +21,9 @@ |
21 | #ifdef HAVE_TERMCAP_H | 21 | #ifdef HAVE_TERMCAP_H |
22 | # include <termcap.h> | 22 | # include <termcap.h> |
23 | #endif | 23 | #endif |
24 | #include <sys/types.h> | ||
25 | #include <sys/stat.h> | ||
26 | #include <time.h> | ||
24 | 27 | ||
25 | const char *argp_program_version = "scan (" PACKAGE ") " VERSION; | 28 | const char *argp_program_version = "scan (" PACKAGE ") " VERSION; |
26 | const char *argp_program_bug_address = "<bug-mailutils@gnu.org>"; | 29 | const char *argp_program_bug_address = "<bug-mailutils@gnu.org>"; |
... | @@ -57,19 +60,12 @@ struct mh_option mh_option[] = { | ... | @@ -57,19 +60,12 @@ struct mh_option mh_option[] = { |
57 | { 0 } | 60 | { 0 } |
58 | }; | 61 | }; |
59 | 62 | ||
60 | static char *scan_folder = "inbox"; | ||
61 | static int clear; | 63 | static int clear; |
62 | static char *formfile; | 64 | static char *format_str = mh_list_format; |
63 | static char *format_str = | ||
64 | "%4(msg)%<(cur)+%| %>%<{replied}-%?{encrypted}E%| %>" | ||
65 | "%02(mon{date})/%02(mday{date})" | ||
66 | "%<{date} %|*%>" | ||
67 | "%<(mymbox{from})%<{to}To:%14(friendly{to})%>%>" | ||
68 | "%<(zero)%17(friendly{from})%>" | ||
69 | " %{subject}%<{body}<<%{body}>>%>"; | ||
70 | 65 | ||
71 | static int width = 80; | 66 | static int width = 80; |
72 | static int reverse; | 67 | static int reverse; |
68 | static int header; | ||
73 | 69 | ||
74 | static mh_format_t format; | 70 | static mh_format_t format; |
75 | 71 | ||
... | @@ -82,7 +78,7 @@ opt_handler (int key, char *arg, void *unused) | ... | @@ -82,7 +78,7 @@ opt_handler (int key, char *arg, void *unused) |
82 | switch (key) | 78 | switch (key) |
83 | { | 79 | { |
84 | case 'f': | 80 | case 'f': |
85 | scan_folder = arg; | 81 | current_folder = arg; |
86 | break; | 82 | break; |
87 | 83 | ||
88 | case 'c': | 84 | case 'c': |
... | @@ -90,7 +86,7 @@ opt_handler (int key, char *arg, void *unused) | ... | @@ -90,7 +86,7 @@ opt_handler (int key, char *arg, void *unused) |
90 | break; | 86 | break; |
91 | 87 | ||
92 | case 'F': | 88 | case 'F': |
93 | formfile = arg; | 89 | format_str = mh_read_formfile (arg); |
94 | break; | 90 | break; |
95 | 91 | ||
96 | case 't': | 92 | case 't': |
... | @@ -98,7 +94,7 @@ opt_handler (int key, char *arg, void *unused) | ... | @@ -98,7 +94,7 @@ opt_handler (int key, char *arg, void *unused) |
98 | break; | 94 | break; |
99 | 95 | ||
100 | case 'H': | 96 | case 'H': |
101 | clear = arg[0] == 'y'; | 97 | header = arg[0] == 'y'; |
102 | break; | 98 | break; |
103 | 99 | ||
104 | case 'w': | 100 | case 'w': |
... | @@ -128,54 +124,31 @@ opt_handler (int key, char *arg, void *unused) | ... | @@ -128,54 +124,31 @@ opt_handler (int key, char *arg, void *unused) |
128 | return 0; | 124 | return 0; |
129 | } | 125 | } |
130 | 126 | ||
131 | void | ||
132 | set_folder () | ||
133 | { | ||
134 | scan_folder = mu_tilde_expansion (scan_folder, "/", NULL); | ||
135 | if (strchr (scan_folder, '/') == NULL) | ||
136 | { | ||
137 | char *p = mu_get_homedir (); | ||
138 | asprintf (&scan_folder, "mh:%s/Mail/%s", p, scan_folder); | ||
139 | if (!scan_folder) | ||
140 | { | ||
141 | mh_error ("low memory"); | ||
142 | exit (1); | ||
143 | } | ||
144 | } | ||
145 | else if (strchr (scan_folder, ':') == NULL) | ||
146 | { | ||
147 | char *p; | ||
148 | p = xmalloc (strlen (scan_folder) + 4); | ||
149 | strcat (strcpy (p, "mh:"), scan_folder); | ||
150 | scan_folder = p; | ||
151 | } | ||
152 | } | ||
153 | 127 | ||
154 | int | 128 | int |
155 | main (int argc, char **argv) | 129 | main (int argc, char **argv) |
156 | { | 130 | { |
157 | mailbox_t mbox = NULL; | 131 | mailbox_t mbox = NULL; |
158 | 132 | ||
159 | mh_init (); | ||
160 | mh_argp_parse (argc, argv, options, mh_option, args_doc, doc, | 133 | mh_argp_parse (argc, argv, options, mh_option, args_doc, doc, |
161 | opt_handler, NULL); | 134 | opt_handler, NULL); |
135 | mh_init (); | ||
162 | 136 | ||
163 | set_folder (); | ||
164 | if (mh_format_parse (format_str, &format)) | 137 | if (mh_format_parse (format_str, &format)) |
165 | { | 138 | { |
166 | mh_error ("Bad format string"); | 139 | mh_error ("Bad format string"); |
167 | exit (1); | 140 | exit (1); |
168 | } | 141 | } |
169 | 142 | ||
170 | if (mailbox_create_default (&mbox, scan_folder)) | 143 | if (mailbox_create_default (&mbox, current_folder)) |
171 | { | 144 | { |
172 | mh_error ("Can't create mailbox %s: %s", scan_folder, strerror (errno)); | 145 | mh_error ("Can't create mailbox %s: %s", current_folder, strerror (errno)); |
173 | exit (1); | 146 | exit (1); |
174 | } | 147 | } |
175 | 148 | ||
176 | if (mailbox_open (mbox, MU_STREAM_READ)) | 149 | if (mailbox_open (mbox, MU_STREAM_READ)) |
177 | { | 150 | { |
178 | mh_error ("Can't open mailbox %s: %s", scan_folder, strerror (errno)); | 151 | mh_error ("Can't open mailbox %s: %s", current_folder, strerror (errno)); |
179 | exit (1); | 152 | exit (1); |
180 | } | 153 | } |
181 | 154 | ||
... | @@ -194,29 +167,33 @@ putstdout(char c) | ... | @@ -194,29 +167,33 @@ putstdout(char c) |
194 | void | 167 | void |
195 | clear_screen () | 168 | clear_screen () |
196 | { | 169 | { |
197 | #ifdef HAVE_TERMCAP_H | ||
198 | if (clear) | 170 | if (clear) |
199 | { | 171 | { |
172 | #ifdef HAVE_TERMCAP_H | ||
173 | if (isatty (1)) | ||
174 | { | ||
200 | char termcap_buf[1024]; | 175 | char termcap_buf[1024]; |
201 | char *buffer; | 176 | char *buffer = termcap_buf; |
202 | char *termname; | 177 | char *termname; |
203 | 178 | ||
204 | if ((termname = getenv("TERM")) == NULL) | 179 | if ((termname = getenv("TERM")) == NULL) |
205 | /* No terminal; Try ansi */ | 180 | /* No terminal; Try ansi */ |
206 | termname = "ansi"; | 181 | termname = "ansi"; |
207 | 182 | ||
208 | if (tgetent(termcap_buf, termname) != 1) | 183 | if (tgetent(termcap_buf, termname) == 1) |
209 | fprintf (stdout, "\f"); | ||
210 | else | ||
211 | { | 184 | { |
212 | char *clr = tgetstr ("cl", &buffer); | 185 | char *clr = tgetstr ("cl", &buffer); |
213 | if (clr) | 186 | if (clr) |
187 | { | ||
214 | tputs(clr, 1, (int (*)())putstdout); | 188 | tputs(clr, 1, (int (*)())putstdout); |
215 | else | 189 | return; |
216 | fprintf (stdout, "\f"); | 190 | } |
217 | } | 191 | } |
218 | } | 192 | } |
219 | #endif | 193 | #endif |
194 | /* Fall back to formfeed */ | ||
195 | fprintf (stdout, "\f"); | ||
196 | } | ||
220 | } | 197 | } |
221 | 198 | ||
222 | int | 199 | int |
... | @@ -227,6 +204,18 @@ scan (mailbox_t mbox) | ... | @@ -227,6 +204,18 @@ scan (mailbox_t mbox) |
227 | 204 | ||
228 | buffer = xmalloc (width); | 205 | buffer = xmalloc (width); |
229 | 206 | ||
207 | if (header) | ||
208 | { | ||
209 | url_t url = NULL; | ||
210 | char datestr[64]; | ||
211 | time_t t; | ||
212 | |||
213 | mailbox_get_url (mbox, &url); | ||
214 | time (&t); | ||
215 | strftime (datestr, sizeof datestr, "%c", localtime (&t)); | ||
216 | printf ("Folder %s %s\n", url_to_string (url), datestr); | ||
217 | } | ||
218 | |||
230 | mailbox_messages_count (mbox, &total); | 219 | mailbox_messages_count (mbox, &total); |
231 | 220 | ||
232 | if (reverse) | 221 | if (reverse) | ... | ... |
-
Please register or sign in to post a comment