Commit 0b549877 0b5498778bdd187f62657e29a9a37f6b39282e2b by Alain Magloire

See Changelog for the gory details.

1 parent 2f13ebfe
2001-04-13 Alain Magloire
* mailbox/folder_imap.c: When calling imap_writeline () the
cookie for the tag should be unsigned %d --> %u.
(imap_send) : The number of bytes in memmove was wrong.
* mailbox/mbx_imap.c: Some duplicate degug calls MAILBOX_DEBUG0()
removed.
(attribute_string): IMAP does not have a \\Read flag it should be
the same as \\Seen so attribute_read() == attribute_seen().
(flag_string): New function.
(imap_attr_set_flags): Use flag_string(), instead.
* mailbox/include/imap0.h: CLEAR_STATE() should also deselect
the current mailbox.
* mailbox/mbx_pop.c (pop_write): The number of bytes in the memmove
was wrong.
* lib/vasprintf.c: Taken from libit.
* configure.in: AC_REP_FUNC(vasprintf).
2001-04-13 Sam Roberts
QNX needed to include <strings.h> for many of the useful string
functions also to define _QNX_SOURCE so <sys/time.h> doesn't have
an internal warning.
* configure.in: Check for libgen.h.
* imap4d/imap4d.h: Define __QNX_SOURCE.
* mailbox/mime.c: wasn't including config.h
* mailbox/attachment.c: QNX needed libgen.h for basename(),
include <strings.h> if define.
* mailbox/filter.c: Include <strings.h>.
* mailbox/mbx_mbox.c: Include <strings.h>.
* mailbox/folder_imap.c: Include <strings.h>.
* mailbox/header.c: Include <strings.h>.
* mailbox/property.c: Include <strings.h>.
* mailbox/registrar.c: Include <strings.h>.
* mailbox/url.c: Include <strings.h>.
* mailbox/url_pop.c: Include <strings.h>.
* pop3d/user.c: QNX says getspnam(char* n), I cast away the error.
2001-04-13 Sam Roberts
* mailbox/parse822.c, include/mailutils/parse822.h: now can
......
......@@ -46,7 +46,7 @@ dnl Check for headers
AC_HEADER_STDC
AC_HEADER_DIRENT
AM_C_PROTOTYPES
AC_CHECK_HEADERS(errno.h fcntl.h inttypes.h limits.h malloc.h \
AC_CHECK_HEADERS(errno.h fcntl.h inttypes.h libgen.h limits.h malloc.h \
paths.h shadow.h stdio.h stdlib.h string.h strings.h sys/file.h syslog.h \
unistd.h)
......@@ -68,7 +68,7 @@ AC_FUNC_ALLOCA
AC_FUNC_MMAP
# FIXME: Provide the GNU one for loosing platforms
AC_FUNC_FNMATCH
AC_REPLACE_FUNCS(snprintf strtok_r)
AC_REPLACE_FUNCS(snprintf strtok_r vasprintf)
AC_CHECK_FUNCS(mkstemp)
dnl Check for libraries
......
......@@ -22,6 +22,7 @@
#include <config.h>
#endif
#define _QNX_SOURCE
#define _GNU_SOURCE
#ifdef HAVE_SHADOW_H
......@@ -42,6 +43,9 @@
#include <stdarg.h>
#include <sys/time.h>
#include <sys/stat.h>
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <mailutils/mailbox.h>
#include <mailutils/message.h>
......
......@@ -26,6 +26,14 @@
#include <unistd.h>
#include <ctype.h>
#ifdef HAVE_LIBGEN_H
# include <libgen.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <mailutils/message.h>
#include <mailutils/filter.h>
#include <mailutils/stream.h>
......
......@@ -23,6 +23,10 @@
#include <string.h>
#include <errno.h>
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <attribute0.h>
static int flags_to_string __P ((int, char *, size_t, size_t *));
......
......@@ -28,6 +28,10 @@ First draft: Alain Magloire.
#include <string.h>
#include <stdlib.h>
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <filter0.h>
#include <mailutils/iterator.h>
......
......@@ -27,6 +27,10 @@
#include <assert.h>
#include <fnmatch.h>
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <imap0.h>
/* Variable use for the registrar. */
......@@ -160,7 +164,7 @@ imap_user (authority_t auth)
{
CHECK_ERROR_CLOSE (folder, f_imap, EINVAL);
}
status = imap_writeline (f_imap, "g%d LOGIN %s %s\r\n",
status = imap_writeline (f_imap, "g%u LOGIN %s %s\r\n",
f_imap->seq++, f_imap->user, f_imap->passwd);
CHECK_ERROR_CLOSE(folder, f_imap, status);
FOLDER_DEBUG1 (folder, MU_DEBUG_PROT, "LOGIN %s *\n", f_imap->user);
......@@ -352,7 +356,7 @@ folder_imap_close (folder_t folder)
switch (f_imap->state)
{
case IMAP_NO_STATE:
status = imap_writeline (f_imap, "g%d LOGOUT\r\n", f_imap->seq++);
status = imap_writeline (f_imap, "g%u LOGOUT\r\n", f_imap->seq++);
CHECK_ERROR (f_imap, status);
FOLDER_DEBUG0 (folder, MU_DEBUG_PROT, f_imap->buffer);
f_imap->state = IMAP_LOGOUT;
......@@ -375,6 +379,7 @@ folder_imap_close (folder_t folder)
break;
}
f_imap->state = IMAP_NO_STATE;
f_imap->selected = NULL;
return 0;
}
......@@ -398,7 +403,7 @@ folder_imap_create (folder_t folder)
if (path == NULL)
return ENOMEM;
url_get_path (folder->url, path, len + 1, NULL);
status = imap_writeline (f_imap, "g%d CREATE %s\r\n", f_imap->seq++,
status = imap_writeline (f_imap, "g%u CREATE %s\r\n", f_imap->seq++,
path);
free (path);
CHECK_ERROR (f_imap, status);
......@@ -435,7 +440,7 @@ folder_imap_delete (folder_t folder, const char *name)
switch (f_imap->state)
{
case IMAP_NO_STATE:
status = imap_writeline (f_imap, "g%d DELETE %s\r\n", f_imap->seq++,
status = imap_writeline (f_imap, "g%u DELETE %s\r\n", f_imap->seq++,
name);
CHECK_ERROR (f_imap, status);
FOLDER_DEBUG0 (folder, MU_DEBUG_PROT, f_imap->buffer);
......@@ -552,7 +557,7 @@ folder_imap_list (folder_t folder, const char *ref, const char *name,
switch (f_imap->state)
{
case IMAP_NO_STATE:
status = imap_writeline (f_imap, "g%d LIST \"%s\" \"%s\"\r\n",
status = imap_writeline (f_imap, "g%u LIST \"%s\" \"%s\"\r\n",
f_imap->seq++, ref, path);
free (path);
CHECK_ERROR (f_imap, status);
......@@ -626,7 +631,7 @@ folder_imap_lsub (folder_t folder, const char *ref, const char *name,
switch (f_imap->state)
{
case IMAP_NO_STATE:
status = imap_writeline (f_imap, "g%d LSUB \"%s\" \"%s\"\r\n",
status = imap_writeline (f_imap, "g%u LSUB \"%s\" \"%s\"\r\n",
f_imap->seq++, ref, name);
CHECK_ERROR (f_imap, status);
FOLDER_DEBUG0 (folder, MU_DEBUG_PROT, f_imap->buffer);
......@@ -691,7 +696,7 @@ folder_imap_rename (folder_t folder, const char *oldpath, const char *newpath)
switch (f_imap->state)
{
case IMAP_NO_STATE:
status = imap_writeline (f_imap, "g%d RENAME %s %s\r\n",
status = imap_writeline (f_imap, "g%u RENAME %s %s\r\n",
f_imap->seq++, oldpath, newpath);
CHECK_ERROR (f_imap, status);
FOLDER_DEBUG0 (folder, MU_DEBUG_PROT, f_imap->buffer);
......@@ -725,7 +730,7 @@ folder_imap_subscribe (folder_t folder, const char *name)
switch (f_imap->state)
{
case IMAP_NO_STATE:
status = imap_writeline (f_imap, "g%d SUBSCRIBE %s\r\n",
status = imap_writeline (f_imap, "g%u SUBSCRIBE %s\r\n",
f_imap->seq++, name);
CHECK_ERROR (f_imap, status);
FOLDER_DEBUG0 (folder, MU_DEBUG_PROT, f_imap->buffer);
......@@ -759,7 +764,7 @@ folder_imap_unsubscribe (folder_t folder, const char *name)
switch (f_imap->state)
{
case IMAP_NO_STATE:
status = imap_writeline (f_imap, "g%d UNSUBSCRIBE %s\r\n",
status = imap_writeline (f_imap, "g%u UNSUBSCRIBE %s\r\n",
f_imap->seq++, name);
CHECK_ERROR (f_imap, status);
FOLDER_DEBUG0 (folder, MU_DEBUG_PROT, f_imap->buffer);
......@@ -1035,7 +1040,7 @@ section_name (msg_imap_t msg_imap)
char *tmp;
char part[64];
size_t partlen;
snprintf (part, sizeof (partlen), "%d", msg_imap->part);
snprintf (part, sizeof (partlen), "%u", msg_imap->part);
partlen = strlen (part);
tmp = realloc (section, sectionlen + partlen + 2);
if (tmp == NULL)
......@@ -1582,19 +1587,18 @@ imap_send (f_imap_t f_imap)
if (f_imap->ptr > f_imap->buffer)
{
size_t len;
size_t n = 0;
len = f_imap->ptr - f_imap->buffer;
status = stream_write (f_imap->folder->stream, f_imap->buffer, len,
0, &len);
0, &n);
if (status == 0)
{
memmove (f_imap->buffer, f_imap->buffer + len, len);
f_imap->ptr -= len;
memmove (f_imap->buffer, f_imap->buffer + n, len - n);
f_imap->ptr -= n;
}
}
else
{
f_imap->ptr = f_imap->buffer;
}
f_imap->ptr = f_imap->buffer;
return status;
}
......@@ -1895,6 +1899,7 @@ imap_parse (f_imap_t f_imap)
done = 1;
monitor_wrlock (f_imap->folder->monitor);
f_imap->isopen = 0;
f_imap->selected = NULL;
monitor_unlock (f_imap->folder->monitor);
stream_close (f_imap->folder->stream);
}
......
......@@ -25,6 +25,10 @@
#include <stdio.h>
#include <errno.h>
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <mailutils/stream.h>
#include <header0.h>
......
......@@ -39,7 +39,7 @@ extern "C" {
#endif /*__P */
#define CLEAR_STATE(f_imap) \
f_imap->id = 0, f_imap->func = NULL, f_imap->state = IMAP_NO_STATE
f_imap->selected = NULL, f_imap->id = 0, f_imap->func = NULL, f_imap->state = IMAP_NO_STATE
/* Clear the state and close the stream. */
#define CHECK_ERROR_CLOSE(folder, f_imap, status) \
......
......@@ -235,7 +235,6 @@ mailbox_imap_close (mailbox_t mailbox)
case IMAP_CLOSE:
status = imap_send (f_imap);
CHECK_EAGAIN (f_imap, status);
MAILBOX_DEBUG0 (mailbox, MU_DEBUG_PROT, f_imap->buffer);
f_imap->state = IMAP_CLOSE_ACK;
case IMAP_CLOSE_ACK:
......@@ -507,7 +506,6 @@ imap_messages_count (mailbox_t mailbox, size_t *pnum)
case IMAP_SELECT:
status = imap_send (f_imap);
CHECK_EAGAIN (f_imap, status);
MAILBOX_DEBUG0 (mailbox, MU_DEBUG_PROT, f_imap->buffer);
if (status != 0)
f_imap->selected = NULL;
f_imap->state = IMAP_SELECT_ACK;
......@@ -667,7 +665,7 @@ attribute_string (attribute_t attribute, char **pbuf)
strcat (abuf, " ");
strcat (abuf, "\\Deleted");
}
if (attribute_is_seen (attribute))
if (attribute_is_seen (attribute) || attribute_is_read (attribute))
{
char *tmp = realloc (abuf, strlen (abuf) + strlen ("\\Seen") + 2);
if (tmp == NULL)
......@@ -814,7 +812,6 @@ imap_append_message (mailbox_t mailbox, message_t msg)
case IMAP_APPEND:
status = imap_send (f_imap);
CHECK_EAGAIN (f_imap, status);
MAILBOX_DEBUG0 (m_imap->mailbox, MU_DEBUG_PROT, f_imap->buffer);
f_imap->state = IMAP_APPEND_CONT;
case IMAP_APPEND_CONT:
......@@ -905,7 +902,6 @@ imap_copy_message (mailbox_t mailbox, message_t msg)
case IMAP_COPY:
status = imap_send (f_imap);
CHECK_EAGAIN (f_imap, status);
MAILBOX_DEBUG0 (mailbox, MU_DEBUG_PROT, f_imap->buffer);
f_imap->state = IMAP_COPY_ACK;
case IMAP_COPY_ACK:
......@@ -1325,7 +1321,80 @@ imap_attr_get_flags (attribute_t attribute, int *pflags)
}
static int
imap_attr_set_flags (attribute_t attribute, int flags)
flags_string (int flag, char **pbuf)
{
char *abuf = *pbuf;
if (flag & MU_ATTRIBUTE_DELETED)
{
char *tmp = realloc (abuf, strlen (abuf) + strlen ("\\Deleted") + 2);
if (tmp == NULL)
{
free (abuf);
return ENOMEM;
}
abuf = tmp;
if (*abuf)
strcat (abuf, " ");
strcat (abuf, "\\Deleted");
}
if ((flag & MU_ATTRIBUTE_SEEN) || (flag & MU_ATTRIBUTE_READ))
{
char *tmp = realloc (abuf, strlen (abuf) + strlen ("\\Seen") + 2);
if (tmp == NULL)
{
free (abuf);
return ENOMEM;
}
abuf = tmp;
if (*abuf)
strcat (abuf, " ");
strcat (abuf, "\\Seen");
}
if (flag & MU_ATTRIBUTE_ANSWERED)
{
char *tmp = realloc (abuf, strlen (abuf) + strlen ("\\Answered") + 2);
if (tmp == NULL)
{
free (abuf);
return ENOMEM;
}
abuf = tmp;
if (*abuf)
strcat (abuf, " ");
strcat (abuf, "\\Answered");
}
if (flag & MU_ATTRIBUTE_DRAFT)
{
char *tmp = realloc (abuf, strlen (abuf) + strlen ("\\Draft") + 2);
if (tmp == NULL)
{
free (abuf);
return ENOMEM;
}
abuf = tmp;
if (*abuf)
strcat (abuf, " ");
strcat (abuf, "\\Draft");
}
if (flag & MU_ATTRIBUTE_FLAGGED)
{
char *tmp = realloc (abuf, strlen (abuf) + strlen ("\\Flagged") + 2);
if (tmp == NULL)
{
free (abuf);
return ENOMEM;
}
abuf = tmp;
if (*abuf)
strcat (abuf, " ");
strcat (abuf, "\\Flagged");
}
*pbuf = abuf;
return 0;
}
static int
imap_attr_set_flags (attribute_t attribute, int flag)
{
message_t msg = attribute_get_owner (attribute);
msg_imap_t msg_imap = message_get_owner (msg);
......@@ -1336,15 +1405,21 @@ imap_attr_set_flags (attribute_t attribute, int flags)
/* The delete FLAG is not pass yet but only on the expunge. */
if (f_imap->state == IMAP_NO_STATE)
{
status = imap_writeline (f_imap, "g%d STORE %d +FLAGS.SILENT (%s %s %s %s)\r\n",
f_imap->seq++, msg_imap->num,
(flags & MU_ATTRIBUTE_ANSWERED) ? "\\Answered" : "",
(flags & MU_ATTRIBUTE_SEEN) ? "\\Seen" : "",
(flags & MU_ATTRIBUTE_DRAFT) ? "\\Draft" : "",
(flags & MU_ATTRIBUTE_FLAGGED) ? "\\Flagged" : "");
char *abuf = malloc (1);
if (abuf == NULL)
return ENOMEM;
*abuf = '\0';
status = flags_string (flag, &abuf);
if (status != 0)
return status;
/* No flags to send?? */
if (*abuf == '\0')
return 0;
status = imap_writeline (f_imap, "g%d STORE %d +FLAGS.SILENT (%s)\r\n",
f_imap->seq++, msg_imap->num, abuf);
CHECK_ERROR (f_imap, status);
MAILBOX_DEBUG0 (m_imap->mailbox, MU_DEBUG_PROT, f_imap->buffer);
msg_imap->flags |= flags;
msg_imap->flags |= flag;
f_imap->state = IMAP_FETCH;
}
return message_operation (f_imap, msg_imap, NULL, 0, NULL);
......
......@@ -37,6 +37,9 @@
# define _XOPEN_SOURCE 500
# include <pthread.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <mailutils/message.h>
#include <mailutils/stream.h>
......
......@@ -27,6 +27,9 @@
#include <unistd.h>
#include <fcntl.h>
#include <stdarg.h>
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <mailutils/stream.h>
#include <mailutils/body.h>
......@@ -1773,12 +1776,13 @@ pop_write (pop_data_t mpd)
if (mpd->ptr > mpd->buffer)
{
size_t len;
size_t n = 0;
len = mpd->ptr - mpd->buffer;
status = stream_write (mpd->mbox->stream, mpd->buffer, len, 0, &len);
status = stream_write (mpd->mbox->stream, mpd->buffer, len, 0, &n);
if (status == 0)
{
memmove (mpd->buffer, mpd->buffer + len, len);
mpd->ptr -= len;
memmove (mpd->buffer, mpd->buffer + n, len - n);
mpd->ptr -= n;
}
}
else
......
......@@ -16,6 +16,10 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
......@@ -23,6 +27,9 @@
#include <ctype.h>
#include <time.h>
#include <unistd.h>
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <mailutils/message.h>
#include <mailutils/stream.h>
......
......@@ -18,6 +18,9 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <property0.h>
......
......@@ -22,6 +22,9 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <mailutils/iterator.h>
#include <mailutils/monitor.h>
......
......@@ -22,6 +22,9 @@
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <mailutils/registrar.h>
#include <misc.h>
......
......@@ -23,6 +23,9 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <registrar0.h>
#include <url0.h>
......
......@@ -23,6 +23,9 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <url0.h>
#include <registrar0.h>
......
......@@ -73,6 +73,7 @@
#define BUFFERSIZE 1024
#define _GNU_SOURCE
#define _QNX_SOURCE
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
......@@ -96,6 +97,9 @@
#include <ctype.h>
#include "md5.h"
#include "getopt.h"
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <mailutils/mailbox.h>
#include <mailutils/message.h>
......
......@@ -142,7 +142,7 @@ pop3_user (const char *arg)
{
#ifdef HAVE_SHADOW_H
struct spwd *spw;
spw = getspnam (arg);
spw = getspnam ((char *)arg);
if (spw == NULL || strcmp (spw->sp_pwdp, crypt (pass, spw->sp_pwdp)))
#endif /* HAVE_SHADOW_H */
return ERR_BAD_LOGIN;
......