summaryrefslogtreecommitdiff
path: root/mailbox2
diff options
context:
space:
mode:
authorAlain Magloire <alainm@gnu.org>2001-08-01 03:33:36 +0000
committerAlain Magloire <alainm@gnu.org>2001-08-01 03:33:36 +0000
commita6483b1164098d209d8d7a69533b9fe187591120 (patch)
tree776f8764c1af6c7646449c08df19a5bb7a36914c /mailbox2
parenteaaa3d36a6c31330379668902c1e3065dc894b4b (diff)
downloadmailutils-a6483b1164098d209d8d7a69533b9fe187591120.tar.gz
mailutils-a6483b1164098d209d8d7a69533b9fe187591120.tar.bz2
New batch of files.
Diffstat (limited to 'mailbox2')
-rw-r--r--mailbox2/Makefile.am21
-rw-r--r--mailbox2/address.c268
-rw-r--r--mailbox2/attribute.c443
-rw-r--r--mailbox2/envelope.c77
-rw-r--r--mailbox2/fstream.c9
-rw-r--r--mailbox2/include/mailutils/Makefile.am21
-rw-r--r--mailbox2/include/mailutils/address.h67
-rw-r--r--mailbox2/include/mailutils/attribute.h92
-rw-r--r--mailbox2/include/mailutils/base.h24
-rw-r--r--mailbox2/include/mailutils/envelope.h51
-rw-r--r--mailbox2/include/mailutils/iterator.h19
-rw-r--r--mailbox2/include/mailutils/list.h53
-rw-r--r--mailbox2/include/mailutils/observer.h81
-rw-r--r--mailbox2/include/mailutils/parse822.h117
-rw-r--r--mailbox2/include/mailutils/pop3.h16
-rw-r--r--mailbox2/include/mailutils/stream.h14
-rw-r--r--mailbox2/include/mailutils/sys/Makefile.am16
-rw-r--r--mailbox2/include/mailutils/sys/address.h75
-rw-r--r--mailbox2/include/mailutils/sys/attribute.h80
-rw-r--r--mailbox2/include/mailutils/sys/envelope.h58
-rw-r--r--mailbox2/include/mailutils/sys/iterator.h8
-rw-r--r--mailbox2/include/mailutils/sys/list.h72
-rw-r--r--mailbox2/include/mailutils/sys/observer.h73
-rw-r--r--mailbox2/include/mailutils/sys/pop3.h8
-rw-r--r--mailbox2/include/mailutils/sys/stream.h9
-rw-r--r--mailbox2/list.c332
-rw-r--r--mailbox2/observable.c160
-rw-r--r--mailbox2/observer.c140
-rw-r--r--mailbox2/parse822.c1664
29 files changed, 4017 insertions, 51 deletions
diff --git a/mailbox2/Makefile.am b/mailbox2/Makefile.am
index 61cfa9da2..4e1ebe558 100644
--- a/mailbox2/Makefile.am
+++ b/mailbox2/Makefile.am
@@ -11,10 +11,17 @@ SUBDIRS = include pop3 mbox
lib_LTLIBRARIES = libmailbox.la
libmailbox_la_SOURCES = \
- bstream.c \
- fstream.c \
- iterator.c \
- md5-rsa.c \
- mstream.c \
- stream.c \
- tcp.c
+ address.c \
+ attribute.c \
+ bstream.c \
+ envelope.c \
+ fstream.c \
+ iterator.c \
+ list.c \
+ md5-rsa.c \
+ mstream.c \
+ observable.c \
+ observer.c \
+ parse822.c \
+ stream.c \
+ tcpstream.c
diff --git a/mailbox2/address.c b/mailbox2/address.c
new file mode 100644
index 000000000..36ed5dc33
--- /dev/null
+++ b/mailbox2/address.c
@@ -0,0 +1,268 @@
+/* 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 <string.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <string.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include <mailutils/parse822.h>
+#include <mailutils/mutil.h>
+#include <mailutils/sys/address.h>
+
+/* Get email address from rfc822 address. */
+int
+address_create (address_t *a, const char *s)
+{
+ /* 'paddress' must exist, and can't already have been initialized
+ */
+ int status;
+
+ if (!a)
+ return EINVAL;
+
+ *a = NULL;
+ status = parse822_address_list (a, (char*) s);
+ if (status == 0)
+ {
+ /* And address-list may contain 0 addresses but parse correctly.
+ */
+ if (!*a)
+ return ENOENT;
+
+ (*a)->addr = strdup (s);
+ if (!(*a)->addr)
+ {
+ address_destroy (*a);
+ return ENOMEM;
+ }
+ }
+ return status;
+}
+
+int
+address_destroy (address_t address)
+{
+ if (address)
+ {
+ address_t current;
+ for (; address; address = current)
+ {
+ if (address->addr)
+ free (address->addr);
+ if (address->comments)
+ free (address->comments);
+ if (address->personal)
+ free (address->personal);
+ if (address->email)
+ free (address->email);
+ if (address->local_part)
+ free (address->local_part);
+ if (address->domain)
+ free (address->domain);
+ if (address->route)
+ free (address->route);
+ current = address->next;
+ free (address);
+ }
+ }
+ return 0;
+}
+
+int
+address_get_personal (address_t addr, size_t no, char *buf, size_t len,
+ size_t *n)
+{
+ size_t i, j;
+ int status = ENOENT;
+ if (addr == NULL)
+ return EINVAL;
+ for (i = 0, j = 1; addr; addr = addr->next, j++)
+ {
+ if (j == no)
+ {
+ i = util_cpystr (buf, addr->personal, len);
+ status = 0;
+ break;
+ }
+ }
+ if (n)
+ *n = i;
+ return status;
+}
+
+int
+address_get_comments (address_t addr, size_t no, char *buf, size_t len,
+ size_t *n)
+{
+ size_t i, j;
+ int status = ENOENT;
+ if (addr == NULL)
+ return EINVAL;
+ for (j = 1; addr; addr = addr->next, j++)
+ {
+ if (j == no)
+ {
+ i = util_cpystr (buf, addr->comments, len);
+ if (n)
+ *n = i;
+ status = 0;
+ break;
+ }
+ }
+ return status;
+}
+
+int
+address_get_email (address_t addr, size_t no, char *buf, size_t len, size_t *n)
+{
+ size_t i, j;
+ int status = ENOENT;
+ if (addr == NULL)
+ return EINVAL;
+ for (j = 1; addr; addr = addr->next, j++)
+ {
+ if (j == no)
+ {
+ i = util_cpystr (buf, addr->email, len);
+ if (n)
+ *n = i;
+ status = 0;
+ break;
+ }
+ }
+ return status;
+}
+
+int
+address_get_local_part (address_t addr, size_t no, char *buf, size_t len, size_t *n)
+{
+ size_t i, j;
+ int status = ENOENT;
+ if (addr == NULL)
+ return EINVAL;
+ for (j = 1; addr; addr = addr->next, j++)
+ {
+ if (j == no)
+ {
+ i = util_cpystr (buf, addr->local_part, len);
+ if (n)
+ *n = i;
+ status = 0;
+ break;
+ }
+ }
+ return status;
+}
+
+int
+address_get_domain (address_t addr, size_t no, char *buf, size_t len, size_t *n)
+{
+ size_t i, j;
+ int status = ENOENT;
+ if (addr == NULL)
+ return EINVAL;
+ for (j = 1; addr; addr = addr->next, j++)
+ {
+ if (j == no)
+ {
+ i = util_cpystr (buf, addr->domain, len);
+ if (n)
+ *n = i;
+ status = 0;
+ break;
+ }
+ }
+ return status;
+}
+
+int
+address_get_route (address_t addr, size_t no, char *buf, size_t len, size_t *n)
+{
+ size_t i, j;
+ int status = ENOENT;
+ if (addr == NULL)
+ return EINVAL;
+ for (j = 1; addr; addr = addr->next, j++)
+ {
+ if (j == no)
+ {
+ i = util_cpystr (buf, addr->route, len);
+ if (n)
+ *n = i;
+ status = 0;
+ break;
+ }
+ }
+ return status;
+}
+
+int
+address_is_group (address_t addr, size_t no, int* yes)
+{
+ size_t j;
+ int status = ENOENT;
+ if(addr == NULL)
+ return EINVAL;
+ for (j = 1; addr; addr = addr->next, j++)
+ {
+ if (j == no)
+ {
+ status = 0;
+ if(yes)
+ {
+ *yes = 0;
+ if(addr->personal && !addr->local_part && !addr->domain)
+ *yes = 1;
+ }
+ break;
+ }
+ }
+ return status;
+}
+
+int
+address_to_string (address_t addr, char *buf, size_t len, size_t *n)
+{
+ size_t i;
+ if (addr == NULL)
+ return EINVAL;
+ if (buf)
+ *buf = '\0';
+ i = util_cpystr (buf, addr->addr, len);
+ if (n)
+ *n = i;
+ return 0;
+}
+
+int
+address_get_count (address_t addr, size_t *pcount)
+{
+ size_t j;
+ for (j = 0; addr; addr = addr->next, j++)
+ ;
+ if (pcount)
+ *pcount = j;
+ return 0;
+}
diff --git a/mailbox2/attribute.c b/mailbox2/attribute.c
new file mode 100644
index 000000000..93e1f321f
--- /dev/null
+++ b/mailbox2/attribute.c
@@ -0,0 +1,443 @@
+/* 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 <sys/types.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+
+#include <mailutils/error.h>
+#include <mailutils/sys/attribute.h>
+
+int
+(attribute_add_ref) (attribute_t attribute)
+{
+ if (attribute == NULL || attribute->vtable == NULL
+ || attribute->vtable->add_ref == NULL)
+ return MU_ERROR_NOT_SUPPORTED;
+ return attribute->vtable->add_ref (attribute);
+}
+
+int
+(attribute_release) (attribute_t attribute)
+{
+ if (attribute == NULL || attribute->vtable == NULL
+ || attribute->vtable->release == NULL)
+ return MU_ERROR_NOT_SUPPORTED;
+ return attribute->vtable->release (attribute);
+}
+
+int
+(attribute_destroy) (attribute_t attribute)
+{
+ if (attribute == NULL || attribute->vtable == NULL
+ || attribute->vtable->destroy == NULL)
+ return MU_ERROR_NOT_SUPPORTED;
+ return attribute->vtable->destroy (attribute);
+}
+
+int
+(attribute_get_flags) (attribute_t attribute, int *pflags)
+{
+ if (attribute == NULL || attribute->vtable == NULL
+ || attribute->vtable->get_flags == NULL)
+ return MU_ERROR_NOT_SUPPORTED;
+ return attribute->vtable->get_flags (attribute, pflags);
+}
+
+int
+(attribute_set_flags) (attribute_t attribute, int flags)
+{
+ if (attribute == NULL || attribute->vtable == NULL
+ || attribute->vtable->set_flags == NULL)
+ return MU_ERROR_NOT_SUPPORTED;
+ return attribute->vtable->set_flags (attribute, flags);
+}
+
+int
+(attribute_unset_flags) (attribute_t attribute, int flags)
+{
+ if (attribute == NULL || attribute->vtable == NULL
+ || attribute->vtable->unset_flags == NULL)
+ return MU_ERROR_NOT_SUPPORTED;
+ return attribute->vtable->unset_flags (attribute, flags);
+}
+
+int
+(attribute_clear_flags) (attribute_t attribute)
+{
+ if (attribute == NULL || attribute->vtable == NULL
+ || attribute->vtable->clear_flags == NULL)
+ return MU_ERROR_NOT_SUPPORTED;
+ return attribute->vtable->clear_flags (attribute);
+}
+
+
+/* Stub helpers for the wellknown flags. */
+int
+attribute_set_seen (attribute_t attribute)
+{
+ if (attribute == NULL)
+ return MU_ERROR_INVALID_PARAMETER;
+ return attribute_set_flags (attribute, MU_ATTRIBUTE_SEEN);
+}
+
+int
+attribute_set_answered (attribute_t attribute)
+{
+ if (attribute == NULL)
+ return MU_ERROR_INVALID_PARAMETER;
+ return attribute_set_flags (attribute, MU_ATTRIBUTE_ANSWERED);
+}
+
+int
+attribute_set_flagged (attribute_t attribute)
+{
+ if (attribute == NULL)
+ return MU_ERROR_INVALID_PARAMETER;
+ return attribute_set_flags (attribute, MU_ATTRIBUTE_FLAGGED);
+}
+
+int
+attribute_set_read (attribute_t attribute)
+{
+ if (attribute == NULL)
+ return MU_ERROR_INVALID_PARAMETER;
+ return attribute_set_flags (attribute, MU_ATTRIBUTE_READ);
+}
+
+int
+attribute_set_deleted (attribute_t attribute)
+{
+ if (attribute == NULL)
+ return MU_ERROR_INVALID_PARAMETER;
+ return attribute_set_flags (attribute, MU_ATTRIBUTE_DELETED);
+}
+
+int
+attribute_set_draft (attribute_t attribute)
+{
+ if (attribute == NULL)
+ return MU_ERROR_INVALID_PARAMETER;
+ return attribute_set_flags (attribute, MU_ATTRIBUTE_DRAFT);
+}
+
+int
+attribute_set_recent (attribute_t attribute)
+{
+ if (attribute == NULL)
+ return MU_ERROR_INVALID_PARAMETER;
+ attribute_unset_flags (attribute, MU_ATTRIBUTE_READ);
+ return attribute_unset_flags (attribute, MU_ATTRIBUTE_SEEN);
+}
+
+int
+attribute_set_modified (attribute_t attribute)
+{
+ if (attribute == NULL)
+ return MU_ERROR_INVALID_PARAMETER;
+ return attribute_set_flags (attribute, MU_ATTRIBUTE_MODIFIED);
+}
+
+int
+attribute_is_seen (attribute_t attribute)
+{
+ int flags = 0;
+ if (attribute == NULL)
+ return 0;
+ attribute_get_flags (attribute, &flags);
+ return flags & MU_ATTRIBUTE_SEEN;
+}
+
+int
+attribute_is_answered (attribute_t attribute)
+{
+ int flags = 0;
+ if (attribute == NULL)
+ return 0;
+ attribute_get_flags (attribute, &flags);
+ return flags & MU_ATTRIBUTE_ANSWERED;
+}
+
+int
+attribute_is_flagged (attribute_t attribute)
+{
+ int flags = 0;
+ if (attribute == NULL)
+ return 0;
+ attribute_get_flags (attribute, &flags);
+ return flags & MU_ATTRIBUTE_FLAGGED;
+}
+
+int
+attribute_is_read (attribute_t attribute)
+{
+ int flags = 0;
+ if (attribute == NULL)
+ return 0;
+ attribute_get_flags (attribute, &flags);
+ return flags & MU_ATTRIBUTE_READ;
+}
+
+int
+attribute_is_deleted (attribute_t attribute)
+{
+ int flags = 0;
+ if (attribute == NULL)
+ return 0;
+ attribute_get_flags (attribute, &flags);
+ return flags & MU_ATTRIBUTE_DELETED;
+}
+
+int
+attribute_is_draft (attribute_t attribute)
+{
+ int flags = 0;
+ if (attribute == NULL)
+ return 0;
+ attribute_get_flags (attribute, &flags);
+ return flags & MU_ATTRIBUTE_DRAFT;
+}
+
+int
+attribute_is_recent (attribute_t attribute)
+{
+ int flags = 0;
+ if (attribute == NULL)
+ return 0;
+ attribute_get_flags (attribute, &flags);
+ /* Something is recent when it is not read and not seen. */
+ return (flags == 0
+ || ! ((flags & MU_ATTRIBUTE_SEEN) || (flags & MU_ATTRIBUTE_READ)));
+}
+
+int
+attribute_is_modified (attribute_t attribute)
+{
+ int flags = 0;
+ if (attribute == NULL)
+ return 0;
+ attribute_get_flags (attribute, &flags);
+ return flags & MU_ATTRIBUTE_MODIFIED;
+}
+
+int
+attribute_unset_seen (attribute_t attribute)
+{
+ if (attribute == NULL)
+ return 0;
+ return attribute_unset_flags (attribute, MU_ATTRIBUTE_SEEN);
+}
+
+int
+attribute_unset_answered (attribute_t attribute)
+{
+ if (attribute == NULL)
+ return 0;
+ return attribute_unset_flags (attribute, MU_ATTRIBUTE_ANSWERED);
+}
+
+int
+attribute_unset_flagged (attribute_t attribute)
+{
+ if (attribute == NULL)
+ return 0;
+ return attribute_unset_flags (attribute, MU_ATTRIBUTE_FLAGGED);
+}
+
+int
+attribute_unset_read (attribute_t attribute)
+{
+ if (attribute == NULL)
+ return 0;
+ return attribute_unset_flags (attribute, MU_ATTRIBUTE_READ);
+}
+
+int
+attribute_unset_deleted (attribute_t attribute)
+{
+ if (attribute == NULL)
+ return 0;
+ return attribute_unset_flags (attribute, MU_ATTRIBUTE_DELETED);
+}
+
+int
+attribute_unset_draft (attribute_t attribute)
+{
+ if (attribute == NULL)
+ return 0;
+ return attribute_unset_flags (attribute, MU_ATTRIBUTE_DRAFT);
+}
+
+int
+attribute_unset_recent (attribute_t attribute)
+{
+ if (attribute == NULL)
+ return 0;
+ return attribute_unset_flags (attribute, MU_ATTRIBUTE_SEEN);
+}
+
+int
+attribute_unset_modified (attribute_t attribute)
+{
+ if (attribute == NULL)
+ return 0;
+ return attribute_unset_flags (attribute, MU_ATTRIBUTE_MODIFIED);
+}
+
+/* Miscellaneous. */
+int
+attribute_is_equal (attribute_t attribute1, attribute_t attribute2)
+{
+ int flags1 = 0;
+ int flags2 = 0;
+ if (attribute1)
+ attribute_get_flags (attribute1, &flags1);
+ if (attribute2)
+ attribute_get_flags (attribute2, &flags2);
+ return flags1 == flags2;
+}
+
+int
+attribute_copy (attribute_t dest, attribute_t src)
+{
+ int sflags = 0;
+ if (dest == NULL || src == NULL)
+ return MU_ERROR_INVALID_PARAMETER;
+ attribute_get_flags (src, &sflags);
+ attribute_clear_flags (dest);
+ attribute_set_flags (dest, sflags);
+ return 0;
+}
+
+static int
+_da_add_ref (attribute_t attribute)
+{
+ struct _da *da = (struct _da *)attribute;
+ int status;
+ monitor_lock (da->lock);
+ status = ++da->ref;
+ monitor_unlock (da->lock);
+ return status;
+}
+
+static int
+_da_destroy (attribute_t attribute)
+{
+ struct _da *da = (struct _da *)attribute;
+ monitor_destroy (da->lock);
+ free (da);
+ return 0;
+}
+
+static int
+_da_release (attribute_t attribute)
+{
+ struct _da *da = (struct _da *)attribute;
+ int status;
+ monitor_lock (da->lock);
+ status = --da->ref;
+ if (status <= 0)
+ {
+ monitor_unlock (da->lock);
+ _da_destroy (attribute);
+ return 0;
+ }
+ monitor_unlock (da->lock);
+ return status;
+}
+
+static int
+_da_get_flags (attribute_t attribute, int *pflags)
+{
+ struct _da *da = (struct _da *)attribute;
+ monitor_lock (da->lock);
+ if (pflags)
+ *pflags = da->flags;
+ monitor_unlock (da->lock);
+ return 0;
+}
+
+static int
+_da_set_flags (attribute_t attribute, int flags)
+{
+ struct _da *da = (struct _da *)attribute;
+ monitor_lock (da->lock);
+ da->flags |= (flags | MU_ATTRIBUTE_MODIFIED);
+ monitor_unlock (da->lock);
+ return 0;
+}
+
+static int
+_da_unset_flags (attribute_t attribute, int flags)
+{
+ struct _da *da = (struct _da *)attribute;
+ monitor_lock (da->lock);
+ da->flags &= ~flags;
+ /* If Modified was being unset do not reset it. */
+ if (!(flags & MU_ATTRIBUTE_MODIFIED))
+ da->flags |= MU_ATTRIBUTE_MODIFIED;
+ monitor_unlock (da->lock);
+ return 0;
+}
+
+static int
+_da_clear_flags (attribute_t attribute)
+{
+ struct _da *da = (struct _da *)attribute;
+ monitor_lock (da->lock);
+ da->flags = 0;
+ monitor_unlock (da->lock);
+ return 0;
+}
+
+static struct _attribute_vtable _da_vtable =
+{
+ _da_add_ref,
+ _da_release,
+ _da_destroy,
+
+ _da_get_flags,
+ _da_set_flags,
+ _da_unset_flags,
+ _da_clear_flags
+};
+
+int
+attribute_create (attribute_t *pattribute)
+{
+ struct _da *da;
+ if (pattribute == NULL)
+ return MU_ERROR_INVALID_PARAMETER;
+ da = calloc (1, sizeof *da);
+ if (da == NULL)
+ return MU_ERROR_NO_MEMORY;
+
+ da->base.vtable = &_da_vtable;
+ da->ref = 1;
+ da->flags = 0;
+ monitor_create (&(da->lock));
+ *pattribute = &da->base;
+ return 0;
+}
diff --git a/mailbox2/envelope.c b/mailbox2/envelope.c
new file mode 100644
index 000000000..512aa1622
--- /dev/null
+++ b/mailbox2/envelope.c
@@ -0,0 +1,77 @@
+/* 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 <mailutils/error.h>
+#include <mailutils/sys/envelope.h>
+
+int
+(envelope_add_ref) (envelope_t envelope)
+{
+ if (envelope == NULL || envelope->vtable == NULL
+ || envelope->vtable->add_ref == NULL)
+ return MU_ERROR_NOT_SUPPORTED;
+ return envelope->vtable->add_ref (envelope);
+}
+
+int
+(envelope_release) (envelope_t envelope)
+{
+ if (envelope == NULL || envelope->vtable == NULL
+ || envelope->vtable->release == NULL)
+ return MU_ERROR_NOT_SUPPORTED;
+ return envelope->vtable->release (envelope);
+}
+
+int
+(envelope_destroy) (envelope_t envelope)
+{
+ if (envelope == NULL || envelope->vtable == NULL
+ || envelope->vtable->destroy == NULL)
+ return MU_ERROR_NOT_SUPPORTED;
+ return envelope->vtable->destroy (envelope);
+}
+
+int
+(envelope_sender) (envelope_t envelope, address_t *paddr)
+{
+ if (envelope == NULL || envelope->vtable == NULL
+ || envelope->vtable->sender == NULL)
+ return MU_ERROR_NOT_SUPPORTED;
+ return envelope->vtable->sender (envelope, paddr);
+}
+
+int
+(envelope_recipient) (envelope_t envelope, address_t *paddr)
+{
+ if (envelope == NULL || envelope->vtable == NULL
+ || envelope->vtable->recipient == NULL)
+ return MU_ERROR_NOT_SUPPORTED;
+ return envelope->vtable->recipient (envelope, paddr);
+}
+
+int
+(envelope_date) (envelope_t envelope, struct tm *tm, struct mu_timezone *tz)
+{
+ if (envelope == NULL || envelope->vtable == NULL
+ || envelope->vtable->date == NULL)
+ return MU_ERROR_NOT_SUPPORTED;
+ return envelope->vtable->date (envelope, tm, tz);
+}
diff --git a/mailbox2/fstream.c b/mailbox2/fstream.c
index 022d25066..afafbd809 100644
--- a/mailbox2/fstream.c
+++ b/mailbox2/fstream.c
@@ -26,8 +26,9 @@
#include <sys/types.h>
#include <sys/stat.h>
-#include <fcntl.h>
#include <unistd.h>
+#include <fcntl.h>
+#include <stdio.h>
#include <mailutils/sys/fstream.h>
#include <mailutils/error.h>
@@ -76,7 +77,7 @@ static int
_fs_read (stream_t stream, void *optr, size_t osize, size_t *nbytes)
{
struct _fs *fs = (struct _fs *)stream;
- size_t n;
+ size_t n = 0;
int err = 0;
if (fs->file)
@@ -123,7 +124,7 @@ static int
_fs_write (stream_t stream, const void *iptr, size_t isize, size_t *nbytes)
{
struct _fs *fs = (struct _fs *)stream;
- size_t n;
+ size_t n = 0;
int err = 0;
if (fs->file)
@@ -334,7 +335,7 @@ _fs_open (stream_t stream, const char *filename, int port, int flags)
|| fdbuf.st_ino != filebuf.st_ino
|| fdbuf.st_nlink != 1
|| filebuf.st_nlink != 1
- || (fdbuf.st_mode & S_IFMT) != S_IFREG)
+ || !S_ISREG(fdbuf.st_mode))
{
mu_error ("%s must be a plain file with one link\n", filename);
close (fd);
diff --git a/mailbox2/include/mailutils/Makefile.am b/mailbox2/include/mailutils/Makefile.am
new file mode 100644
index 000000000..51b9a785f
--- /dev/null
+++ b/mailbox2/include/mailutils/Makefile.am
@@ -0,0 +1,21 @@
+# Use automake to process this file -*-Makefile-*-
+
+
+SUBDIRS = sys
+
+pkginclude_HEADERS = \
+ address.h \
+ attribute.h \
+ base.h \
+ envelope.h \
+ error.h \
+ iterator.h \
+ list.h \
+ mbox.h \
+ md5-rsa.h \
+ monitor.h \
+ mutil.h \
+ observer.h \
+ parse822.h \
+ pop3.h \
+ stream.h
diff --git a/mailbox2/include/mailutils/address.h b/mailbox2/include/mailutils/address.h
new file mode 100644
index 000000000..489145527
--- /dev/null
+++ b/mailbox2/include/mailutils/address.h
@@ -0,0 +1,67 @@
+/* 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. */
+
+#ifndef _MAILUTILS_ADDRESS_H
+#define _MAILUTILS_ADDRESS_H
+
+#include <sys/types.h>
+
+#ifndef __P
+# ifdef __STDC__
+# define __P(args) args
+# else
+# define __P(args) ()
+# endif
+#endif /*__P */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct _address;
+typedef struct _address *address_t;
+
+extern int address_create __P ((address_t *, const char *));
+
+extern int address_add_ref __P ((address_t));
+extern int address_release __P ((address_t));
+extern int address_destroy __P ((address_t));
+
+extern int address_get_email
+ __P ((address_t, size_t, char *, size_t, size_t *));
+extern int address_get_local_part
+ __P ((address_t, size_t, char *, size_t, size_t *));
+extern int address_get_domain
+ __P ((address_t, size_t, char *, size_t, size_t *));
+extern int address_get_personal
+ __P ((address_t, size_t, char *, size_t, size_t *));
+extern int address_get_comments
+ __P ((address_t, size_t, char *, size_t, size_t *));
+extern int address_get_route
+ __P ((address_t, size_t, char *, size_t, size_t *));
+
+extern int address_is_group
+ __P ((address_t, size_t, int*));
+
+extern int address_to_string __P ((address_t, char *, size_t, size_t *));
+extern int address_get_count __P ((address_t, size_t *));
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _MAILUTILS_ADDRESS_H */
diff --git a/mailbox2/include/mailutils/attribute.h b/mailbox2/include/mailutils/attribute.h
new file mode 100644
index 000000000..1b1253e2b
--- /dev/null
+++ b/