Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #70933 > unrolled thread

Add "Received:" header to email msg in correct position?

Started byGrant Edwards <invalid@invalid.invalid>
First post2014-05-05 19:51 +0000
Last post2014-05-07 14:33 +0000
Articles 16 on this page of 36 — 12 participants

Back to article view | Back to comp.lang.python


Contents

  Add "Received:" header to email msg in correct position? Grant Edwards <invalid@invalid.invalid> - 2014-05-05 19:51 +0000
    Re: Add "Received:" header to email msg in correct position? Ethan Furman <ethan@stoneleaf.us> - 2014-05-05 13:01 -0700
      Re: Add "Received:" header to email msg in correct position? Grant Edwards <invalid@invalid.invalid> - 2014-05-05 20:58 +0000
        Re: Add "Received:" header to email msg in correct position? Tim Chase <python.list@tim.thechases.com> - 2014-05-05 16:09 -0500
          Re: Add "Received:" header to email msg in correct position? Grant Edwards <invalid@invalid.invalid> - 2014-05-06 02:13 +0000
            Re: Add "Received:" header to email msg in correct position? Steven D'Aprano <steve@pearwood.info> - 2014-05-06 08:22 +0000
              Re: Add "Received:" header to email msg in correct position? Grant Edwards <invalid@invalid.invalid> - 2014-05-06 14:12 +0000
        Re: Add "Received:" header to email msg in correct position? Terry Reedy <tjreedy@udel.edu> - 2014-05-06 14:16 -0400
        Re: Add "Received:" header to email msg in correct position? Chris Angelico <rosuav@gmail.com> - 2014-05-07 10:13 +1000
    Re: Add "Received:" header to email msg in correct position? alister <alister.nospam.ware@ntlworld.com> - 2014-05-06 09:15 +0000
      Re: Add "Received:" header to email msg in correct position? Chris Angelico <rosuav@gmail.com> - 2014-05-06 19:47 +1000
        Re: Add "Received:" header to email msg in correct position? alister <alister.nospam.ware@ntlworld.com> - 2014-05-06 10:26 +0000
          Re: Add "Received:" header to email msg in correct position? Chris Angelico <rosuav@gmail.com> - 2014-05-06 20:41 +1000
      Re: Add "Received:" header to email msg in correct position? Grant Edwards <invalid@invalid.invalid> - 2014-05-06 14:15 +0000
        Re: Add "Received:" header to email msg in correct position? Grant Edwards <invalid@invalid.invalid> - 2014-05-06 14:19 +0000
        Re: Add "Received:" header to email msg in correct position? Chris Angelico <rosuav@gmail.com> - 2014-05-07 00:26 +1000
        Re: Add "Received:" header to email msg in correct position? alister <alister.nospam.ware@ntlworld.com> - 2014-05-06 15:16 +0000
      Re: Add "Received:" header to email msg in correct position? Burak Arslan <burak.arslan@arskom.com.tr> - 2014-05-06 18:11 +0300
        Re: Add "Received:" header to email msg in correct position? Grant Edwards <invalid@invalid.invalid> - 2014-05-06 15:26 +0000
          Re: Add "Received:" header to email msg in correct position? Burak Arslan <burak.arslan@arskom.com.tr> - 2014-05-07 18:06 +0300
          Re: Add "Received:" header to email msg in correct position? Chris Angelico <rosuav@gmail.com> - 2014-05-08 01:11 +1000
          Re: Add "Received:" header to email msg in correct position? Ian Kelly <ian.g.kelly@gmail.com> - 2014-05-07 16:29 -0600
            Re: Add "Received:" header to email msg in correct position? Grant Edwards <invalid@invalid.invalid> - 2014-05-08 13:28 +0000
              Re: Add "Received:" header to email msg in correct position? Chris Angelico <rosuav@gmail.com> - 2014-05-08 23:47 +1000
              Re: Add "Received:" header to email msg in correct position? Ethan Furman <ethan@stoneleaf.us> - 2014-05-08 06:46 -0700
              Re: Add "Received:" header to email msg in correct position? Skip Montanaro <skip@pobox.com> - 2014-05-08 09:50 -0500
                Re: Add "Received:" header to email msg in correct position? Grant Edwards <invalid@invalid.invalid> - 2014-05-08 18:39 +0000
                  Re: Add "Received:" header to email msg in correct position? Tim Chase <python.list@tim.thechases.com> - 2014-05-08 13:48 -0500
                    Re: Add "Received:" header to email msg in correct position? Grant Edwards <invalid@invalid.invalid> - 2014-05-09 14:28 +0000
                  Re: Add "Received:" header to email msg in correct position? Ethan Furman <ethan@stoneleaf.us> - 2014-05-08 17:00 -0700
    Re: Add "Received:" header to email msg in correct position? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2014-05-07 08:58 +0200
      Re: Add "Received:" header to email msg in correct position? Grant Edwards <invalid@invalid.invalid> - 2014-05-07 14:32 +0000
        Re: Add "Received:" header to email msg in correct position? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2014-05-08 09:44 +0200
    Re: Add "Received:" header to email msg in correct position? Emre Hasegeli <emre@hasegeli.com> - 2014-05-07 11:11 +0300
    Re: Add "Received:" header to email msg in correct position? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2014-05-07 10:57 +0200
      Re: Add "Received:" header to email msg in correct position? Grant Edwards <invalid@invalid.invalid> - 2014-05-07 14:33 +0000

