Commit b845fd2c b845fd2c1d962390dbe0ae9241a2322dc29ce0f7 by Alain Magloire

* mailbox/body.c: body_lines () nd body_size () were not

	properly overriden given the wrong size and line number, fixed.
	* mailbox/mbx_imap.c (mailbox_imap_close): Not to send another SELECT
	but rather just close the mailbox if not selected.
	(imap_scan0): If there is no messages in the mailbox no need to
	send the FETCH 1:*.
	* mailbox/message.c (message_is_modified): Protect against null
	pointer.

	* TODO: Some stuff todo 8).
1 parent e9091575
2001-10-23 Alain Magloire
* mailbox/body.c: body_lines () nd body_size () were not
properly overriden given the wrong size and line number, fixed.
* mailbox/mbx_imap.c (mailbox_imap_close): Not to send another SELECT
but rather just close the mailbox if not selected.
(imap_scan0): If there is no messages in the mailbox no need to
send the FETCH 1:*.
* mailbox/message.c (message_is_modified): Protect against null
pointer.
* TODO: Some stuff todo 8).
2001-10-23 Sergey Poznyakoff
* mailbox/mutil.c: New function mu_get_user_email.
......@@ -23,7 +36,7 @@
of hardcoded ones.
* mh/inc.c: Do not call mh_init() explicitly.
* mh/scan.c: Likewise.
2001-10-22 Jeff Bailey <jbailey@outpost.dnsalias.org>
* doc/texinfo/Makefile.am: Remove version.texi, it's implied.
......
......@@ -23,10 +23,14 @@ IMPORTANT:
+ crypt is linked even if pam was detected, it should be one or the other (JB Oct 08/99)
- SSL support
[imap4d]
- Check interaction with imap clients.
- Better support of multi-access mailbox
- implement charsets in search: 1 SEARCH CHARSET ISO-8859-2 TEXT ...
- implement AUTHENTICATE command (at least kerberos?)
......@@ -35,6 +39,22 @@ IMPORTANT:
- Add MIME support.
[mailbox]
- finish rewrite 8-)
- Configuration API
- Mailcap API
- Mime.types API
- imap4 client login referals
- imap4 client mailbox referals
- Maildir mailbox support
[sieve]
- bug: imap_fetch() can loop forever when sieve tries fileinto (sr - seen
......
......@@ -31,14 +31,17 @@
#include <mailutils/stream.h>
#include <body0.h>
static int lazy_create __P ((body_t));
static int _body_flush __P ((stream_t));
static int _body_get_fd __P ((stream_t, int *));
static int _body_read __P ((stream_t, char *, size_t, off_t, size_t *));
static int lazy_create __P ((body_t));
static int _body_flush __P ((stream_t));
static int _body_get_fd __P ((stream_t, int *));
static int _body_read __P ((stream_t, char *, size_t, off_t, size_t *));
static int _body_readline __P ((stream_t, char *, size_t, off_t, size_t *));
static int _body_write __P ((stream_t, const char *, size_t, off_t, size_t *));
static int _body_truncate __P ((stream_t, off_t));
static int _body_size __P ((stream_t, off_t *));
static int _body_size __P ((stream_t, off_t *));
static int _body_lines __P ((stream_t, size_t *));
static int _body_write __P ((stream_t, const char *, size_t, off_t, size_t *));
static int _body_get_size __P ((body_t, size_t *));
static int _body_get_lines __P ((body_t, size_t *));
int
body_create (body_t *pbody, void *owner)
......@@ -158,6 +161,9 @@ body_get_stream (body_t body, stream_t *pstream)
stream_set_truncate (body->stream, _body_truncate, body);
stream_set_size (body->stream, _body_size, body);
stream_set_flush (body->stream, _body_flush, body);
/* Override the defaults. */
body->_lines = _body_get_lines;
body->_size = _body_get_size;
}
*pstream = body->stream;
return 0;
......@@ -202,39 +208,13 @@ body_lines (body_t body, size_t *plines)
int
body_size (body_t body, size_t *psize)
{
int status = 0;
if (body == NULL)
return EINVAL;
/* Check to see if they want to doit themselves,
* it was probably not a floating message */
if (body->_size)
return body->_size (body, psize);
/* ok we should handle this */
if (body->stream)
{
off_t off = 0;
status = stream_size (body->stream, &off);
if (status == 0)
if (psize)
*psize = off;
}
else if (body->filename)
{
struct stat st;
if (stat (body->filename, &st) == 0)
{
if (psize)
*psize = st.st_size;
}
else
status = errno;
}
else if (psize)
if (psize)
*psize = 0;
return status;
return 0;
}
int
......@@ -297,6 +277,39 @@ _body_flush (stream_t stream)
return stream_flush (body->fstream);
}
static int
_body_get_size (body_t body, size_t *plines)
{
off_t off = 0;
int status = _body_size (body->stream, &off);
if (plines)
*plines = off;
return status;
}
static int
_body_get_lines (body_t body, size_t *plines)
{
int status = stream_flush (body->fstream);
size_t lines = 0;
if (status == 0)
{
char buf[128];
size_t n = 0;
off_t off = 0;
while ((status = stream_readline (body->fstream, buf, sizeof buf,
off, &n)) == 0 && n > 0)
{
if (buf[n - 1] == '\n')
lines++;
off += n;
}
}
if (plines)
*plines = lines;
return status;
}
#ifndef P_tmpdir
# define P_tmpdir "/tmp"
#endif
......
......@@ -233,6 +233,10 @@ mailbox_imap_close (mailbox_t mailbox)
f_imap_t f_imap = m_imap->f_imap;
int status = 0;
/* If we are not the selected mailbox, just close the stream. */
if (m_imap != f_imap->selected)
return folder_close (mailbox->folder);
/* Select first. */
status = imap_messages_count (mailbox, NULL);
if (status != 0)
......@@ -582,6 +586,10 @@ imap_scan0 (mailbox_t mailbox, size_t msgno, size_t *pcount, int notif)
if (status != 0)
return status;
/* No need to scan, there is no messages. */
if (count == 0)
return 0;
switch (f_imap->state)
{
case IMAP_NO_STATE:
......@@ -792,18 +800,18 @@ imap_append_message (mailbox_t mailbox, message_t msg)
status = flags_to_string (&abuf, flags);
if (status != 0)
return status;
if (*abuf != '\0')
{
char *tmp = calloc (strlen (abuf) + 3, 1);
if (tmp == NULL)
{
free (abuf);
return ENOMEM;
}
sprintf (tmp, "(%s)", abuf);
free (abuf);
abuf = tmp;
}
/* Put the surrounding parenthesis, wu-IMAP is sensible to this. */
{
char *tmp = calloc (strlen (abuf) + 3, 1);
if (tmp == NULL)
{
free (abuf);
return ENOMEM;
}
sprintf (tmp, "(%s)", abuf);
free (abuf);
abuf = tmp;
}
}
/* Get the mailbox filepath. */
......
......@@ -163,9 +163,12 @@ int
message_is_modified (message_t msg)
{
int mod = 0;
mod |= header_is_modified (msg->header);
mod |= attribute_is_modified (msg->attribute);
mod |= body_is_modified (msg->body);
if (msg)
{
mod |= header_is_modified (msg->header);
mod |= attribute_is_modified (msg->attribute);
mod |= body_is_modified (msg->body);
}
return mod;
}
......
......@@ -30,6 +30,7 @@
#include <unistd.h>
#include <string.h>
#include <netdb.h>
#include <errno.h>
#include <mailutils/mutil.h>
#include <mailutils/iterator.h>
......@@ -414,7 +415,7 @@ mu_get_user_email (char *name)
struct hostent *hp;
char *domainpart;
char *email;
if (!name)
{
struct passwd *pw = getpwuid (getuid ());
......
......@@ -78,16 +78,18 @@ struct work_buf
char *ptr;
char *nl;
size_t len;
off_t offset; /* To synchronise with the buffering. */
};
/* Structure to hold things general to POP3 mailbox, like its state, etc ... */
struct _pop3
{
/* Working I/O buffers. */
/* Working I/O buffer. */
/* io.buf: Working io buffer. */
/* io.ptr: Points to the end of the buffer, the non consume chars. */
/* io.nl: Points to the '\n' char in the string. */
/* io.len: Len of io_buf. */
/* io.offset; full the stream_t implementation. */
struct work_buf io;
/* Holds the first line response of the last command, i.e the ACK. */
......@@ -102,7 +104,6 @@ struct _pop3
enum pop3_state state;
stream_t carrier; /* TCP Connection. */
off_t offset; /* To synchronise with the buffering. */
mu_debug_t debug; /* Send the debug info. */
};
......
......@@ -50,10 +50,10 @@ pop3_getline (pop3_t pop3)
}
status = stream_readline (pop3->carrier, pop3->io.buf + total,
pop3->io.len - total, pop3->offset, &n);
pop3->io.len - total, pop3->io.offset, &n);
if (status != 0)
return status;
pop3->offset += n;
pop3->io.offset += n;
/* The server went away: It maybe a timeout and some pop server
does not send the -ERR. Consider this like an error. */
......