Commit 3fefeaa4 3fefeaa458075ca20381284950b32f6afdccfffe by Sergey Poznyakoff

Bugfixes.

* mailbox/rfc2047.c (mu_rfc2047_decode): Rewind in_stream.
* mailbox/stream.c (_stream_scandelim): Break the loop when
the delimiter is found.
* mailbox/streamref.c (_streamref_readdelim): Take into account
the abridgement.
1 parent f96ce94e
...@@ -163,6 +163,7 @@ mu_rfc2047_decode (const char *tocode, const char *input, char **ptostr) ...@@ -163,6 +163,7 @@ mu_rfc2047_decode (const char *tocode, const char *input, char **ptostr)
163 163
164 mu_memory_stream_create (&in_stream, 0); 164 mu_memory_stream_create (&in_stream, 0);
165 mu_stream_write (in_stream, encoded_text, size, NULL); 165 mu_stream_write (in_stream, encoded_text, size, NULL);
166 mu_stream_seek (in_stream, 0, MU_SEEK_SET, NULL);
166 status = mu_decode_filter (&filter, in_stream, filter_type, fromcode, 167 status = mu_decode_filter (&filter, in_stream, filter_type, fromcode,
167 tocode); 168 tocode);
168 if (status != 0) 169 if (status != 0)
......
...@@ -563,6 +563,8 @@ _stream_scandelim (mu_stream_t stream, char *buf, size_t size, int delim, ...@@ -563,6 +563,8 @@ _stream_scandelim (mu_stream_t stream, char *buf, size_t size, int delim,
563 buf += len; 563 buf += len;
564 size -= len; 564 size -= len;
565 nread += len; 565 nread += len;
566 if (p) /* Delimiter found */
567 break;
566 } 568 }
567 *buf = 0; 569 *buf = 0;
568 *pnread = nread; 570 *pnread = nread;
......
...@@ -73,9 +73,33 @@ _streamref_readdelim (struct _mu_stream *str, char *buf, size_t bufsize, ...@@ -73,9 +73,33 @@ _streamref_readdelim (struct _mu_stream *str, char *buf, size_t bufsize,
73 int delim, size_t *pnread) 73 int delim, size_t *pnread)
74 { 74 {
75 struct _mu_streamref *sp = (struct _mu_streamref *)str; 75 struct _mu_streamref *sp = (struct _mu_streamref *)str;
76 return streamref_return (sp, mu_stream_readdelim (sp->transport, 76 int rc;
77 buf, bufsize, 77 size_t nread;
78 delim, pnread)); 78 mu_off_t off;
79
80 rc = mu_stream_seek (sp->transport, sp->offset, MU_SEEK_SET, &off);
81 if (rc == 0)
82 {
83 if (sp->end)
84 {
85 size_t size = sp->end - off + 2; /* extra 1 to account for \0 */
86 if (size < bufsize)
87 bufsize = size;
88 }
89 rc = mu_stream_readdelim (sp->transport, buf, bufsize, delim, &nread);
90 if (rc == 0)
91 {
92 sp->offset += nread;
93 *pnread = nread;
94 }
95 }
96 else if (rc == ESPIPE)
97 {
98 *pnread = 0;
99 mu_stream_clearerr (sp->transport);
100 return 0;
101 }
102 return streamref_return (sp, rc);
79 } 103 }
80 104
81 static int 105 static int
......