Page 2 of 2 — ← Prev page 1 [2]


#71029

FromChris Angelico <rosuav@gmail.com>
Date2014-05-08 01:11 +1000
Message-ID<mailman.9737.1399475504.18130.python-list@python.org>
In reply to#70971
On Thu, May 8, 2014 at 1:06 AM, Burak Arslan <burak.arslan@arskom.com.tr> wrote:
> Seeing how discussion is still going on about this, I'd like to state
> once more what I said above in other words: You just need to do this:
>
> "Received: blah\r\n" + message.to_string()
>
> or better:
>
> socket.write("Received: blah\r\n")
> socket.write(message.to_string())
>
> And again, this is not a hack, this is how it's supposed to work.

Yes, that method does work... if you're taking it in and sending it
right out again. But it means you have to hang onto two pieces of data
- the message and the new Received header - until you write it to a
file/socket.

(By the way, side point: I tend to avoid calling a socket "socket", as
that's the name of the module. I'd use "sock" in examples. Otherwise
someone's liable to go digging for a top-level method "write" in the
"socket" module, and get confused. And then think that sockets are
confusing, which they're not!)

ChrisA

[toc] | [prev] | [next] | [standalone]


#71059

FromIan Kelly <ian.g.kelly@gmail.com>
Date2014-05-07 16:29 -0600
Message-ID<mailman.9751.1399502104.18130.python-list@python.org>
In reply to#70971

[Multipart message — attachments visible in raw view] — view raw

On May 7, 2014 9:13 AM, "Chris Angelico" <rosuav@gmail.com> wrote:
>
> On Thu, May 8, 2014 at 1:06 AM, Burak Arslan <burak.arslan@arskom.com.tr>
wrote:
> > Seeing how discussion is still going on about this, I'd like to state
> > once more what I said above in other words: You just need to do this:
> >
> > "Received: blah\r\n" + message.to_string()
> >
> > or better:
> >
> > socket.write("Received: blah\r\n")
> > socket.write(message.to_string())
> >
> > And again, this is not a hack, this is how it's supposed to work.
>
> Yes, that method does work... if you're taking it in and sending it
> right out again. But it means you have to hang onto two pieces of data
> - the message and the new Received header - until you write it to a
> file/socket.

Alternatively, you could use a BytesIO to prepend the Received header to
the raw data *before* you parse it with the email module.

[toc] | [prev] | [next] | [standalone]


#71097

FromGrant Edwards <invalid@invalid.invalid>
Date2014-05-08 13:28 +0000
Message-ID<lkg0qg$m2c$1@reader1.panix.com>
In reply to#71059
On 2014-05-07, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> On May 7, 2014 9:13 AM, "Chris Angelico" <rosuav@gmail.com> wrote:
>>
>> On Thu, May 8, 2014 at 1:06 AM, Burak Arslan <burak.arslan@arskom.com.tr>
> wrote:
>> > Seeing how discussion is still going on about this, I'd like to state
>> > once more what I said above in other words: You just need to do this:
>> >
>> > "Received: blah\r\n" + message.to_string()
>> >
>> > or better:
>> >
>> > socket.write("Received: blah\r\n")
>> > socket.write(message.to_string())
>> >
>> > And again, this is not a hack, this is how it's supposed to work.
>>
>> Yes, that method does work... if you're taking it in and sending it
>> right out again. But it means you have to hang onto two pieces of data
>> - the message and the new Received header - until you write it to a
>> file/socket.
>
> Alternatively, you could use a BytesIO to prepend the Received header to
> the raw data *before* you parse it with the email module.

That's probably what I ought to do. But subclassing Message and adding
a prepend_header was just too easy, and it avoids having to have my
app know anything about the format of an email message in general or a
header in particular.  For example, I don't know what characters (if
any) need to be escaped or specially encoded in the contents of a
header.  I also don't remember off the top of my head what you're
supposed to do with headers that get too long (I think you just stick
in a \r\n followed by some whitespace and then continue the header,
but I'd have to look that up and then test it).

I did know how to insert a tuple of two strings at the beginning of a
list.  :)

