summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-08-29 18:01:27 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2010-08-29 18:01:27 +0300
commitf4e67b5e949b324617b7c737d63455f0c0da1371 (patch)
treec9721a907069eb118896e484ef2e714bbb2ecc65
parentf1625c353026c160c8db18ac9a4bd3bd35df150c (diff)
downloadmailutils-f4e67b5e949b324617b7c737d63455f0c0da1371.tar.gz
mailutils-f4e67b5e949b324617b7c737d63455f0c0da1371.tar.bz2
amd, pop3d: bugfixes.
* mailbox/amd.c (amd_body_stream_readdelim): Fix the logic. * mailbox/message.c (_message_stream_seek): Fix seeks in backward direction. * pop3d/top.c: Fix output of the body.
-rw-r--r--mailbox/amd.c36
-rw-r--r--mailbox/message.c12
-rw-r--r--pop3d/top.c6
3 files changed, 28 insertions, 26 deletions
diff --git a/mailbox/amd.c b/mailbox/amd.c
index 6d1d85587..2b88ffce2 100644
--- a/mailbox/amd.c
+++ b/mailbox/amd.c
@@ -1648,7 +1648,6 @@ amd_body_stream_readdelim (mu_stream_t is, char *buffer, size_t buflen,
mu_body_t body = amdstr->body;
mu_message_t msg = mu_body_get_owner (body);
struct _amd_message *mhm = mu_message_get_owner (msg);
- size_t nread = 0;
int status = 0;
amd_pool_open (mhm);
@@ -1656,7 +1655,7 @@ amd_body_stream_readdelim (mu_stream_t is, char *buffer, size_t buflen,
if (buffer == NULL || buflen == 0)
{
if (pnread)
- *pnread = nread;
+ *pnread = 0;
return 0;
}
@@ -1669,27 +1668,22 @@ amd_body_stream_readdelim (mu_stream_t is, char *buffer, size_t buflen,
status = mu_stream_seek (mhm->stream, mhm->body_start + amdstr->off,
MU_SEEK_SET, NULL);
- if (status)
+ if (status == 0)
{
- buflen--;
- while (buflen)
- {
- size_t ln, rdsize;
+ size_t nread = 0;
+ size_t ln;
- ln = mhm->body_end - (mhm->body_start + amdstr->off);
- if (ln > 0)
- {
- rdsize = ((size_t)ln < buflen) ? (size_t)ln : buflen;
- status = mu_stream_readdelim (mhm->stream, buffer, rdsize,
- delim, &rdsize);
- amdstr->off += nread;
- nread += rdsize;
- if (status)
- break;
- buflen -= rdsize;
- buffer += rdsize;
- }
+ ln = mhm->body_end - (mhm->body_start + amdstr->off) + 1;
+ if (ln > 0)
+ {
+ size_t rdsize = ((size_t)ln < buflen) ? (size_t)ln : buflen;
+ status = mu_stream_readdelim (mhm->stream, buffer, rdsize,
+ delim, &nread);
+ amdstr->off += rdsize;
}
+
+ if (pnread)
+ *pnread = nread;
}
mu_monitor_unlock (mhm->amd->mailbox->monitor);
@@ -1697,8 +1691,6 @@ amd_body_stream_readdelim (mu_stream_t is, char *buffer, size_t buflen,
pthread_cleanup_pop (0);
#endif
- if (pnread)
- *pnread = nread;
return status;
}
diff --git a/mailbox/message.c b/mailbox/message.c
index 1d95c7185..8ac125871 100644
--- a/mailbox/message.c
+++ b/mailbox/message.c
@@ -182,7 +182,17 @@ _message_stream_seek (struct _mu_stream *str, mu_off_t off, mu_off_t *ppos)
return rc;
/* fall through */
case _mss_body:
- off -= hsize;
+ if (off > hsize)
+ off -= hsize;
+ else
+ {
+ mu_stream_destroy (&sp->transport);
+ sp->state = _mss_init;
+ rc = _check_stream_state (sp);
+ if (rc)
+ return rc;
+ }
+
break;
default:
diff --git a/pop3d/top.c b/pop3d/top.c
index bab0583ac..73d6a272d 100644
--- a/pop3d/top.c
+++ b/pop3d/top.c
@@ -71,13 +71,13 @@ pop3d_top (char *arg)
{
char *buf = NULL;
size_t size = 0, n;
- while (lines > 0 &&
+ for (; lines > 0 &&
mu_stream_getline (stream, &buf, &size, &n) == 0 &&
- n > 0)
+ n > 0; lines--)
{
if (buf[0] == '.')
pop3d_outf (".");
- pop3d_outf ("%s\n", buf);
+ pop3d_outf ("%s", buf);
}
mu_stream_destroy (&stream);
free (buf);

Return to:

Send suggestions and report system problems to the System administrator.