Commit 9253cfd5 9253cfd525f4af5f3369fb3d036bd4c100909357 by Alain Magloire

First draft to set `property' on the mailbox, setting a property

will permit to change the behaviour of the mailbox.  For example
POP3 and IMAP4 streams are RFC822 meaning they end with "\r\n",
Now I'm doing ugly hack to convert it and maintain the offset,
that does not work well.  Rather lets put the trouble on
the client ;-) but by setting property_set ("RFC822_FORMAT");
the conversion "\r\n" can still be done. But it will be up
to the client to do the offset calculation.
1 parent 15461173
2001-02-22 Alain Magloire
* mailbox/property.c : New file.
* include/mailutils/property.h : New file.
* mailbox/mailbox.c (mailbox_get_property) : New function,
a first draft to let set "property" on a mailbox that can
change its behaviour.
* mailbox/include/mailbox0.h : New field in struct _mailbox, property.
* sieve/lex-sieve.lex : Add LGPL banner.
* sieve/gram-sieve.y : Add LGPL banner.
2001-02-22 Alain Magloire
* sieve : New Directory.
* sieve/lex-sieve.lex : RFC3028 tokenizer.
* sieve/gram-sieve.y : RFC3028 grammar.
......
......@@ -27,6 +27,7 @@ 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/auth.h>
#include <mailutils/locker.h>
......@@ -83,6 +84,9 @@ extern int mailbox_set_authority __P ((mailbox_t, authority_t));
extern int mailbox_get_ticket __P ((mailbox_t, ticket_t *));
extern int mailbox_set_ticket __P ((mailbox_t, ticket_t));
/* Property. */
extern int mailbox_get_property __P ((mailbox_t, property_t *));
/* URL. */
extern int mailbox_get_url __P ((mailbox_t, url_t *));
......
/* 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;
enum property_type { TYPE_POINTER, TYPE_LONG };
extern int property_create __P ((property_t *));
extern void property_destroy __P ((property_t *));
extern int property_set_value __P ((property_t, const char *k, const void *v,
enum property_type));
extern int property_get_value __P ((property_t, const char *k, void **,
enum property_type *));
extern int property_set __P ((property_t, const char *k));
extern int property_unset __P ((property_t, const char *k));
extern int property_is_set __P ((property_t, const char *k));
extern int property_set_int __P ((property_t, const char *, int));
extern int property_get_int __P ((property_t, const char *));
extern int property_set_long __P ((property_t, const char *, long));
extern long property_get_long __P ((property_t, const char *));
extern int property_set_pointer __P ((property_t, const char *, void *));
extern void *property_get_pointer __P ((property_t, const char *));
#ifdef _cplusplus
}
#endif
#endif /* _MAILUTILS_PROPERTY_H */
......@@ -48,6 +48,7 @@ struct _mailbox
debug_t debug;
ticket_t ticket;
authority_t authority;
property_t property;
locker_t locker;
stream_t stream;
url_t url;
......
......@@ -392,6 +392,16 @@ mailbox_get_observable (mailbox_t mbox, observable_t *pobservable)
}
int
mailbox_get_property (mailbox_t mbox, property_t *pproperty)
{
if (mbox == NULL || pproperty == NULL)
return EINVAL;
*pproperty = mbox->property;
return 0;
}
int
mailbox_set_debug (mailbox_t mbox, debug_t debug)
{
if (mbox == NULL)
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000 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 <mailutils/property.h>
#include <mailutils/list.h>
#include <mailutils/iterator.h>
struct property_data
{
size_t hash;
enum property_type type;
union
{
long l;
void *v;
} value;
};
struct _property
{
list_t list;
};
static int property_find __P ((list_t, const char *, struct property_data **));
static size_t hash __P ((const char *));
int
property_create (property_t *pp)
{
property_t prop;
int status;
if (pp == NULL)
return EINVAL;
prop = calloc (1, sizeof (*prop));
if (prop == NULL)
return ENOMEM;
status = list_create (&(prop->list));
if (status != 0)
{
free (prop);
return status;
}
*pp = prop;
return 0;
}
void
property_destroy (property_t *pp)
{
if (pp && *pp)
{
property_t prop = *pp;
list_destroy (&(prop->list));
free (prop);
*pp = NULL;
}
}
int
property_set_value (property_t prop, const char *key, const void *value,
enum property_type type)
{
struct property_data *pd;
int status;
if (prop == NULL)
return EINVAL;
status = property_find (prop->list, key, &pd);
if (status != 0)
return status;
if (pd == NULL)
{
pd = calloc (1, sizeof (*pd));
if (pd == NULL)
return ENOMEM;
pd->hash = hash (key);
pd->type = type;
switch (type)
{
case TYPE_POINTER:
pd->value.v = (void *)value;
break;
case TYPE_LONG:
pd->value.l = (long)value;
break;
}
list_append (prop->list, (void *)pd);
}
else
pd->value.v = (void *)value;
return 0;
}
int
property_get_value (property_t prop, const char *key, void **pvalue,
enum property_type *ptype)
{
struct property_data *pd;
int status;
if (prop == NULL)
return EINVAL;
status = property_find (prop->list, key, &pd);
if (status != 0)
return status;
if (pd == NULL)
return ENOENT;
if (ptype)
*ptype = pd->type;
if (pvalue)
*pvalue = pd->value.v;
return 0;
}
int
property_set (property_t prop, const char *k)
{
return property_set_int (prop, k, 1);
}
int
property_unset (property_t prop, const char *k)
{
return property_set_int (prop, k, 0);
}
int
property_is_set (property_t prop, const char *k)
{
return property_get_int (prop, k);
}
int
property_set_int (property_t prop, const char *k, int i)
{
return property_set_value (prop, k, (void *)i, TYPE_LONG);
}
int
property_get_int (property_t prop, const char *k)
{
int value = 0;
property_get_value (prop, k, (void **)&value, NULL);
return value;
}
int
property_set_long (property_t prop, const char *k, long l)
{
return property_set_value (prop, k, (const void *)l, TYPE_LONG);
}
long
property_get_long (property_t prop, const char *k)
{
long value = 0;
property_get_value (prop, k, (void **)&value, NULL);
return value;
}
int
property_set_pointer (property_t prop, const char *k, void *p)
{
return property_set_value (prop, k, p, TYPE_POINTER);
}
void *
property_get_pointer (property_t prop, const char *k)
{
void *value = NULL;
property_get_value (prop, k, &value, NULL);
return value;
}
static size_t
hash (const char *s)
{
size_t hashval;
for (hashval = 0; *s != '\0' ; s++)
{
hashval += (unsigned)*s ;
hashval += (hashval <<10);
hashval ^= (hashval >>6) ;
}
hashval += (hashval <<3);
hashval ^= (hashval >>11);
hashval += (hashval <<15);
return hashval;
}
static int
property_find (list_t list, const char *key, struct property_data **p)
{
int status;
size_t h;
struct property_data *pd = NULL;
iterator_t iterator;
status = iterator_create (&iterator, list);
if (status != 0)
return status;
h = hash (key);
for (iterator_first (iterator); !iterator_is_done (iterator);
iterator_next (iterator))
{
iterator_current (iterator, (void **)&pd);
if (pd && pd->hash == h)
{
break;
}
pd = NULL;
}
iterator_destroy (&iterator);
*p = pd;
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. */
%}
%token SIEVE_ADDRESS SIEVE_ALL SIEVE_ALLOF SIEVE_ANYOF SIEVE_COMPARATOR
......
/* Scanner for Sieve
created : Alain Magloire
ref: RFC 3028 */
%{
/* 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. */
#include <stdio.h>
#include "y.tab.h"
/* Scanner for Sieve
created : Alain Magloire
ref: RFC 3028 */
void count ();
%}
......