Commit f88a8d05 f88a8d059027ab10e2b6f0bd0f59764a6947474c by Sergey Poznyakoff

frm,messages,readmsg: Use MU streams instead of stdio.

* frm/common.c: Use MU streams instead of stdio.
* frm/frm.c: Likewise.
* messages/messages.c: Likewise.
* readmsg/readmsg.c: Likewise.
* frm/frm.h: Include mailutils/stdstream.h
* readmsg/readmsg.h: Likewise.
1 parent 1f44f1ad
...@@ -127,7 +127,7 @@ puts_bidi (char *string) ...@@ -127,7 +127,7 @@ puts_bidi (char *string)
127 } 127 }
128 128
129 if (fb_charset_num == 0) 129 if (fb_charset_num == 0)
130 puts (string); 130 mu_printf ("%s\n", string);
131 else 131 else
132 { 132 {
133 FriBidiStrIndex len; 133 FriBidiStrIndex len;
...@@ -186,20 +186,20 @@ puts_bidi (char *string) ...@@ -186,20 +186,20 @@ puts_bidi (char *string)
186 new_len = fribidi_unicode_to_charset (fb_charset_num, 186 new_len = fribidi_unicode_to_charset (fb_charset_num,
187 visual + st, inlen, 187 visual + st, inlen,
188 outstring); 188 outstring);
189 printf ("%s", outstring); 189 mu_printf ("%s", outstring);
190 } 190 }
191 putchar ('\n'); 191 mu_printf ("\n");
192 } 192 }
193 else 193 else
194 { 194 {
195 /* Print the string as is */ 195 /* Print the string as is */
196 puts (string); 196 mu_printf ("%s\n", string);
197 } 197 }
198 } 198 }
199 } 199 }
200 #else 200 #else
201 # define alloc_logical(s) 201 # define alloc_logical(s)
202 # define puts_bidi puts 202 # define puts_bidi(s) mu_stream_printf ("%s\n", s)
203 #endif 203 #endif
204 204
205 205
...@@ -236,7 +236,7 @@ print_line () ...@@ -236,7 +236,7 @@ print_line ()
236 curcol = nextstart = 0; 236 curcol = nextstart = 0;
237 } 237 }
238 else 238 else
239 putchar ('\n'); 239 mu_printf ("\n");
240 curfield = 0; 240 curfield = 0;
241 } 241 }
242 242
...@@ -245,9 +245,9 @@ format_field_simple (const char *fmt, ...) ...@@ -245,9 +245,9 @@ format_field_simple (const char *fmt, ...)
245 { 245 {
246 va_list ap; 246 va_list ap;
247 if (curfield++) 247 if (curfield++)
248 putchar ('\t'); 248 mu_printf ("\t");
249 va_start (ap, fmt); 249 va_start (ap, fmt);
250 vprintf (fmt, ap); 250 mu_stream_vprintf (mu_strout, fmt, ap);
251 va_end (ap); 251 va_end (ap);
252 } 252 }
253 253
...@@ -266,7 +266,7 @@ format_field_align (const char *fmt, ...) ...@@ -266,7 +266,7 @@ format_field_align (const char *fmt, ...)
266 { 266 {
267 puts_bidi (linebuf); 267 puts_bidi (linebuf);
268 linepos = 0; 268 linepos = 0;
269 printf ("%*s", nextstart, ""); 269 mu_printf ("%*s", nextstart, "");
270 } 270 }
271 else 271 else
272 { 272 {
...@@ -526,7 +526,7 @@ frm_abort (mu_mailbox_t *mbox) ...@@ -526,7 +526,7 @@ frm_abort (mu_mailbox_t *mbox)
526 (mu_message_t). It returns non-zero if that message is to be displayed 526 (mu_message_t). It returns non-zero if that message is to be displayed
527 and zero otherwise. 527 and zero otherwise.
528 528
529 Upon finishing scanning, the function places the overall number of 529 Upon finishing scanning, the function places total number of
530 the messages processed into the memory location pointed to by 530 the messages processed into the memory location pointed to by
531 TOTAL */ 531 TOTAL */
532 void 532 void
......
...@@ -266,16 +266,16 @@ frm (char *mailbox_name) ...@@ -266,16 +266,16 @@ frm (char *mailbox_name)
266 if (show_summary) 266 if (show_summary)
267 { 267 {
268 if (total == 0) 268 if (total == 0)
269 printf (_("Folder contains no messages.")); 269 mu_printf (_("Folder contains no messages."));
270 else 270 else
271 { 271 {
272 char *delim = ""; 272 char *delim = "";
273 273
274 printf (_("Folder contains ")); 274 mu_printf (_("Folder contains "));
275 275
276 if (counter.new) 276 if (counter.new)
277 { 277 {
278 printf (ngettext ("%lu new message", 278 mu_printf (ngettext ("%lu new message",
279 "%lu new messages", 279 "%lu new messages",
280 counter.new), 280 counter.new),
281 (u_long) counter.new); 281 (u_long) counter.new);
...@@ -284,9 +284,9 @@ frm (char *mailbox_name) ...@@ -284,9 +284,9 @@ frm (char *mailbox_name)
284 284
285 if (counter.unread) 285 if (counter.unread)
286 { 286 {
287 printf ("%s", delim); 287 mu_printf ("%s", delim);
288 288
289 printf (ngettext ("%lu unread message", 289 mu_printf (ngettext ("%lu unread message",
290 "%lu unread messages", 290 "%lu unread messages",
291 counter.unread), 291 counter.unread),
292 (u_long) counter.unread); 292 (u_long) counter.unread);
...@@ -295,9 +295,9 @@ frm (char *mailbox_name) ...@@ -295,9 +295,9 @@ frm (char *mailbox_name)
295 295
296 if (counter.read) 296 if (counter.read)
297 { 297 {
298 printf ("%s", delim); 298 mu_printf ("%s", delim);
299 299
300 printf (ngettext ("%lu read message", 300 mu_printf (ngettext ("%lu read message",
301 "%lu read messages", 301 "%lu read messages",
302 counter.read), 302 counter.read),
303 (u_long) counter.read); 303 (u_long) counter.read);
...@@ -309,16 +309,16 @@ frm (char *mailbox_name) ...@@ -309,16 +309,16 @@ frm (char *mailbox_name)
309 Leave it as it is unless your language requires to reorder 309 Leave it as it is unless your language requires to reorder
310 the parts of speach in the message 310 the parts of speach in the message
311 */ 311 */
312 printf (_(".")); 312 mu_printf (_("."));
313 } 313 }
314 printf ("\n"); 314 mu_printf ("\n");
315 } 315 }
316 else if (show_query) 316 else if (show_query)
317 { 317 {
318 if (total > 0) 318 if (total > 0)
319 printf (_("There are messages in that folder.\n")); 319 mu_printf (_("There are messages in that folder.\n"));
320 else 320 else
321 printf (_("No messages in that folder!\n")); 321 mu_printf (_("No messages in that folder!\n"));
322 } 322 }
323 323
324 /* EXIT STATUS 324 /* EXIT STATUS
...@@ -366,7 +366,7 @@ main (int argc, char **argv) ...@@ -366,7 +366,7 @@ main (int argc, char **argv)
366 else 366 else
367 for (; c < argc; c++) 367 for (; c < argc; c++)
368 { 368 {
369 printf ("%s:\n", argv[c]); 369 mu_printf ("%s:\n", argv[c]);
370 status = frm (argv[c]); 370 status = frm (argv[c]);
371 } 371 }
372 372
......
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
55 #include <mailutils/observer.h> 55 #include <mailutils/observer.h>
56 #include <mailutils/registrar.h> 56 #include <mailutils/registrar.h>
57 #include <mailutils/stream.h> 57 #include <mailutils/stream.h>
58 #include <mailutils/stdstream.h>
58 #include <mailutils/url.h> 59 #include <mailutils/url.h>
59 #include <mailutils/nls.h> 60 #include <mailutils/nls.h>
60 #include <mailutils/tls.h> 61 #include <mailutils/tls.h>
......
...@@ -144,7 +144,7 @@ main (int argc, char **argv) ...@@ -144,7 +144,7 @@ main (int argc, char **argv)
144 144
145 if (count_only) 145 if (count_only)
146 { 146 {
147 printf (ngettext ("There is %lu message in your incoming mailbox.\n", 147 mu_printf (ngettext ("There is %lu message in your incoming mailbox.\n",
148 "There are %lu messages in your incoming mailbox.\n", 148 "There are %lu messages in your incoming mailbox.\n",
149 total), 149 total),
150 (unsigned long) total); 150 (unsigned long) total);
......
...@@ -166,9 +166,10 @@ messages_count (const char *box) ...@@ -166,9 +166,10 @@ messages_count (const char *box)
166 } 166 }
167 167
168 if (silent) 168 if (silent)
169 printf ("%lu\n", (unsigned long) count); 169 mu_printf ("%lu\n", (unsigned long) count);
170 else 170 else
171 printf (_("Number of messages in %s: %lu\n"), box, (unsigned long) count); 171 mu_printf (_("Number of messages in %s: %lu\n"), box,
172 (unsigned long) count);
172 173
173 status = mu_mailbox_close (mbox); 174 status = mu_mailbox_close (mbox);
174 if (status != 0) 175 if (status != 0)
......
...@@ -175,7 +175,7 @@ print_unix_header (mu_message_t message) ...@@ -175,7 +175,7 @@ print_unix_header (mu_message_t message)
175 175
176 if (mu_envelope_sget_sender (envelope, &buf)) 176 if (mu_envelope_sget_sender (envelope, &buf))
177 buf = "UNKNOWN"; 177 buf = "UNKNOWN";
178 printf ("From %s ", buf); 178 mu_printf ("From %s ", buf);
179 179
180 if (mu_envelope_sget_date (envelope, &buf)) 180 if (mu_envelope_sget_date (envelope, &buf))
181 { 181 {
...@@ -189,10 +189,10 @@ print_unix_header (mu_message_t message) ...@@ -189,10 +189,10 @@ print_unix_header (mu_message_t message)
189 buf = datebuf; 189 buf = datebuf;
190 } 190 }
191 191
192 printf ("%s", buf); 192 mu_printf ("%s", buf);
193 size = strlen (buf); 193 size = strlen (buf);
194 if (size > 1 && buf[size-1] != '\n') 194 if (size > 1 && buf[size-1] != '\n')
195 putchar ('\n'); 195 mu_printf ("\n");
196 } 196 }
197 197
198 static void 198 static void
...@@ -205,17 +205,9 @@ print_header (mu_message_t message, int unix_header, int weedc, char **weedv) ...@@ -205,17 +205,9 @@ print_header (mu_message_t message, int unix_header, int weedc, char **weedv)
205 if (weedc == 0) 205 if (weedc == 0)
206 { 206 {
207 mu_stream_t stream = NULL; 207 mu_stream_t stream = NULL;
208 size_t len = 0;
209 char buf[128];
210 208
211 /* FIXME: Use mu_stream_copy */
212 mu_header_get_streamref (header, &stream); 209 mu_header_get_streamref (header, &stream);
213 while (mu_stream_read (stream, buf, sizeof (buf) - 1, &len) == 0 210 mu_stream_copy (mu_strout, stream, 0, NULL);
214 && len != 0)
215 {
216 buf[len] = '\0';
217 printf ("%s", buf);
218 }
219 mu_stream_destroy (&stream); 211 mu_stream_destroy (&stream);
220 } 212 }
221 else 213 else
...@@ -235,11 +227,11 @@ print_header (mu_message_t message, int unix_header, int weedc, char **weedv) ...@@ -235,11 +227,11 @@ print_header (mu_message_t message, int unix_header, int weedc, char **weedv)
235 for (i = 1; i <= count; i++) 227 for (i = 1; i <= count; i++)
236 { 228 {
237 int j; 229 int j;
238 char *name = NULL; 230 const char *name = NULL;
239 char *value = NULL; 231 const char *value = NULL;
240 232
241 mu_header_aget_field_name (header, i, &name); 233 mu_header_sget_field_name (header, i, &name);
242 mu_header_aget_field_value (header, i, &value); 234 mu_header_sget_field_value (header, i, &value);
243 for (j = 0; j < weedc; j++) 235 for (j = 0; j < weedc; j++)
244 { 236 {
245 if (weedv[j][0] == '!') 237 if (weedv[j][0] == '!')
...@@ -249,15 +241,13 @@ print_header (mu_message_t message, int unix_header, int weedc, char **weedv) ...@@ -249,15 +241,13 @@ print_header (mu_message_t message, int unix_header, int weedc, char **weedv)
249 } 241 }
250 else if (string_starts_with (name, weedv[j])) 242 else if (string_starts_with (name, weedv[j]))
251 { 243 {
252 /* Check if mu_header_aget_value return an empty string. */ 244 /* Check if mu_header_sget_value returns an empty string. */
253 if (value && *value) 245 if (value && *value)
254 printf ("%s: %s\n", name, value); 246 mu_printf ("%s: %s\n", name, value);
255 } 247 }
256 } 248 }
257 free (value);
258 free (name);
259 } 249 }
260 putchar ('\n'); 250 mu_printf ("\n");
261 } 251 }
262 } 252 }
263 253
...@@ -265,26 +255,17 @@ static void ...@@ -265,26 +255,17 @@ static void
265 print_body (mu_message_t message) 255 print_body (mu_message_t message)
266 { 256 {
267 int status; 257 int status;
268 char buf[128];
269 mu_body_t body = NULL; 258 mu_body_t body = NULL;
270 mu_stream_t stream = NULL; 259 mu_stream_t stream = NULL;
271 size_t len = 0;
272 mu_message_get_body (message, &body); 260 mu_message_get_body (message, &body);
273 261
274 /* FIXME: Use mu_stream_copy */
275 status = mu_body_get_streamref (body, &stream); 262 status = mu_body_get_streamref (body, &stream);
276 if (status) 263 if (status)
277 { 264 {
278 mu_error (_("cannot get body stream: %s"), mu_strerror (status)); 265 mu_error (_("cannot get body stream: %s"), mu_strerror (status));
279 return; 266 return;
280 } 267 }
281 268 mu_stream_copy (mu_strout, stream, 0, NULL);
282 while (mu_stream_read (stream, buf, sizeof (buf) - 1, &len) == 0
283 && len != 0)
284 {
285 buf[len] = '\0';
286 printf ("%s", buf);
287 }
288 mu_stream_destroy (&stream); 269 mu_stream_destroy (&stream);
289 } 270 }
290 271
...@@ -410,13 +391,10 @@ main (int argc, char **argv) ...@@ -410,13 +391,10 @@ main (int argc, char **argv)
410 print_header (msg, unix_header, weedc, weedv); 391 print_header (msg, unix_header, weedc, weedv);
411 392
412 print_body (msg); 393 print_body (msg);
413 if (form_feed) 394 mu_printf (form_feed ? "\f" : "\n");
414 putchar ('\f');
415 else
416 putchar ('\n');
417 } 395 }
418 396
419 putchar ('\n'); 397 mu_printf ("\n");
420 398
421 mu_mailbox_close (mbox); 399 mu_mailbox_close (mbox);
422 mu_mailbox_destroy (&mbox); 400 mu_mailbox_destroy (&mbox);
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
43 #include <mailutils/filter.h> 43 #include <mailutils/filter.h>
44 #include <mailutils/registrar.h> 44 #include <mailutils/registrar.h>
45 #include <mailutils/stream.h> 45 #include <mailutils/stream.h>
46 #include <mailutils/stdstream.h>
46 #include <mailutils/url.h> 47 #include <mailutils/url.h>
47 #include <mailutils/nls.h> 48 #include <mailutils/nls.h>
48 #include <mailutils/tls.h> 49 #include <mailutils/tls.h>
......