Email module, how to add header to the top of an email?

2008-01-24 Thread David Erickson
I have been using the Email module and Message class for awhile,
however I have been unable to find a way to add a header to the top of
the email similar to what is done with Received: headers... the
add_header method only appends to the bottom.  Is there someway this
can be done?

Thanks
David
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Email module, how to add header to the top of an email?

2008-01-24 Thread David Erickson
On Jan 24, 2:41 pm, Martin Marcher <[EMAIL PROTECTED]> wrote:
> On Thursday 24 January 2008 20:32 David Erickson wrote:
>
> > I have been using the Email module and Message class for awhile,
> > however I have been unable to find a way to add a header to the top of
> > the email similar to what is done with Received: headers... the
> > add_header method only appends to the bottom.  Is there someway this
> > can be done?
>
> if by bottom you mean added as the "new last" header than you don't have to
> care, afaik email headers do not have a notion of order
>
> e.g
>
> To: [EMAIL PROTECTED]
> From: [EMAIL PROTECTED]
>
> is equal to
>
> From: [EMAIL PROTECTED]
> To: [EMAIL PROTECTED]
>
> if by bottom you mean it's appended to the body...well that is a problem :)
>
> hth
> martin

Bottom of the headers... but I am looking to insert at the top, and re-
ordering/inserting does matter depending on what type of header you
are, received headers for example must be inserted at the top of the
header list so you can watch the progression of the email.  I was
unable to find a clean way to do this via the API which seems very
strange to me.. but perhaps I am just missing something?

Thanks,
-David
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Email module, how to add header to the top of an email?

2008-01-25 Thread David Erickson
On Jan 25, 5:04 am, "Karlheinz Klingbeil"
<[EMAIL PROTECTED]> wrote:
> Am 25.01.2008, 06:21 Uhr, schrieb David Erickson <[EMAIL PROTECTED]>:
>
> > Bottom of the headers... but I am looking to insert at the top, and re-
> > ordering/inserting does matter depending on what type of header you
> > are, received headers for example must be inserted at the top of the
> > header list so you can watch the progression of the email.  I was
> > unable to find a clean way to do this via the API which seems very
> > strange to me.. but perhaps I am just missing something?
>
> I think your are really missing something. First, Email-headers are
> unordered
> and every relay can, and probably will,  rearrange them, add or delete
> headers.
> You therefore most definitely should not add any headers which are
> position-dependent.
> If you want to track mails somehow, add headers with timestamps.
> This way you can watch the progression of an email without being
> dependend on "sorted" headerlines.

This is incorrect, quoting directly from RFC 2822:

   It is important to note that the header fields are not guaranteed
to
   be in a particular order.  They may appear in any order, and they
   have been known to be reordered occasionally when transported over
   the Internet.  However, for the purposes of this standard, header
   fields SHOULD NOT be reordered when a message is transported or
   transformed.  More importantly, the trace header fields and resent
   header fields MUST NOT be reordered, and SHOULD be kept in blocks
   prepended to the message.  See sections 3.6.6 and 3.6.7 for more
   information.

Trace header fields are not to be ordered, and should be prepended
when added to a message.  Now that said I am not trying to track
anything, I simply want to prepend my additional headers onto the top
of the email, and seem to be unable to do that via the API, which I
think ought to be possible.  If for example I was writing some kind of
an SMTP server with Python and needed to add said trace headers they
would need to be prepended, and currently cannot be (without doing it
by hand).

-David
-- 
http://mail.python.org/mailman/listinfo/python-list


File object wrapper for a String?

2008-02-14 Thread David Erickson
I am using the Popen class from subprocess and would like to feed a
string in as the stdin parameter, however primarily it only takes a
File object.  Does there exist a wrapper for a string to do this?  I
know I can just dump the string to a temp file and feed that in but
that is pretty hacky.

Thanks,
David
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File object wrapper for a String?

2008-02-14 Thread David Erickson
On Feb 14, 3:07 pm, Christian Heimes <[EMAIL PROTECTED]> wrote:
> David Erickson wrote:
> > I am using the Popen class from subprocess and would like to feed a
> > string in as the stdin parameter, however primarily it only takes a
> > File object.  Does there exist a wrapper for a string to do this?  I
> > know I can just dump the string to a temp file and feed that in but
> > that is pretty hacky.
>
> You don't need a file like object:
>
> popen = subprocess.Popen(..., stdin=subprocess.PIPE)
> popen.stdin.write("yourstring")
>
> Christian

Perfect.  Thanks.

-David
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File object wrapper for a String?

2008-02-14 Thread David Erickson
On Feb 14, 3:16 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> David Erickson schrieb:
>
> > I am using the Popen class from subprocess and would like to feed a
> > string in as the stdin parameter, however primarily it only takes a
> > File object.  Does there exist a wrapper for a string to do this?  I
> > know I can just dump the string to a temp file and feed that in but
> > that is pretty hacky.
>
> Christian told you how to work with popen. Just for the record thogh:
> there are the StringIO and cStringIO-modules.
>
> Diez

Good to know, thanks Diez.

-David
-- 
http://mail.python.org/mailman/listinfo/python-list