Use stringrefs, add some guidelines for further editing.
* comsat/action.c * imap4d/fetch.c * imap4d/search.c * mh/burst.c * mh/comp.c * mh/forw.c * mh/mh_ctx.c * mh/mh_format.c * mh/mh_list.c * mh/mhn.c * mh/pick.y * pop3d/retr.c * pop3d/top.c * readmsg/msglist.c * readmsg/readmsg.c
Showing
15 changed files
with
109 additions
and
114 deletions
... | @@ -155,7 +155,7 @@ expand_escape (char **pp, mu_message_t msg, struct obstack *stk) | ... | @@ -155,7 +155,7 @@ expand_escape (char **pp, mu_message_t msg, struct obstack *stk) |
155 | if (lncount == 0) | 155 | if (lncount == 0) |
156 | lncount = maxlines; | 156 | lncount = maxlines; |
157 | if (mu_message_get_body (msg, &body) == 0 | 157 | if (mu_message_get_body (msg, &body) == 0 |
158 | && mu_body_get_stream (body, &stream) == 0) | 158 | && mu_body_get_streamref (body, &stream) == 0) |
159 | { | 159 | { |
160 | size_t nread; | 160 | size_t nread; |
161 | char *buf = malloc (size+1); | 161 | char *buf = malloc (size+1); |
... | @@ -179,6 +179,7 @@ expand_escape (char **pp, mu_message_t msg, struct obstack *stk) | ... | @@ -179,6 +179,7 @@ expand_escape (char **pp, mu_message_t msg, struct obstack *stk) |
179 | } | 179 | } |
180 | obstack_grow (stk, buf, size); | 180 | obstack_grow (stk, buf, size); |
181 | } | 181 | } |
182 | mu_stream_destroy (&stream); | ||
182 | free (buf); | 183 | free (buf); |
183 | } | 184 | } |
184 | *pp = p; | 185 | *pp = p; | ... | ... |
... | @@ -886,6 +886,7 @@ _frt_body (struct fetch_function_closure *ffc, | ... | @@ -886,6 +886,7 @@ _frt_body (struct fetch_function_closure *ffc, |
886 | mu_message_t msg; | 886 | mu_message_t msg; |
887 | mu_stream_t stream = NULL; | 887 | mu_stream_t stream = NULL; |
888 | size_t size = 0, lines = 0; | 888 | size_t size = 0, lines = 0; |
889 | int rc; | ||
889 | 890 | ||
890 | set_seen (ffc, frt); | 891 | set_seen (ffc, frt); |
891 | if (ffc->name) | 892 | if (ffc->name) |
... | @@ -898,10 +899,12 @@ _frt_body (struct fetch_function_closure *ffc, | ... | @@ -898,10 +899,12 @@ _frt_body (struct fetch_function_closure *ffc, |
898 | util_send (" \"\""); | 899 | util_send (" \"\""); |
899 | return RESP_OK; | 900 | return RESP_OK; |
900 | } | 901 | } |
901 | mu_message_get_stream (msg, &stream); | 902 | mu_message_get_streamref (msg, &stream); |
902 | mu_message_size (msg, &size); | 903 | mu_message_size (msg, &size); |
903 | mu_message_lines (msg, &lines); | 904 | mu_message_lines (msg, &lines); |
904 | return fetch_io (stream, ffc->start, ffc->size, size + lines); | 905 | rc = fetch_io (stream, ffc->start, ffc->size, size + lines); |
906 | mu_stream_destroy (&stream); | ||
907 | return rc; | ||
905 | } | 908 | } |
906 | 909 | ||
907 | static int | 910 | static int |
... | @@ -912,6 +915,7 @@ _frt_body_text (struct fetch_function_closure *ffc, | ... | @@ -912,6 +915,7 @@ _frt_body_text (struct fetch_function_closure *ffc, |
912 | mu_body_t body = NULL; | 915 | mu_body_t body = NULL; |
913 | mu_stream_t stream = NULL; | 916 | mu_stream_t stream = NULL; |
914 | size_t size = 0, lines = 0; | 917 | size_t size = 0, lines = 0; |
918 | int rc; | ||
915 | 919 | ||
916 | set_seen (ffc, frt); | 920 | set_seen (ffc, frt); |
917 | if (ffc->name) | 921 | if (ffc->name) |
... | @@ -928,8 +932,10 @@ _frt_body_text (struct fetch_function_closure *ffc, | ... | @@ -928,8 +932,10 @@ _frt_body_text (struct fetch_function_closure *ffc, |
928 | mu_message_get_body (msg, &body); | 932 | mu_message_get_body (msg, &body); |
929 | mu_body_size (body, &size); | 933 | mu_body_size (body, &size); |
930 | mu_body_lines (body, &lines); | 934 | mu_body_lines (body, &lines); |
931 | mu_body_get_stream (body, &stream); | 935 | mu_body_get_streamref (body, &stream); |
932 | return fetch_io (stream, ffc->start, ffc->size, size + lines); | 936 | rc = fetch_io (stream, ffc->start, ffc->size, size + lines); |
937 | mu_stream_destroy (&stream); | ||
938 | return rc; | ||
933 | } | 939 | } |
934 | 940 | ||
935 | static int | 941 | static int |
... | @@ -953,6 +959,7 @@ _frt_header (struct fetch_function_closure *ffc, | ... | @@ -953,6 +959,7 @@ _frt_header (struct fetch_function_closure *ffc, |
953 | mu_header_t header = NULL; | 959 | mu_header_t header = NULL; |
954 | mu_stream_t stream = NULL; | 960 | mu_stream_t stream = NULL; |
955 | size_t size = 0, lines = 0; | 961 | size_t size = 0, lines = 0; |
962 | int rc; | ||
956 | 963 | ||
957 | set_seen (ffc, frt); | 964 | set_seen (ffc, frt); |
958 | if (ffc->name) | 965 | if (ffc->name) |
... | @@ -969,8 +976,10 @@ _frt_header (struct fetch_function_closure *ffc, | ... | @@ -969,8 +976,10 @@ _frt_header (struct fetch_function_closure *ffc, |
969 | mu_message_get_header (msg, &header); | 976 | mu_message_get_header (msg, &header); |
970 | mu_header_size (header, &size); | 977 | mu_header_size (header, &size); |
971 | mu_header_lines (header, &lines); | 978 | mu_header_lines (header, &lines); |
972 | mu_header_get_stream (header, &stream); | 979 | mu_header_get_streamref (header, &stream); |
973 | return fetch_io (stream, ffc->start, ffc->size, size + lines); | 980 | rc = fetch_io (stream, ffc->start, ffc->size, size + lines); |
981 | mu_stream_destroy (&stream); | ||
982 | return rc; | ||
974 | } | 983 | } |
975 | 984 | ||
976 | static int | 985 | static int | ... | ... |
... | @@ -842,7 +842,7 @@ _scan_body (struct parsebuf *pb, char *text) | ... | @@ -842,7 +842,7 @@ _scan_body (struct parsebuf *pb, char *text) |
842 | mu_message_get_body (pb->msg, &body); | 842 | mu_message_get_body (pb->msg, &body); |
843 | mu_body_size (body, &size); | 843 | mu_body_size (body, &size); |
844 | mu_body_lines (body, &lines); | 844 | mu_body_lines (body, &lines); |
845 | mu_body_get_stream (body, &stream); | 845 | mu_body_get_streamref (body, &stream); |
846 | rc = 0; | 846 | rc = 0; |
847 | while (rc == 0 | 847 | while (rc == 0 |
848 | && mu_stream_read (stream, buffer, sizeof(buffer)-1, &n) == 0 | 848 | && mu_stream_read (stream, buffer, sizeof(buffer)-1, &n) == 0 |
... | @@ -851,6 +851,7 @@ _scan_body (struct parsebuf *pb, char *text) | ... | @@ -851,6 +851,7 @@ _scan_body (struct parsebuf *pb, char *text) |
851 | buffer[n] = 0; | 851 | buffer[n] = 0; |
852 | rc = util_strcasestr (buffer, text) != NULL; | 852 | rc = util_strcasestr (buffer, text) != NULL; |
853 | } | 853 | } |
854 | mu_stream_destroy (&stream); | ||
854 | return rc; | 855 | return rc; |
855 | } | 856 | } |
856 | 857 | ... | ... |
... | @@ -286,8 +286,7 @@ burst_digest (mu_message_t msg) | ... | @@ -286,8 +286,7 @@ burst_digest (mu_message_t msg) |
286 | exit (1); | 286 | exit (1); |
287 | } | 287 | } |
288 | 288 | ||
289 | mu_message_get_stream (msg, &is); | 289 | mu_message_get_streamref (msg, &is); |
290 | mu_stream_seek (is, 0, MU_SEEK_SET, NULL); | ||
291 | while (mu_stream_read (is, buf, bufsize, &n) == 0 | 290 | while (mu_stream_read (is, buf, bufsize, &n) == 0 |
292 | && n > 0) | 291 | && n > 0) |
293 | { | 292 | { |
... | @@ -339,6 +338,7 @@ burst_digest (mu_message_t msg) | ... | @@ -339,6 +338,7 @@ burst_digest (mu_message_t msg) |
339 | 338 | ||
340 | flush_stream (&os, buf + start, i - start); | 339 | flush_stream (&os, buf + start, i - start); |
341 | } | 340 | } |
341 | mu_stream_destroy (&is); | ||
342 | 342 | ||
343 | free (buf); | 343 | free (buf); |
344 | if (os) | 344 | if (os) |
... | @@ -390,8 +390,10 @@ burst_or_copy (mu_message_t msg, int recursive, int copy) | ... | @@ -390,8 +390,10 @@ burst_or_copy (mu_message_t msg, int recursive, int copy) |
390 | mu_body_t body; | 390 | mu_body_t body; |
391 | 391 | ||
392 | mu_message_get_body (msg, &body); | 392 | mu_message_get_body (msg, &body); |
393 | mu_body_get_stream (body, &str); | 393 | mu_body_get_streamref (body, &str); |
394 | 394 | /* FIXME: Check if str is actually destroyed. | |
395 | See mailbox/message_stream.c | ||
396 | */ | ||
395 | msg = mh_stream_to_message (str); | 397 | msg = mh_stream_to_message (str); |
396 | } | 398 | } |
397 | free (value); | 399 | free (value); |
... | @@ -487,8 +489,6 @@ msg_copy (size_t num, const char *file) | ... | @@ -487,8 +489,6 @@ msg_copy (size_t num, const char *file) |
487 | mu_attribute_t attr = NULL; | 489 | mu_attribute_t attr = NULL; |
488 | mu_stream_t istream, ostream; | 490 | mu_stream_t istream, ostream; |
489 | int rc; | 491 | int rc; |
490 | size_t n; | ||
491 | char buf[512]; | ||
492 | 492 | ||
493 | if ((rc = mu_file_stream_create (&ostream, | 493 | if ((rc = mu_file_stream_create (&ostream, |
494 | file, | 494 | file, |
... | @@ -501,13 +501,16 @@ msg_copy (size_t num, const char *file) | ... | @@ -501,13 +501,16 @@ msg_copy (size_t num, const char *file) |
501 | } | 501 | } |
502 | 502 | ||
503 | mu_mailbox_get_message (tmpbox, num, &msg); | 503 | mu_mailbox_get_message (tmpbox, num, &msg); |
504 | mu_message_get_stream (msg, &istream); | 504 | mu_message_get_streamref (msg, &istream); |
505 | mu_stream_seek (istream, 0, MU_SEEK_SET, NULL); | ||
506 | while (rc == 0 | ||
507 | && mu_stream_read (istream, buf, sizeof buf, &n) == 0 | ||
508 | && n > 0) | ||
509 | /* FIXME: Implement RFC 934 FSA? */ | 505 | /* FIXME: Implement RFC 934 FSA? */ |
510 | rc = mu_stream_write (ostream, buf, n, NULL); | 506 | rc = mu_stream_copy (ostream, istream, 0); |
507 | if (rc) | ||
508 | { | ||
509 | mu_error (_("copy stream error: %s"), mu_strerror (rc)); | ||
510 | exit (1); | ||
511 | } | ||
512 | |||
513 | mu_stream_destroy (&istream); | ||
511 | 514 | ||
512 | mu_stream_close (ostream); | 515 | mu_stream_close (ostream); |
513 | mu_stream_destroy (&ostream); | 516 | mu_stream_destroy (&ostream); | ... | ... |
... | @@ -160,21 +160,9 @@ copy_message (mu_mailbox_t mbox, size_t n, const char *file) | ... | @@ -160,21 +160,9 @@ copy_message (mu_mailbox_t mbox, size_t n, const char *file) |
160 | mu_stream_t in; | 160 | mu_stream_t in; |
161 | mu_stream_t out; | 161 | mu_stream_t out; |
162 | int rc; | 162 | int rc; |
163 | size_t size; | ||
164 | char *buffer; | ||
165 | size_t bufsize, rdsize; | ||
166 | 163 | ||
167 | mu_mailbox_get_message (mbox, n, &msg); | 164 | mu_mailbox_get_message (mbox, n, &msg); |
168 | mu_message_size (msg, &size); | 165 | mu_message_get_streamref (msg, &in); |
169 | |||
170 | for (bufsize = size; bufsize > 0 && (buffer = malloc (bufsize)) == 0; | ||
171 | bufsize /= 2) | ||
172 | ; | ||
173 | |||
174 | if (!bufsize) | ||
175 | mh_err_memory (1); | ||
176 | |||
177 | mu_message_get_stream (msg, &in); | ||
178 | 166 | ||
179 | if ((rc = mu_file_stream_create (&out, | 167 | if ((rc = mu_file_stream_create (&out, |
180 | file, MU_STREAM_RDWR|MU_STREAM_CREAT)) != 0 | 168 | file, MU_STREAM_RDWR|MU_STREAM_CREAT)) != 0 |
... | @@ -182,27 +170,20 @@ copy_message (mu_mailbox_t mbox, size_t n, const char *file) | ... | @@ -182,27 +170,20 @@ copy_message (mu_mailbox_t mbox, size_t n, const char *file) |
182 | { | 170 | { |
183 | mu_error (_("cannot open output file \"%s\": %s"), | 171 | mu_error (_("cannot open output file \"%s\": %s"), |
184 | file, mu_strerror (rc)); | 172 | file, mu_strerror (rc)); |
185 | free (buffer); | 173 | mu_stream_destroy (&in); |
186 | return 1; | 174 | return rc; |
187 | } | ||
188 | |||
189 | mu_stream_seek (in, 0, MU_SEEK_SET, NULL); | ||
190 | while (size > 0 | ||
191 | && (rc = mu_stream_read (in, buffer, bufsize, &rdsize)) == 0 | ||
192 | && rdsize > 0) | ||
193 | { | ||
194 | if ((rc = mu_stream_write (out, buffer, rdsize, NULL)) != 0) | ||
195 | { | ||
196 | mu_error (_("error writing to \"%s\": %s"), | ||
197 | file, mu_strerror (rc)); | ||
198 | break; | ||
199 | } | ||
200 | size -= rdsize; | ||
201 | } | 175 | } |
202 | 176 | ||
177 | rc = mu_stream_copy (out, in, 0); | ||
178 | mu_stream_destroy (&in); | ||
203 | mu_stream_close (out); | 179 | mu_stream_close (out); |
204 | mu_stream_destroy (&out); | 180 | mu_stream_destroy (&out); |
205 | 181 | ||
182 | if (rc) | ||
183 | { | ||
184 | mu_error (_("error copying to \"%s\": %s"), | ||
185 | file, mu_strerror (rc)); | ||
186 | } | ||
206 | return rc; | 187 | return rc; |
207 | } | 188 | } |
208 | 189 | ... | ... |
... | @@ -249,10 +249,9 @@ msg_copy (mu_message_t msg, mu_stream_t ostream) | ... | @@ -249,10 +249,9 @@ msg_copy (mu_message_t msg, mu_stream_t ostream) |
249 | char buf[512]; | 249 | char buf[512]; |
250 | enum rfc934_state state = S1; | 250 | enum rfc934_state state = S1; |
251 | 251 | ||
252 | rc = mu_message_get_stream (msg, &istream); | 252 | rc = mu_message_get_streamref (msg, &istream); |
253 | if (rc) | 253 | if (rc) |
254 | return rc; | 254 | return rc; |
255 | mu_stream_seek (istream, 0, SEEK_SET, NULL); | ||
256 | while (rc == 0 | 255 | while (rc == 0 |
257 | && mu_stream_read (istream, buf, sizeof buf, &n) == 0 | 256 | && mu_stream_read (istream, buf, sizeof buf, &n) == 0 |
258 | && n > 0) | 257 | && n > 0) |
... | @@ -286,6 +285,7 @@ msg_copy (mu_message_t msg, mu_stream_t ostream) | ... | @@ -286,6 +285,7 @@ msg_copy (mu_message_t msg, mu_stream_t ostream) |
286 | if (i > start) | 285 | if (i > start) |
287 | rc = mu_stream_write (ostream, buf + start, i - start, NULL); | 286 | rc = mu_stream_write (ostream, buf + start, i - start, NULL); |
288 | } | 287 | } |
288 | mu_stream_destroy (&istream); | ||
289 | return rc; | 289 | return rc; |
290 | } | 290 | } |
291 | 291 | ... | ... |
... | @@ -146,16 +146,15 @@ mh_context_write (mh_context_t *ctx) | ... | @@ -146,16 +146,15 @@ mh_context_write (mh_context_t *ctx) |
146 | return MU_ERR_FAILURE; | 146 | return MU_ERR_FAILURE; |
147 | } | 147 | } |
148 | 148 | ||
149 | mu_header_get_stream (ctx->header, &stream); | 149 | /* FIXME: Use mu_stream+copy */ |
150 | 150 | mu_header_get_streamref (ctx->header, &stream); | |
151 | mu_stream_seek (stream, 0, MU_SEEK_SET, NULL); | ||
152 | while (mu_stream_read (stream, buffer, sizeof buffer - 1, &n) == 0 | 151 | while (mu_stream_read (stream, buffer, sizeof buffer - 1, &n) == 0 |
153 | && n != 0) | 152 | && n != 0) |
154 | { | 153 | { |
155 | buffer[n] = '\0'; | 154 | buffer[n] = '\0'; |
156 | fprintf (fp, "%s", buffer); | 155 | fprintf (fp, "%s", buffer); |
157 | } | 156 | } |
158 | 157 | mu_stream_destroy (&stream); | |
159 | fclose (fp); | 158 | fclose (fp); |
160 | return 0; | 159 | return 0; |
161 | } | 160 | } | ... | ... |
... | @@ -609,8 +609,10 @@ mh_format (mh_format_t *fmt, mu_message_t msg, size_t msgno, | ... | @@ -609,8 +609,10 @@ mh_format (mh_format_t *fmt, mu_message_t msg, size_t msgno, |
609 | strobj_free (&mach.arg_str); | 609 | strobj_free (&mach.arg_str); |
610 | mu_message_get_body (mach.message, &body); | 610 | mu_message_get_body (mach.message, &body); |
611 | mu_body_size (body, &size); | 611 | mu_body_size (body, &size); |
612 | mu_body_get_stream (body, &stream); | 612 | if (size == 0) |
613 | if (size == 0 || !stream) | 613 | break; |
614 | mu_body_get_streamref (body, &stream); | ||
615 | if (!stream) | ||
614 | break; | 616 | break; |
615 | if (size > rest) | 617 | if (size > rest) |
616 | size = rest; | 618 | size = rest; |
... | @@ -619,7 +621,6 @@ mh_format (mh_format_t *fmt, mu_message_t msg, size_t msgno, | ... | @@ -619,7 +621,6 @@ mh_format (mh_format_t *fmt, mu_message_t msg, size_t msgno, |
619 | mach.arg_str.size = size; | 621 | mach.arg_str.size = size; |
620 | 622 | ||
621 | str_off = 0; | 623 | str_off = 0; |
622 | mu_stream_seek (stream, 0, MU_SEEK_SET, NULL); | ||
623 | while (!mu_stream_read (stream, mach.arg_str.ptr + str_off, | 624 | while (!mu_stream_read (stream, mach.arg_str.ptr + str_off, |
624 | mach.arg_str.size - str_off, &nread) | 625 | mach.arg_str.size - str_off, &nread) |
625 | && nread != 0 | 626 | && nread != 0 |
... | @@ -629,6 +630,7 @@ mh_format (mh_format_t *fmt, mu_message_t msg, size_t msgno, | ... | @@ -629,6 +630,7 @@ mh_format (mh_format_t *fmt, mu_message_t msg, size_t msgno, |
629 | if (nread) | 630 | if (nread) |
630 | str_off += nread; | 631 | str_off += nread; |
631 | } | 632 | } |
633 | mu_stream_destroy (&stream); | ||
632 | mach.arg_str.ptr[str_off] = 0; | 634 | mach.arg_str.ptr[str_off] = 0; |
633 | } | 635 | } |
634 | break; | 636 | break; | ... | ... |
... | @@ -687,7 +687,7 @@ eval_body (struct eval_env *env) | ... | @@ -687,7 +687,7 @@ eval_body (struct eval_env *env) |
687 | env->prefix = env->svar[S_COMPONENT]; | 687 | env->prefix = env->svar[S_COMPONENT]; |
688 | 688 | ||
689 | mu_message_get_body (env->msg, &body); | 689 | mu_message_get_body (env->msg, &body); |
690 | mu_body_get_stream (body, &input); | 690 | mu_body_get_streamref (body, &input); |
691 | 691 | ||
692 | if (env->bvar[B_DECODE]) | 692 | if (env->bvar[B_DECODE]) |
693 | { | 693 | { |
... | @@ -707,15 +707,13 @@ eval_body (struct eval_env *env) | ... | @@ -707,15 +707,13 @@ eval_body (struct eval_env *env) |
707 | } | 707 | } |
708 | } | 708 | } |
709 | 709 | ||
710 | mu_stream_seek (input, 0, SEEK_SET, NULL); | ||
711 | while (mu_stream_readline (input, buf, sizeof buf, &n) == 0 | 710 | while (mu_stream_readline (input, buf, sizeof buf, &n) == 0 |
712 | && n > 0) | 711 | && n > 0) |
713 | { | 712 | { |
714 | buf[n] = 0; | 713 | buf[n] = 0; |
715 | print (env, buf, 0); | 714 | print (env, buf, 0); |
716 | } | 715 | } |
717 | if (dstr) | 716 | mu_stream_destroy (&input); |
718 | mu_stream_destroy (&dstr); | ||
719 | return 0; | 717 | return 0; |
720 | } | 718 | } |
721 | 719 | ... | ... |
... | @@ -962,6 +962,7 @@ _free_env (char **env) | ... | @@ -962,6 +962,7 @@ _free_env (char **env) |
962 | free (env); | 962 | free (env); |
963 | } | 963 | } |
964 | 964 | ||
965 | /* FIXME: Use mimehdr.c functions instead */ | ||
965 | int | 966 | int |
966 | get_extbody_params (mu_message_t msg, char **content, char **descr) | 967 | get_extbody_params (mu_message_t msg, char **content, char **descr) |
967 | { | 968 | { |
... | @@ -972,8 +973,7 @@ get_extbody_params (mu_message_t msg, char **content, char **descr) | ... | @@ -972,8 +973,7 @@ get_extbody_params (mu_message_t msg, char **content, char **descr) |
972 | size_t n; | 973 | size_t n; |
973 | 974 | ||
974 | mu_message_get_body (msg, &body); | 975 | mu_message_get_body (msg, &body); |
975 | mu_body_get_stream (body, &stream); | 976 | mu_body_get_streamref (body, &stream); |
976 | mu_stream_seek (stream, 0, SEEK_SET, NULL); | ||
977 | 977 | ||
978 | while (rc == 0 | 978 | while (rc == 0 |
979 | && mu_stream_readline (stream, buf, sizeof buf, &n) == 0 | 979 | && mu_stream_readline (stream, buf, sizeof buf, &n) == 0 |
... | @@ -1006,6 +1006,7 @@ get_extbody_params (mu_message_t msg, char **content, char **descr) | ... | @@ -1006,6 +1006,7 @@ get_extbody_params (mu_message_t msg, char **content, char **descr) |
1006 | *content = strdup (p); | 1006 | *content = strdup (p); |
1007 | } | 1007 | } |
1008 | } | 1008 | } |
1009 | mu_stream_destroy (&stream); | ||
1009 | return 0; | 1010 | return 0; |
1010 | } | 1011 | } |
1011 | 1012 | ||
... | @@ -1113,7 +1114,7 @@ mhn_message_size (mu_message_t msg, size_t *psize) | ... | @@ -1113,7 +1114,7 @@ mhn_message_size (mu_message_t msg, size_t *psize) |
1113 | { | 1114 | { |
1114 | mu_stream_t dstr = NULL, bstr = NULL; | 1115 | mu_stream_t dstr = NULL, bstr = NULL; |
1115 | 1116 | ||
1116 | if (mu_body_get_stream (body, &bstr) == 0) | 1117 | if (mu_body_get_streamref (body, &bstr) == 0) |
1117 | { | 1118 | { |
1118 | mu_header_t hdr; | 1119 | mu_header_t hdr; |
1119 | char *encoding; | 1120 | char *encoding; |
... | @@ -1132,7 +1133,6 @@ mhn_message_size (mu_message_t msg, size_t *psize) | ... | @@ -1132,7 +1133,6 @@ mhn_message_size (mu_message_t msg, size_t *psize) |
1132 | char buf[512]; | 1133 | char buf[512]; |
1133 | size_t n; | 1134 | size_t n; |
1134 | 1135 | ||
1135 | mu_stream_seek (dstr, 0, MU_SEEK_SET, NULL); | ||
1136 | while (mu_stream_read (dstr, buf, sizeof buf, &n) == 0 | 1136 | while (mu_stream_read (dstr, buf, sizeof buf, &n) == 0 |
1137 | && n > 0) | 1137 | && n > 0) |
1138 | size += n; | 1138 | size += n; |
... | @@ -1141,6 +1141,7 @@ mhn_message_size (mu_message_t msg, size_t *psize) | ... | @@ -1141,6 +1141,7 @@ mhn_message_size (mu_message_t msg, size_t *psize) |
1141 | *psize = size; | 1141 | *psize = size; |
1142 | return 0; | 1142 | return 0; |
1143 | } | 1143 | } |
1144 | mu_stream_destroy (&bstr); | ||
1144 | } | 1145 | } |
1145 | } | 1146 | } |
1146 | 1147 | ||
... | @@ -1246,20 +1247,6 @@ mhn_list () | ... | @@ -1246,20 +1247,6 @@ mhn_list () |
1246 | 1247 | ||
1247 | static mu_list_t mhl_format; | 1248 | static mu_list_t mhl_format; |
1248 | 1249 | ||
1249 | void | ||
1250 | cat_message (mu_stream_t out, mu_stream_t in) | ||
1251 | { | ||
1252 | int rc = 0; | ||
1253 | char buf[512]; | ||
1254 | size_t n; | ||
1255 | |||
1256 | mu_stream_seek (in, 0, SEEK_SET, NULL); | ||
1257 | while (rc == 0 | ||
1258 | && mu_stream_read (in, buf, sizeof buf, &n) == 0 | ||
1259 | && n > 0) | ||
1260 | rc = mu_stream_write (out, buf, n, NULL); | ||
1261 | } | ||
1262 | |||
1263 | int | 1250 | int |
1264 | show_internal (mu_message_t msg, msg_part_t part, char *encoding, mu_stream_t out) | 1251 | show_internal (mu_message_t msg, msg_part_t part, char *encoding, mu_stream_t out) |
1265 | { | 1252 | { |
... | @@ -1274,15 +1261,14 @@ show_internal (mu_message_t msg, msg_part_t part, char *encoding, mu_stream_t ou | ... | @@ -1274,15 +1261,14 @@ show_internal (mu_message_t msg, msg_part_t part, char *encoding, mu_stream_t ou |
1274 | mu_strerror (rc)); | 1261 | mu_strerror (rc)); |
1275 | return 0; | 1262 | return 0; |
1276 | } | 1263 | } |
1277 | mu_body_get_stream (body, &bstr); | 1264 | mu_body_get_streamref (body, &bstr); |
1278 | rc = mu_filter_create (&dstr, bstr, encoding, | 1265 | rc = mu_filter_create (&dstr, bstr, encoding, |
1279 | MU_FILTER_DECODE, MU_STREAM_READ | MU_STREAM_NO_CLOSE); | 1266 | MU_FILTER_DECODE, MU_STREAM_READ | MU_STREAM_NO_CLOSE); |
1280 | if (rc == 0) | 1267 | if (rc == 0) |
1281 | bstr = dstr; | 1268 | bstr = dstr; |
1282 | cat_message (out, bstr); | 1269 | rc = mu_stream_copy (out, bstr, 0); |
1283 | if (dstr) | 1270 | mu_stream_destroy (&bstr); |
1284 | mu_stream_destroy (&dstr); | 1271 | return rc; |
1285 | return 0; | ||
1286 | } | 1272 | } |
1287 | 1273 | ||
1288 | int | 1274 | int |
... | @@ -1965,14 +1951,15 @@ copy_header_to_stream (mu_message_t msg, mu_stream_t stream) | ... | @@ -1965,14 +1951,15 @@ copy_header_to_stream (mu_message_t msg, mu_stream_t stream) |
1965 | size_t bufsize = 0, n = 0; | 1951 | size_t bufsize = 0, n = 0; |
1966 | 1952 | ||
1967 | mu_message_get_header (msg, &hdr); | 1953 | mu_message_get_header (msg, &hdr); |
1968 | mu_header_get_stream (hdr, &in); | 1954 | mu_header_get_streamref (hdr, &in); |
1969 | mu_stream_seek (in, 0, SEEK_SET, NULL); | 1955 | /* FIXME: Use mu_stream_copy */ |
1970 | while (mu_stream_getline (in, &buf, &bufsize, &n) == 0 && n > 0) | 1956 | while (mu_stream_getline (in, &buf, &bufsize, &n) == 0 && n > 0) |
1971 | { | 1957 | { |
1972 | if (n == 1 && buf[0] == '\n') | 1958 | if (n == 1 && buf[0] == '\n') |
1973 | break; | 1959 | break; |
1974 | mu_stream_write (stream, buf, n, NULL); | 1960 | mu_stream_write (stream, buf, n, NULL); |
1975 | } | 1961 | } |
1962 | mu_stream_destroy (&in); | ||
1976 | free (buf); | 1963 | free (buf); |
1977 | } | 1964 | } |
1978 | 1965 | ||
... | @@ -2010,29 +1997,29 @@ finish_text_msg (struct compose_env *env, mu_message_t *msg, int ascii) | ... | @@ -2010,29 +1997,29 @@ finish_text_msg (struct compose_env *env, mu_message_t *msg, int ascii) |
2010 | 1997 | ||
2011 | mu_message_create (&newmsg, NULL); | 1998 | mu_message_create (&newmsg, NULL); |
2012 | mu_message_get_header (newmsg, &hdr); | 1999 | mu_message_get_header (newmsg, &hdr); |
2013 | mu_header_get_stream (hdr, &output); | ||
2014 | copy_header (*msg, hdr); | 2000 | copy_header (*msg, hdr); |
2015 | mu_header_set_value (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING, | 2001 | mu_header_set_value (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING, |
2016 | "quoted-printable", 0); | 2002 | "quoted-printable", 0); |
2017 | 2003 | ||
2018 | mu_message_get_body (newmsg, &body); | 2004 | mu_message_get_body (newmsg, &body); |
2019 | mu_body_get_stream (body, &output); | 2005 | mu_body_get_streamref (body, &output); |
2020 | mu_stream_seek (output, 0, SEEK_SET, NULL); | ||
2021 | 2006 | ||
2022 | mu_message_get_body (*msg, &body); | 2007 | mu_message_get_body (*msg, &body); |
2023 | mu_body_get_stream (body, &input); | 2008 | mu_body_get_streamref (body, &input); |
2024 | rc = mu_filter_create (&fstr, input, "quoted-printable", | 2009 | rc = mu_filter_create (&fstr, input, "quoted-printable", |
2025 | MU_FILTER_ENCODE, | 2010 | MU_FILTER_ENCODE, |
2026 | MU_STREAM_READ | MU_STREAM_NO_CLOSE); | 2011 | MU_STREAM_READ | MU_STREAM_NO_CLOSE); |
2027 | if (rc == 0) | 2012 | if (rc == 0) |
2028 | { | 2013 | { |
2029 | cat_message (output, fstr); | 2014 | mu_stream_copy (output, fstr, 0); |
2030 | mu_stream_destroy (&fstr); | 2015 | mu_stream_destroy (&fstr); |
2031 | mu_message_unref (*msg); | 2016 | mu_message_unref (*msg); |
2032 | *msg = newmsg; | 2017 | *msg = newmsg; |
2033 | } | 2018 | } |
2034 | else | 2019 | else |
2035 | mu_message_destroy (&newmsg, NULL); | 2020 | mu_message_destroy (&newmsg, NULL); |
2021 | mu_stream_destroy (&input); | ||
2022 | mu_stream_destroy (&output); | ||
2036 | } | 2023 | } |
2037 | finish_msg (env, msg); | 2024 | finish_msg (env, msg); |
2038 | } | 2025 | } |
... | @@ -2076,18 +2063,19 @@ edit_extern (char *cmd, struct compose_env *env, mu_message_t *msg, int level) | ... | @@ -2076,18 +2063,19 @@ edit_extern (char *cmd, struct compose_env *env, mu_message_t *msg, int level) |
2076 | return 1; | 2063 | return 1; |
2077 | 2064 | ||
2078 | mu_message_get_body (*msg, &body); | 2065 | mu_message_get_body (*msg, &body); |
2079 | mu_body_get_stream (body, &out); | 2066 | mu_body_get_streamref (body, &out); |
2080 | mu_stream_seek (out, 0, SEEK_SET, NULL); | ||
2081 | 2067 | ||
2082 | if (!id) | 2068 | if (!id) |
2083 | id = mh_create_message_id (env->subpart); | 2069 | id = mh_create_message_id (env->subpart); |
2084 | mu_header_set_value (hdr2, MU_HEADER_CONTENT_ID, id, 1); | 2070 | mu_header_set_value (hdr2, MU_HEADER_CONTENT_ID, id, 1); |
2085 | free (id); | 2071 | free (id); |
2086 | 2072 | ||
2087 | mu_header_get_stream (hdr2, &in); | 2073 | mu_header_get_streamref (hdr2, &in); |
2088 | mu_stream_seek (in, 0, SEEK_SET, NULL); | 2074 | mu_stream_copy (out, in, 0); |
2089 | cat_message (out, in); | 2075 | mu_stream_destroy (&in); |
2090 | mu_stream_close (out); | 2076 | mu_stream_close (out); |
2077 | mu_stream_destroy (&out); | ||
2078 | |||
2091 | mu_header_destroy (&hdr2); | 2079 | mu_header_destroy (&hdr2); |
2092 | 2080 | ||
2093 | finish_msg (env, msg); | 2081 | finish_msg (env, msg); |
... | @@ -2312,11 +2300,11 @@ edit_mime (char *cmd, struct compose_env *env, mu_message_t *msg, int level) | ... | @@ -2312,11 +2300,11 @@ edit_mime (char *cmd, struct compose_env *env, mu_message_t *msg, int level) |
2312 | } | 2300 | } |
2313 | 2301 | ||
2314 | mu_message_get_body (*msg, &body); | 2302 | mu_message_get_body (*msg, &body); |
2315 | mu_body_get_stream (body, &out); | 2303 | mu_body_get_streamref (body, &out); |
2316 | cat_message (out, fstr); | 2304 | mu_stream_copy (out, fstr, 0); |
2317 | 2305 | ||
2318 | mu_stream_close (out); | 2306 | mu_stream_close (out); |
2319 | 2307 | mu_stream_destroy (&out); | |
2320 | mu_stream_destroy (&fstr); | 2308 | mu_stream_destroy (&fstr); |
2321 | finish_msg (env, msg); | 2309 | finish_msg (env, msg); |
2322 | return rc; | 2310 | return rc; |
... | @@ -2339,7 +2327,7 @@ mhn_edit (struct compose_env *env, int level) | ... | @@ -2339,7 +2327,7 @@ mhn_edit (struct compose_env *env, int level) |
2339 | char *buf = NULL; | 2327 | char *buf = NULL; |
2340 | size_t bufsize = 0, n; | 2328 | size_t bufsize = 0, n; |
2341 | mu_body_t body; | 2329 | mu_body_t body; |
2342 | mu_stream_t output; | 2330 | mu_stream_t output = NULL; |
2343 | mu_message_t msg = NULL; | 2331 | mu_message_t msg = NULL; |
2344 | size_t line_count = 0; | 2332 | size_t line_count = 0; |
2345 | int ascii_buf; | 2333 | int ascii_buf; |
... | @@ -2351,12 +2339,15 @@ mhn_edit (struct compose_env *env, int level) | ... | @@ -2351,12 +2339,15 @@ mhn_edit (struct compose_env *env, int level) |
2351 | if (!msg) | 2339 | if (!msg) |
2352 | { | 2340 | { |
2353 | mu_header_t hdr; | 2341 | mu_header_t hdr; |
2342 | |||
2343 | /* Destroy old stream */ | ||
2344 | mu_stream_destroy (&output); | ||
2345 | |||
2354 | /* Create new message */ | 2346 | /* Create new message */ |
2355 | mu_message_create (&msg, NULL); | 2347 | mu_message_create (&msg, NULL); |
2356 | mu_message_get_header (msg, &hdr); | 2348 | mu_message_get_header (msg, &hdr); |
2357 | mu_message_get_body (msg, &body); | 2349 | mu_message_get_body (msg, &body); |
2358 | mu_body_get_stream (body, &output); | 2350 | mu_body_get_streamref (body, &output); |
2359 | mu_stream_seek (output, 0, SEEK_SET, NULL); | ||
2360 | line_count = 0; | 2351 | line_count = 0; |
2361 | ascii_buf = 1; /* Suppose it is ascii */ | 2352 | ascii_buf = 1; /* Suppose it is ascii */ |
2362 | env->subpart++; | 2353 | env->subpart++; |
... | @@ -2391,6 +2382,8 @@ mhn_edit (struct compose_env *env, int level) | ... | @@ -2391,6 +2382,8 @@ mhn_edit (struct compose_env *env, int level) |
2391 | free (b2); | 2382 | free (b2); |
2392 | 2383 | ||
2393 | mu_stream_close (output); | 2384 | mu_stream_close (output); |
2385 | mu_stream_destroy (&output); | ||
2386 | |||
2394 | if (line_count) | 2387 | if (line_count) |
2395 | /* Close and append the previous part */ | 2388 | /* Close and append the previous part */ |
2396 | finish_text_msg (env, &msg, ascii_buf); | 2389 | finish_text_msg (env, &msg, ascii_buf); |
... | @@ -2473,6 +2466,7 @@ mhn_edit (struct compose_env *env, int level) | ... | @@ -2473,6 +2466,7 @@ mhn_edit (struct compose_env *env, int level) |
2473 | else | 2466 | else |
2474 | mu_message_unref (msg); | 2467 | mu_message_unref (msg); |
2475 | } | 2468 | } |
2469 | mu_stream_destroy (&output); | ||
2476 | 2470 | ||
2477 | return status; | 2471 | return status; |
2478 | } | 2472 | } |
... | @@ -2621,14 +2615,14 @@ mhn_compose () | ... | @@ -2621,14 +2615,14 @@ mhn_compose () |
2621 | mu_mime_create (&mime, NULL, 0); | 2615 | mu_mime_create (&mime, NULL, 0); |
2622 | 2616 | ||
2623 | mu_message_get_body (message, &body); | 2617 | mu_message_get_body (message, &body); |
2624 | mu_body_get_stream (body, &stream); | 2618 | mu_body_get_streamref (body, &stream); |
2625 | mu_stream_seek (stream, 0, SEEK_SET, NULL); | ||
2626 | 2619 | ||
2627 | env.mime = mime; | 2620 | env.mime = mime; |
2628 | env.input = stream; | 2621 | env.input = stream; |
2629 | env.subpart = 0; | 2622 | env.subpart = 0; |
2630 | env.line = 0; | 2623 | env.line = 0; |
2631 | rc = mhn_edit (&env, 0); | 2624 | rc = mhn_edit (&env, 0); |
2625 | mu_stream_destroy (&stream); | ||
2632 | if (rc) | 2626 | if (rc) |
2633 | return rc; | 2627 | return rc; |
2634 | 2628 | ||
... | @@ -2671,8 +2665,9 @@ mhn_compose () | ... | @@ -2671,8 +2665,9 @@ mhn_compose () |
2671 | 2665 | ||
2672 | mhn_header (message, msg); | 2666 | mhn_header (message, msg); |
2673 | copy_header_to_stream (message, stream); | 2667 | copy_header_to_stream (message, stream); |
2674 | mu_message_get_stream (msg, &in); | 2668 | mu_message_get_streamref (msg, &in); |
2675 | cat_message (stream, in); | 2669 | mu_stream_copy (stream, in, 0); |
2670 | mu_stream_destroy (&in); | ||
2676 | mu_stream_destroy (&stream); | 2671 | mu_stream_destroy (&stream); |
2677 | 2672 | ||
2678 | /* Preserve the backup copy and replace the draft */ | 2673 | /* Preserve the backup copy and replace the draft */ | ... | ... |
... | @@ -324,8 +324,7 @@ match_message (mu_message_t msg, regex_t *regex) | ... | @@ -324,8 +324,7 @@ match_message (mu_message_t msg, regex_t *regex) |
324 | char buf[128]; | 324 | char buf[128]; |
325 | size_t n; | 325 | size_t n; |
326 | 326 | ||
327 | mu_message_get_stream (msg, &str); | 327 | mu_message_get_streamref (msg, &str); |
328 | mu_stream_seek (str, 0, SEEK_SET, NULL); | ||
329 | while (mu_stream_readline (str, buf, sizeof buf, &n) == 0 | 328 | while (mu_stream_readline (str, buf, sizeof buf, &n) == 0 |
330 | && n > 0) | 329 | && n > 0) |
331 | { | 330 | { |
... | @@ -333,6 +332,7 @@ match_message (mu_message_t msg, regex_t *regex) | ... | @@ -333,6 +332,7 @@ match_message (mu_message_t msg, regex_t *regex) |
333 | if (regexec (regex, buf, 0, NULL, 0) == 0) | 332 | if (regexec (regex, buf, 0, NULL, 0) == 0) |
334 | return 1; | 333 | return 1; |
335 | } | 334 | } |
335 | mu_stream_destroy (&str); | ||
336 | return 0; | 336 | return 0; |
337 | } | 337 | } |
338 | 338 | ... | ... |
... | @@ -44,6 +44,7 @@ pop3d_retr (char *arg) | ... | @@ -44,6 +44,7 @@ pop3d_retr (char *arg) |
44 | if (pop3d_is_deleted (attr)) | 44 | if (pop3d_is_deleted (attr)) |
45 | return ERR_MESG_DELE; | 45 | return ERR_MESG_DELE; |
46 | 46 | ||
47 | /* FIXME: Use crlf filter + mu_stream_copy instead of the loop below */ | ||
47 | mu_message_get_stream (msg, &stream); | 48 | mu_message_get_stream (msg, &stream); |
48 | pop3d_outf ("+OK\r\n"); | 49 | pop3d_outf ("+OK\r\n"); |
49 | 50 | ... | ... |
... | @@ -59,6 +59,7 @@ pop3d_top (char *arg) | ... | @@ -59,6 +59,7 @@ pop3d_top (char *arg) |
59 | 59 | ||
60 | /* Header. */ | 60 | /* Header. */ |
61 | mu_message_get_header (msg, &hdr); | 61 | mu_message_get_header (msg, &hdr); |
62 | /* FIXME: Use crlf filter + mu_stream_copy instead of the below loop */ | ||
62 | mu_header_get_stream (hdr, &stream); | 63 | mu_header_get_stream (hdr, &stream); |
63 | n = 0; | 64 | n = 0; |
64 | while (mu_stream_readline (stream, buf, sizeof(buf), &n) == 0 | 65 | while (mu_stream_readline (stream, buf, sizeof(buf), &n) == 0 |
... | @@ -80,6 +81,7 @@ pop3d_top (char *arg) | ... | @@ -80,6 +81,7 @@ pop3d_top (char *arg) |
80 | int prev_nl = 1; | 81 | int prev_nl = 1; |
81 | 82 | ||
82 | mu_message_get_body (msg, &body); | 83 | mu_message_get_body (msg, &body); |
84 | /* FIXME: Use the crlf filter + mu_stream_copy */ | ||
83 | mu_body_get_stream (body, &stream); | 85 | mu_body_get_stream (body, &stream); |
84 | n = 0; | 86 | n = 0; |
85 | while (mu_stream_readline (stream, buf, sizeof(buf), &n) == 0 | 87 | while (mu_stream_readline (stream, buf, sizeof(buf), &n) == 0 | ... | ... |
... | @@ -124,8 +124,7 @@ msglist (mu_mailbox_t mbox, int show_all, int argc, char **argv, | ... | @@ -124,8 +124,7 @@ msglist (mu_mailbox_t mbox, int show_all, int argc, char **argv, |
124 | mu_stream_t stream = NULL; | 124 | mu_stream_t stream = NULL; |
125 | 125 | ||
126 | mu_mailbox_get_message (mbox, j, &msg); | 126 | mu_mailbox_get_message (mbox, j, &msg); |
127 | mu_message_get_stream (msg, &stream); | 127 | mu_message_get_streamref (msg, &stream); |
128 | mu_stream_seek (stream, 0, MU_SEEK_SET, NULL); | ||
129 | while (mu_stream_readline (stream, buf, sizeof buf, &len) == 0 | 128 | while (mu_stream_readline (stream, buf, sizeof buf, &len) == 0 |
130 | && len > 0) | 129 | && len > 0) |
131 | { | 130 | { | ... | ... |
... | @@ -211,14 +211,15 @@ print_header (mu_message_t message, int unix_header, int weedc, char **weedv) | ... | @@ -211,14 +211,15 @@ print_header (mu_message_t message, int unix_header, int weedc, char **weedv) |
211 | size_t len = 0; | 211 | size_t len = 0; |
212 | char buf[128]; | 212 | char buf[128]; |
213 | 213 | ||
214 | mu_header_get_stream (header, &stream); | 214 | /* FIXME: Use mu_stream_copy */ |
215 | mu_stream_seek (stream, 0, MU_SEEK_SET, NULL); | 215 | mu_header_get_streamref (header, &stream); |
216 | while (mu_stream_read (stream, buf, sizeof (buf) - 1, &len) == 0 | 216 | while (mu_stream_read (stream, buf, sizeof (buf) - 1, &len) == 0 |
217 | && len != 0) | 217 | && len != 0) |
218 | { | 218 | { |
219 | buf[len] = '\0'; | 219 | buf[len] = '\0'; |
220 | printf ("%s", buf); | 220 | printf ("%s", buf); |
221 | } | 221 | } |
222 | mu_stream_destroy (&stream); | ||
222 | } | 223 | } |
223 | else | 224 | else |
224 | { | 225 | { |
... | @@ -264,7 +265,9 @@ print_body (mu_message_t message) | ... | @@ -264,7 +265,9 @@ print_body (mu_message_t message) |
264 | mu_stream_t stream = NULL; | 265 | mu_stream_t stream = NULL; |
265 | size_t len = 0; | 266 | size_t len = 0; |
266 | mu_message_get_body (message, &body); | 267 | mu_message_get_body (message, &body); |
267 | mu_body_get_stream (body, &stream); | 268 | |
269 | /* FIXME: Use mu_stream_copy */ | ||
270 | mu_body_get_streamref (body, &stream); | ||
268 | 271 | ||
269 | while (mu_stream_read (stream, buf, sizeof (buf) - 1, &len) == 0 | 272 | while (mu_stream_read (stream, buf, sizeof (buf) - 1, &len) == 0 |
270 | && len != 0) | 273 | && len != 0) |
... | @@ -272,6 +275,7 @@ print_body (mu_message_t message) | ... | @@ -272,6 +275,7 @@ print_body (mu_message_t message) |
272 | buf[len] = '\0'; | 275 | buf[len] = '\0'; |
273 | printf ("%s", buf); | 276 | printf ("%s", buf); |
274 | } | 277 | } |
278 | mu_stream_destroy (&stream); | ||
275 | } | 279 | } |
276 | 280 | ||
277 | int | 281 | int | ... | ... |
-
Please register or sign in to post a comment