-- 
Grant Edwards               grant.b.edwards        Yow! All this time I've
                                  at               been VIEWING a RUSSIAN
                              gmail.com            MIDGET SODOMIZE a HOUSECAT!

[toc] | [prev] | [next] | [standalone]


#71101

FromChris Angelico <rosuav@gmail.com>
Date2014-05-08 23:47 +1000
Message-ID<mailman.9779.1399556856.18130.python-list@python.org>
In reply to#71097
On Thu, May 8, 2014 at 11:28 PM, Grant Edwards <invalid@invalid.invalid> wrote:
> I also don't remember off the top of my head what you're
> supposed to do with headers that get too long (I think you just stick
> in a \r\n followed by some whitespace and then continue the header,
> but I'd have to look that up and then test it).

That would be correct, fwiw.

ChrisA

[toc] | [prev] | [next] | [standalone]


#71106

FromEthan Furman <ethan@stoneleaf.us>
Date2014-05-08 06:46 -0700
Message-ID<mailman.9782.1399559703.18130.python-list@python.org>
In reply to#71097
On 05/08/2014 06:28 AM, Grant Edwards wrote:
>
> Yow! All this time I've at been VIEWING a RUSSIAN MIDGET SODOMIZE a HOUSECAT!

Some filtering of your sigs would be appreciated.

--
~Ethan~

[toc] | [prev] | [next] | [standalone]


#71108

FromSkip Montanaro <skip@pobox.com>
Date2014-05-08 09:50 -0500
Message-ID<mailman.9784.1399560634.18130.python-list@python.org>
In reply to#71097
On Thu, May 8, 2014 at 8:46 AM, Ethan Furman <ethan@stoneleaf.us> wrote:
> Some filtering of your sigs would be appreciated.

Looks like a Zippy the Pinhead quote to me...

http://rosinstrument.com/cgi-bin/fortune.pl/21?97

Skip

[toc] | [prev] | [next] | [standalone]


#71117

FromGrant Edwards <invalid@invalid.invalid>
Date2014-05-08 18:39 +0000
Message-ID<lkgj0v$foa$1@reader1.panix.com>
In reply to#71108
On 2014-05-08, Skip Montanaro <skip@pobox.com> wrote:
> On Thu, May 8, 2014 at 8:46 AM, Ethan Furman <ethan@stoneleaf.us> wrote:
>> Some filtering of your sigs would be appreciated.
>
> Looks like a Zippy the Pinhead quote to me...
>
> http://rosinstrument.com/cgi-bin/fortune.pl/21?97

Yep.  I've removed a few of them from the file over the years because
some people were offended by them.  And I'll continue to do so...

-- 
Grant Edwards               grant.b.edwards        Yow! I don't understand
                                  at               the HUMOUR of the THREE
                              gmail.com            STOOGES!!

[toc] | [prev] | [next] | [standalone]


#71121

FromTim Chase <python.list@tim.thechases.com>
Date2014-05-08 13:48 -0500
Message-ID<mailman.9793.1399576740.18130.python-list@python.org>
In reply to#71117
On 2014-05-08 18:39, Grant Edwards wrote:
> > Looks like a Zippy the Pinhead quote to me...
> 
> Yep.  

I'm kinda disappointed having the curtain pulled back like that.  I'd
just assumed it was some nifty tool that turned a GPG/PGP signature
into MadLibs™-style fill-in-the-blank and then flowed into various
templates, allowing Grant to confirm/deny message authorship based on
the unspoofability of the signature with any other message-body.

Sounds like a fun weekend project ;-)

