+ Gustav-Martin Olsen <[EMAIL PROTECTED]>:

| <When you call qmail-inject, just replace "$SENDER" on the command
| <line by whatever you want the envelope sender to be.
| 
| That what i want, but how can i replace the $SENDER variable?
| How can i change environment variable?
| 
| I use in .qmail [...]
| | parse-mail-header | qmail-inject -f "$SENDER" -- "$DEFAULT"
| 
| in parse-mail-header, i fix the header and set the from field new.
| The new $SENDER is my from field as parse-mail-header, how can i
| this value put in the $SENDER variable?

Oh dear.  This is no longer a qmail issue; what you need is a course
on unix scripting.  Even though this is now off-topic for the qmail
list, I'll give you a few hints to get you started:

First, you don't say what kind of program parse-mail-header is.  The
complexity of the solution will depend on that.  If it's a reasonably
complete programming language, in which you (say) read in the full
header, then parse and modify it before writing out the modified
header followed by the body, it should be easy enough.  You rewrite
the program so it no longer simply outputs the modified message to
stdout, but instead creates a pipe and invokes qmail-inject itself,
essentially running

  qmail-inject -f whatever-you-want-the-envelope-sender-to-be -- "$DEFAULT"

Here is one (grossly inefficient) way to hack it via a shell script:

#!/bin/sh
SENDER="`parse-mail-header-and-print-out-the-envelope-sender`"
rewind
parse-mail-header | qmail-inject -f "$SENDER" -- "$DEFAULT"

Note the rewind in there.  Since
parse-mail-header-and-print-out-the-envelope-sender must read parts of
the message, stdin must be rewound so parse-mail-header can read the
whole thing.  Since rewind is not a standard unix command, you can
create it yourself from the following C code:

#include <stdio.h>
#include <unistd.h>

int main(int argc, char* argv[]) {
  if (argc>1) {fprintf(stderr, "Usage: %s", argv[0]); exit(2);}
  if (lseek(0,0,SEEK_SET)<0) {perror("rewind"); exit(1);}
  return 0;
}

It only remains to name the shell script something like
parse-mail-header-and-inject and put the line

| parse-mail-header-and-inject

in .qmail.  Plus, of course, you must write the script
parse-mail-header-and-print-out-the-envelope-sender.

I will not post any more to the qmail list on this topic.  Feel free
to send me personal mail if this is not clear enough, but I cannot
promise an answer, since my time is limited.

- Harald

Reply via email to