4 messages in net.sourceforge.lists.courier-maildrop[maildropl] Re: Setting environment v...
FromSent OnAttachments
Courier UserNov 16, 2003 5:07 pm 
Matthias AndreeNov 17, 2003 6:29 am 
Courier UserNov 17, 2003 7:02 am 
Courier UserJan 15, 2004 4:45 am.patch
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:[maildropl] Re: Setting environment variable in maildrop to "" deletes it?Actions...
From:Courier User (cour@asfast.net)
Date:Jan 15, 2004 4:45:47 am
List:net.sourceforge.lists.courier-maildrop
Attachments:

Courier User <cour@asfast.net> writes:

[ Note: I recently posted this message to the courier-users group. Clearly, it's pertinent here, as well. ]

In trying to debug some problems in a program that I'm invoking via xfilter in maildrop, I have realized that the following construct in a maildrop recipe file doesn't do exactly what I expected:

VARIABLE=""

In this case, maildrop completely removes the environment variable called "VARIABLE". I was expecting that it would cause that variable to exist and to be bound to an empty string.

Attached is a patch to maildrop (in the 0.44.2.20031219 release of Courier) which implements the following features:

1. VAR=""

No longer unsets the variable, but simply sets it to an empty string, as does every other variable-setting language that I know of.

2. unset VAR

A new directive that completely removes the variable.

Sam has already applied this patch to the maildrop that comes with the latest official Courier release (courier-0.44.2.20040114). I presume that it will be applied soon to the stand-alone version of maildrop, as well. But in the mean time, you can use this on your own version.

I've done a small amount of testing, and it seems to work fine. However, please do your own testing, as well.

*** maildrop/lexer.C.save Wed Jan 14 09:31:21 2004 --- maildrop/lexer.C Wed Jan 14 09:32:29 2004 *************** *** 384,389 **** --- 384,391 ---- t.Type(Token::importtoken); else if (pattern == "-") // Hack t.Type(Token::minus); + else if (pattern == "unset") + t.Type(Token::unset); else t.Type(Token::qstring); return; *** maildrop/recipenode.C.save Wed Jan 14 09:27:59 2004 --- maildrop/recipenode.C Wed Jan 14 09:49:54 2004 *************** *** 1066,1071 **** --- 1066,1089 ---- b.append( (unsigned long)t ); } break; + case unset: + if (!firstChild) + throw "Internal error in unset statement."; + firstChild->Evaluate(r, b); + { + Buffer s; + + if (VerboseLevel() > 3) + { + s="unset "; + s += b; + s += '\0'; + r.errmsg(*this, s); + } + + UnsetVar(b); + } + break; } }

*** maildrop/recipenode.h.save Wed Jan 14 09:27:46 2004 --- maildrop/recipenode.h Wed Jan 14 09:48:48 2004 *************** *** 116,122 **** gdbmfetch, gdbmstore, timetoken, ! importtoken } nodeType;

RecipeNode(RecipeNodeType); --- 116,123 ---- gdbmfetch, gdbmstore, timetoken, ! importtoken, ! unset } nodeType;

RecipeNode(RecipeNodeType); *** maildrop/recipeparse.C.save Wed Jan 14 09:28:08 2004 --- maildrop/recipeparse.C Wed Jan 14 09:46:47 2004 *************** *** 235,240 **** --- 235,248 ---- throw "Syntax error."; lex->token(cur_tok); return (n); + case Token::unset: + lex->token(cur_tok); + n=alloc(RecipeNode::unset); + n->AppendSibling( ParseExpr()); + if (cur_tok.Type() != Token::semicolon) + throw "Syntax error."; + lex->token(cur_tok); + return (n); default: break; } *** maildrop/token.C.save Wed Jan 14 09:32:48 2004 --- maildrop/token.C Wed Jan 14 09:35:07 2004 *************** *** 67,73 **** "gdbmfetch", "gdbmstore", "time", ! "import" } ;

static Buffer namebuf; --- 67,74 ---- "gdbmfetch", "gdbmstore", "time", ! "import", ! "unset" } ;

static Buffer namebuf; *** maildrop/token.h.save Wed Jan 14 09:32:53 2004 --- maildrop/token.h Wed Jan 14 09:46:33 2004 *************** *** 84,89 **** --- 84,90 ---- gdbmstore, timetoken, importtoken, + unset, }; private: tokentype type; *** maildrop/varlist.C.save Wed Jan 14 09:15:22 2004 --- maildrop/varlist.C Wed Jan 14 09:22:41 2004 *************** *** 16,21 **** --- 16,52 ----

static Variable *varlist[101];

+ void UnsetVar(const Buffer &var) + { + int varlen=var.Length(); + unsigned n=0; + int i; + const char *p=var; + for (i=varlen; i; --i) + n = (n << 1) ^ (unsigned char)*p++; + + if (var.Length() == 7 && + strncmp( (const char *)var, "VERBOSE", 7) == 0) + { + maildrop.verbose_level=0; + } + + n %= sizeof(varlist)/sizeof(varlist[0]); + + Variable **v; + + for (v= &varlist[n]; *v; v= &(*v)->next) + if ( (*v)->name == var ) + { + Variable *vv= (*v); + + (*v)= vv->next; + delete vv; + break; + } + return; + } + void SetVar(const Buffer &var, const Buffer &value) { int varlen=var.Length(); *************** *** 34,55 **** }

n %= sizeof(varlist)/sizeof(varlist[0]); - - if (value.Length() == 0) // Delete variable - { - Variable **v; - - for (v= &varlist[n]; *v; v= &(*v)->next) - if ( (*v)->name == var ) - { - Variable *vv= (*v); - - (*v)= vv->next; - delete vv; - break; - } - return; - }

Variable *v;

--- 65,70 ---- *** maildrop/varlist.h.save Wed Jan 14 09:23:42 2004 --- maildrop/varlist.h Wed Jan 14 09:24:05 2004 *************** *** 9,14 **** --- 9,15 ----

class Buffer;

+ void UnsetVar(const Buffer &); void SetVar(const Buffer &, const Buffer &); const Buffer *GetVar(const Buffer &); const char *GetVarStr(const Buffer &);