Commit 28e0ef50 28e0ef5060a787c8a8b4d03641abd4107abc46fa by Alain Magloire

To much to add log entries.

1 parent 48bddeaf
Showing 46 changed files with 3569 additions and 203 deletions
......@@ -13,15 +13,26 @@ lib_LTLIBRARIES = libmailbox.la
libmailbox_la_SOURCES = \
address.c \
attribute.c \
authority.c \
bstream.c \
dotlock.c \
envelope.c \
folder.c \
fstream.c \
header.c \
iterator.c \
list.c \
locker.c \
mailbox.c \
md5-rsa.c \
memstream.c \
message.c \
mstream.c \
mutil.c \
observable.c \
observer.c \
parse822.c \
pticket.c \
stream.c \
tcpstream.c
tcpstream.c \
ticket.c
......
/* 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 <stdlib.h>
#include <mailutils/error.h>
#include <mailutils/sys/authority.h>
int
authority_add_ref (authority_t authority)
{
if (authority == NULL || authority->vtable == NULL
|| authority->vtable->add_ref == NULL)
return MU_ERROR_NOT_SUPPORTED;
return authority->vtable->add_ref (authority);
}
int
authority_release (authority_t authority)
{
if (authority == NULL || authority->vtable == NULL
|| authority->vtable->release == NULL)
return MU_ERROR_NOT_SUPPORTED;
return authority->vtable->release (authority);
}
int
authority_destroy (authority_t authority)
{
if (authority == NULL || authority->vtable == NULL
|| authority->vtable->destroy == NULL)
return MU_ERROR_NOT_SUPPORTED;
return authority->vtable->destroy (authority);
}
int
authority_set_ticket (authority_t authority, ticket_t ticket)
{
if (authority == NULL || authority->vtable == NULL
|| authority->vtable->set_ticket == NULL)
return MU_ERROR_NOT_SUPPORTED;
return authority->vtable->set_ticket (authority, ticket);
}
int
authority_get_ticket (authority_t authority, ticket_t *pticket)
{
if (authority == NULL || authority->vtable == NULL
|| authority->vtable->get_ticket == NULL)
return MU_ERROR_NOT_SUPPORTED;
return authority->vtable->get_ticket (authority, pticket);
}
int
authority_authenticate (authority_t authority)
{
if (authority == NULL || authority->vtable == NULL
|| authority->vtable->authenticate == NULL)
return MU_ERROR_NOT_SUPPORTED;
return authority->vtable->authenticate (authority);
}
/* 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 <errno.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <limits.h>
#include <sys/stat.h>
#include <unistd.h>
#include <time.h>
#include <utime.h>
#include <signal.h>
#include <mailutils/error.h>
#include <mailutils/sys/locker.h>
#include <mailutils/monitor.h>
/* locking flags */
#define MU_DOTLOCK_PID 1
#define MU_DOTLOCK_FCNTL 2
#define MU_DOTLOCK_TIME 4
#define MU_DOTLOCK_EXPIRE_TIME (5 * 60)
#define LOCKFILE_ATTR 0444
/* First draft by Brian Edmond. */
struct _dotlock
{
struct _locker base;
monitor_t lock;
int fd;
int ref;
int refcnt;
char *fname;
int flags;
};
static int
_dotlock_add_ref (locker_t locker)
{
int status;
struct _dotlock *dotlock = (struct _dotlock *)locker;
monitor_lock (dotlock->lock);
status = ++dotlock->ref;
monitor_unlock (dotlock->lock);
return status;
}
static int
_dotlock_destroy (locker_t locker)
{
struct _dotlock *dotlock = (struct _dotlock *)locker;
free (dotlock->fname);
monitor_destroy (dotlock->lock);
free (dotlock);
return 0;
}
static int
_dotlock_release (locker_t locker)
{
int status;
struct _dotlock *dotlock = (struct _dotlock *)locker;
monitor_lock (dotlock->lock);
status = --dotlock->ref;
if (status <= 0)
{
monitor_unlock (dotlock->lock);
_dotlock_destroy (locker);
return 0;
}
monitor_unlock (dotlock->lock);
return status;
}
static int
_dotlock_lock (locker_t locker)
{
struct _dotlock *dotlock = (struct _dotlock *)locker;
int fd = -1;
char buf[16];
pid_t pid;
int removed = 0;
if (dotlock == NULL)
return MU_ERROR_INVALID_PARAMETER;
/* Is the lock already applied?
FIXME: should we check flags != lock->flags ?? */
if (dotlock->fd != -1)
{
dotlock->refcnt++;
return 0;
}
/*
Check for lock existance:
if it exists but the process is gone the lock can be removed,
if the lock is expired, remove it. */
fd = open (dotlock->fname, O_RDONLY);
if (fd != -1)
{
/* Check to see if this process is still running. */
if (dotlock->flags & MU_DOTLOCK_PID)
{
int nread = read (fd, buf, sizeof (buf) - 1);
if (nread > 0)
{
buf[nread] = '\0';
pid = strtol (buf, NULL, 10);
if (pid > 0)
{
/* Process is gone so we try to remove the lock. */
if (kill (pid, 0) == -1)
removed = 1;
}
else
removed = 1; /* Corrupted file, remove the lock. */
}
}
/* Check to see if the lock expired. */
if (dotlock->flags & MU_DOTLOCK_TIME)
{
struct stat stbuf;
fstat (fd, &stbuf);
/* The lock has expired. */
if ((time (NULL) - stbuf.st_mtime) > MU_DOTLOCK_EXPIRE_TIME)
removed = 1;
}
close (fd);
if (removed)
unlink (dotlock->fname);
}
/* Try to create the lockfile. */
fd = open (dotlock->fname, O_WRONLY | O_CREAT | O_EXCL, LOCKFILE_ATTR);
if (fd == -1)
return errno;
else
{
struct stat fn_stat;
struct stat fd_stat;
if (lstat (dotlock->fname, &fn_stat)
|| fstat(fd, &fd_stat)
|| fn_stat.st_nlink != 1
|| fn_stat.st_dev != fd_stat.st_dev
|| fn_stat.st_ino != fd_stat.st_ino
|| fn_stat.st_uid != fd_stat.st_uid
|| fn_stat.st_gid != fd_stat.st_gid)
{
close (fd);
unlink (dotlock->fname);
return EPERM;
}
}
/* Success. */
sprintf (buf, "%ld", (long)getpid ());
write (fd, buf, strlen (buf));
/* Try to get a file lock. */
if (dotlock->flags & MU_DOTLOCK_FCNTL)
{
struct flock fl;
memset (&fl, 0, sizeof (struct flock));
fl.l_type = F_WRLCK;
if (fcntl (fd, F_SETLK, &fl) == -1)
{
int err = errno;
/* Could not get the file lock. */
close (fd);
unlink (dotlock->fname); /* Remove the file I created. */
return err;
}
}
dotlock->fd = fd;
dotlock->refcnt++;
return 0;
}
static int
_dotlock_touchlock (locker_t locker)
{
struct _dotlock *dotlock = (struct _dotlock *)locker;
if (!dotlock || !dotlock->fname || dotlock->fd == -1)
return MU_ERROR_INVALID_PARAMETER;
return utime (dotlock->fname, NULL);
}
static int
_dotlock_unlock (locker_t locker)
{
struct _dotlock *dotlock = (struct _dotlock *)locker;
if (!dotlock || !dotlock->fname || dotlock->fd == -1 || dotlock->refcnt <= 0)
return EINVAL;
if (--dotlock->refcnt > 0)
return 0;
if (dotlock->flags & MU_DOTLOCK_FCNTL)
{
struct flock fl;
memset (&fl, 0, sizeof (struct flock));
fl.l_type = F_UNLCK;
/* Unlock failed? */
if (fcntl (dotlock->fd, F_SETLK, &fl) == -1)
return errno;
}
close (dotlock->fd);
dotlock->fd = -1;
unlink (dotlock->fname);
return 0;
}
static struct _locker_vtable _dotlock_vtable =
{
_dotlock_add_ref,
_dotlock_release,
_dotlock_destroy,
_dotlock_lock,
_dotlock_touchlock,
_dotlock_unlock,
};
int
locker_dotlock_create (locker_t *plocker, const char *filename)
{
struct _dotlock *dotlock;
if (plocker == NULL || filename == NULL)
return MU_ERROR_INVALID_PARAMETER;
dotlock = calloc (1, sizeof *dotlock);
if (dotlock == NULL)
return MU_ERROR_NO_MEMORY;
dotlock->fname = calloc (strlen (filename) + 5 /*strlen(".lock")*/ + 1, 1);
if (dotlock->fname == NULL)
{
free (dotlock);
return MU_ERROR_NO_MEMORY;
}
strcpy (dotlock->fname, filename);
strcat (dotlock->fname, ".lock");
dotlock->base.vtable = &_dotlock_vtable;
dotlock->flags = MU_DOTLOCK_PID | MU_DOTLOCK_TIME | MU_DOTLOCK_FCNTL;
dotlock->fd = -1;
dotlock->ref = 1;
dotlock->refcnt = 0;
*plocker = &dotlock->base;
return 0;
}
/* 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 Library 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 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. */
#include <stdlib.h>
#include <mailutils/error.h>
#include <mailutils/sys/folder.h>
int
folder_add_ref (folder_t folder)
{
if (folder == NULL || folder->vtable == NULL
|| folder->vtable->add_ref == NULL)
return MU_ERROR_NOT_SUPPORTED;
return folder->vtable->add_ref (folder);
}
int
folder_release (folder_t folder)
{
if (folder == NULL || folder->vtable == NULL
|| folder->vtable->release == NULL)
return MU_ERROR_NOT_SUPPORTED;
return folder->vtable->release (folder);
}
int
folder_destroy (folder_t folder)
{
if (folder == NULL || folder->vtable == NULL
|| folder->vtable->destroy == NULL)
return MU_ERROR_NOT_SUPPORTED;
return folder->vtable->destroy (folder);
}
int
folder_open (folder_t folder, int flag)
{
if (folder == NULL || folder->vtable == NULL
|| folder->vtable->open == NULL)
return MU_ERROR_NOT_SUPPORTED;
return folder->vtable->open (folder, flag);
}
int
folder_close (folder_t folder)
{
if (folder == NULL || folder->vtable == NULL
|| folder->vtable->close == NULL)
return MU_ERROR_NOT_SUPPORTED;
return folder->vtable->close (folder);
}
int
folder_delete (folder_t folder, const char *name)
{
if (folder == NULL || folder->vtable == NULL
|| folder->vtable->delete == NULL)
return MU_ERROR_NOT_SUPPORTED;
return folder->vtable->delete (folder, name);
}
int
folder_rename (folder_t folder, const char *oldname, const char *newname)
{
if (folder == NULL || folder->vtable == NULL
|| folder->vtable->rename == NULL)
return MU_ERROR_NOT_SUPPORTED;
return folder->vtable->rename (folder, oldname, newname);
}
int
folder_subscribe (folder_t folder, const char *name)
{
if (folder == NULL || folder->vtable == NULL
|| folder->vtable->subscribe == NULL)
return MU_ERROR_NOT_SUPPORTED;
return folder->vtable->subscribe (folder, name);
}
int
folder_unsubscribe (folder_t folder, const char *name)
{
if (folder == NULL || folder->vtable == NULL
|| folder->vtable->unsubscribe == NULL)
return MU_ERROR_NOT_SUPPORTED;
return folder->vtable->unsubscribe (folder, name);
}
int
folder_list (folder_t folder, const char *dir, const char *name,
iterator_t *iterator)
{
if (folder == NULL || folder->vtable == NULL
|| folder->vtable->list == NULL)
return MU_ERROR_NOT_SUPPORTED;
return folder->vtable->list (folder, dir, name, iterator);
}
int
folder_lsub (folder_t folder, const char *dir, const char *name,
iterator_t *iterator)
{
if (folder == NULL || folder->vtable == NULL
|| folder->vtable->lsub == NULL)
return MU_ERROR_NOT_SUPPORTED;
return folder->vtable->lsub (folder, dir, name, iterator);
}
/* Stream settings. */
int
folder_get_stream (folder_t folder, stream_t *stream)
{
if (folder == NULL || folder->vtable == NULL
|| folder->vtable->get_stream == NULL)
return MU_ERROR_NOT_SUPPORTED;
return folder->vtable->get_stream (folder, stream);
}
int
folder_set_stream (folder_t folder, stream_t stream)
{
if (folder == NULL || folder->vtable == NULL
|| folder->vtable->set_stream == NULL)
return MU_ERROR_NOT_SUPPORTED;
return folder->vtable->set_stream (folder, stream);
}
/* Notifications. */
int
folder_get_observable (folder_t folder, observable_t *observable)
{
if (folder == NULL || folder->vtable == NULL
|| folder->vtable->get_observable == NULL)
return MU_ERROR_NOT_SUPPORTED;
return folder->vtable->get_observable (folder, observable);
}
int
folder_get_debug (folder_t folder, mu_debug_t *debug)
{
if (folder == NULL || folder->vtable == NULL
|| folder->vtable->get_debug == NULL)
return MU_ERROR_NOT_SUPPORTED;
return folder->vtable->get_debug (folder, debug);
}
int
folder_set_debug (folder_t folder, mu_debug_t debug)
{
if (folder == NULL || folder->vtable == NULL
|| folder->vtable->set_debug == NULL)
return MU_ERROR_NOT_SUPPORTED;
return folder->vtable->set_debug (folder, debug);
}
/* Authentication. */
int
folder_get_authority (folder_t folder, authority_t *authority)
{
if (folder == NULL || folder->vtable == NULL
|| folder->vtable->get_authority == NULL)
return MU_ERROR_NOT_SUPPORTED;
return folder->vtable->get_authority (folder, authority);
}
int
folder_set_authority (folder_t folder, authority_t authority)
{
if (folder == NULL || folder->vtable == NULL
|| folder->vtable->set_authority == NULL)
return MU_ERROR_NOT_SUPPORTED;
return folder->vtable->set_authority (folder, authority);
}
/* URL. */
int
folder_get_url (folder_t folder, url_t *url)
{
if (folder == NULL || folder->vtable == NULL
|| folder->vtable->get_url == NULL)
return MU_ERROR_NOT_SUPPORTED;
return folder->vtable->get_url (folder, url);
}
......@@ -148,7 +148,7 @@ static int
_fs_truncate (stream_t stream, off_t len)
{
struct _fs *fs = (struct _fs *)stream;
if (fs->file && ftruncate (fileno(fs->file), len) != 0)
if (fs->file && ftruncate (fileno (fs->file), len) != 0)
return MU_ERROR_IO;
return 0;
}
......@@ -162,7 +162,7 @@ _fs_get_size (stream_t stream, off_t *psize)
if (fs->file)
{
fflush (fs->file);
if (fstat(fileno(fs->file), &stbuf) == -1)
if (fstat (fileno (fs->file), &stbuf) == -1)
return errno;
}
if (psize)
......@@ -404,6 +404,7 @@ stream_file_create (stream_t *pstream)
fs->ref = 1;
fs->file = NULL;
fs->flags = 0;
monitor_create (&(fs->lock));
*pstream = &fs->base;
return 0;
}
......
......@@ -4,19 +4,29 @@
SUBDIRS = sys
pkginclude_HEADERS = \
address.h \
attribute.h \
base.h \
envelope.h \
error.h \
address.h \
attribute.h \
authority.h \
body.h \
debug.h \
envelope.h \
error.h \
folder.h \
header.h \
iterator.h \
list.h \
mbox.h \
md5-rsa.h \
monitor.h \
mutil.h \
observer.h \
parse822.h \
pop3.h \
stream.h
iterator.h \
list.h \
locker.h \
mailbox.h \
mbox.h \
md5-rsa.h \
message.h \
monitor.h \
mutil.h \
observable.h \
observer.h \
parse822.h \
pop3.h \
property.h \
stream.h \
ticket.h \
url.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. */
#ifndef _MAILUTILS_AUTHORITY_H
#define _MAILUTILS_AUTHORITY_H
#include <sys/types.h>
#include <mailutils/ticket.h>
#ifndef __P
#ifdef __STDC__
#define __P(args) args
#else
#define __P(args) ()
#endif
#endif /*__P */
#ifdef __cplusplus
extern "C" {
#endif
/* forward declaration */
struct _authority;
typedef struct _authority *authority_t;
extern int authority_add_ref __P ((authority_t));
extern int authority_release __P ((authority_t));
extern int authority_destroy __P ((authority_t));
extern int authority_set_ticket __P ((authority_t, ticket_t));
extern int authority_get_ticket __P ((authority_t, ticket_t *));
extern int authority_authenticate __P ((authority_t));
extern int authority_userpass_create __P ((authority_t *));
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_AUTHORITY_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. */
#ifndef _MAILUTILS_BASE_H
#define _MAILUTILS_BASE_H
#include <sys/types.h>
#ifdef __cplusplus
# define __MAILUTILS_START_DECLS extern "C" {
# define __MAILUTILS_END_DECLS }
#else
# define __MAILUTILS_BEGIN_DECLS
# define __MAILUTILS_END_DECLS
#endif
#ifndef __P
# ifdef __STDC__
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /*__P */
__MAILUTILS_BEGIN_DECLS
/* Forward declarations. */
struct _url;
typedef struct _url *url_t;
struct _mailer;
typedef struct _mailer *mailer_t;
struct _folder;
typedef struct _folder *folder_t;
struct _mailbox;
typedef struct _mailbox *mailbox_t;
struct _mime;
struct _mime *mime_t;
struct _message;
typedef struct _message *message_t;
struct _header;
typedef struct _header *header_t;
struct _body;
typedef struct _body *body_t;
struct _ticket;
typedef struct _ticket *ticket_t;
struct _authority;
typedef struct _authority *authority_t;
struct _locker;
typedef struct _locker *locker_t;
struct _debug;
typedef struct _debug *mu_debug_t;
struct _filter;
typedef struct _filter *filter_t;
struct _property;
typedef struct _property *property_t;
__MAILUTILS_END_DECLS
#endif /*_MAILUTILS_BASE_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. */
#ifndef _MAILUTILS_BODY_H
#define _MAILUTILS_BODY_H
#include <sys/types.h>
#include <mailutils/property.h>
#include <mailutils/stream.h>
#ifndef __P
# ifdef __STDC__
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /* __P */
#ifdef __cplusplus
extern "C" {
#endif
/* forward declaration */
struct _body;
typedef struct _body *body_t;
extern int body_add_ref __P ((body_t));
extern int body_release __P ((body_t));
extern int body_destroy __P ((body_t));
extern int body_is_modified __P ((body_t));
extern int body_clear_modified __P ((body_t));
extern int body_get_stream __P ((body_t, stream_t *));
extern int body_get_property __P ((body_t, property_t *));
extern int body_get_size __P ((body_t, size_t*));
extern int body_get_lines __P ((body_t, size_t *));
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_BODY_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. */
#ifndef _MAILUTILS_DEBUG_H
#define _MAILUTILS_DEBUG_H
#include <sys/types.h>
#include <stdarg.h>
#ifndef __P
#ifdef __STDC__
#define __P(args) args
#else
#define __P(args) ()
#endif
#endif /*__P */
#ifdef __cplusplus
extern "C" {
#endif
struct _debug;
typedef struct _debug* mu_debug_t;
#define MU_DEBUG_TRACE 1
#define MU_DEBUG_PROT 2
extern int mu_debug_add_ref __P ((mu_debug_t));
extern int mu_debug_release __P ((mu_debug_t));
extern int mu_debug_destroy __P ((mu_debug_t));
extern int mu_debug_set_level __P ((mu_debug_t, size_t level));
extern int mu_debug_get_level __P ((mu_debug_t, size_t *plevel));
extern int mu_debug_print __P ((mu_debug_t debug, size_t level,
const char *format, ...));
extern int mu_debug_printv __P ((mu_debug_t debug, size_t level,
const char *format, va_list argp));
extern int mu_debug_stderr_create __P ((mu_debug_t *));
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_DEBUG_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 Library 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 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_FOLDER_H
# define _MAILUTILS_FOLDER_H
#include <sys/types.h>
#include <mailutils/url.h>
#include <mailutils/observable.h>
#include <mailutils/debug.h>
#include <mailutils/stream.h>
#include <mailutils/authority.h>
#include <mailutils/stream.h>
#include <mailutils/iterator.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __P
# ifdef __STDC__
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /*__P */
/* Forward declaration. */
struct _folder;
typedef struct _folder *folder_t;
#define MU_FOLDER_ATTRIBUTE_DIRECTORY 0x001
#define MU_FOLDER_ATTRIBUTE_FILE 0x002
struct list_response
{
int type;
int separator;
char *name;
};
extern int folder_create __P ((folder_t *, const char *));
extern int folder_add_ref __P ((folder_t));
extern int folder_release __P ((folder_t));
extern int folder_destroy __P ((folder_t));
extern int folder_open __P ((folder_t, int flag));
extern int folder_close __P ((folder_t));
extern int folder_delete __P ((folder_t, const char *));
extern int folder_rename __P ((folder_t, const char *, const char *));
extern int folder_subscribe __P ((folder_t, const char *));
extern int folder_unsubscribe __P ((folder_t, const char *));
extern int folder_list __P ((folder_t, const char *, const char *,
iterator_t *));
extern int folder_lsub __P ((folder_t, const char *, const char *,
iterator_t *));
/* Stream settings. */
extern int folder_get_stream __P ((folder_t, stream_t *));
extern int folder_set_stream __P ((folder_t, stream_t));
/* Notifications. */
extern int folder_get_observable __P ((folder_t, observable_t *));
extern int folder_get_debug __P ((folder_t, mu_debug_t *));
extern int folder_set_debug __P ((folder_t, mu_debug_t));
/* Authentication. */
extern int folder_get_authority __P ((folder_t, authority_t *));
extern int folder_set_authority __P ((folder_t, authority_t));
/* URL. */
extern int folder_get_url __P ((folder_t, url_t *));
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_FOLDER_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. */
#ifndef _MAILUTILS_LOCKER_H
#define _MAILUTILS_LOCKER_H
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __P
# ifdef __STDC__
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /*__P */
struct _locker;
typedef struct _locker *locker_t;
extern int locker_add_ref __P ((locker_t));
extern int locker_release __P ((locker_t));
extern int locker_destroy __P ((locker_t));
extern int locker_lock __P ((locker_t));
extern int locker_touchlock __P ((locker_t));
extern int locker_unlock __P ((locker_t));
extern int locker_dotlock_create __P ((locker_t *, const char *filename));
extern int locker_nfslock_create __P ((locker_t *, const char *filename));
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_MAILBOX_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 Library 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 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_MAILBOX_H
#define _MAILUTILS_MAILBOX_H
#include <sys/types.h>
/* Forward declaration. */
struct _mailbox;
typedef struct _mailbox *mailbox_t;
#include <mailutils/url.h>
#include <mailutils/observer.h>
#include <mailutils/debug.h>
#include <mailutils/property.h>
#include <mailutils/message.h>
#include <mailutils/authority.h>
#include <mailutils/stream.h>
#include <mailutils/folder.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __P
# ifdef __STDC__
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /*__P */
/* Constructor/destructor and possible types. */
extern int mailbox_add_ref __P ((mailbox_t));
extern int mailbox_release __P ((mailbox_t));
extern int mailbox_destroy __P ((mailbox_t));
extern int mailbox_get_folder __P ((mailbox_t, folder_t *));
extern int mailbox_open __P ((mailbox_t, int flag));
extern int mailbox_close __P ((mailbox_t));
extern int mailbox_uidvalidity __P ((mailbox_t, unsigned long *));
extern int mailbox_uidnext __P ((mailbox_t, size_t *));
/* Messages. */
extern int mailbox_get_message __P ((mailbox_t, size_t msgno, message_t *));
extern int mailbox_append_message __P ((mailbox_t, message_t));
extern int mailbox_messages_count __P ((mailbox_t, size_t *));
extern int mailbox_messages_recent __P ((mailbox_t, size_t *));
extern int mailbox_messages_unseen __P ((mailbox_t, size_t *));
extern int mailbox_expunge __P ((mailbox_t));
extern int mailbox_save_attributes __P ((mailbox_t));
/* Update and scanning. */
extern int mailbox_get_size __P ((mailbox_t, off_t *size));
extern int mailbox_is_updated __P ((mailbox_t));
extern int mailbox_scan __P ((mailbox_t, size_t no, size_t *count));
/* Mailbox Stream. */
extern int mailbox_get_stream __P ((mailbox_t, stream_t *));
/* Authentication. */
extern int mailbox_get_authority __P ((mailbox_t, authority_t *));
extern int mailbox_set_authority __P ((mailbox_t, authority_t));
/* Property. */
extern int mailbox_get_property __P ((mailbox_t, property_t *));
/* URL. */
extern int mailbox_get_url __P ((mailbox_t, url_t *));
/* For any debuging */
extern int mailbox_get_debug __P ((mailbox_t, mu_debug_t *));
extern int mailbox_set_debug __P ((mailbox_t, mu_debug_t));
/* Events. */
extern int mailbox_get_observable __P ((mailbox_t, observable_t *));
extern int mailbox_create __P ((mailbox_t *, const char *));
extern int mailbox_create_default __P ((mailbox_t *, const char *));
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_MAILBOX_H */
......@@ -18,14 +18,26 @@
#ifndef _MAILUTILS_MBOX_H
#define _MAILUTILS_MBOX_H
#include <mailutils/iterator.h>
#include <mailutils/stream.h>
#include <mailutils/message.h>
#include <mailutils/observer.h>
__MAILUTILS_BEGIN_DECLS
#ifdef __cplusplus
extern "C" {
#endif
extern int mbox_create __P ((mbox_t));
#ifndef __P
# ifdef __STDC__
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /*__P */
struct _mbox;
typedef struct _mbox *mbox_t;
extern int mbox_create __P ((mbox_t *));
extern int mbox_destroy __P ((mbox_t));
extern int mbox_uidvalidity __P ((mbox_t, unsigned long *));
......@@ -34,35 +46,28 @@ extern int mbox_uidnext __P ((mbox_t, unsigned long));
extern int mbox_open __P ((mbox_t, const char *, int));
extern int mbox_close __P ((mbox_t));
extern int mbox_get_message __P ((mbox_t, unsigned int, message_t *));
extern int mbox_get_envelope __P ((mbox_t, unsigned int, envelope_t *));
extern int mbox_set_envelope __P ((mbox_t, unsigned int, envelope_t));
extern int mbox_get_header __P ((mbox_t, unsigned int, stream_t *));
extern int mbox_set_header __P ((mbox_t, unsigned int, stream_t));
extern int mbox_header_size __P ((mbox_t, unsigned int, size_t *));
extern int mbox_hdr_get_value __P ((mbox_t, unsigned int, char *, size_t, size_t *));
extern int mbox_hdr_set_value __P ((mbox_t, unsigned int, char *, size_t, int));
extern int mbox_get_body __P ((mbox_t, unsigned int, stream_t *));
extern int mbox_set_body __P ((mbox_t, unsigned int, stream_t));
extern int mbox_body_size __P ((mbox_t, unsigned int, size_t *));
extern int mbox_get_header __P ((mbox_t, unsigned int, header_t *));
extern int mbox_get_body __P ((mbox_t, unsigned int, body_t *));
extern int mbox_get_flags __P ((mbox_t, unsigned int, int *));
extern int mbox_set_flags __P ((mbox_t, unsigned int, int));
extern int mbox_size __P ((mbox_t, unsigned long *));
extern int mbox_get_size __P ((mbox_t, unsigned long *));
extern int mbox_save_attributes __P ((mbox_t));
extern int mbox_expunge __P ((mbox_t));
extern int mbox_is_modified __P ((mbox_t));
extern int mbox_scan __P ((mbox_t, unsigned int, unsigned int *));
extern int mbox_get_count __P ((mbox_t, unsigned int *));
extern int mbox_get_oberver __P ((mbox_t, observer_t));
extern int mbox_messages_count __P ((mbox_t, unsigned int *));
extern int mbox_get_obervable __P ((mbox_t, observable_t *));
extern int mbox_append __P ((mbox_t, stream_t));
extern int mbox_append __P ((mbox_t, message_t));
__MAILUTILS_END_DECLS
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_MBOX_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. */
#ifndef _MAILUTILS_MESSAGE_H
#define _MAILUTILS_MESSAGE_H
#include <sys/types.h>
/* forward declaration */
struct _message;
typedef struct _message *message_t;
#include <mailutils/envelope.h>
#include <mailutils/header.h>
#include <mailutils/body.h>
#include <mailutils/stream.h>
#include <mailutils/attribute.h>
#include <mailutils/mailbox.h>
#ifndef __P
# ifdef __STDC__
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /* __P */
#ifdef __cplusplus
extern "C" {
#endif
/* A message is considered to be a container for:
header_t, body_t, and its attribute_t. */
extern int message_add_ref __P ((message_t));
extern int message_release __P ((message_t));
extern int message_destroy __P ((message_t));
extern int message_is_modified __P ((message_t));
extern int message_clear_modified __P ((message_t));
extern int message_get_mailbox __P ((message_t, mailbox_t *));
extern int message_get_envelope __P ((message_t, envelope_t *));
extern int message_get_header __P ((message_t, header_t *));
extern int message_get_body __P ((message_t, body_t *));
extern int message_get_attribute __P ((message_t, attribute_t *));
extern int message_get_stream __P ((message_t, stream_t *));
extern int message_get_property __P ((message_t, property_t *));
extern int message_is_multipart __P ((message_t, int *));
extern int message_get_size __P ((message_t, size_t *));
extern int message_get_lines __P ((message_t, size_t *));
extern int message_get_num_parts __P ((message_t, size_t *nparts));
extern int message_get_part __P ((message_t, size_t, message_t *));
extern int message_get_uidl __P ((message_t, char *, size_t, size_t *));
extern int message_get_uid __P ((message_t, size_t *));
/* misc functions */
extern int message_create_attachment __P ((const char *content_type,
const char *encoding,
const char *filename,
message_t *newmsg));
extern int message_save_attachment __P ((message_t msg,
const char *filename, void **data));
extern int message_encapsulate __P ((message_t msg, message_t *newmsg,
void **data));
extern int message_unencapsulate __P ((message_t msg, message_t *newmsg,
void **data));
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_MESSAGE_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. */
#ifndef _MAILUTILS_MUTIL_H
#define _MAILUTILS_MUTIL_H
/*
Collection of useful utility routines that are worth sharing,
but don't have a natural home somewhere else.
*/
#include <time.h>
#ifndef __P
# ifdef __STDC__
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /*__P */
#ifdef __cplusplus
extern "C" {
#endif
extern unsigned long mu_hex2ul __P ((char hex));
extern size_t mu_hexstr2ul __P ((unsigned long* ul, const char* hex, size_t len));
struct mu_timezone
{
int utc_offset;
/* Seconds east of UTC. */
const char *tz_name;
/* Nickname for this timezone, if known. It is always considered
* to be a pointer to static string, so will never be freed. */
};
typedef struct mu_timezone mu_timezone;
extern int mu_parse_imap_date_time __P ((const char **p, struct tm * tm,
mu_timezone * tz));
extern int mu_parse_ctime_date_time __P ((const char **p, struct tm * tm,
mu_timezone * tz));
extern time_t mu_utc_offset __P ((void));
extern time_t mu_tm2time __P ((struct tm * timeptr, mu_timezone * tz));
extern char * mu_get_homedir __P ((void));
extern char * mu_tilde_expansion __P ((const char *ref, const char *delim, const char *homedir));
extern size_t util_cpystr __P ((char *dst, const char *src, size_t size));
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_MUTIL_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. */
#ifndef _MAILUTILS_OBSERVABLE_H
#define _MAILUTILS_OBSERVABLE_H
#include <sys/types.h>
#include <mailutils/observer.h>
#ifndef __P
#ifdef __STDC__
#define __P(args) args
#else
#define __P(args) ()
#endif
#endif /*__P */
#ifdef __cplusplus
extern "C" {
#endif
struct _observable;
typedef struct _observable *observable_t;
extern int observable_create __P ((observable_t *));
extern int observable_release __P ((observable_t));
extern int observable_destroy __P ((observable_t));
extern int observable_attach __P ((observable_t, int, observer_t));
extern int observable_detach __P ((observable_t, observer_t));
extern int observable_notify_all __P ((observable_t, struct event));
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_OBSERVABLE_H */
......@@ -19,7 +19,6 @@
#define _MAILUTILS_OBSERVER_H
#include <sys/types.h>
#include <mailutils/base.h>
#ifndef __P
#ifdef __STDC__
......@@ -34,19 +33,17 @@ extern "C" {
#endif
struct _observer;
struct _observable;
typedef struct _observer * observer_t;
typedef struct _observable * observable_t;
struct event
{
int type;
union
{
mailbox_t mailbox; /* For corrupted mailbox. */
void *mailbox; /* For corrupted mailbox. */
int msgno; /* For new message. */
int percentage; /* Scan progress. */
message_t message; /* message sent. */
void *message; /* message sent. */
} data ;
};
......@@ -56,23 +53,14 @@ struct event
#define MU_EVT_MAILBOX_CORRUPT 0x040
#define MU_EVT_MAILER_MESSAGE_SENT 0x080
extern int observer_create __P ((observer_t *, int (*action)
extern int observer_create __P ((observer_t *, int (*action)
__P ((void *, struct event)), void *));
extern int observer_add_ref __P ((observer_t));
extern int observer_release __P ((observer_t));
extern int observer_destroy __P ((observer_t));
extern int observer_add_ref __P ((observer_t));
extern int observer_release __P ((observer_t));
extern int observer_destroy __P ((observer_t));
extern int observer_action __P ((observer_t, struct event));
extern int observable_create __P ((observable_t *));
extern int observable_release __P ((observable_t));
extern int observable_destroy __P ((observable_t));
extern int observable_attach __P ((observable_t, int, observer_t));
extern int observable_detach __P ((observable_t, observer_t));
extern int observable_notify_all __P ((observable_t, struct event));
extern int observer_action __P ((observer_t, struct event));
#ifdef __cplusplus
}
......
/* 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_PROPERTY_H
#define _MAILUTILS_PROPERTY_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 _property;
typedef struct _property *property_t;
extern int property_create __P ((property_t *));
extern int property_destroy __P ((property_t));
extern int property_set_value __P ((property_t, const char *, const char *,
int));
extern int property_get_value __P ((property_t, const char *, char * const *));
/* Helper functions. */
extern int property_set __P ((property_t, const char *));
extern int property_unset __P ((property_t, const char *));
extern int property_is_set __P ((property_t, const char *));
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_PROPERTY_H */
# Use automake to process this file -*-Makefile-*-
pkginclude_HEADERS = \
address.h \
attribute.h \
bstream.h \
envelope.h \
fstream.h \
header.h \
iterator.h \
list.h \
mbox.h \
mstream.h \
observer.h \
pop3.h \
stream.h \
tcpstream.h
address.h \
attribute.h \
authority.h \
bstream.h \
envelope.h \
folder.h \
fstream.h \
header.h \
iterator.h \
list.h \
locker.h \
mailbox.h \
mbox.h \
memstream.h \
message.h \
mstream.h \
observable.h \
observer.h \
pop3.h \
stream.h \
tcpstream.h \
ticket.h \
url.h
......
......@@ -63,16 +63,6 @@ struct _da
monitor_t lock;
};
#define attribute_add_ref(a) ((a)->vtable->add_ref)(s)
#define attribute_release(a) ((a)->vtable->release)(s)
#define attribute_destroy(a) ((a)->vtable->destroy)(s)
#define attribute_get_flags(a,pf) ((a)->vtable->get_flags)(a,pf)
#define attribute_set_flags(a,f) ((a)->vtable->set_flags)(a,f)
#define attribute_unset_flags(a,f) ((a)->vtable->unset_flags)(a,f)
#define attribute_clear_flags(a) ((a)->vtable->clear_flags)(a)
#ifdef __cplusplus
}
#endif
......
/* 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_SYS_AUTHORITY_H
#define _MAILUTILS_SYS_AUTHORITY_H
#ifdef DMALLOC
#include <dmalloc.h>
#endif
#include <mailutils/authority.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __P
# ifdef __STDC__
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /*__P */
struct _authority_vtable
{
int (*add_ref) __P ((authority_t));
int (*release) __P ((authority_t));
int (*destroy) __P ((authority_t));
int (*set_ticket) __P ((authority_t, ticket_t));
int (*get_ticket) __P ((authority_t, ticket_t *));
int (*authenticate) __P ((authority_t));
};
struct _authority
{
struct _authority_vtable *vtable;
};
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_SYS_AUTHORITY_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 Library 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 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_SYS_FOLDER_H
#define _MAILUTILS_SYS_FOLDER_H
#include <mailutils/folder.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __P
# ifdef __STDC__
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /*__P */
struct _folder_vtable
{
int (*add_ref) __P ((folder_t));
int (*release) __P ((folder_t));
int (*destroy) __P ((folder_t));
int (*open) __P ((folder_t, int flag));
int (*close) __P ((folder_t));
int (*delete) __P ((folder_t, const char *));
int (*rename) __P ((folder_t, const char *, const char *));
int (*subscribe) __P ((folder_t, const char *));
int (*unsubscribe) __P ((folder_t, const char *));
int (*list) __P ((folder_t, const char *, const char *, iterator_t *));
int (*lsub) __P ((folder_t, const char *, const char *, iterator_t *));
/* Stream settings. */
int (*get_stream) __P ((folder_t, stream_t *));
int (*set_stream) __P ((folder_t, stream_t));
/* Notifications. */
int (*get_observable) __P ((folder_t, observable_t *));
int (*get_debug) __P ((folder_t, mu_debug_t *));
int (*set_debug) __P ((folder_t, mu_debug_t));
/* Authentication. */
int (*get_authority) __P ((folder_t, authority_t *));
int (*set_authority) __P ((folder_t, authority_t));
/* URL. */
int (*get_url) __P ((folder_t, url_t *));
};
struct _folder
{
struct _folder_vtable *vtable;
};
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_SYS_FOLDER_H */
......@@ -48,7 +48,7 @@ struct _header_vtable
int (*get_field_value) __P ((header_t, size_t, char *, size_t, size_t *));
int (*get_field_name) __P ((header_t, size_t, char *, size_t, size_t *));
int (*get_stream) __P ((header_t, stream_t *));
int (*get_stream) __P ((header_t, stream_t *));
int (*get_size) __P ((header_t, size_t *));
int (*get_lines) __P ((header_t, size_t *));
......
......@@ -42,16 +42,6 @@ struct _iterator
struct _iterator_vtable *vtable;
};
/* Use macros for the implentation. */
#define iterator_add_ref(i) ((i)->vtable->add_ref)(i)
#define iterator_release(i) ((i)->vtable->release)(i)
#define iterator_destroy(i) ((i)->vtable->destroy)(i)
#define iterator_first(i) ((i)->vtable->first)(i)
#define iterator_next(i) ((i)->vtable->next)(i)
#define iterator_current(i,a) ((i)->vtable->current)(i,a)
#define iterator_is_done(i) ((i)->vtable->is_done)(i)
#ifdef __cplusplus
}
#endif
......
/* 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_SYS_LOCKER_H
#define _MAILUTILS_SYS_LOCKER_H
#ifdef DMALLOC
#include <dmalloc.h>
#endif
#include <mailutils/locker.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __P
# ifdef __STDC__
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /*__P */
struct _locker_vtable
{
int (*add_ref) __P ((locker_t));
int (*release) __P ((locker_t));
int (*destroy) __P ((locker_t));
int (*lock) __P ((locker_t));
int (*touchlock) __P ((locker_t));
int (*unlock) __P ((locker_t));
};
struct _locker
{
struct _locker_vtable *vtable;
};
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_SYS_ENVELOPE_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 Library 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 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_SYS_MAILBOX_H
#define _MAILUTILS_SYS_MAILBOX_H
#include <mailutils/mailbox.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __P
# ifdef __STDC__
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /*__P */
struct _mailbox_vtable
{
/* Constructor/destructor and possible types. */
int (*add_ref) __P ((mailbox_t));
int (*release) __P ((mailbox_t));
int (*destroy) __P ((mailbox_t));
int (*get_folder) __P ((mailbox_t, folder_t *));
int (*open) __P ((mailbox_t, int flag));
int (*close) __P ((mailbox_t));
int (*uidvalidity) __P ((mailbox_t, unsigned long *));
int (*uidnext) __P ((mailbox_t, size_t *));
/* Messages. */
int (*get_message) __P ((mailbox_t, size_t msgno, message_t *));
int (*append_message) __P ((mailbox_t, message_t));
int (*messages_count) __P ((mailbox_t, size_t *));
int (*messages_recent) __P ((mailbox_t, size_t *));
int (*messages_unseen) __P ((mailbox_t, size_t *));
int (*expunge) __P ((mailbox_t));
int (*save_attributes) __P ((mailbox_t));
/* Update and scanning. */
int (*get_size) __P ((mailbox_t, off_t *size));
int (*is_updated) __P ((mailbox_t));
int (*scan) __P ((mailbox_t, size_t no, size_t *count));
/* Mailbox Stream. */
int (*get_stream) __P ((mailbox_t, stream_t *));
/* Authentication. */
int (*get_authority) __P ((mailbox_t, authority_t *));
int (*set_authority) __P ((mailbox_t, authority_t));
/* Property. */
int (*get_property) __P ((mailbox_t, property_t *));
/* URL. */
int (*get_url) __P ((mailbox_t, url_t *));
/* For any debuging */
int (*get_debug) __P ((mailbox_t, mu_debug_t *));
int (*set_debug) __P ((mailbox_t, mu_debug_t));
/* Events. */
int (*get_observable) __P ((mailbox_t, observable_t *));
};
struct _mailbox
{
struct _mailbox_vtable *vtable;
};
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_SYS_MAILBOX_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. */
#ifndef _MAILUTILS_SYS_MBOX_H
#define _MAILUTILS_SYS_MBOX_H
#include <time.h>
#include <mailutils/mbox.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _mbox_message* mbox_message_t;
/* Below are the headers field-names that we are caching for speed, it is
more or less the list of headers in ENVELOPE command from IMAP. */
#define HDRSIZE 15
const char *fhdr_table[] =
{
#define H_BCC 0
"Bcc",
#define H_CC 1
"Cc",
#define H_CONTENT_LANGUAGE 2
"Content-Language",
#define H_CONTENT_TRANSFER_ENCODING 3
"Content-Transfer-Encoding",
#define H_CONTENT_TYPE 4
"Content-Type",
#define H_DATE 5
"Date",
#define H_FROM 6
"From",
#define H_IN_REPLY_TO 7
"In-Reply-To",
#define H_MESSAGE_ID 8
"Message-ID",
#define H_REFERENCE 9
"Reply-To",
#define H_REPLY_TO 10
"Reply-To",
#define H_SENDER 11
"Sender",
#define H_SUBJECT 12
"Subject",
#define H_TO 13
"To",
#define H_X_UIDL 14
"X-UIDL"
};
/* Keep the file positions of where the headers and bodies start and end.
attr_flags is the "Status:" message. */
struct _mbox_message
{
/* Offset of the messages in the mailbox. */
off_t header_from;
off_t header_from_end;
off_t body;
off_t body_end;
/* Fast header retrieve, we save here the most common headers. This will
speed the header search. The entire headers are copied, when modified,
by the header_t object, we do not have to worry about updating them. */
char *fhdr[HDRSIZE];
size_t uid; /* IMAP uid. */
int attr_flags; /* The attr_flags contains the "Status:" attribute */
size_t header_lines;
size_t body_lines;
message_t message; /* A message attach to it. */
mbox_t mud; /* Back pointer. */
};
/* The umessages is an array of pointers that contains umessages_count of
mbox_message_t*; umessages[umessages_count]. We do it this way because
realloc() can move everything to a new memory region and invalidate all
the pointers. Thanks to <Dave Inglis> for pointing this out. The
messages_count is the count number of messages parsed so far. */
struct _mbox
{
mbox_message_t *umessages; /* Array. */
size_t umessages_count; /* How big is the umessages[]. */
size_t messages_count; /* How many valid entry in umessages[]. */
stream_t stream;
off_t size; /* Size of the mailbox. */
time_t mtime; /* Modified time. */
unsigned long uidvalidity;
size_t uidnext;
char *filename;
/* The variables below are use to hold the state when appending messages. */
enum mbox_state
{
MBOX_NO_STATE = 0,
MBOX_STATE_APPEND_SENDER, MBOX_STATE_APPEND_DATE, MBOX_STATE_APPEND_HEADER,
MBOX_STATE_APPEND_ATTRIBUTE, MBOX_STATE_APPEND_UID, MBOX_STATE_APPEND_BODY,
MBOX_STATE_APPEND_MESSAGE
} state ;
char *sender;
char *to;
char *date;
off_t off;
monitor_t lock;
locker_t dotlock;
};
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_SYS_MBOX_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 Library 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 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_SYS_MEMSTREAM_H
#define MAILUTILS_SYS_MEMSTREAM_H
#include <sys/types.h>
#include <mailutils/monitor.h>
#include <mailutils/sys/stream.h>
struct _memory_stream
{
struct _stream base;
int ref;
char *ptr;
size_t size;
off_t offset;
int flags;
monitor_t lock;
};
#endif /* _MAILUTILS_SYS_MEMSTREAM_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. */
#ifndef _MAILUTILS_SYS_MESSAGE_H
#define _MAILUTILS_SYS_MESSAGE_H
#include <mailutils/message.h>
#ifndef __P
# ifdef __STDC__
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /* __P */
#ifdef __cplusplus
extern "C" {
#endif
/* A message is considered to be a container for:
header_t, body_t, and its attribute_t. */
struct _message_vtable
{
int (*add_ref) __P ((message_t));
int (*release) __P ((message_t));
int (*destroy) __P ((message_t));
int (*is_modified) __P ((message_t));
int (*clear_modified) __P ((message_t));
int (*get_mailbox) __P ((message_t, mailbox_t *));
int (*get_envelope) __P ((message_t, envelope_t *));
int (*get_header) __P ((message_t, header_t *));
int (*get_body) __P ((message_t, body_t *));
int (*get_attribute) __P ((message_t, attribute_t *));
int (*get_stream) __P ((message_t, stream_t *));
int (*get_property) __P ((message_t, property_t *));
int (*is_multipart) __P ((message_t, int *));
int (*get_size) __P ((message_t, size_t *));
int (*get_lines) __P ((message_t, size_t *));
int (*get_num_parts) __P ((message_t, size_t *nparts));
int (*get_part) __P ((message_t, size_t, message_t *));
int (*get_uidl) __P ((message_t, char *, size_t, size_t *));
int (*get_uid) __P ((message_t, size_t *));
};
struct _message
{
struct _message_vtable *vtable;
};
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_SYS_MESSAGE_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. */
#ifndef _MAILUTILS_SYS_OBSERVABLE_H
#define _MAILUTILS_SYS_OBSERVABLE_H
#ifdef DMALLOC
# include <dmalloc.h>
#endif
#include <mailutils/monitor.h>
#include <mailutils/list.h>
#include <mailutils/observable.h>
#ifndef __P
#ifdef __STDC__
#define __P(args) args
#else
#define __P(args) ()
#endif
#endif /*__P */
#ifdef __cplusplus
extern "C" {
#endif
struct _observable
{
list_t list;
};
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_SYS_OBSERVER_H */
......@@ -54,28 +54,6 @@ struct _stream
struct _stream_vtable *vtable;
};
#define stream_add_ref(s) ((s)->vtable->add_ref)(s)
#define stream_release(s) ((s)->vtable->release)(s)
#define stream_destroy(s) ((s)->vtable->destroy)(s)
#define stream_open(s,h,p,f) ((s)->vtable->open)(s,h,p,f)
#define stream_close(s) ((s)->vtable->close)(s)
#define stream_read(s,b,l,n) ((s)->vtable->read)(s,b,l,n)
#define stream_readline(s,b,l,n) ((s)->vtable->readline)(s,b,l,n)
#define stream_write(s,b,l,n) ((s)->vtable->write)(s,b,l,n)
#define stream_seek(s,o,w) ((s)->vtable->seek)(s,o,w)
#define stream_tell(s,o) ((s)->vtable->tell)(s,o)
#define stream_get_size(s,o) ((s)->vtable->get_size)(s,o)
#define stream_flush(s) ((s)->vtable->flush)(s)
#define stream_truncate(s,o) ((s)->vtable->truncate)(s,o)
#define stream_get_fd(s,f) ((s)->vtable->get_fd)(s,f)
#define stream_get_flags(s,f) ((s)->vtable->get_flags)(s,f)
#define stream_get_state(s,f) ((s)->vtable->get_state)(s,f)
#ifdef __cplusplus
}
#endif
......
/* 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_SYS_TICKET_H
#define _MAILUTILS_SYS_TICKET_H
#ifdef DMALLOC
#include <dmalloc.h>
#endif
#include <mailutils/ticket.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __P
# ifdef __STDC__
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /*__P */
struct _ticket_vtable
{
int (*add_ref) __P ((ticket_t));
int (*release) __P ((ticket_t));
int (*destroy) __P ((ticket_t));
int (*pop) __P ((ticket_t, const char *, char **));
};
struct _ticket
{
struct _ticket_vtable *vtable;
};
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_SYS_TICKET_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 Library 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 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_SYS_URL_H
#define _MAILUTILS_SYS_URL_H 1
#ifdef DMALLOC
# include <dmalloc.h>
#endif
#include <mailutils/url.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __P
# if __STDC__
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /*!__P */
struct _url
{
/* Data */
char *name;
char *scheme;
char *user;
char *passwd;
char *auth;
char *host;
long port;
char *path;
char *query;
void *data;
void (*_destroy) __P ((url_t url));
/* Methods */
int (*_get_scheme) __P ((const url_t, char *, size_t, size_t *));
int (*_get_user) __P ((const url_t, char *, size_t, size_t *));
int (*_get_passwd) __P ((const url_t, char *, size_t, size_t *));
int (*_get_auth) __P ((const url_t, char *, size_t, size_t *));
int (*_get_host) __P ((const url_t, char *, size_t, size_t *));
int (*_get_port) __P ((const url_t, long *));
int (*_get_path) __P ((const url_t, char *, size_t, size_t *));
int (*_get_query) __P ((const url_t, char *, size_t, size_t *));
};
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_SYS_URL_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. */
#ifndef _MAILUTILS_TICKET_H
#define _MAILUTILS_TICKET_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
/* forward declaration */
struct _ticket;
typedef struct _ticket *ticket_t;
extern int ticket_add_ref __P ((ticket_t));
extern int ticket_release __P ((ticket_t));
extern int ticket_destroy __P ((ticket_t));
extern int ticket_pop __P ((ticket_t, const char *, char **));
extern int ticket_prompt_create __P ((ticket_t *));
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_TICKET_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 Library 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 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_URL_H
#define _MAILUTILS_URL_H 1
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __P
# if __STDC__
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /*!__P */
/* Forward declaration. */
struct _url;
typedef struct _url * url_t;
extern int url_destroy __P ((url_t));
extern int url_parse __P ((url_t));
extern int url_get_scheme __P ((const url_t, char *, size_t, size_t *));
extern int url_get_user __P ((const url_t, char *, size_t, size_t *));
extern int url_get_passwd __P ((const url_t, char *, size_t, size_t *));
extern int url_get_auth __P ((const url_t, char *, size_t, size_t *));
extern int url_get_host __P ((const url_t, char *, size_t, size_t *));
extern int url_get_port __P ((const url_t, long *));
extern int url_get_path __P ((const url_t, char *, size_t, size_t *));
extern int url_get_query __P ((const url_t, char *, size_t, size_t *));
extern const char* url_to_string __P ((const url_t));
extern int url_is_same_scheme __P ((url_t, url_t));
extern int url_is_same_user __P ((url_t, url_t));
extern int url_is_same_path __P ((url_t, url_t));
extern int url_is_same_host __P ((url_t, url_t));
extern int url_is_same_port __P ((url_t, url_t));
extern char* url_decode __P ((const char *s));
extern int url_imap_create __P ((url_t *, const char *));
extern int url_pop_create __P ((url_t *, const char *));
extern int url_file_create __P ((url_t *, const char *));
extern int url_path_create __P ((url_t *, const char *));
extern int url_mbox_create __P ((url_t *, const char *));
extern int url_smtp_create __P ((url_t *, const char *));
#ifdef __cplusplus
}
#endif
#endif /* _MAILUTILS_URL_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 <stdlib.h>
#include <mailutils/error.h>
#include <mailutils/sys/locker.h>
int
(locker_add_ref) (locker_t locker)
{
if (locker == NULL || locker->vtable == NULL
|| locker->vtable->add_ref == NULL)
return MU_ERROR_NOT_SUPPORTED;
return locker->vtable->add_ref (locker);
}
int
(locker_release) (locker_t locker)
{
if (locker == NULL || locker->vtable == NULL
|| locker->vtable->release == NULL)
return MU_ERROR_NOT_SUPPORTED;
return locker->vtable->release (locker);
}
int
(locker_destroy) (locker_t locker)
{
if (locker == NULL || locker->vtable == NULL
|| locker->vtable->destroy == NULL)
return MU_ERROR_NOT_SUPPORTED;
return locker->vtable->destroy (locker);
}
int
(locker_lock) (locker_t locker)
{
if (locker == NULL || locker->vtable == NULL
|| locker->vtable->lock == NULL)
return MU_ERROR_NOT_SUPPORTED;
return locker->vtable->lock (locker);
}
int
(locker_touchlock) (locker_t locker)
{
if (locker == NULL || locker->vtable == NULL
|| locker->vtable->lock == NULL)
return MU_ERROR_NOT_SUPPORTED;
return locker->vtable->lock (locker);
}
int
(locker_unlock) (locker_t locker)
{
if (locker == NULL || locker->vtable == NULL
|| locker->vtable->lock == NULL)
return MU_ERROR_NOT_SUPPORTED;
return locker->vtable->lock (locker);
}
/* 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 Library 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 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. */
#include <mailutils/error.h>
#include <mailutils/sys/mailbox.h>
int
mailbox_add_ref (mailbox_t mailbox)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->add_ref == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->add_ref (mailbox);
}
int
mailbox_release (mailbox_t mailbox)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->release == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->release (mailbox);
}
int
mailbox_destroy (mailbox_t mailbox)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->destroy == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->destroy (mailbox);
}
int
mailbox_get_folder (mailbox_t mailbox, folder_t *folder)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->get_folder == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->get_folder (mailbox, folder);
}
int
mailbox_open (mailbox_t mailbox, int flag)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->open == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->open (mailbox, flag);
}
int
mailbox_close (mailbox_t mailbox)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->close == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->close (mailbox);
}
int
mailbox_uidvalidity (mailbox_t mailbox, unsigned long *uidvalidity)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->uidvalidity == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->uidvalidity (mailbox, uidvalidity);
}
int
mailbox_uidnext (mailbox_t mailbox, size_t *uidnext)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->uidnext == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->uidnext (mailbox, uidnext);
}
/* Messages. */
int
mailbox_get_message (mailbox_t mailbox, size_t msgno, message_t *msg)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->get_message == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->get_message (mailbox, msgno, msg);
}
int
mailbox_append_message (mailbox_t mailbox, message_t msg)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->append_message == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->append_message (mailbox, msg);
}
int
mailbox_messages_count (mailbox_t mailbox, size_t *count)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->messages_count == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->messages_count (mailbox, count);
}
int
mailbox_messages_recent (mailbox_t mailbox, size_t *recent)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->messages_recent == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->messages_recent (mailbox, recent);
}
int
mailbox_messages_unseen (mailbox_t mailbox, size_t *unseen)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->messages_unseen == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->messages_unseen (mailbox, unseen);
}
int
mailbox_expunge (mailbox_t mailbox)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->expunge == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->expunge (mailbox);
}
int
mailbox_save_attributes (mailbox_t mailbox)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->save_attributes == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->save_attributes (mailbox);
}
/* Update and scanning. */
int
mailbox_get_size (mailbox_t mailbox, off_t *size)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->get_size == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->get_size (mailbox, size);
}
int
mailbox_is_updated (mailbox_t mailbox)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->is_updated == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->is_updated (mailbox);
}
int
mailbox_scan (mailbox_t mailbox, size_t no, size_t *count)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->scan == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->scan (mailbox, no, count);
}
/* Mailbox Stream. */
int
mailbox_get_stream (mailbox_t mailbox, stream_t *stream)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->get_stream == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->get_stream (mailbox, stream);
}
/* Authentication. */
int
mailbox_get_authority (mailbox_t mailbox, authority_t *authority)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->get_authority == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->get_authority (mailbox, authority);
}
int
mailbox_set_authority (mailbox_t mailbox, authority_t authority)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->set_authority == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->set_authority (mailbox, authority);
}
/* Property. */
int
mailbox_get_property (mailbox_t mailbox, property_t *property)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->get_property == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->get_property (mailbox, property);
}
/* URL. */
int
mailbox_get_url (mailbox_t mailbox, url_t *url)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->get_url == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->get_url (mailbox, url);
}
/* For any debuging */
int
mailbox_get_debug (mailbox_t mailbox, mu_debug_t *debug)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->get_debug == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->get_debug (mailbox, debug);
}
int
mailbox_set_debug (mailbox_t mailbox, mu_debug_t debug)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->set_debug == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->set_debug (mailbox, debug);
}
/* Events. */
int
mailbox_get_observable (mailbox_t mailbox, observable_t *observable)
{
if (mailbox == NULL || mailbox->vtable == NULL
|| mailbox->vtable->get_observable == NULL)
return MU_ERROR_NOT_SUPPORTED;
return mailbox->vtable->get_observable (mailbox, observable);
}
/* 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 <errno.h>
#include <stdlib.h>
#include <string.h>
#include <mailutils/error.h>
#include <mailutils/sys/memstream.h>
static int
_memory_add_ref (stream_t stream)
{
int status;
struct _memory_stream *mem = (struct _memory_stream *)stream;
monitor_lock (mem->lock);
status = ++mem->ref;
monitor_unlock (mem->lock);
return status;
}
static int
_memory_destroy (stream_t stream)
{
struct _memory_stream *mem = (struct _memory_stream *)stream;
if (mem && mem->ptr != NULL)
free (mem->ptr);
free (mem);
return 0;
}
static int
_memory_release (stream_t stream)
{
int status;
struct _memory_stream *mem = (struct _memory_stream *)stream;
monitor_lock (mem->lock);
status = --mem->ref;
if (status <= 0)
{
monitor_unlock (mem->lock);
_memory_destroy (stream);
return 0;
}
monitor_unlock (mem->lock);
return status;
}
static int
_memory_read (stream_t stream, void *optr, size_t osize, size_t *nbytes)
{
struct _memory_stream *mem = (struct _memory_stream *)stream;
size_t n = 0;
if (mem->ptr != NULL && (mem->offset < (off_t)mem->size))
{
n = ((mem->offset + osize) > mem->size) ?
mem->size - mem->offset : osize;
memcpy (optr, mem->ptr + mem->offset, n);
mem->offset += n;
}
if (nbytes)
*nbytes = n;
return 0;
}
static int
_memory_readline (stream_t stream, char *optr, size_t osize, size_t *nbytes)
{
struct _memory_stream *mem = (struct _memory_stream *)stream;
char *nl;
size_t n = 0;
if (mem->ptr && (mem->offset < (off_t)mem->size))
{
/* Save space for the null byte. */
osize--;
nl = memchr (mem->ptr + mem->offset, '\n', mem->size - mem->offset);
n = (nl) ? nl - (mem->ptr + mem->offset) + 1 : mem->size - mem->offset;
n = (n > osize) ? osize : n;
memcpy (optr, mem->ptr + mem->offset, n);
optr[n] = '\0';
mem->offset += n;
}
if (nbytes)
*nbytes = n;
return 0;
}
static int
_memory_write (stream_t stream, const void *iptr, size_t isize, size_t *nbytes)
{
struct _memory_stream *mem = (struct _memory_stream *)stream;
/* Bigger we have to realloc. */
if (mem->size < (mem->offset + isize))
{
char *tmp = realloc (mem->ptr, mem->offset + isize);
if (tmp == NULL)
return ENOMEM;
mem->ptr = tmp;
mem->size = mem->offset + isize;
}
memcpy (mem->ptr + mem->offset, iptr, isize);
mem->offset += isize;
if (nbytes)
*nbytes = isize;
return 0;
}
static int
_memory_truncate (stream_t stream, off_t len)
{
struct _memory_stream *mem = (struct _memory_stream *)stream;
if (len == 0)
{
free (mem->ptr);
mem->ptr = NULL;
}
else
{
char *tmp = realloc (mem, len);
if (tmp == NULL)
return ENOMEM;
mem->ptr = tmp;
}
mem->size = len;
mem->offset = len;
return 0;
}
static int
_memory_get_size (stream_t stream, off_t *psize)
{
struct _memory_stream *mem = (struct _memory_stream *)stream;
if (psize)
*psize = mem->size;
return 0;
}
static int
_memory_close (stream_t stream)
{
struct _memory_stream *mem = (struct _memory_stream *)stream;
if (mem->ptr)
free (mem->ptr);
mem->ptr = NULL;
mem->size = 0;
mem->offset = 0;
return 0;
}
static int
_memory_flush (stream_t stream)
{
(void)stream;
return 0;
}
static int
_memory_get_fd (stream_t stream, int *pfd)
{
(void)stream; (void)pfd;
return MU_ERROR_NOT_SUPPORTED;
}
static int
_memory_get_flags (stream_t stream, int *flags)
{
struct _memory_stream *mem = (struct _memory_stream *)stream;
if (flags == NULL)
return MU_ERROR_INVALID_PARAMETER;
*flags = mem->flags;
return 0;
}
static int
_memory_get_state (stream_t stream, enum stream_state *state)
{
(void)stream;
if (state == NULL)
return MU_ERROR_INVALID_PARAMETER;
*state = MU_STREAM_NO_STATE;
return 0;
}
static int
_memory_seek (stream_t stream, off_t off, enum stream_whence whence)
{
struct _memory_stream *mem = (struct _memory_stream *)stream;
off_t noff = mem->offset;
int err = 0;
if (whence == MU_STREAM_WHENCE_SET)
noff = off;
else if (whence == MU_STREAM_WHENCE_CUR)
noff += off;
else if (whence == MU_STREAM_WHENCE_END)
noff = mem->size + off;
else
noff = -1; /* error. */
if (noff >= 0)
{
if (noff > mem->offset)
_memory_truncate (stream, noff);
mem->offset = noff;
}
else
err = MU_ERROR_INVALID_PARAMETER;
return err;
}
static int
_memory_tell (stream_t stream, off_t *off)
{
struct _memory_stream *mem = (struct _memory_stream *)stream;
if (off == NULL)
return MU_ERROR_INVALID_PARAMETER;
*off = mem->offset;
return 0;
}
static int
_memory_open (stream_t stream, const char *filename, int port, int flags)
{
struct _memory_stream *mem = (struct _memory_stream *)stream;
(void)port; /* Ignored. */
(void)filename; /* Ignored. */
(void)flags; /* Ignored. */
/* Close any previous file. */
if (mem->ptr)
free (mem->ptr);
mem->ptr = NULL;
mem->size = 0;
mem->offset = 0;
mem->flags = flags;
return 0;
}
static struct _stream_vtable _mem_vtable =
{
_memory_add_ref,
_memory_release,
_memory_destroy,
_memory_open,
_memory_close,
_memory_read,
_memory_readline,
_memory_write,
_memory_seek,
_memory_tell,
_memory_get_size,
_memory_truncate,
_memory_flush,
_memory_get_fd,
_memory_get_flags,
_memory_get_state
};
int
stream_memory_create (stream_t *pstream)
{
struct _memory_stream *mem;
if (pstream == NULL)
return MU_ERROR_INVALID_PARAMETER;
mem = calloc (1, sizeof (*mem));
if (mem == NULL)
return MU_ERROR_NO_MEMORY;
mem->base.vtable = &_mem_vtable;
mem->ref = 1;
mem->ptr = NULL;
mem->size = 0;
mem->offset = 0;
mem->flags = 0;
monitor_create (&(mem->lock));
*pstream = &mem->base;
return 0;
}
/* 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 <stdlib.h>
#include <mailutils/error.h>
#include <mailutils/sys/message.h>
int
message_add_ref (message_t msg)
{
if (msg == NULL || msg->vtable == NULL
|| msg->vtable->add_ref == NULL)
return MU_ERROR_NOT_SUPPORTED;
return msg->vtable->add_ref (msg);
}
int
message_release (message_t msg)
{
if (msg == NULL || msg->vtable == NULL
|| msg->vtable->release == NULL)
return MU_ERROR_NOT_SUPPORTED;
return msg->vtable->release (msg);
}
int
message_destroy (message_t msg)
{
if (msg == NULL || msg->vtable == NULL
|| msg->vtable->destroy == NULL)
return MU_ERROR_NOT_SUPPORTED;
return msg->vtable->destroy (msg);
}
int
message_is_modified (message_t msg)
{
if (msg == NULL || msg->vtable == NULL
|| msg->vtable->is_modified == NULL)
return MU_ERROR_NOT_SUPPORTED;
return msg->vtable->is_modified (msg);
}
int
message_clear_modified (message_t msg)
{
if (msg == NULL || msg->vtable == NULL
|| msg->vtable->clear_modified == NULL)
return MU_ERROR_NOT_SUPPORTED;
return msg->vtable->clear_modified (msg);
}
int
message_get_mailbox (message_t msg, mailbox_t *mbox)
{
if (msg == NULL || msg->vtable == NULL
|| msg->vtable->get_mailbox == NULL)
return MU_ERROR_NOT_SUPPORTED;
return msg->vtable->get_mailbox (msg, mbox);
}
int
message_get_envelope (message_t msg, envelope_t *envelope)
{
if (msg == NULL || msg->vtable == NULL
|| msg->vtable->get_envelope == NULL)
return MU_ERROR_NOT_SUPPORTED;
return msg->vtable->get_envelope (msg, envelope);
}
int
message_get_header (message_t msg, header_t *header)
{
if (msg == NULL || msg->vtable == NULL
|| msg->vtable->get_header == NULL)
return MU_ERROR_NOT_SUPPORTED;
return msg->vtable->get_header (msg, header);
}
int
message_get_body (message_t msg, body_t *body)
{
if (msg == NULL || msg->vtable == NULL
|| msg->vtable->get_body == NULL)
return MU_ERROR_NOT_SUPPORTED;
return msg->vtable->get_body (msg, body);
}
int
message_get_attribute (message_t msg, attribute_t *attribute)
{
if (msg == NULL || msg->vtable == NULL
|| msg->vtable->get_attribute == NULL)
return MU_ERROR_NOT_SUPPORTED;
return msg->vtable->get_attribute (msg, attribute);
}
int
message_get_stream (message_t msg, stream_t *stream)
{
if (msg == NULL || msg->vtable == NULL
|| msg->vtable->get_stream == NULL)
return MU_ERROR_NOT_SUPPORTED;
return msg->vtable->get_stream (msg, stream);
}
int
message_get_property (message_t msg, property_t *property)
{
if (msg == NULL || msg->vtable == NULL
|| msg->vtable->get_property == NULL)
return MU_ERROR_NOT_SUPPORTED;
return msg->vtable->get_property (msg, property);
}
int
message_is_multipart (message_t msg, int *ismulti)
{
if (msg == NULL || msg->vtable == NULL
|| msg->vtable->is_multipart == NULL)
return MU_ERROR_NOT_SUPPORTED;
return msg->vtable->is_multipart (msg, ismulti);
}
int
message_get_size (message_t msg, size_t *size)
{
if (msg == NULL || msg->vtable == NULL
|| msg->vtable->get_size == NULL)
return MU_ERROR_NOT_SUPPORTED;
return msg->vtable->get_size (msg, size);
}
int
message_get_lines (message_t msg, size_t *lines)
{
if (msg == NULL || msg->vtable == NULL
|| msg->vtable->get_lines == NULL)
return MU_ERROR_NOT_SUPPORTED;
return msg->vtable->get_lines (msg, lines);
}
int
message_get_num_parts (message_t msg, size_t *nparts)
{
if (msg == NULL || msg->vtable == NULL
|| msg->vtable->get_num_parts == NULL)
return MU_ERROR_NOT_SUPPORTED;
return msg->vtable->get_num_parts (msg, nparts);
}
int
message_get_part (message_t msg, size_t partno, message_t *submsg)
{
if (msg == NULL || msg->vtable == NULL
|| msg->vtable->get_part == NULL)
return MU_ERROR_NOT_SUPPORTED;
return msg->vtable->get_part (msg, partno, submsg);
}
int
message_get_uidl (message_t msg, char *uidl, size_t len, size_t *plen)
{
if (msg == NULL || msg->vtable == NULL
|| msg->vtable->get_uidl == NULL)
return MU_ERROR_NOT_SUPPORTED;
return msg->vtable->get_uidl (msg, uidl, len, plen);
}
int
message_get_uid (message_t msg, size_t *uid)
{
if (msg == NULL || msg->vtable == NULL
|| msg->vtable->get_uid == NULL)
return MU_ERROR_NOT_SUPPORTED;
return msg->vtable->get_uid (msg, uid);
}
......@@ -471,6 +471,7 @@ stream_mapfile_create (stream_t *pstream)
ms->offset = -1;
ms->flags = 0;
ms->mflags = 0;
monitor_create (&(ms->lock));
*pstream = &ms->base;
return 0;
......
/* Copyright (C) 2001 Free Software Foundation, Inc.
A wrapper for mktime function allowing to specify the timezone.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library 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 the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#include <string.h>
#include <time.h>
#include <pwd.h>
#include <unistd.h>
#include <mailutils/mutil.h>
/* convert a sequence of hex characters into an integer */
unsigned long mu_hex2ul(char hex)
{
if (hex >= '0' && hex <= '9')
return hex - '0';
if (hex >= 'a' && hex <= 'z')
return hex - 'a';
if (hex >= 'A' && hex <= 'Z')
return hex - 'A';
return -1;
}
size_t mu_hexstr2ul(unsigned long* ul, const char* hex, size_t len)
{
size_t r;
*ul = 0;
for (r = 0; r < len; r++)
{
unsigned long v = mu_hex2ul(hex[r]);
if (v == (unsigned long)-1)
return r;
*ul = *ul * 16 + v;
}
return r;
}
/* Convert struct tm into time_t, taking into account timezone offset.
mktime() always treats tm as if it was localtime, so convert it
to UTC, then adjust by the tm's real timezone, if it is known.
NOTE: 1. mktime converts localtime struct tm to *time_t in UTC*
2. adding mu_utc_offset() compensates for the localtime
corrections in mktime(), i.e. it yields the time_t in
the current zone of struct tm.
3. finally, subtracting TZ offset yields the UTC.
*/
time_t
mu_tm2time (struct tm *timeptr, mu_timezone* tz)
{
int offset = tz ? tz->utc_offset : 0;
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)
{
time_t t = 0;
struct tm* tm = gmtime(&t);
return - mktime(tm);
}
static const char *months[] =
{
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL
};
static const char *wdays[] =
{
"Mon", "Teu", "Wed", "Thr", "Fri", "Sat", "Sun", NULL
};
int
mu_parse_imap_date_time (const char **p, struct tm *tm, mu_timezone *tz)
{
int year, mon, day, hour, min, sec;
char zone[6] = "+0000"; /* ( "+" / "-" ) hhmm */
char month[5] = "";
int hh = 0;
int mm = 0;
int sign = 1;
int scanned = 0, scanned3;
int i;
int tzoffset;
day = mon = year = hour = min = sec = 0;
memset (tm, 0, sizeof (*tm));
switch (sscanf (*p,
"%2d-%3s-%4d%n %2d:%2d:%2d %5s%n",
&day, month, &year, &scanned3, &hour, &min, &sec, zone,
&scanned))
{
case 3:
scanned = scanned3;
break;
case 7:
break;
default:
return -1;
}
tm->tm_sec = sec;
tm->tm_min = min;
tm->tm_hour = hour;
tm->tm_mday = day;
for (i = 0; i < 12; i++)
{
if (strncasecmp (month, months[i], 3) == 0)
{
mon = i;
break;
}
}
tm->tm_mon = mon;
tm->tm_year = (year > 1900) ? year - 1900 : year;
tm->tm_yday = 0; /* unknown. */
tm->tm_wday = 0; /* unknown. */
#if HAVE_TM_ISDST
tm->tm_isdst = -1; /* unknown. */
#endif
hh = (zone[1] - '0') * 10 + (zone[2] - '0');
mm = (zone[3] - '0') * 10 + (zone[4] - '0');
sign = (zone[0] == '-') ? -1 : +1;
tzoffset = sign * (hh * 60 * 60 + mm * 60);
#if HAVE_TM_GMTOFFSET
tm->tm_gmtoffset = tzoffset;
#endif
if (tz)
{
tz->utc_offset = tzoffset;
tz->tz_name = NULL;
}
*p += scanned;
return 0;
}
/* "ctime" format is: Thu Jul 01 15:58:27 1999, with no trailing \n. */
int
mu_parse_ctime_date_time (const char **p, struct tm *tm, mu_timezone * tz)
{
int wday = 0;
int year = 0;
int mon = 0;
int day = 0;
int hour = 0;
int min = 0;
int sec = 0;
int n = 0;
int i;
char weekday[5] = "";
char month[5] = "";
if (sscanf (*p, "%3s %3s %2d %2d:%2d:%2d %d%n\n",
weekday, month, &day, &hour, &min, &sec, &year, &n) != 7)
return -1;
*p += n;
for (i = 0; i < 7; i++)
{
if (strncasecmp (weekday, wdays[i], 3) == 0)
{
wday = i;
break;
}
}
for (i = 0; i < 12; i++)
{
if (strncasecmp (month, months[i], 3) == 0)
{
mon = i;
break;
}
}
if (tm)
{
memset (tm, 0, sizeof (struct tm));
tm->tm_sec = sec;
tm->tm_min = min;
tm->tm_hour = hour;
tm->tm_mday = day;
tm->tm_wday = wday;
tm->tm_mon = mon;
tm->tm_year = (year > 1900) ? year - 1900 : year;
#ifdef HAVE_TM_ISDST
tm->tm_isdst = -1; /* unknown. */
#endif
}
/* ctime has no timezone information, set tz to UTC if they ask. */
if (tz)
memset (tz, 0, sizeof (struct mu_timezone));
return 0;
}
char *
mu_get_homedir (void)
{
char *homedir = getenv ("HOME");
if (!homedir)
{
struct passwd *pwd;
pwd = getpwuid(getuid());
if (!pwd)
return NULL;
homedir = pwd->pw_dir;
}
return homedir;
}
/* NOTE: Allocates Memory. */
/* Expand: ~ --> /home/user and to ~guest --> /home/guest. */
char *
mu_tilde_expansion (const char *ref, const char *delim, const char *homedir)
{
char *p = strdup (ref);
if (*p == '~')
{
p++;
if (*p == delim[0] || *p == '\0')
{
char *s;
if (!homedir)
{
homedir = mu_get_homedir ();
if (!homedir)
return NULL;
}
s = calloc (strlen (homedir) + strlen (p) + 1, 1);
strcpy (s, homedir);
strcat (s, p);
free (--p);
p = s;
}
else
{
struct passwd *pw;
char *s = p;
char *name;
while (*s && *s != delim[0])
s++;
name = calloc (s - p + 1, 1);
memcpy (name, p, s - p);
name [s - p] = '\0';
pw = getpwnam (name);
free (name);
if (pw)
{
char *buf = calloc (strlen (pw->pw_dir) + strlen (s) + 1, 1);
strcpy (buf, pw->pw_dir);
strcat (buf, s);
free (--p);
p = buf;
}
else
p--;
}
}
return p;
}
/* Smart strncpy that always add the null and returns the number of bytes
written. */
size_t
util_cpystr (char *dst, const char *src, size_t size)
{
size_t len = src ? strlen (src) : 0 ;
if (dst == NULL || size == 0)
return len;
if (len >= size)
len = size - 1;
memcpy (dst, src, len);
dst[len] = '\0';
return len;
}
......@@ -23,7 +23,7 @@
#include <stdlib.h>
#include <mailutils/iterator.h>
#include <mailutils/error.h>
#include <mailutils/sys/observer.h>
#include <mailutils/sys/observable.h>
struct observer_info
{
......
/* 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 <errno.h>
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <termios.h>
#include <mailutils/error.h>
#include <mailutils/monitor.h>
#include <mailutils/sys/ticket.h>
struct _prompt_ticket
{
struct _ticket base;
int ref;
monitor_t lock;
};
static void
echo_off(struct termios *stored_settings)
{
struct termios new_settings;
tcgetattr (0, stored_settings);
new_settings = *stored_settings;
new_settings.c_lflag &= (~ECHO);
tcsetattr (0, TCSANOW, &new_settings);
}
static void
echo_on(struct termios *stored_settings)
{
tcsetattr (0, TCSANOW, stored_settings);
}
static int
_prompt_add_ref (ticket_t ticket)
{
int status;
struct _prompt_ticket *prompt = (struct _prompt_ticket *)ticket;
monitor_lock (prompt->lock);
status = ++prompt->ref;
monitor_unlock (prompt->lock);
return status;
}
static int
_prompt_destroy (ticket_t ticket)
{
struct _prompt_ticket *prompt = (struct _prompt_ticket *)ticket;
monitor_destroy (prompt->lock);
free (prompt);
return 0;
}
static int
_prompt_release (ticket_t ticket)
{
int status;
struct _prompt_ticket *prompt = (struct _prompt_ticket *)ticket;
monitor_lock (prompt->lock);
status = --prompt->ref;
if (status <= 0)
{
monitor_unlock (prompt->lock);
_prompt_destroy (ticket);
return 0;
}
monitor_unlock (prompt->lock);
return status;
}
static int
_prompt_pop (ticket_t ticket, const char *challenge, char **parg)
{
char arg[256];
struct termios stored_settings;
int echo = 1;
(void)ticket;
/* Being smart if we see "Passwd" and turning off echo. */
if (strstr (challenge, "ass") != NULL
|| strstr (challenge, "ASS") != NULL)
echo = 0;
fprintf (stdout, "%s", challenge);
fflush (stdout);
if (!echo)
echo_off (&stored_settings);
fgets (arg, sizeof (arg), stdin);
if (!echo)
{
echo_on (&stored_settings);
fputc ('\n', stdout);
fflush (stdout);
}
arg [strlen (arg) - 1] = '\0'; /* nuke the trailing line. */
*parg = strdup (arg);
return 0;
}
static struct _ticket_vtable _prompt_vtable =
{
_prompt_add_ref,
_prompt_release,
_prompt_destroy,
_prompt_pop,
};
int
ticket_prompt_create (ticket_t *pticket)
{
struct _prompt_ticket *prompt;
if (pticket == NULL)
return MU_ERROR_INVALID_PARAMETER;
prompt = calloc (1, sizeof *prompt);
if (prompt == NULL)
return MU_ERROR_NO_MEMORY;
prompt->base.vtable = &_prompt_vtable;
prompt->ref = 1;
monitor_create (&(prompt->lock));
*pticket = &prompt->base;
return 0;
}
......@@ -376,7 +376,7 @@ static struct _stream_vtable _tcp_vtable =
_tcp_get_fd,
_tcp_get_flags,
_tcp_get_state,
_tcp_get_state
};
int
......@@ -397,6 +397,7 @@ stream_tcp_create (stream_t *pstream)
tcp->host = NULL;
tcp->port = -1;
tcp->state = TCP_STATE_INIT;
monitor_create (&(tcp->lock));
*pstream = &tcp->base;
return 0;
}
......
/* 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 <stdlib.h>
#include <mailutils/error.h>
#include <mailutils/sys/ticket.h>
int
ticket_add_ref (ticket_t ticket)
{
if (ticket == NULL || ticket->vtable == NULL
|| ticket->vtable->add_ref == NULL)
return MU_ERROR_NOT_SUPPORTED;
return ticket->vtable->add_ref (ticket);
}
int
ticket_release (ticket_t ticket)
{
if (ticket == NULL || ticket->vtable == NULL
|| ticket->vtable->release == NULL)
return MU_ERROR_NOT_SUPPORTED;
return ticket->vtable->release (ticket);
}
int
ticket_destroy (ticket_t ticket)
{
if (ticket == NULL || ticket->vtable == NULL
|| ticket->vtable->destroy == NULL)
return MU_ERROR_NOT_SUPPORTED;
return ticket->vtable->destroy (ticket);
}
int
ticket_pop (ticket_t ticket, const char *challenge, char **parg)
{
if (ticket == NULL || ticket->vtable == NULL
|| ticket->vtable->pop == NULL)
return MU_ERROR_NOT_SUPPORTED;
return ticket->vtable->pop (ticket, challenge, parg);
}