Commit d16d6f1f d16d6f1fce477a7cc1f84d51a6d79d45baa47483 by Alain Magloire

* sieve/{exitcodes.h hmac-md5.h md5.c md5.h md5global.h}: Removed.

	* sieve/md5-rsa.c: New file, clear identiy that the algo.
	is from RSA and not GNU md5.
	* sieve/md5-rsa.h : New file.
	* sieve/Makefile.am:  added md5-rsa.[ch].
	* sieve/message.h:  lcase() change for strlower ().
	* sieve/script.c: Include md5-rsa.h.
	* sieve/sieve-gram.y: lcase changed for strlower ().
	* sieve/util.c: Remove all the unnecassary code and
	only implement strlower() and strupper().
	* sieve/util.h: Only export strlower and struppper ().
1 parent a1c387de
......@@ -25,7 +25,6 @@ SRC = \
comparator.c \
imparse.c \
interp.c \
md5.c \
message.c \
parseaddr.c \
script.c \
......@@ -38,12 +37,8 @@ SRC = \
HDR = \
comparator.h \
exitcodes.h \
hmac-md5.h \
imparse.h \
interp.h \
md5.h \
md5global.h \
message.h \
parseaddr.h \
script.h \
......
/* exitcodes.h -- wrapper around sysextis.h
* $Id$
*
* Copyright (c) 1998-2000 Carnegie Mellon University. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The name "Carnegie Mellon University" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For permission or any other legal
* details, please contact
* Office of Technology Transfer
* Carnegie Mellon University
* 5000 Forbes Avenue
* Pittsburgh, PA 15213-3890
* (412) 268-4387, fax: (412) 268-7395
* tech-transfer@andrew.cmu.edu
*
* 4. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by Computing Services
* at Carnegie Mellon University (http://www.cmu.edu/computing/)."
*
* CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
/* Sendmail has some weird ideas on what constitutes permenant failure. On
more than one occasion, we have gotten burned by this moving users around
through various inadvisable means, screwing up the mailboxes file,
whatever.
We don't want to fail out permenantly on things like EX_USAGE, EX_SOFTWARE,
etc., because that generally means someone was just screwing with the mail
store and we don't want to lose mail.
Instead, we map these EC_* codes to EX_* codes, thereby lying to Sendmail,
since we don't derive any benefit from Sendmail knowing what the error was.
We just want it to retry all the time anyway. This way, should sendmail's
behavior be different and we start deriving benefit from Sendmail knowing
stuff, we can easily change it back.
So other code uses the EC_* error, then we maybe change it to TEMPFAIL if
we don't agree on whether the error should be permenant or not.
Comments below stolen from sysexits.h. */
#ifndef INCLUDED_EXITCODES_H
#define INCLUDED_EXITCODES_H
#include <sysexits.h>
#define EC_OK 0 /* successful termination */
#define EC_USAGE EX_TEMPFAIL /* command line usage error */
#define EC_DATAERR EX_DATAERR /* data format error */
#define EC_NOINPUT EX_TEMPFAIL /* cannot open input */
#define EC_NOUSER EX_NOUSER /* addressee unknown */
#define EC_NOHOST EX_TEMPFAIL /* host name unknown */
#define EC_UNAVAILABLE EX_TEMPFAIL /* service unavailable */
#define EC_SOFTWARE EX_TEMPFAIL /* internal software error */
#define EC_OSERR EX_TEMPFAIL /* system error (e.g., can't fork) */
#define EC_OSFILE EX_TEMPFAIL /* critical OS file missing */
#define EC_CANTCREAT EX_TEMPFAIL /* can't create (user) output file */
#define EC_IOERR EX_TEMPFAIL /* input/output error */
#define EC_TEMPFAIL EX_TEMPFAIL /* user is invited to retry */
#define EC_PROTOCOL EX_TEMPFAIL /* remote error in protocol */
#define EC_NOPERM EX_TEMPFAIL /* permission denied */
#define EC_CONFIG EX_TEMPFAIL /* configuration error */
#endif /* INCLUDED_EXITCODES_H */
/* hmac-md5.h -- HMAC_MD5 functions
*/
#ifndef HMAC_MD5_H
#define HMAC_MD5_H 1
#define HMAC_MD5_SIZE 16
/* intermediate MD5 context */
typedef struct HMAC_MD5_CTX_s {
MD5_CTX ictx, octx;
} HMAC_MD5_CTX;
/* intermediate HMAC state
* values stored in network byte order (Big Endian)
*/
typedef struct HMAC_MD5_STATE_s {
UINT4 istate[4];
UINT4 ostate[4];
} HMAC_MD5_STATE;
/* One step hmac computation
*
* digest may be same as text or key
*/
void hmac_md5(const unsigned char *text, int text_len,
const unsigned char *key, int key_len,
unsigned char digest[HMAC_MD5_SIZE]);
/* create context from key
*/
void hmac_md5_init(HMAC_MD5_CTX *hmac,
const unsigned char *key, int key_len);
/* precalculate intermediate state from key
*/
void hmac_md5_precalc(HMAC_MD5_STATE *hmac,
const unsigned char *key, int key_len);
/* initialize context from intermediate state
*/
void hmac_md5_import(HMAC_MD5_CTX *hmac, HMAC_MD5_STATE *state);
#define hmac_md5_update(hmac, text, text_len) MD5Update(&(hmac)->ictx, (text), (text_len))
/* finish hmac from intermediate result. Intermediate result is zeroed.
*/
void hmac_md5_final(unsigned char digest[HMAC_MD5_SIZE],
HMAC_MD5_CTX *hmac);
#endif /* HMAC_MD5_H */
/* MD5.H - header file for MD5C.C
*/
/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
rights reserved.
License to copy and use this software is granted provided that it
is identified as the "RSA Data Security, Inc. MD5 Message-Digest
Algorithm" in all material mentioning or referencing this software
or this function.
License is also granted to make and use derivative works provided
that such works are identified as "derived from the RSA Data
Security, Inc. MD5 Message-Digest Algorithm" in all material
mentioning or referencing the derived work.
RSA Data Security, Inc. makes no representations concerning either
the merchantability of this software or the suitability of this
software for any particular purpose. It is provided "as is"
without express or implied warranty of any kind.
These notices must be retained in any copies of any part of this
documentation and/or software.
*/
/* MD5 context. */
typedef struct {
UINT4 state[4]; /* state (ABCD) */
UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */
unsigned char buffer[64]; /* input buffer */
} MD5_CTX;
void MD5Init PROTO_LIST ((MD5_CTX *));
void MD5Update PROTO_LIST
((MD5_CTX *, unsigned char *, unsigned int));
void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *));
void hmac_md5 PROTO_LIST ((unsigned char *, int, unsigned char *, int, unsigned char*));
/* GLOBAL.H - RSAREF types and constants
*/
/* PROTOTYPES should be set to one if and only if the compiler supports
function argument prototyping.
The following makes PROTOTYPES default to 0 if it has not already
been defined with C compiler flags.
*/
#ifndef PROTOTYPES
#define PROTOTYPES 0
#endif
/* POINTER defines a generic pointer type */
typedef unsigned char *POINTER;
/* UINT2 defines a two byte word */
typedef unsigned short int UINT2;
/* UINT4 defines a four byte word */
typedef unsigned long int UINT4;
/* PROTO_LIST is defined depending on how PROTOTYPES is defined above.
If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it
returns an empty list.
*/
#if PROTOTYPES
#define PROTO_LIST(list) list
#else
#define PROTO_LIST(list) ()
#endif
......@@ -85,7 +85,7 @@ int do_reject(action_list_t *a, char *msg)
return 0;
}
/* fileinto message m into mailbox
/* fileinto message m into mailbox
*
* incompatible with: reject
*/
......@@ -235,7 +235,7 @@ int do_vacation(action_list_t *a, char *addr, char *fromaddr,
int do_setflag(action_list_t *a, char *flag)
{
action_list_t *b = NULL;
/* see if this conflicts with any previous actions taken on this message */
while (a != NULL) {
b = a;
......@@ -243,7 +243,7 @@ int do_setflag(action_list_t *a, char *flag)
return SIEVE_RUN_ERROR;
a = a->next;
}
/* add to the action list */
a = (action_list_t *) xmalloc(sizeof(action_list_t));
if (a == NULL)
......@@ -262,7 +262,7 @@ int do_setflag(action_list_t *a, char *flag)
int do_addflag(action_list_t *a, char *flag)
{
action_list_t *b = NULL;
/* see if this conflicts with any previous actions taken on this message */
while (a != NULL) {
b = a;
......@@ -270,7 +270,7 @@ int do_addflag(action_list_t *a, char *flag)
return SIEVE_RUN_ERROR;
a = a->next;
}
/* add to the action list */
a = (action_list_t *) xmalloc(sizeof(action_list_t));
if (a == NULL)
......@@ -289,7 +289,7 @@ int do_addflag(action_list_t *a, char *flag)
int do_removeflag(action_list_t *a, char *flag)
{
action_list_t *b = NULL;
/* see if this conflicts with any previous actions taken on this message */
while (a != NULL) {
b = a;
......@@ -297,7 +297,7 @@ int do_removeflag(action_list_t *a, char *flag)
return SIEVE_RUN_ERROR;
a = a->next;
}
/* add to the action list */
a = (action_list_t *) xmalloc(sizeof(action_list_t));
if (a == NULL)
......@@ -317,7 +317,7 @@ int do_removeflag(action_list_t *a, char *flag)
int do_mark(action_list_t *a)
{
action_list_t *b = NULL;
/* see if this conflicts with any previous actions taken on this message */
while (a != NULL) {
b = a;
......@@ -325,7 +325,7 @@ int do_mark(action_list_t *a)
return SIEVE_RUN_ERROR;
a = a->next;
}
/* add to the action list */
a = (action_list_t *) xmalloc(sizeof(action_list_t));
if (a == NULL)
......@@ -344,7 +344,7 @@ int do_mark(action_list_t *a)
int do_unmark(action_list_t *a)
{
action_list_t *b = NULL;
/* see if this conflicts with any previous actions taken on this message */
while (a != NULL) {
b = a;
......@@ -352,7 +352,7 @@ int do_unmark(action_list_t *a)
return SIEVE_RUN_ERROR;
a = a->next;
}
/* add to the action list */
a = (action_list_t *) xmalloc(sizeof(action_list_t));
if (a == NULL)
......@@ -435,7 +435,7 @@ int do_denotify(notify_action_t *notify)
if (notify->headers)
free_sl(notify->headers);
}
notify->exists = 0;
return 0;
......@@ -480,9 +480,9 @@ char *get_address(address_part_t addrpart, void **data, void **marker,
ret = NULL;
} else {
if (canon_domain && a->domain)
lcase(a->domain);
strlower (a->domain);
switch (addrpart) {
switch (addrpart) {
case ADDRESS_ALL:
#define U_DOMAIN "unspecified-domain"
#define U_USER "unknown-user"
......@@ -501,7 +501,7 @@ char *get_address(address_part_t addrpart, void **data, void **marker,
case ADDRESS_LOCALPART:
ret = a->mailbox;
break;
case ADDRESS_DOMAIN:
ret = a->domain;
break;
......@@ -551,10 +551,10 @@ int free_address(void **data, void **marker)
#define NEWMAIL_MSG "You have new mail"
notify_action_t *default_notify_action(void)
notify_action_t *default_notify_action(void)
{
notify_action_t *ret = xmalloc(sizeof(notify_action_t));
ret->exists = -1; /* flag as default action */
ret->priority = "medium";
ret->message = xstrdup(NEWMAIL_MSG);
......
......@@ -31,8 +31,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <stdlib.h>
#include <string.h>
#include <md5global.h>
#include <md5.h>
#include <md5-rsa.h>
#include <ctype.h>
#ifdef HAVE_STRINGS_H
# include <strings.h>
......@@ -179,7 +178,7 @@ char **stringlist_to_chararray(stringlist_t *list)
tmp=tmp->next;
free(tofree);
}
return ret;
}
......@@ -226,10 +225,10 @@ static int look_for_me(char *myaddr, stringlist_t *myaddrs, const char **body)
for (l = 0; body[l] != NULL && !found; l++) {
void *data = NULL, *marker = NULL;
char *addr;
parse_address(body[l], &data, &marker);
/* loop through each address in the header */
while (!found && ((addr = get_address(ADDRESS_ALL,
while (!found && ((addr = get_address(ADDRESS_ALL,
&data, &marker, 1)) != NULL)) {
if (!strcmp(addr, myaddr)) {
found = 1;
......@@ -281,7 +280,7 @@ static int evaltest(sieve_interp_t *i, test_t *t, void *m)
const char **body;
/* use getheader for address, getenvelope for envelope */
if (((t->type == ADDRESS) ?
if (((t->type == ADDRESS) ?
i->getheader(m, sl->s, &body) :
i->getenvelope(m, sl->s, &body)) != SIEVE_OK) {
continue; /* try next header */
......@@ -294,7 +293,7 @@ static int evaltest(sieve_interp_t *i, test_t *t, void *m)
parse_address(body[l], &data, &marker);
val = get_address(addrpart, &data, &marker, 0);
while (val != NULL && !res) {
while (val != NULL && !res) {
/* loop through each address */
res |= t->u.ae.comp(pl->p, val);
val = get_address(addrpart, &data, &marker, 0);
......@@ -371,7 +370,7 @@ static int evaltest(sieve_interp_t *i, test_t *t, void *m)
note that this is very stack hungry; we just evaluate the AST in
the naivest way. if we implement some sort of depth limit, we'll
be ok here; otherwise we'd want to transform it a little smarter */
static int eval(sieve_interp_t *i, commandlist_t *c,
static int eval(sieve_interp_t *i, commandlist_t *c,
void *m, action_list_t *actions, notify_action_t *notify_action,
const char **errmsg)
{
......@@ -472,7 +471,7 @@ static int eval(sieve_interp_t *i, commandlist_t *c,
for (sl = c->u.v.addresses; sl != NULL; sl = sl->next)
if (!strcmp(sl->s, reply_to))
l = SIEVE_DONE;
/* ok, is it a system address? */
if (l == SIEVE_OK && sysaddr(reply_to)) {
l = SIEVE_DONE;
......@@ -485,7 +484,7 @@ static int eval(sieve_interp_t *i, commandlist_t *c,
/* ok, we're willing to respond to the sender.
but is this message to me? that is, is my address
in the TO, CC or BCC fields? */
if (strcpy(buf, "to"),
if (strcpy(buf, "to"),
i->getheader(m, buf, &body) == SIEVE_OK)
found = look_for_me(myaddr, c->u.v.addresses, body);
......@@ -503,11 +502,11 @@ static int eval(sieve_interp_t *i, commandlist_t *c,
if (l == SIEVE_OK) {
/* ok, ok, if we got here maybe we should reply */
if (c->u.v.subject == NULL) {
/* we have to generate a subject */
const char **s;
strcpy(buf, "subject");
if (i->getheader(m, buf, &s) != SIEVE_OK ||
s[0] == NULL) {
......@@ -530,11 +529,11 @@ static int eval(sieve_interp_t *i, commandlist_t *c,
} else {
fromaddr = myaddr;
}
res = do_vacation(actions, reply_to, strdup(fromaddr),
strdup(buf),
c->u.v.message, c->u.v.days, c->u.v.mime);
if (res == SIEVE_RUN_ERROR)
*errmsg = "Vacation can not be used with Reject or Vacation";
......@@ -584,7 +583,7 @@ static int eval(sieve_interp_t *i, commandlist_t *c,
*errmsg = "Unmark can not be used with Reject";
break;
case NOTIFY:
res = do_notify(i,m,notify_action, c->u.n.priority, c->u.n.message,
res = do_notify(i,m,notify_action, c->u.n.priority, c->u.n.message,
c->u.n.headers_list);
break;
case DENOTIFY:
......@@ -605,14 +604,14 @@ static int eval(sieve_interp_t *i, commandlist_t *c,
#define GROW_AMOUNT 100
static void add_header(sieve_interp_t *i, char *header,
void *message_context, char **out,
static void add_header(sieve_interp_t *i, char *header,
void *message_context, char **out,
int *outlen, int *outalloc)
{
const char **h;
int addlen;
/* get header value */
i->getheader(message_context, header, &h);
i->getheader(message_context, header, &h);
if (!h || !h[0])
return;
......@@ -635,7 +634,7 @@ static void add_header(sieve_interp_t *i, char *header,
*outlen += addlen;
}
static int fillin_headers(sieve_interp_t *i, stringlist_t *sl,
static int fillin_headers(sieve_interp_t *i, stringlist_t *sl,
void *message_context, char **out, int *outlen)
{
int allocsize = GROW_AMOUNT;
......@@ -650,7 +649,7 @@ static int fillin_headers(sieve_interp_t *i, stringlist_t *sl,
add_header(i,"From", message_context, out, outlen, &allocsize);
add_header(i,"Subject", message_context, out, outlen, &allocsize);
} else {
while (sl!=NULL)
{
add_header(i,sl->s,message_context, out, outlen, &allocsize);
......@@ -665,13 +664,13 @@ static int fillin_headers(sieve_interp_t *i, stringlist_t *sl,
static int sieve_addflag(sieve_imapflags_t *imapflags, char *flag)
{
int n;
/* search for flag already in list */
for (n = 0; n < imapflags->nflags; n++) {
if (!strcmp(imapflags->flag[n], flag))
break;
}
/* add flag to list, iff not in list */
if (n == imapflags->nflags) {
imapflags->nflags++;
......@@ -680,55 +679,55 @@ static int sieve_addflag(sieve_imapflags_t *imapflags, char *flag)
imapflags->nflags*sizeof(char *));
imapflags->flag[imapflags->nflags-1] = strdup(flag);
}
return SIEVE_OK;
}
static int sieve_removeflag(sieve_imapflags_t *imapflags, char *flag)
{
int n;
/* search for flag already in list */
for (n = 0; n < imapflags->nflags; n++) {
if (!strcmp(imapflags->flag[n], flag))
break;
}
/* remove flag from list, iff in list */
if (n < imapflags->nflags) {
free(imapflags->flag[n]);
imapflags->nflags--;
for (; n < imapflags->nflags; n++)
imapflags->flag[n] = imapflags->flag[n+1];
imapflags->flag =
(char **) xrealloc((char *)imapflags->flag,
imapflags->nflags*sizeof(char *));
}
return SIEVE_OK;
}
static int send_notify_callback(sieve_script_t *s, void *message_context,
static int send_notify_callback(sieve_script_t *s, void *message_context,
notify_action_t *notify, char *actions_string,
const char **errmsg)
{
char *headers;
int headerslen;
int headerslen;
int ret;
sieve_notify_context_t nc;
fillin_headers(&(s->interp), notify->headers, message_context,
fillin_headers(&(s->interp), notify->headers, message_context,
&headers, &headerslen);
nc.message = xmalloc(strlen(notify->message) + headerslen +
nc.message = xmalloc(strlen(notify->message) + headerslen +
strlen(actions_string) + 30);
strcpy(nc.message,notify->message);
strcat(nc.message,"\n\n");
strcat(nc.message,headers);
strcat(nc.message,"\n");
free(headers);
......@@ -740,7 +739,7 @@ static int send_notify_callback(sieve_script_t *s, void *message_context,
s->interp.interp_context,
s->script_context,
message_context,
errmsg);
errmsg);
free(nc.message);
......@@ -812,7 +811,7 @@ int sieve_execute_script(sieve_script_t *s, void *message_context)
notify_action_t *notify_action;
char actions_string[4096] = "";
const char *errmsg = NULL;
notify_action = default_notify_action();
if (notify_action == NULL)
return SIEVE_NOMEM;
......@@ -822,18 +821,18 @@ int sieve_execute_script(sieve_script_t *s, void *message_context)
ret = SIEVE_NOMEM;
goto error;
}
if (eval(&s->interp, s->cmds, message_context, actions,
notify_action, &errmsg) < 0)
return SIEVE_RUN_ERROR;
/* now perform actions attached to m */
a = actions;
implicit_keep = 1;
while (a != NULL) {
lastaction = a->a;
errmsg = NULL;
switch (a->a) {
case ACTION_REJECT:
implicit_keep = 0;
......@@ -844,10 +843,10 @@ int sieve_execute_script(sieve_script_t *s, void *message_context)
s->script_context,
message_context,
&errmsg);
if (ret == SIEVE_OK)
snprintf(actions_string+strlen(actions_string),
sizeof(actions_string)-strlen(actions_string),
sizeof(actions_string)-strlen(actions_string),
"Rejected with: %s\n", a->u.rej.msg);
break;
......@@ -930,7 +929,7 @@ int sieve_execute_script(sieve_script_t *s, void *message_context)
/* send the response */
ret = s->interp.vacation->send_response(&a->u.vac.send,
s->interp.interp_context,
s->script_context,
s->script_context,
message_context,
&errmsg);
......@@ -946,11 +945,11 @@ int sieve_execute_script(sieve_script_t *s, void *message_context)
ret = SIEVE_OK;
}
break;
}
case ACTION_SETFLAG:
free_imapflags(&s->interp.curflags);
ret = sieve_addflag(&s->interp.curflags, a->u.fla.flag);
......@@ -1001,7 +1000,7 @@ int sieve_execute_script(sieve_script_t *s, void *message_context)
}
error: /* report run-time errors */
if (ret != SIEVE_OK) {
if (lastaction == -1) /* we never executed an action */
snprintf(actions_string+strlen(actions_string),
......@@ -1015,13 +1014,13 @@ int sieve_execute_script(sieve_script_t *s, void *message_context)
action_to_string(lastaction),
errmsg ? errmsg : sieve_errstr(ret));
}
/* Process notify action if there is one */
if (s->interp.notify && notify_action->exists) {
ret |= send_notify_callback(s, message_context, notify_action,
actions_string, &errmsg);
}
if ((ret != SIEVE_OK) && s->interp.err) {
char buf[1024];
if (lastaction == -1) /* we never executed an action */
......@@ -1029,7 +1028,7 @@ int sieve_execute_script(sieve_script_t *s, void *message_context)
else
sprintf(buf, "%s: %s", action_to_string(lastaction),
errmsg ? errmsg : sieve_errstr(ret));
ret |= s->interp.execute_err(buf, s->interp.interp_context,
s->script_context, message_context);
}
......@@ -1039,7 +1038,7 @@ int sieve_execute_script(sieve_script_t *s, void *message_context)
int keep_ret;
keep_context.imapflags = &s->interp.curflags;
lastaction = ACTION_KEEP;
keep_ret = s->interp.keep(&keep_context, s->interp.interp_context,
s->script_context, message_context, &errmsg);
......
......@@ -143,7 +143,7 @@ reqs: /* empty */
require: REQUIRE stringlist ';' { if (!check_reqs($2)) {
yyerror("unsupported feature");
YYERROR;
YYERROR;
} }
;
......@@ -236,7 +236,7 @@ action: REJCT STRING { if (!parse_script->support.reject) {
YYERROR;
}
$$ = new_command(NOTIFY);
$$ = new_command(NOTIFY);
$$->u.n.priority = $2;
$$->u.n.message = $3;
$$->u.n.headers_list = $4;
......@@ -255,31 +255,31 @@ priority: /* nothing */ { $$ = "medium"; }
| HIGH { $$ = "high"; }
;
optional_headers: /* empty */ {
optional_headers: /* empty */ {
$$ = NULL;
}
| stringlist { $$ = $1; }
;
vtags: /* empty */ { $$ = new_vtags(); }
| vtags DAYS NUMBER { if ($$->days != -1) {
| vtags DAYS NUMBER { if ($$->days != -1) {
yyerror("duplicate :days"); YYERROR; }
else { $$->days = $3; } }
| vtags ADDRESSES stringlist { if ($$->addresses != NULL) {
yyerror("duplicate :addresses");
| vtags ADDRESSES stringlist { if ($$->addresses != NULL) {
yyerror("duplicate :addresses");
YYERROR;
} else if (!verify_addresses($3)) {
YYERROR;
} else {
$$->addresses = $3; } }
| vtags SUBJECT STRING { if ($$->subject != NULL) {
yyerror("duplicate :subject");
| vtags SUBJECT STRING { if ($$->subject != NULL) {
yyerror("duplicate :subject");
YYERROR;
} else if (!ok_header($3)) {
YYERROR;
} else { $$->subject = $3; } }
| vtags MIME { if ($$->mime != -1) {
yyerror("duplicate :mime");
| vtags MIME { if ($$->mime != -1) {
yyerror("duplicate :mime");
YYERROR; }
else { $$->mime = MIME; } }
;
......@@ -312,7 +312,7 @@ test: ANYOF testlist { $$ = new_test(ANYOF); $$->u.tl = $2; }
else
#endif
pl = (patternlist_t *) $4;
$$ = build_header(HEADER, $2, $3, pl);
if ($$ == NULL) { YYERROR; } }
| addrorenv aetags stringlist stringlist
......@@ -326,7 +326,7 @@ test: ANYOF testlist { $$ = new_test(ANYOF); $$->u.tl = $2; }
else
#endif
pl = (patternlist_t *) $4;
$$ = build_address($1, $2, $3, pl);
if ($$ == NULL) { YYERROR; } }
| NOT test { $$ = new_test(NOT); $$->u.t = $2; }
......@@ -341,27 +341,27 @@ addrorenv: ADDRESS { $$ = ADDRESS; }
aetags: /* empty */ { $$ = new_aetags(); }
| aetags addrparttag { $$ = $1;
if ($$->addrtag != -1) {
if ($$->addrtag != -1) {
yyerror("duplicate or conflicting address part tag");
YYERROR; }
else { $$->addrtag = $2; } }
| aetags comptag { $$ = $1;
if ($$->comptag != -1) {
if ($$->comptag != -1) {
yyerror("duplicate comparator type tag"); YYERROR; }
else { $$->comptag = $2; } }
| aetags COMPARATOR STRING { $$ = $1;
if ($$->comparator != NULL) {
if ($$->comparator != NULL) {
yyerror("duplicate comparator tag"); YYERROR; }
else { $$->comparator = $3; } }
;
htags: /* empty */ { $$ = new_htags(); }
| htags comptag { $$ = $1;
if ($$->comptag != -1) {
if ($$->comptag != -1) {
yyerror("duplicate comparator type tag"); YYERROR; }
else { $$->comptag = $2; } }
| htags COMPARATOR STRING { $$ = $1;
if ($$->comparator != NULL) {
if ($$->comparator != NULL) {
yyerror("duplicate comparator tag");
YYERROR; }
else { $$->comparator = $3; } }
......@@ -426,7 +426,7 @@ int yyerror(char *msg)
parse_script->err++;
if (parse_script->interp.err) {
ret = parse_script->interp.err(yylineno, msg,
ret = parse_script->interp.err(yylineno, msg,
parse_script->interp.interp_context,
parse_script->script_context);
}
......@@ -438,7 +438,7 @@ static int check_reqs(stringlist_t *sl)
{
int i = 1;
stringlist_t *s;
while (sl != NULL) {
s = sl;
sl = sl->next;
......@@ -575,7 +575,7 @@ static struct vtags *canon_vtags(struct vtags *v)
assert(parse_script->interp.vacation != NULL);
if (v->days == -1) { v->days = 7; }
if (v->days < parse_script->interp.vacation->min_response)
if (v->days < parse_script->interp.vacation->min_response)
{ v->days = parse_script->interp.vacation->min_response; }
if (v->days > parse_script->interp.vacation->max_response)
{ v->days = parse_script->interp.vacation->max_response; }
......@@ -628,9 +628,9 @@ static int verify_mailboxes(stringlist_t *sl)
static int verify_flag(char *f)
{
char errbuf[100];
if (f[0] == '\\') {
lcase(f);
strlower(f);
if (strcmp(f, "\\seen") && strcmp(f, "\\answered") &&
strcmp(f, "\\flagged") && strcmp(f, "\\draft") &&
strcmp(f, "\\deleted")) {
......@@ -647,7 +647,7 @@ static int verify_flag(char *f)
}
return 1;
}
static int verify_flags(stringlist_t *sl)
{
for (; sl != NULL && verify_flag(sl->s); sl = sl->next) ;
......
/* util.c -- general utility functions
*
* Copyright (c) 1998-2000 Carnegie Mellon University. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The name "Carnegie Mellon University" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For permission or any other legal
* details, please contact
* Office of Technology Transfer
* Carnegie Mellon University
* 5000 Forbes Avenue
* Pittsburgh, PA 15213-3890
* (412) 268-4387, fax: (412) 268-7395
* tech-transfer@andrew.cmu.edu
*
* 4. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by Computing Services
* at Carnegie Mellon University (http://www.cmu.edu/computing/)."
*
* CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Author: Chris Newman
* Start Date: 4/6/93
*/
/* $Id$
*/
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
#include <config.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "util.h"
/* from OS: */
extern char *malloc(), *realloc();
#define BEAUTYBUFSIZE 4096
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.
const unsigned char convert_to_lowercase[256] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0x40, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z', 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
0x60, 'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z', 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
};
const unsigned char convert_to_uppercase[256] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0x40, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
0x60, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
};
/* convert string to all lower case
*/
char *lcase(char* str)
{
char *scan = str;
while (*scan) {
*scan = TOLOWER(*scan);
scan++;
}
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.
return (str);
}
/* convert string to all upper case
*/
char *ucase(char* str)
{
char *scan = str;
while (*scan) {
*scan = convert_to_uppercase[(unsigned char)(*scan)];
scan++;
}
return (str);
}
/* clean up control characters in a string while copying it
* returns pointer to end of dst string.
* dst must have twice the length of source
*/
char *beautify_copy(char* dst, const char* src)
{
unsigned char c;
while (*src) {
c = *src++ & 0x7F;
if (!isprint(c)) {
*dst++ = '^';
if (c > ' ') {
c = '?';
} else {
c += '@';
}
}
*dst++ = c;
}
*dst = '\0';
return (dst);
}
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 <util.h>
#include <ctype.h>
/* clean up control characters in a string while copying it
* returns pointer to a static buffer containing the cleaned-up version
* returns NULL on malloc() error
*/
char *beautify_string(const char* src)
char *
strupper (char *s)
{
static char *beautybuf = NULL;
static int beautysize = 0;
int len;
len = strlen(src) * 2 + 1;
if (beautysize < len) {
if (!beautysize) {
beautysize = len > BEAUTYBUFSIZE ? len : BEAUTYBUFSIZE;
beautybuf = malloc(beautysize);
} else {
beautysize *= 2;
if (len > beautysize) beautysize = len;
beautybuf = realloc(beautybuf, beautysize);
}
if (!beautybuf) {
beautysize = 0;
return "";
}
}
(void) beautify_copy(beautybuf, src);
return (beautybuf);
char *t = s;
while (*t)
{
if (islower ((unsigned)*t))
*t = toupper ((unsigned)*t);
t++;
}
return s;
}
/* do a binary search in a keyvalue array
* nelem is the number of keyvalue elements in the kv array
* cmpf is the comparison function (strcmp, strcasecmp, etc).
* returns NULL if not found, or key/value pair if found.
*/
keyvalue *kv_bsearch(const char* key, keyvalue* kv, int nelem,
int (*cmpf) (const char *s1, const char *s2))
char *
strlower (char *s)
{
int top, mid = 0, bot, cmp = 0;
cmp = 1;
bot = 0;
top = nelem - 1;
while (top >= bot && (cmp = (*cmpf)(key, kv[mid = (bot + top) >> 1].key)))
if (cmp < 0) {
top = mid - 1;
} else {
bot = mid + 1;
}
return (cmp ? NULL : kv + mid);
char *t = s;
while (*t)
{
if (isupper ((unsigned)*t))
*t = tolower ((unsigned)*t);
t++;
}
return s;
}
......
/* util.h -- general utility functions
* $Id$
*
* Copyright (c) 1999-2000 Carnegie Mellon University. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The name "Carnegie Mellon University" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For permission or any other legal
* details, please contact
* Office of Technology Transfer
* Carnegie Mellon University
* 5000 Forbes Avenue
* Pittsburgh, PA 15213-3890
* (412) 268-4387, fax: (412) 268-7395
* tech-transfer@andrew.cmu.edu
*
* 4. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by Computing Services
* at Carnegie Mellon University (http://www.cmu.edu/computing/)."
*
* CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Author: Chris Newman
* Start Date: 4/6/93
*/
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
#ifndef INCLUDED_UTIL_H
#define INCLUDED_UTIL_H
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.
extern const unsigned char convert_to_lowercase[256];
extern const unsigned char convert_to_uppercase[256];
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.
#define TOUPPER(c) (convert_to_uppercase[(unsigned char)(c)])
#define TOLOWER(c) (convert_to_lowercase[(unsigned char)(c)])
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. */
typedef struct keyvalue {
char *key, *value;
} keyvalue;
#ifndef INCLUDED_UTIL_H
#define INCLUDED_UTIL_H
/* convert string to all lower case
*/
extern char *lcase (char *str);
extern char *strlower (char *str);
/* convert string to all upper case
*/
extern char *ucase (char *str);
/* clean up control characters in a string while copying it
* returns pointer to end of dst string.
* dst must have twice the length of source
*/
extern char *beautify_copy (char *dst, const char *src);
/* clean up control characters in a string while copying it
* returns pointer to a static buffer containing the cleaned-up version
* returns NULL on malloc() error
*/
extern char *beautify_string (const char *src);
/* do a binary search in a keyvalue array
* nelem is the number of keyvalue elements in the kv array
* cmpf is the comparison function (strcmp, stricmp, etc).
* returns NULL if not found, or key/value pair if found.
*/
extern keyvalue *kv_bsearch (const char *key, keyvalue *kv, int nelem,
int (*cmpf)(const char *s1, const char *s2));
extern char *strupper (char *str);
#endif /* INCLUDED_UTIL_H */
......