Commit 8b262f17 8b262f172f15fb5afa3cb73b7c619650ee5d556f by Alain Magloire

* configure.in: AC_REPLACE_FUNCS(fgetpwent);

	* include/mailutils/parse822.h: Add a prototype for
	parse822_skip_nl().

	* lib/Makefile.am: add fgetpwent.c
	* lib/fgetpwent.c: New file.

	* mail/from.c (mail_from): Use the cover functions
	attribute_is_xxxx() instead of getting the flag.

	* mailbox/attribute.c: Cleanup the mess.
	attribute_set_{read,delete,seen,flagged,answered}.
	attribute_unset_{read,delete,seen,flagged,answered}.
	attribute_is_{read,delete,seen,flagged,answered}
	should be no more then cover functions calling
	attribute_set_flags(), attribute_get_flags() and
	attribute_unset_flags().

	* mailbox/folder_imap.c: MU_ATTRIBUTE_READ, is not
	part of IMAP protocol use \\Seen.
	* mailbox/mbx_imap.c: Remove the hack trying to reconnect,
	it does not work.

	* mailbox/mbx_pop.c(pop_get_messages): Set the new
	functions for the attribute.
	(pop_get_attribute): New functions.
	(pop_set_attribute): New functions.
	(pop_unset_attribute): New functions.
	(pop_attr_flags): Removed.

	* mutil.c (mu_hex2ul): GNU coding std.
	(parse822_time): Do not use tzname as a variable name tzname
	is global variable in libc, better clear away.
	(parse822_date_time): Likewised.

	* pop3d/Makefile.am: add virtual.c
	* pop3d/pop3d.c (main): register getpwnam_ip_virtual,
	getpwnam_host_virtual
	* pop3d/pop3d.h: declare,
	getpwnam_ip_virtual(), getpwnam_host_virtual().
	* pop3d/virtual.c: New file.