-tkc


[toc] | [prev] | [next] | [standalone]


#71174

FromGrant Edwards <invalid@invalid.invalid>
Date2014-05-09 14:28 +0000
Message-ID<lkiomj$tt$1@reader1.panix.com>
In reply to#71121
On 2014-05-08, Tim Chase <python.list@tim.thechases.com> wrote:
> On 2014-05-08 18:39, Grant Edwards wrote:
>> > Looks like a Zippy the Pinhead quote to me...
>> 
>> Yep.  
>
> I'm kinda disappointed having the curtain pulled back like that.  I'd
> just assumed it was some nifty tool that turned a GPG/PGP signature
> into MadLibs™-style fill-in-the-blank and then flowed into various
> templates, allowing Grant to confirm/deny message authorship based on
> the unspoofability of the signature with any other message-body.

That would be cool...

-- 
Grant Edwards               grant.b.edwards        Yow! Boy, am I glad it's
                                  at               only 1971...
                              gmail.com            

[toc] | [prev] | [next] | [standalone]


#71146

FromEthan Furman <ethan@stoneleaf.us>
Date2014-05-08 17:00 -0700
Message-ID<mailman.9808.1399600285.18130.python-list@python.org>
In reply to#71117
On 05/08/2014 11:39 AM, Grant Edwards wrote:
>
> Yep.  I've removed a few of them from the file over the years because
> some people were offended by them.  And I'll continue to do so...

Thanks, much appreciated.

--
~Ethan~

[toc] | [prev] | [next] | [standalone]


#71010

FromAntoon Pardon <antoon.pardon@rece.vub.ac.be>
Date2014-05-07 08:58 +0200
Message-ID<mailman.9727.1399445993.18130.python-list@python.org>
In reply to#70933
On 05-05-14 21:51, Grant Edwards wrote:
> I'm working on a Python app that receives an e-mail message via SMTP,
> does some trivial processing on it, and forwards it to another SMTP
> server.
>
> I'd like to do the polite thing and add a "Received:" header, but I
> can't figure out how to get Python's email module to add it in the
> correct place.  It always ends up at the "bottom" of the headers below
> From: To: etc.  It's supposed to go at the above all the Received:
> headers that where there when I received it.

I thought that was the job of the SMTP servers, not of email
applications. So I'm not sure
that what you want to do is the polite thing to do.

-- 
Antoon Pardon

[toc] | [prev] | [next] | [standalone]


#71025

FromGrant Edwards <invalid@invalid.invalid>
Date2014-05-07 14:32 +0000
Message-ID<lkdg6b$ldb$1@reader1.panix.com>
In reply to#71010
On 2014-05-07, Antoon Pardon <antoon.pardon@rece.vub.ac.be> wrote:
> On 05-05-14 21:51, Grant Edwards wrote:
>> I'm working on a Python app that receives an e-mail message via SMTP,
>> does some trivial processing on it, and forwards it to another SMTP
>> server.
>>
>> I'd like to do the polite thing and add a "Received:" header, but I
>> can't figure out how to get Python's email module to add it in the
>> correct place.  It always ends up at the "bottom" of the headers below
>> From: To: etc.  It's supposed to go at the above all the Received:
>> headers that where there when I received it.
>
> I thought that was the job of the SMTP servers, not of email
> applications.

Exactly.  And the SMTP server I'm writing uses the email module to
manipulate headers as messages are processed.

> So I'm not sure that what you want to do is the polite thing to do.

Why not?

-- 
Grant Edwards               grant.b.edwards        Yow! Th' MIND is the Pizza
                                  at               Palace of th' SOUL
                              gmail.com            

[toc] | [prev] | [next] | [standalone]


#71083

FromAntoon Pardon <antoon.pardon@rece.vub.ac.be>
Date2014-05-08 09:44 +0200
Message-ID<mailman.9763.1399535093.18130.python-list@python.org>
In reply to#71025
On 07-05-14 16:32, Grant Edwards wrote:

