Boris K�ster <[EMAIL PROTECTED]> wrote:
>
> thanks for your very interesting reply, I see there is a lot wrong in
> my code...
Well, perhaps not "lots" -- just several simple errors.
> CC> readlines() isn't really what you want here, anyway -- the envelope, in
> CC> particular, won't contain linefeeds. It's ASCII NUL terminated strings
> CC> in series.
>
> Aha, interesting to know, I am completely wrong at this point.
What you probably want to do is something more like this:
data = fd1.read()
parts = string.split (data, '\0')
sender = parts[0]
recips = parts[1:-1]
This reads the whole contents of the envelope into the "data" variable.
Then it uses string.split() to separate out the parts bound by ASCII NUL
-- since the file ends with two NULs, there will be an empty part at the
end. The sender is the first ([0]), and the recipients are 1 through
N-1 (skip the last empty one).
To write it out again, do something like:
fd1.write (sender + '\0')
for recip in recips:
fd1.write (recip + '\0')
fd1.write ('\0')
> >> koz=''
> >> for key in fd0:
> >> koz=koz + key + "\n"
>
> CC> What are you trying to do here? Add additional linefeeds to each line
> CC> in the message? That will mess the header up nicely -- only the first
> CC> line will remain in the header; the rest of it will be considered part
> CC> of the body due to the extra linefeed after the first line.
>
> Aaaaah yes, I understand (hope) lol.
Yes, the lines still have their linefeeds when you read them in with
readlines(). If you really want to lose them, do something like:
lines = map (lambda x: x[-1] == '\n' and x[:-1] or x, lines)
after readlines().
> >> koz ="/var/qmail/bin/qmail-queue.orig "+koz
>
> CC> ... then you prepend the path to qmail-queue to the message contents...
>
> >> infd, outfd = popen2.popen2(koz)
>
> CC> Then you try to open the whole mess of a string as a command. It
> CC> doesn't exist. I think you mean to open the command and then feed it
> CC> the message on stdin, but this is not the way to do it.
>
> Yes I have seen this, too. Puh..
You probably want something more like:
out, in = popen2.popen2 (command)
in.write (message)
in.close ()
commandoutput = out.read ()
But see the docs for popen2 for more details.
> I am writing the blue marked module for QSP specified here:
> http://www.x-itec.de/QSP/index-modules.html
I had a look; good luck.
Charles
--
-----------------------------------------------------------------------
Charles Cazabon <[EMAIL PROTECTED]>
GPL'ed software available at: http://www.qcc.sk.ca/~charlesc/software/
-----------------------------------------------------------------------