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


Groups > comp.lang.python > #70936

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

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'exercise': 0.04; 'source,': 0.04; 'insert': 0.05; 'none:': 0.07; 'subject:position': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; "wouldn't": 0.14; '**_params):': 0.16; '-tkc': 0.16; 'filename:fname piece:signature': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'matters,': 0.16; 'subclass': 0.16; 'subject:Add': 0.16; 'version?': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'module': 0.19; "python's": 0.19; 'skip:p 40': 0.19; 'code,': 0.22; 'cc:addr:python.org': 0.22; 'headers': 0.24; 'skip:e 30': 0.24; 'sorry,': 0.24; 'specify': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'source': 0.25; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'correct': 0.29; 'leave': 0.29; "doesn't": 0.30; 'lines': 0.31; 'header,': 0.31; 'index,': 0.31; 'class': 0.32; 'figure': 0.32; 'skip:m 30': 0.32; 'supposed': 0.32; 'skip:_ 10': 0.34; "i'd": 0.34; "can't": 0.35; 'something': 0.35; 'but': 0.35; 'add': 0.35; 'there': 0.35; 'charset:us-ascii': 0.36; "i'll": 0.36; 'subject:?': 0.36; 'should': 0.36; 'too': 0.37; 'list': 0.37; '(i.e.,': 0.38; 'ends': 0.38; 'pm,': 0.38; 'skip:p 20': 0.39; 'how': 0.40; 'easy': 0.60; 'mentioned': 0.61; 'received:': 0.65; 'ethan': 0.84; 'furman': 0.84; 'received:50.22': 0.84; 'edwards': 0.91
Date Mon, 5 May 2014 16:09:30 -0500
From Tim Chase <python.list@tim.thechases.com>
To Grant Edwards <invalid@invalid.invalid>
Subject Re: Add "Received:" header to email msg in correct position?
In-Reply-To <lk8u1h$sid$1@reader1.panix.com>
References <lk8q3j$3mg$2@reader1.panix.com> <mailman.9687.1399323113.18130.python-list@python.org> <lk8u1h$sid$1@reader1.panix.com>
X-Mailer Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu)
Mime-Version 1.0
Content-Type multipart/signed; micalg=PGP-SHA512; boundary="Sig_/Fw=sNtfUJ7agePW139/w/QD"; protocol="application/pgp-signature"
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - boston.accountservergroup.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - tim.thechases.com
X-Get-Message-Sender-Via boston.accountservergroup.com: authenticated_id: tim@thechases.com
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.9688.1399324196.18130.python-list@python.org> (permalink)
Lines 65
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1399324196 news.xs4all.nl 2930 [2001:888:2000:d::a6]:49434
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:70936

Show key headers only | View raw


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

On 2014-05-05 20:58, Grant Edwards wrote:
> On 2014-05-05, Ethan Furman <ethan@stoneleaf.us> wrote:
> > On 05/05/2014 12:51 PM, Grant Edwards wrote:
> >> 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 don't know that it matters, but which Python version?
> 
> Sorry, should have mentioned it: 2.7.5

Looking at the stdlib source, it doesn't look like there's an easy
way to specify where it gets inserted.  However, the source to
email.message.Message.add_header() is all of 9 lines of code, so it
wouldn't be too hard to subclass Message and twiddle self._headers as
you would any other list (i.e., using .insert() to specify an index).

It might look something like

  class MyMessage(email.message.Message):
    def insert_header(self, index, _name, _value, **_params):
      parts = []
      for k, v in _params.items():
        if v is None:
          parts.append(k.replace('_', '-'))
        else:
          parts.append(_formatparam(k.replace('_', '-'), v))
      if _value is not None:
        parts.insert(0, _value)
      self._headers.insert(index, (_name, SEMISPACE.join(parts)))

You might still need to search for *where* you want to insert it, but
I'll leave that as an exercise to the reader. :-)

-tkc





Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web