>> So I'm not sure that what you want to do is the polite thing to do.
> Why not?

Nevermind, I originally hadn't thought things completly through.

-- 
Antoon Pardon

[toc] | [prev] | [next] | [standalone]


#71011

FromEmre Hasegeli <emre@hasegeli.com>
Date2014-05-07 11:11 +0300
Message-ID<mailman.9728.1399451691.18130.python-list@python.org>
In reply to#70933

[Multipart message — attachments visible in raw view] — view raw

Antoon Pardon <antoon.pardon@rece.vub.ac.be>:

> I'm working on a Python app that receives an e-mail message via SMTP,
> > does some trivial processing on it, and forwards it to another SMTP
> > server.
> >
> > I'd like to do the polite thing and add a "Received:" header, but I
> > can't figure out how to get Python's email module to add it in the
> > correct place.  It always ends up at the "bottom" of the headers below
> > From: To: etc.  It's supposed to go at the above all the Received:
> > headers that where there when I received it.
>
> I thought that was the job of the SMTP servers, not of email
> applications. So I'm not sure
> that what you want to do is the polite thing to do.
>

This application seems like an SMTP server.

[toc] | [prev] | [next] | [standalone]


#71013

FromAntoon Pardon <antoon.pardon@rece.vub.ac.be>
Date2014-05-07 10:57 +0200
Message-ID<mailman.9730.1399453083.18130.python-list@python.org>
In reply to#70933

[Multipart message — attachments visible in raw view] — view raw

On 07-05-14 10:11, Emre Hasegeli wrote:
> Antoon Pardon <antoon.pardon@rece.vub.ac.be
> <mailto:antoon.pardon@rece.vub.ac.be>>:
>
>     > I'm working on a Python app that receives an e-mail message via
>     SMTP,
>     > does some trivial processing on it, and forwards it to another SMTP
>     > server.
>     >
>     > I'd like to do the polite thing and add a "Received:" header, but I
>     > can't figure out how to get Python's email module to add it in the
>     > correct place.  It always ends up at the "bottom" of the headers
>     below
>     > From: To: etc.  It's supposed to go at the above all the Received:
>     > headers that where there when I received it.
>
>     I thought that was the job of the SMTP servers, not of email
>     applications. So I'm not sure
>     that what you want to do is the polite thing to do.
>
>
> This application seems like an SMTP server.
>
It doesn't to me. As far as I can see what he wants to do can be done
by a mail program like procmail in combination with some mail
filtering/processing.

-- 
Antoon Pardon

[toc] | [prev] | [next] | [standalone]


#71026

FromGrant Edwards <invalid@invalid.invalid>
Date2014-05-07 14:33 +0000
Message-ID<lkdg7n$ldb$2@reader1.panix.com>
In reply to#71013
On 2014-05-07, Antoon Pardon <antoon.pardon@rece.vub.ac.be> wrote:
> On 07-05-14 10:11, Emre Hasegeli wrote:
>> Antoon Pardon <antoon.pardon@rece.vub.ac.be
>> <mailto:antoon.pardon@rece.vub.ac.be>>:
>>
>>     > I'm working on a Python app that receives an e-mail message via
>>     SMTP,
>>     > does some trivial processing on it, and forwards it to another SMTP
>>     > server.
>>     >
>>     > I'd like to do the polite thing and add a "Received:" header, but I
>>     > can't figure out how to get Python's email module to add it in the
>>     > correct place.  It always ends up at the "bottom" of the headers
>>     below
>>     > From: To: etc.  It's supposed to go at the above all the Received:
>>     > headers that where there when I received it.
>>
>>     I thought that was the job of the SMTP servers, not of email
>>     applications. So I'm not sure
>>     that what you want to do is the polite thing to do.
>>
>>
>> This application seems like an SMTP server.
>
> It doesn't to me. As far as I can see what he wants to do can be done
> by a mail program like procmail in combination with some mail
> filtering/processing.

Does procmail implement the server-side of SMTP?

-- 
Grant Edwards               grant.b.edwards        Yow! I brought my BOWLING
                                  at               BALL -- and some DRUGS!!
                              gmail.com            

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.python


csiph-web