1 parent 7191f1db
2001-09-03 Alain Magloire
* configure.in: AC_REPLACE_FUNCS(fgetpwent);
* include/mailutils/parse822.h: Add a prototype for
parse822_skip_nl().
* lib/Makefile.am: add fgetpwent.c
* lib/fgetpwent.c: New file.
* mail/from.c (mail_from): Use the cover functions
attribute_is_xxxx() instead of getting the flag.
* mailbox/attribute.c: Cleanup the mess.
attribute_set_{read,delete,seen,flagged,answered}.
attribute_unset_{read,delete,seen,flagged,answered}.
attribute_is_{read,delete,seen,flagged,answered}
should be no more then cover functions calling
attribute_set_flags(), attribute_get_flags() and
attribute_unset_flags().
* mailbox/folder_imap.c: MU_ATTRIBUTE_READ, is not
part of IMAP protocol use \\Seen.
* mailbox/mbx_imap.c: Remove the hack trying to reconnect,
it does not work.
* mailbox/mbx_pop.c(pop_get_messages): Set the new
functions for the attribute.
(pop_get_attribute): New functions.
(pop_set_attribute): New functions.
(pop_unset_attribute): New functions.
(pop_attr_flags): Removed.
* mutil.c (mu_hex2ul): GNU coding std.
(parse822_time): Do not use tzname as a variable name tzname
is global variable in libc, better clear away.
(parse822_date_time): Likewised.
* pop3d/Makefile.am: add virtual.c
* pop3d/pop3d.c (main): register getpwnam_ip_virtual,
getpwnam_host_virtual
* pop3d/pop3d.h: declare,
getpwnam_ip_virtual(), getpwnam_host_virtual().
* pop3d/virtual.c: New file.
2001-09-02 Alain Magloire
* mailbox/mutil.c (getpwma_virtual): Memory overrun, did not
......
......@@ -113,8 +113,8 @@ AC_FUNC_FNMATCH
if test "$ac_cv_func_fnmatch_works" = "no"; then
: LIBOBJS="$LIBOBJS fnmatch.o"
fi
AC_REPLACE_FUNCS(setenv snprintf strtok_r strncasecmp strcasecmp strsignal \
vasprintf)
AC_REPLACE_FUNCS(fgetpwent setenv snprintf strtok_r strncasecmp strcasecmp \
strsignal vasprintf)
AC_CHECK_FUNCS(mkstemp sigaction sysconf)
dnl Check for libraries
......
......@@ -60,6 +60,7 @@ extern int parse822_skip_crlf __P ((const char** p, const char* e));
extern int parse822_skip_lwsp_char __P ((const char** p, const char* e));
extern int parse822_skip_lwsp __P ((const char** p, const char* e));
extern int parse822_skip_comments __P ((const char** p, const char* e));
extern int parse822_skip_nl __P ((const char** p, const char* e));
extern int parse822_digits __P ((const char** p, const char* e, int min, int max, int* digits));
extern int parse822_special __P ((const char** p, const char* e, char c));
......@@ -104,7 +105,7 @@ extern int parse822_field_name __P ((const char** p, const char *e, char**
extern int parse822_day __P ((const char** p, const char* e, int* day));
extern int parse822_date __P ((const char** p, const char* e, int* day, int* mon, int* year));
extern int parse822_time __P ((const char** p, const char* e, int* h, int* m, int* s, int* tz, const char** tzname));
extern int parse822_time __P ((const char** p, const char* e, int* h, int* m, int* s, int* tz, const char** tz_name));
extern int parse822_date_time __P ((const char** p, const char* e, struct tm* tm, mu_timezone* tz));
......
......@@ -7,7 +7,8 @@ libmailutils_a_SOURCES = basename.c getopt.c getopt1.c md5.c getline.c \
xstrdup.c xmalloc.c argcv.c
EXTRA_DIST = alloca.c fnmatch.c setenv.c snprintf.c strchrnul.c strndup.c \
strnlen.c strtok_r.c strsignal.c xstrtol.c vasprintf.c malloc.c realloc.c
strnlen.c strtok_r.c strsignal.c xstrtol.c vasprintf.c malloc.c realloc.c \
fgetpwent.c
noinst_HEADERS = argcv.h error.h fnmatch.h getline.h getopt.h md5.h \
regex.h snprintf.h xalloc.h xstrtol.h
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Library Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <pwd.h>
#include <string.h>
#include <stdlib.h>
/*
Written by Alain Magloire.
Simple replacement for fgetpwent(), it is not :
- thread safe;
- static buffer was not use since it will limit the size
of the entry. But rather memory is allocated and __never__
release. The memory will grow if need be.
- no support for shadow
- no support for NIS(+)
*/
static char *buffer;
static size_t buflen;
static struct passwd pw;
static char *
parse_line (char *s, char **p)
{
if (*s)
{
char *sep = strchr (s, ':');
if (sep)
{
*sep++ = '\0';
*p = sep;
}
else
*p = s + strlen (s);
}
else
*p = s;
return s;
}
static struct passwd *
getentry (char *s)
{
char *p;
pw.pw_name = parse_line (s, &p);
s = p;
pw.pw_passwd = parse_line (s, &p);
s = p;
pw.pw_uid = strtoul (parse_line (s, &p), NULL, 10);
s = p;
pw.pw_gid = strtoul (parse_line (s, &p), NULL, 10);
s = p;
pw.pw_gecos = parse_line (s, &p);
s = p;
pw.pw_dir = parse_line (s, &p);
s = p;
pw.pw_shell = parse_line (s, &p);
return &pw;
}
struct passwd *
fgetpwent (FILE *fp)
{
size_t pos = 0;
int done = 0;
struct passwd *pw = NULL;
/* Allocate buffer if not yet available. */
/* This buffer will be never free(). */
if (buffer == NULL)
{
buflen = 1024;
buffer = malloc (buflen);
if (buffer == NULL)
return NULL;
}
do
{
if (fgets (buffer + pos, buflen, fp) != NULL)
{
/* Need a full line. */
if (buffer[strlen (buffer) - 1] == '\n')
{
/* reset marker position. */
pos = 0;
/* Nuke trailing newline. */
buffer[strlen (buffer) - 1] = '\0';
/* Skip comments. */
if (buffer[0] != '#')
{
done = 1;
pw = getentry (buffer);
}
}
else
{
/* Line is too long reallocate the buffer. */
char *tmp;
pos = strlen (buffer);
buflen *= 2;
tmp = realloc (buffer, buflen);
if (tmp)
buffer = tmp;
else
done = 1;
}
}
else
done = 1;
} while (!done);
return pw;
}
#ifdef STANDALONE
int
main ()
{
FILE *fp = fopen ("/etc/passwd", "r");
if (fp)
{
struct passwd *pwd;
while ((pwd = fgetpwent (fp)))
{
printf ("--------------------------------------\n");
printf ("name %s\n", pwd->pw_name);
printf ("passwd %s\n", pwd->pw_passwd);
printf ("uid %d\n", pwd->pw_uid);
printf ("gid %d\n", pwd->pw_gid);
printf ("gecos %s\n", pwd->pw_gecos);
printf ("dir %s\n", pwd->pw_dir);
printf ("shell %s\n", pwd->pw_shell);
}
}
return 0;
}
#endif
......@@ -36,7 +36,7 @@ mail_from (int argc, char **argv)
int froml, subjl;
char date[80], st[10];
int cols = util_getcols () - 6;
int flags, cflag;
int cflag;
size_t m_size = 0, m_lines = 0;
const char *p;
struct tm tm;
......@@ -78,7 +78,6 @@ mail_from (int argc, char **argv)
}
message_get_attribute (msg, &attr);
attribute_get_flags (attr, &flags);
if (attribute_is_userflag(attr, MAIL_ATTRIBUTE_MBOXED))
cflag = 'M';
......@@ -86,9 +85,9 @@ mail_from (int argc, char **argv)
cflag = '*';
else if (attribute_is_userflag(attr, MAIL_ATTRIBUTE_TAGGED))
cflag = 'T';
else if (flags & MU_ATTRIBUTE_READ)
else if (attribute_is_read (attr))
cflag = 'R';
else if (flags & MU_ATTRIBUTE_SEEN)
else if (attribute_is_seen (attr))
cflag = 'U';
else if (attribute_is_recent(attr))
cflag = 'N';
......
......@@ -42,5 +42,3 @@ mail_mbox (int argc, char **argv)
}
return 0;
}
......
......@@ -100,5 +100,3 @@ mail_print (int argc, char **argv)
}
return 1;
}
......
......@@ -47,4 +47,3 @@ mail_tag (int argc, char **argv)
msgset_free (msgset);
return 0;
}
......
......@@ -53,7 +53,7 @@ attribute_destroy (attribute_t *pattr, void *owner)
attribute_t attr = *pattr;
if (attr->owner == owner)
free (*pattr);
/* loose the link */
/* Loose the link */
*pattr = NULL;
}
}
......@@ -74,9 +74,6 @@ int
attribute_clear_modified (attribute_t attr)
{
if (!attr)
return 0;
if (attr->_unset_flags)
attr->_unset_flags (attr, MU_ATTRIBUTE_MODIFIED);
attr->flags &= ~MU_ATTRIBUTE_MODIFIED;
return 0;
}
......@@ -84,23 +81,18 @@ attribute_clear_modified (attribute_t attr)
int
attribute_set_modified (attribute_t attr)
{
int status;
if (!attr)
return EINVAL;
if (attr->_set_flags)
status = attr->_set_flags (attr, MU_ATTRIBUTE_MODIFIED);
attr->flags |= MU_ATTRIBUTE_MODIFIED;
return status;
return 0;
}
int
attribute_get_flags (attribute_t attr, int *pflags)
{
if (attr == NULL)
if (attr == NULL || pflags == NULL)
return EINVAL;
if (attr->_get_flags)
return attr->_get_flags (attr, pflags);
if (pflags)
*pflags = attr->flags;
return 0;
}
......@@ -108,22 +100,30 @@ attribute_get_flags (attribute_t attr, int *pflags)
int
attribute_set_flags (attribute_t attr, int flags)
{
int status = 0;
if (attr == NULL)
return EINVAL;
if (attr->_set_flags)
attr->_set_flags (attr, flags);
status = attr->_set_flags (attr, flags);
else
attr->flags |= flags;
if (status == 0)
attribute_set_modified (attr);
return 0;
}
int
attribute_unset_flags (attribute_t attr, int flags)
{
int status = 0;
if (attr == NULL)
return EINVAL;
if (attr->_unset_flags)
attr->_unset_flags (attr, flags);
status = attr->_unset_flags (attr, flags);
else
attr->flags &= ~flags;
if (status == 0)
attribute_set_modified (attr);
return 0;
}
......@@ -177,91 +177,45 @@ attribute_set_userflag (attribute_t attr, int flag)
int
attribute_set_seen (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return EINVAL;
if (attr->_set_flags)
status = attr->_set_flags (attr, MU_ATTRIBUTE_SEEN | MU_ATTRIBUTE_MODIFIED);
attr->flags |= MU_ATTRIBUTE_SEEN | MU_ATTRIBUTE_MODIFIED;
return status;
return attribute_set_flags (attr, MU_ATTRIBUTE_SEEN);
}
int
attribute_set_answered (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return EINVAL;
if (attr->_set_flags)
status = attr->_set_flags (attr, MU_ATTRIBUTE_ANSWERED | MU_ATTRIBUTE_MODIFIED);
attr->flags |= MU_ATTRIBUTE_ANSWERED | MU_ATTRIBUTE_MODIFIED;
return status;
return attribute_set_flags (attr, MU_ATTRIBUTE_ANSWERED);
}
int
attribute_set_flagged (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return EINVAL;
if (attr->_set_flags)
status = attr->_set_flags (attr, MU_ATTRIBUTE_FLAGGED | MU_ATTRIBUTE_MODIFIED);
attr->flags |= MU_ATTRIBUTE_FLAGGED | MU_ATTRIBUTE_MODIFIED;
return status;
return attribute_set_flags (attr, MU_ATTRIBUTE_FLAGGED);
}
int
attribute_set_read (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return EINVAL;
if (attr->_set_flags)
status = attr->_set_flags (attr, MU_ATTRIBUTE_READ | MU_ATTRIBUTE_MODIFIED);
attr->flags |= MU_ATTRIBUTE_READ | MU_ATTRIBUTE_MODIFIED;
return status;
return attribute_set_flags (attr, MU_ATTRIBUTE_READ);
}
int
attribute_set_deleted (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return EINVAL;
if (attr->_set_flags)
status = attr->_set_flags (attr, MU_ATTRIBUTE_DELETED | MU_ATTRIBUTE_MODIFIED);
attr->flags |= MU_ATTRIBUTE_DELETED | MU_ATTRIBUTE_MODIFIED;
return 0;
return attribute_set_flags (attr, MU_ATTRIBUTE_DELETED);
}
int
attribute_set_draft (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return EINVAL;
if (attr->_set_flags)
status = attr->_set_flags (attr, MU_ATTRIBUTE_DRAFT | MU_ATTRIBUTE_MODIFIED);
attr->flags |= MU_ATTRIBUTE_DRAFT | MU_ATTRIBUTE_MODIFIED;
return status;
return attribute_set_flags (attr, MU_ATTRIBUTE_DRAFT);
}
int
attribute_set_recent (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return EINVAL;
if (attr->_unset_flags)
{
status |= attr->_unset_flags (attr, MU_ATTRIBUTE_READ);
status |= attr->_unset_flags (attr, MU_ATTRIBUTE_SEEN);
}
if (attr == NULL)
{
attr->flags &= ~MU_ATTRIBUTE_READ;
attr->flags &= ~MU_ATTRIBUTE_SEEN;
}
int status = attribute_unset_flags (attr, MU_ATTRIBUTE_READ);
if (status == 0)
status = attribute_unset_flags (attr, MU_ATTRIBUTE_SEEN);
return status;
}
......@@ -276,74 +230,68 @@ attribute_is_userflag (attribute_t attr, int flag)
int
attribute_is_seen (attribute_t attr)
{
if (attr == NULL)
int flags = 0;
if (attribute_get_flags (attr, &flags) == 0)
return flags & MU_ATTRIBUTE_SEEN;
return 0;
if (attr->_get_flags)
attr->_get_flags (attr, &(attr->flags));
return attr->flags & MU_ATTRIBUTE_SEEN;
}
int
attribute_is_answered (attribute_t attr)
{
if (attr == NULL)
int flags = 0;
if (attribute_get_flags (attr, &flags) == 0)
return flags & MU_ATTRIBUTE_ANSWERED;
return 0;
if (attr->_get_flags)
attr->_get_flags (attr, &(attr->flags));
return attr->flags & MU_ATTRIBUTE_ANSWERED;
}
int
attribute_is_flagged (attribute_t attr)
{
if (attr == NULL)
int flags = 0;
if (attribute_get_flags (attr, &flags) == 0)
return flags & MU_ATTRIBUTE_FLAGGED;
return 0;
if (attr->_get_flags)
attr->_get_flags (attr, &(attr->flags));
return attr->flags & MU_ATTRIBUTE_FLAGGED;
}
int
attribute_is_read (attribute_t attr)
{
if (attr == NULL)
int flags = 0;
if (attribute_get_flags (attr, &flags) == 0)
return flags & MU_ATTRIBUTE_READ;
return 0;
if (attr->_get_flags)
attr->_get_flags (attr, &(attr->flags));
return attr->flags & MU_ATTRIBUTE_READ;
}
int
attribute_is_deleted (attribute_t attr)
{
if (attr == NULL)
int flags = 0;
if (attribute_get_flags (attr, &flags) == 0)
return flags & MU_ATTRIBUTE_DELETED;
return 0;
if (attr->_get_flags)
attr->_get_flags (attr, &(attr->flags));
return attr->flags & MU_ATTRIBUTE_DELETED;
}
int
attribute_is_draft (attribute_t attr)
{
if (attr == NULL)
int flags = 0;
if (attribute_get_flags (attr, &flags) == 0)
return flags & MU_ATTRIBUTE_DRAFT;
return 0;
if (attr->_get_flags)
attr->_get_flags (attr, &(attr->flags));
return attr->flags & MU_ATTRIBUTE_DRAFT;
}
int
attribute_is_recent (attribute_t attr)
{
if (attr == NULL)
return 0;
if (attr->_get_flags)
attr->_get_flags (attr, &(attr->flags));
int flags = 0;
if (attribute_get_flags (attr, &flags) == 0)
{
/* something is recent when it is not read and not seen. */
return (attr->flags == 0
|| ! ((attr->flags & MU_ATTRIBUTE_SEEN)
|| (attr->flags & MU_ATTRIBUTE_READ)));
return (flags == 0 || ! ((flags & MU_ATTRIBUTE_SEEN)
|| (flags & MU_ATTRIBUTE_READ)));
}
return 0;
}
int
......@@ -358,105 +306,52 @@ attribute_unset_userflag (attribute_t attr, int flag)
int
attribute_unset_seen (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return 0;
if (attr->_unset_flags)
status = attr->_unset_flags (attr, MU_ATTRIBUTE_SEEN);
attr->flags &= ~MU_ATTRIBUTE_SEEN;
attribute_set_modified (attr);
return status;
return attribute_unset_flags (attr, MU_ATTRIBUTE_SEEN);
}
int
attribute_unset_answered (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return 0;
if (attr->_unset_flags)
status = attr->_unset_flags (attr, MU_ATTRIBUTE_ANSWERED);
attr->flags &= ~MU_ATTRIBUTE_ANSWERED;
attribute_set_modified (attr);
return status;
return attribute_unset_flags (attr, MU_ATTRIBUTE_ANSWERED);
}
int
attribute_unset_flagged (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return 0;
if (attr->_unset_flags)
status = attr->_unset_flags (attr, MU_ATTRIBUTE_FLAGGED);
attr->flags &= ~MU_ATTRIBUTE_FLAGGED;
attribute_set_modified (attr);
return status;
return attribute_unset_flags (attr, MU_ATTRIBUTE_FLAGGED);
}
int
attribute_unset_read (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return 0;
if (attr->_unset_flags)
status = attr->_unset_flags (attr, MU_ATTRIBUTE_READ);
attr->flags &= ~MU_ATTRIBUTE_READ;
attribute_set_modified (attr);
return status;
return attribute_unset_flags (attr, MU_ATTRIBUTE_READ);
}
int
attribute_unset_deleted (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return 0;
if (attr->_unset_flags)
status = attr->_unset_flags (attr, MU_ATTRIBUTE_DELETED);
attr->flags &= ~MU_ATTRIBUTE_DELETED;
attribute_set_modified (attr);
return status;
return attribute_unset_flags (attr, MU_ATTRIBUTE_DELETED);
}
int
attribute_unset_draft (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return 0;
if (attr->_unset_flags)
status = attr->_unset_flags (attr, MU_ATTRIBUTE_DRAFT);
attr->flags &= ~MU_ATTRIBUTE_DRAFT;
attribute_set_modified (attr);
return status;
return attribute_unset_flags (attr, MU_ATTRIBUTE_DRAFT);
}
int
attribute_unset_recent (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return 0;
if (attr->_unset_flags)
status = attr->_unset_flags (attr, MU_ATTRIBUTE_SEEN);
attr->flags |= MU_ATTRIBUTE_SEEN;
attribute_set_modified (attr);
return status;
return attribute_unset_flags (attr, MU_ATTRIBUTE_SEEN);
}
int
attribute_is_equal (attribute_t attr, attribute_t attr2)
{
int status = 0;
if (attr == NULL || attr2 == NULL)
return 0;
if (attr->_get_flags)
status = attr->_get_flags (attr, &(attr->flags));
if (attr2->_get_flags)
status = attr2->_get_flags (attr2, &(attr2->flags));
return attr->flags == attr2->flags;
int flags2 = 0, flags = 0;
attribute_get_flags (attr, &flags);
attribute_get_flags (attr2, &flags2);
return flags == flags;
}
/* Miscellaneous. */
......@@ -550,3 +445,4 @@ flags_to_string (int flags, char *buffer, size_t len, size_t *pn)
*pn = i;
return 0;
}
......
......@@ -1262,7 +1262,10 @@ imap_flags (f_imap_t f_imap, char **ptr)
if (strcasecmp (flag, "\\Seen") == 0)
{
if (msg_imap)
{
msg_imap->flags |= MU_ATTRIBUTE_SEEN;
msg_imap->flags |= MU_ATTRIBUTE_READ;
}
else
f_imap->flags |= MU_ATTRIBUTE_SEEN;
}
......@@ -1294,13 +1297,6 @@ imap_flags (f_imap_t f_imap, char **ptr)
else
f_imap->flags |= MU_ATTRIBUTE_DRAFT;
}
else if (strcasecmp (flag, "\\Read") == 0)
{
if (msg_imap)
msg_imap->flags |= MU_ATTRIBUTE_READ;
else
f_imap->flags |= MU_ATTRIBUTE_READ;
}
}
return 0;
}
......
......@@ -31,6 +31,7 @@
#endif
#include <mailutils/mailbox.h>
#include <mailutils/mutil.h>
#include <mailutils/error.h>
#ifndef _PATH_MAILDIR
......
......@@ -500,18 +500,7 @@ imap_messages_count (mailbox_t mailbox, size_t *pnum)
case IMAP_SELECT:
status = imap_send (f_imap);
if (status != 0)
{
/* HACK!!!!! Force a reconnect here. */
if (status != EAGAIN && status != EINPROGRESS && status != EINTR)
{
CLEAR_STATE (f_imap);
status = folder_open (f_imap->folder, f_imap->folder->flags);
CHECK_EAGAIN (f_imap, status);
return imap_messages_count (mailbox, pnum);
}
return status;
}
f_imap->state = IMAP_SELECT_ACK;
case IMAP_SELECT_ACK:
......@@ -521,7 +510,6 @@ imap_messages_count (mailbox_t mailbox, size_t *pnum)
break;
default:
status = folder_open (f_imap->folder, f_imap->folder->flags);
CHECK_EAGAIN (f_imap, status);
return status;
}
......
......@@ -111,7 +111,9 @@ static int pop_message_fd __P ((stream_t, int *));
static int pop_top __P ((header_t, char *, size_t, off_t, size_t *));
static int pop_retr __P ((pop_message_t, char *, size_t, off_t, size_t *));
static int pop_get_fd __P ((pop_message_t, int *));
static int pop_attr_flags __P ((attribute_t, int *));
static int pop_get_attribute __P ((attribute_t, int *));
static int pop_set_attribute __P ((attribute_t, int));
static int pop_unset_attribute __P ((attribute_t, int));
static int pop_uidl __P ((message_t, char *, size_t, size_t *));
static int pop_uid __P ((message_t, size_t *));
static int fill_buffer __P ((pop_data_t, char *, size_t));
......@@ -140,6 +142,7 @@ struct _pop_message
size_t message_size;
size_t num;
char *uidl; /* Cache the uidl string. */
int attr_flags;
message_t message;
pop_data_t mpd; /* Back pointer. */
};
......@@ -809,7 +812,9 @@ pop_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg)
free (mpm);
return status;
}
attribute_set_get_flags (attribute, pop_attr_flags, msg);
attribute_set_get_flags (attribute, pop_get_attribute, msg);
attribute_set_set_flags (attribute, pop_set_attribute, msg);
attribute_set_unset_flags (attribute, pop_unset_attribute, msg);
message_set_attribute (msg, attribute, mpm);
}
......@@ -1214,19 +1219,47 @@ pop_body_lines (body_t body, size_t *plines)
the RETR some go as much as deleting after the TOP, since technicaly
you can download a message via TOP without RET'reiving it. */
static int
pop_attr_flags (attribute_t attr, int *pflags)
pop_get_attribute (attribute_t attr, int *pflags)
{
message_t msg = attribute_get_owner (attr);
pop_message_t mpm = message_get_owner (msg);
char hdr_status[64];
header_t header = NULL;
if (mpm == NULL)
if (mpm == NULL || pflags == NULL)
return EINVAL;
if (mpm->attr_flags == 0)
{
hdr_status[0] = '\0';
message_get_header (mpm->message, &header);
header_get_value (header, "Status", hdr_status, sizeof (hdr_status), NULL);
string_to_flags (hdr_status, pflags);
header_get_value (header, "Status", hdr_status, sizeof hdr_status, NULL);
string_to_flags (hdr_status, &(mpm->attr_flags));
}
*pflags = mpm->attr_flags;
return 0;
}
static int
pop_set_attribute (attribute_t attr, int flags)
{
message_t msg = attribute_get_owner (attr);
pop_message_t mpm = message_get_owner (msg);
if (mpm == NULL)
return EINVAL;
mpm->attr_flags |= flags;
return 0;
}
static int
pop_unset_attribute (attribute_t attr, int flags)
{
message_t msg = attribute_get_owner (attr);
pop_message_t mpm = message_get_owner (msg);
if (mpm == NULL)
return EINVAL;
mpm->attr_flags &= ~flags;
return 0;
}
......
......@@ -35,7 +35,8 @@
/* convert a sequence of hex characters into an integer */
unsigned long mu_hex2ul(char hex)
unsigned long
mu_hex2ul (char hex)
{
if (hex >= '0' && hex <= '9')
return hex - '0';
......@@ -49,7 +50,8 @@ unsigned long mu_hex2ul(char hex)
return -1;
}
size_t mu_hexstr2ul(unsigned long* ul, const char* hex, size_t len)
size_t
mu_hexstr2ul (unsigned long *ul, const char *hex, size_t len)
{
size_t r;
......@@ -57,9 +59,9 @@ size_t mu_hexstr2ul(unsigned long* ul, const char* hex, size_t len)
for (r = 0; r < len; r++)
{
unsigned long v = mu_hex2ul(hex[r]);
unsigned long v = mu_hex2ul (hex[r]);
if(v == (unsigned long)-1)
if (v == (unsigned long)-1)
return r;
*ul = *ul * 16 + v;
......@@ -83,18 +85,18 @@ mu_tm2time (struct tm *timeptr, mu_timezone* tz)
{
int offset = tz ? tz->utc_offset : 0;
return mktime(timeptr) + mu_utc_offset() - offset;
return mktime (timeptr) + mu_utc_offset () - offset;
}
/* Convert time 0 at UTC to our localtime, that tells us the offset
of our current timezone from UTC. */
time_t
mu_utc_offset(void)
mu_utc_offset (void)
{
time_t t = 0;
struct tm* tm = gmtime(&t);
struct tm* tm = gmtime (&t);
return - mktime(tm);
return - mktime (tm);
}
static const char *months[] =
......@@ -243,7 +245,6 @@ mu_parse_ctime_date_time (const char **p, struct tm *tm, mu_timezone * tz)
return 0;
}
char *
mu_get_homedir (void)
{
......@@ -252,7 +253,7 @@ mu_get_homedir (void)
{
struct passwd *pwd;
pwd = getpwuid(getuid());
pwd = getpwuid (getuid ());
if (!pwd)
return NULL;
homedir = pwd->pw_dir;
......@@ -369,7 +370,7 @@ getpwnam_virtual (const char *u)
{
struct passwd *pw = NULL;
FILE *pfile;
int i = 0, len = strlen (u), delim = 0;
size_t i = 0, len = strlen (u), delim = 0;
char *filename;
mu_virtual_domain = 0;
......
......@@ -1292,7 +1292,7 @@ int parse822_date(const char** p, const char* e, int* day, int* mon, int* year)
}
int parse822_time(const char** p, const char* e,
int* hour, int* min, int* sec, int* tz, const char** tzname)
int* hour, int* min, int* sec, int* tz, const char** tz_name)
{
/* time = hour zone
* hour = 2DIGIT ":" 2DIGIT [":" 2DIGIT] ; 00:00:00 - 23:59:59
......@@ -1323,7 +1323,7 @@ int parse822_time(const char** p, const char* e,
{ "MDT", -6 * 60 * 60 },
{ "PST", -8 * 60 * 60 },
{ "PDT", -7 * 60 * 60 },
{ NULL, }
{ NULL, 0 }
};
const char* save = *p;
......@@ -1370,8 +1370,8 @@ int parse822_time(const char** p, const char* e,
break;
}
if(tzs[z].tzname) {
if(tzname)
*tzname = tzs[z].tzname;
if(tz_name)
*tz_name = tzs[z].tzname;
if(tz)
*tz = tzs[z].tz;
......@@ -1449,7 +1449,7 @@ int parse822_date_time(const char** p, const char* e, struct tm* tm, struct mu_t
int sec = 0;
int tzoffset = 0;
const char* tzname = 0;
const char* tz_name = 0;
if((rc = parse822_day(p, e, &wday))) {
if(rc != EPARSE)
......@@ -1468,7 +1468,7 @@ int parse822_date_time(const char** p, const char* e, struct tm* tm, struct mu_t
*p = save;
return rc;
}
if((rc = parse822_time(p, e, &hour, &min, &sec, &tzoffset, &tzname))) {
if((rc = parse822_time(p, e, &hour, &min, &sec, &tzoffset, &tz_name))) {
*p = save;
return rc;
}
......@@ -1493,14 +1493,14 @@ int parse822_date_time(const char** p, const char* e, struct tm* tm, struct mu_t
tm->tm_gmtoff = tzoffset;
#endif
#ifdef HAVE_TM_ZONE
tm->tm_zone = tzname;
tm->tm_zone = tz_name;
#endif
}
if(tz)
{
tz->utc_offset = tzoffset;
tz->tz_name = tzname;
tz->tz_name = tz_name;
}
return EOK;
......
......@@ -143,7 +143,7 @@ url_parse (url_t url)
{
int err = 0;
char *n = NULL;
struct _url u = { 0, };
struct _url u = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0 ,0, 0};
if (!url || !url->name)
return EINVAL;
......
......@@ -4,6 +4,7 @@ INCLUDES =-I$(srcdir) -I$(top_srcdir)/lib -I$(top_srcdir)/include
sbin_PROGRAMS = pop3d
pop3d_SOURCES = apop.c auth.c capa.c dele.c extra.c pop3d.c pop3d.h \
list.c lock.c noop.c quit.c retr.c rset.c stat.c top.c uidl.c user.c signal.c
list.c lock.c noop.c quit.c retr.c rset.c stat.c signal.c top.c uidl.c \
user.c virtual.c
pop3d_LDADD = ../mailbox/libmailbox.la @AUTHLIBS@ ../lib/libmailutils.a
......
......@@ -134,6 +134,8 @@ main (int argc, char **argv)
#endif
#ifdef USE_VIRTUAL_DOMAINS
mu_register_getpwnam (getpwnam_virtual);
mu_register_getpwnam (getpwnam_ip_virtual);
mu_register_getpwnam (getpwnam_host_virtual);
#endif
/* Set the signal handlers. */
......
......@@ -201,4 +201,7 @@ extern int pop3d_touchlock __P ((void));
extern int pop3d_uidl __P ((const char *));
extern int pop3d_user __P ((const char *));
extern int pop3d_unlock __P ((void));
extern struct passwd * getpwnam_ip_virtual __P ((const char *u));
extern struct passwd * getpwnam_host_virtual __P ((const char *u));
#endif /* _POP3D_H */
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "pop3d.h"
#ifdef USE_VIRTUAL_DOMAINS
struct passwd *
getpwnam_ip_virtual (const char *u)
{
struct sockaddr_in addr;
struct passwd *pw = NULL;
int len = sizeof (addr);
if (getsockname (fileno (ifile), (struct sockaddr *)&addr, &len) == 0)
{
char *ip;
char *user;
ip = inet_ntoa (addr.sin_addr);
user = malloc (strlen (ip) + strlen (u) + 2);
if (user)
{
sprintf (user, "%s!%s", u, ip);
pw = getpwnam_virtual (user);
free (user);
}
}
return pw;
}
struct passwd *
getpwnam_host_virtual (const char *u)
{
struct sockaddr_in addr;
struct passwd *pw = NULL;
int len = sizeof (addr);
if (getsockname (fileno (ifile), (struct sockaddr *)&addr, &len) == 0)
{
struct hostent *info = gethostbyaddr ((char *)&addr.sin_addr,
4, AF_INET);
if (info)
{
char *user = malloc (strlen (info->h_name) + strlen (u) + 2);
if (user)
{
sprintf (user, "%s!%s", u, info->h_name);
pw = getpwnam_virtual (user);
free (user);
}
}
}
return pw;
}
#endif